The scala docs say that Enumeration.Val is ordered, however I get inconsistent behavior when when I try to enforce type restrictions on enumeration values requiring them to support ordering:
object Dogs extends Enumeration {
val Sam, Tom, Rover = Value
}
def doSomething[A <% Ordered[A]](a : List[A]) : Unit = {
println(a.sortWith(_ < _))
}
import Dogs._
val xs = List(Rover, Tom, Sam, Sam, Rover)
println(xs.sortWith(_ < _)) // works!
doSomething(xs) // fails =(
Of the last two statements, the first works and shows that Enumeration values have an ordering defined. The second gives an error:
could not find implicit value for evidence parameter of type (this.Dogs.Value) => Ordered[this.Dogs.Value]
How do I get around this and use enumeration values in generic methods which require ordering?