summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-03-08 16:32:16 +0000
committerPaul Phillips <paulp@improving.org>2011-03-08 16:32:16 +0000
commit4e787be632907667ab89f6ea4eea33901450e848 (patch)
treeeb8975c292aca568abf7e3aa91a5fe00e643de9d
parent0475b23ebd144e0c31da056196e2de287de1a233 (diff)
downloadscala-4e787be632907667ab89f6ea4eea33901450e848.tar.gz
scala-4e787be632907667ab89f6ea4eea33901450e848.tar.bz2
scala-4e787be632907667ab89f6ea4eea33901450e848.zip
Moved SeqDerived into an Ordering.Implicits obj...
Moved SeqDerived into an Ordering.Implicits object. Closes #3152 (only mopping up), no review.
-rw-r--r--src/library/scala/math/Ordering.scala42
1 files changed, 27 insertions, 15 deletions
diff --git a/src/library/scala/math/Ordering.scala b/src/library/scala/math/Ordering.scala
index 25c146e183..b921183f52 100644
--- a/src/library/scala/math/Ordering.scala
+++ b/src/library/scala/math/Ordering.scala
@@ -107,6 +107,26 @@ trait Ordering[T] extends Comparator[T] with PartialOrdering[T] with Serializabl
implicit def mkOrderingOps(lhs: T): Ops = new Ops(lhs)
}
+trait ExtraOrderingImplicits {
+ /** Not in the standard scope due to the potential for divergence:
+ * For instance implicitly[Ordering[Any]] diverges in its presence.
+ */
+ 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
+ }
+
+ Ordering.Boolean.compare(xe.hasNext, ye.hasNext)
+ }
+ }
+}
+
trait LowPriorityOrderingImplicits {
/** This would conflict with all the nice implicit Orderings
* available, but thanks to the magic of prioritized implicits
@@ -125,6 +145,13 @@ trait LowPriorityOrderingImplicits {
object Ordering extends LowPriorityOrderingImplicits {
def apply[T](implicit ord: Ordering[T]) = ord
+ /** An object for implicits which for one reason or another we
+ * aren't ready to put in the default scope.
+ */
+ object Implicits extends ExtraOrderingImplicits {
+
+ }
+
def fromLessThan[T](cmp: (T, T) => Boolean): Ordering[T] = new Ordering[T] {
def compare(x: T, y: T) = if (cmp(x, y)) -1 else if (cmp(y, x)) 1 else 0
// overrides to avoid multiple comparisons
@@ -234,21 +261,6 @@ 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 = {