diff options
author | mihaylov <mihaylov@epfl.ch> | 2006-03-09 16:35:00 +0000 |
---|---|---|
committer | mihaylov <mihaylov@epfl.ch> | 2006-03-09 16:35:00 +0000 |
commit | 285389fb4dbb9425fa28194780fb9ca5c3c30654 (patch) | |
tree | b5ff913ecbd56b93011d23904a77eafcfd74d9f9 | |
parent | b283f88a6f96dfd870ec488a95041aa0e9cad8cf (diff) | |
download | scala-285389fb4dbb9425fa28194780fb9ca5c3c30654.tar.gz scala-285389fb4dbb9425fa28194780fb9ca5c3c30654.tar.bz2 scala-285389fb4dbb9425fa28194780fb9ca5c3c30654.zip |
made the view method implicit
-rw-r--r-- | src/library/scala/Iterable.scala | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/src/library/scala/Iterable.scala b/src/library/scala/Iterable.scala index 501e158154..4700649a63 100644 --- a/src/library/scala/Iterable.scala +++ b/src/library/scala/Iterable.scala @@ -14,22 +14,23 @@ package scala; import Predef.error; object Iterable { - def view[A <% Ordered[A]](x: Iterable[A]): Ordered[Iterable[A]] = new Ordered[Iterable[A]] { - def compareTo[B >: Iterable[A] <% Ordered[B]](that: B): Int = that match { - case y: Iterable[A] => - val xs = x.elements; - val ys = y.elements; - var res = 0; - while (xs.hasNext && ys.hasNext && (res == 0)) { - res = xs.next compareTo ys.next; - } - if (xs.hasNext) 1 - else if (ys.hasNext) -1 - else res; - case _ => - -(that compareTo x) + implicit def view[A <% Ordered[A]](x: Iterable[A]): Ordered[Iterable[A]] = + new Ordered[Iterable[A]] { + def compareTo[B >: Iterable[A] <% Ordered[B]](that: B): Int = that match { + case y: Iterable[A] => + val xs = x.elements; + val ys = y.elements; + var res = 0; + while (xs.hasNext && ys.hasNext && (res == 0)) { + res = xs.next compareTo ys.next; + } + if (xs.hasNext) 1 + else if (ys.hasNext) -1 + else res; + case _ => + -(that compareTo x) + } } - } /** The minimum element of a non-empty sequence of ordered elements */ def min[A <% Ordered[A]](seq: Iterable[A]): A = { |