You should use:
Ordered
and Ordering
are now defined so that the constraints K => Ordered[K]
and K: Ordering
are actually equivalent. Indeed, Ordering.ordered
transforms one into another in one direction, Ordered.orderingToOrdered
transforms in the other
def test[K](implicit ev: K => Ordered[K]) =
implicitly[Ordering[K]] // compiles
def test[K: Ordering] =
implicitly[K => Ordered[K]] // compiles
The context bound MyCollection[K: Ordering]
is a syntax sugar for MyCollection[K](implicit ev: Ordering[K])
.
That's why [K: Ordered[K]]
can't compile at all because of kind mismatch.
Ordering
is a type class but Ordered
is not. Ordered
is an ordinary OOP trait (you're extending it in OOP style rather than define its implicit instances in FP style).
That's why although [K: Ordered]
compiles but it would be incorrect semantically (implicits will not be found).
Ordering and Ordered and comparing Options
Scala Ordering, Ordered, and View Bound
Get Ordering from Ordered in Scala