diff options
Diffstat (limited to 'src/library/scala/Ordering.scala')
-rw-r--r-- | src/library/scala/Ordering.scala | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/library/scala/Ordering.scala b/src/library/scala/Ordering.scala index fed776147f..8b4db3f549 100644 --- a/src/library/scala/Ordering.scala +++ b/src/library/scala/Ordering.scala @@ -104,7 +104,18 @@ trait Ordering[T] extends Comparator[T] with PartialOrdering[T] { implicit def mkOrderingOps(lhs: T): Ops = new Ops(lhs) } -object Ordering { +/** This would conflict with all the nice implicit Orderings + * available, but thanks to the magic of prioritized implicits + * via subclassing we can make Ordered[A] => Ordering[A] only + * turn up if nothing else works. + */ +trait LowPriorityOrderingImplicits { + implicit def ordered[A <: Ordered[A]]: Ordering[A] = new Ordering[A] { + def compare(x: A, y: A) = x.compare(y) + } +} + +object Ordering extends LowPriorityOrderingImplicits { def apply[T](implicit ord : Ordering[T]) = ord @@ -112,10 +123,6 @@ object Ordering { def compare(x: T, y: T) = if (cmp(x, y)) -1 else if (cmp(y, x)) 1 else 0 } - def ordered[A <: Ordered[A]]: Ordering[A] = new Ordering[A] { - def compare(x: A, y: A) = x.compare(y) - } - trait UnitOrdering extends Ordering[Unit] { def compare(x: Unit, y: Unit) = 0 } |