I am switching from scala 2.7 and ordering on scala 2.8 and using order. It looks straightforward, but I was wondering if I can make it a little less verbose. For example:
scala> case class A(i: Int) defined class A scala> object A extends Ordering[A] { def compare(o1: A, o2: A) = o1.i - o2.i} defined module A
If I try to create a TreeMap, I get an error
scala> new collection.immutable.TreeMap[A, String]() <console>:10: error: could not find implicit value for parameter ordering: Ordering[A] new collection.immutable.TreeMap[A, String]() ^
However, if I explicitly specify object A as an order, it works fine.
scala> new collection.immutable.TreeMap[A, String]()(A) res34: scala.collection.immutable.TreeMap[A,String] = Map()
Should I always explicitly state the order or is there a shorter format?
thanks
Dave
source share