Permalink
Browse files

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.
  • Loading branch information...
paulp committed May 5, 2012
1 parent b5e9e4b commit e5f2ddb6c2bc80f26cc004a11a4ab5036b239457
Showing with 18 additions and 0 deletions.
  1. +18 −0 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

0 comments on commit e5f2ddb

Please sign in to comment.