summaryrefslogtreecommitdiff
path: root/src/library/scala/collection/Iterator.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2012-05-04 17:28:57 -0700
committerPaul Phillips <paulp@improving.org>2012-05-04 18:30:53 -0700
commite5f2ddb6c2bc80f26cc004a11a4ab5036b239457 (patch)
tree7a07738209bcbf825912212c51b239457cc13e54 /src/library/scala/collection/Iterator.scala
parentb5e9e4b9502f02c3de31d32b71f82ea1e6723f01 (diff)
downloadscala-e5f2ddb6c2bc80f26cc004a11a4ab5036b239457.tar.gz
scala-e5f2ddb6c2bc80f26cc004a11a4ab5036b239457.tar.bz2
scala-e5f2ddb6c2bc80f26cc004a11a4ab5036b239457.zip
Put corresponds on Iterator.
I guess we can look forward to more and more duplication in the collections. I had to cut and paste the doc comment too, or at least I have no idea how to avoid that given the file I took it from was in parallel somewhere.
Diffstat (limited to 'src/library/scala/collection/Iterator.scala')
-rw-r--r--src/library/scala/collection/Iterator.scala18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/library/scala/collection/Iterator.scala b/src/library/scala/collection/Iterator.scala
index 3b2a7c7820..e9a7906527 100644
--- a/src/library/scala/collection/Iterator.scala
+++ b/src/library/scala/collection/Iterator.scala
@@ -391,6 +391,24 @@ trait Iterator[+A] extends TraversableOnce[A] {
def next() = if (hasNext) { hdDefined = false; hd } else empty.next()
}
+
+ /** Tests whether every element of this iterator relates to the
+ * corresponding element of another collection by satisfying a test predicate.
+ *
+ * @param that the other collection
+ * @param p the test predicate, which relates elements from both collections
+ * @tparam B the type of the elements of `that`
+ * @return `true` if both collections have the same length and
+ * `p(x, y)` is `true` for all corresponding elements `x` of this iterator
+ * and `y` of `that`, otherwise `false`
+ */
+ def corresponds[B](that: GenTraversableOnce[B])(p: (A, B) => Boolean): Boolean = {
+ val that0 = that.toIterator
+ while (hasNext && that0.hasNext)
+ if (!p(next, that0.next)) return false
+
+ hasNext == that0.hasNext
+ }
/** Creates an iterator over all the elements of this iterator that
* satisfy the predicate `p`. The order of the elements