I am trying to use Ordering[T]
with multiple types.
case class Person(name: String, age: Int)
Person("Alice", 20)
Person("Bob", 40)
Person("Charlie", 30)
object PersonOrdering extends Ordering[Person] {
def compare(a:Person, b:Person) =
a.age compare b.age
}
How do I sort by both name and age?
The collection needs to remain sorted with updates.