summaryrefslogtreecommitdiff
path: root/src/library/scala/collection/Iterator.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-11-25 19:38:53 +0000
committerPaul Phillips <paulp@improving.org>2009-11-25 19:38:53 +0000
commitdc683cb316800ad82547e0c1ba325cd7f9cb848d (patch)
tree6d66aae46ab51fe93f4ec08d4b3f071f212f0ea5 /src/library/scala/collection/Iterator.scala
parent0a1d1a616719022ddaf199db7515207dfc824d3c (diff)
downloadscala-dc683cb316800ad82547e0c1ba325cd7f9cb848d.tar.gz
scala-dc683cb316800ad82547e0c1ba325cd7f9cb848d.tar.bz2
scala-dc683cb316800ad82547e0c1ba325cd7f9cb848d.zip
Cleaning up in scala.runtime.*.
Fixed toArray to copy more than one element into the new one. Added sameElements to Iterator to further simplify the case class support logic, and because it should be there anyway.
Diffstat (limited to 'src/library/scala/collection/Iterator.scala')
-rw-r--r--src/library/scala/collection/Iterator.scala15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/library/scala/collection/Iterator.scala b/src/library/scala/collection/Iterator.scala
index 70462cb8d2..74109a0e81 100644
--- a/src/library/scala/collection/Iterator.scala
+++ b/src/library/scala/collection/Iterator.scala
@@ -14,7 +14,6 @@ package scala.collection
import mutable.{Buffer, ArrayBuffer, ListBuffer, StringBuilder}
import immutable.{List, Stream}
import annotation.{ tailrec }
-// import immutable.{List, Nil, ::, Stream}
/** The <code>Iterator</code> object provides various functions for
* creating specialized iterators.
@@ -1031,6 +1030,20 @@ trait Iterator[+A] { self =>
buffer
}
+ /** Checks if the other iterator contains the same elements as this one.
+ *
+ * @note will not terminate for infinite-sized iterators.
+ * @param that the other iterator
+ * @return true, iff both iterators contain the same elements in the same order.
+ */
+ def sameElements(that: Iterator[_]): Boolean = {
+ while (hasNext && that.hasNext)
+ if (next != that.next)
+ return false
+
+ !hasNext && !that.hasNext
+ }
+
/** Returns a string representation of the elements in this iterator. The resulting string
* begins with the string <code>start</code> and is finished by the string
* <code>end</code>. Inside, the string representations of elements (w.r.t.