I need a method to return the first of two ordered values. I've tried:
def first[T <: Ordered[T]](a: T, b: T) = {
a compare b match {
case -1 | 0 => a
case 1 => b
}
}
but get
scala> first(3,4)
<console>:9: error: inferred type arguments [Int] do not conform to method first's
type parameter bounds [T <: Ordered[T]]
first(3,4)
^
I guess this is because Int
needs to be converted to a RichInt
, which is an Ordered[Int]
rather than an Ordered[RichInt]
. What next?