File tree 2 files changed +11
-10
lines changed
src/main/scala/strawman/collection
2 files changed +11
-10
lines changed Original file line number Diff line number Diff line change @@ -97,6 +97,15 @@ trait Iterator[+A] extends IterableOnce[A] { self =>
97
97
def hasNext = self.hasNext && thatIterator.hasNext
98
98
def next () = (self.next(), thatIterator.next())
99
99
}
100
+ def sameElements [B >: A ](that : IterableOnce [B ]): Boolean = {
101
+ val those = that.iterator()
102
+ while (hasNext && those.hasNext)
103
+ if (next() != those.next())
104
+ return false
105
+ // At that point we know that *at least one* iterator has no next element
106
+ // If *both* of them have no elements then the collections are the same
107
+ hasNext == those.hasNext
108
+ }
100
109
}
101
110
102
111
object Iterator {
Original file line number Diff line number Diff line change @@ -59,16 +59,8 @@ trait SeqLike[+A, +C[X] <: Seq[X]]
59
59
/** Do the elements of this collection are the same (and in the same order)
60
60
* as those of `that`?
61
61
*/
62
- def sameElements [B >: A ](that : IterableOnce [B ]): Boolean = {
63
- val these = coll.iterator()
64
- val those = that.iterator()
65
- while (these.hasNext && those.hasNext)
66
- if (these.next() != those.next())
67
- return false
68
- // At that point we know that *at least one* iterator has no next element
69
- // If *both* of them have no elements then the collections are the same
70
- these.hasNext == those.hasNext
71
- }
62
+ def sameElements [B >: A ](that : IterableOnce [B ]): Boolean =
63
+ coll.iterator().sameElements(that)
72
64
73
65
/** Method called from equality methods, so that user-defined subclasses can
74
66
* refuse to be equal to other collections of the same kind.
You can’t perform that action at this time.
0 commit comments