Scala Orderingtrait has a method reversethat seems to be the “official” way to get TreeMap, which is sorted in the “wrong” way.
An excerpt of this trait is as follows:
trait Ordering[T] extends Comparator[T] with PartialOrdering[T] with Serializable {
outer =>
override def reverse: Ordering[T] = new Ordering[T]{
override def reverse = outer
def compare(x: T, y: T) = outer.compare(y, x)
}
}
I thought this would work like Java Collections.reverseOrder, but it Ordering.reversedoesn't work, of course.
How to use reverse order with TreeMap, e. g :.
new TreeMap[Foo, Bar](/*???*/)
source
share