src/main/scala/grade_school.scala

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import scala.collection.mutable
import scala.collection.immutable.SortedMap


class School {
  private val _db = mutable.Map[Int, List[String]]()
  def db = _db.toMap

  def add(name:String, gradeNumber:Int) =
    _db(gradeNumber) = grade(gradeNumber) :+ name

  def sorted = SortedMap(_db.toSeq:_*).mapValues(_ sorted)

  def grade(gradeNumber:Int) = _db.getOrElse(gradeNumber, List())
}

@abo64 thinks this looks great

Comments


You're not logged in right now. Please login via GitHub to comment