diff options
-rw-r--r-- | src/library/scala/math/Ordering.scala | 15 | ||||
-rw-r--r-- | test/files/pos/seq-ordering.scala | 7 |
2 files changed, 22 insertions, 0 deletions
diff --git a/src/library/scala/math/Ordering.scala b/src/library/scala/math/Ordering.scala index 392cbf5e81..c64b3290f0 100644 --- a/src/library/scala/math/Ordering.scala +++ b/src/library/scala/math/Ordering.scala @@ -234,6 +234,21 @@ object Ordering extends LowPriorityOrderingImplicits { } } + implicit def SeqDerived[CC[X] <: collection.Seq[X], T](implicit ord: Ordering[T]): Ordering[CC[T]] = + new Ordering[CC[T]] { + def compare(x: CC[T], y: CC[T]): Int = { + val xe = x.iterator + val ye = y.iterator + + while (xe.hasNext && ye.hasNext) { + val res = ord.compare(xe.next, ye.next) + if (res != 0) return res + } + + Boolean.compare(xe.hasNext, ye.hasNext) + } + } + implicit def Tuple2[T1, T2](implicit ord1: Ordering[T1], ord2: Ordering[T2]): Ordering[(T1, T2)] = new Ordering[(T1, T2)]{ def compare(x: (T1, T2), y: (T1, T2)): Int = { diff --git a/test/files/pos/seq-ordering.scala b/test/files/pos/seq-ordering.scala new file mode 100644 index 0000000000..bcf1a79004 --- /dev/null +++ b/test/files/pos/seq-ordering.scala @@ -0,0 +1,7 @@ +class A { + import Predef.{ implicitly => ? } + + ?[Ordering[List[Int]]] + ?[Ordering[IndexedSeq[(Int, String)]]] + ?[Ordering[Seq[Seq[Int]]]] +} |