sequenceEqualE method
Returns true
if this enumerable is equivalent to the given collection.
Iterates over both this enumerable and the given other
collection. The
comparer
property of the EqualityComparer is applied to elements in
the same position of both collections. If the comparison returns false for
any element pair, sequenceEqualE will return false
.
Furthermore, if either collections iteration ends before the other's does,
the lengths of the collections is deemed unequal, and sequenceEqualE will
return false
.
If the enumerable and the other
collection are the same length and each
element in the corresponsing positions of both are deemed equal by the
EqualityComparer, sequenceEqualE will return true
.
If the EqualityComparer is omitted, comparison will default to strict
equivalency checking (i.e. if (a == b)
).
Implementation
bool sequenceEqualE(Iterable<T> other, {EqualityComparer<T> comparer}) {
ArgumentError.checkNotNull(other);
final _thisIterator = this.iterator;
final _otherIterator = other.iterator;
if (comparer == null) comparer = EqualityComparer.forType<T>();
while (_thisIterator.moveNext()) {
if (_otherIterator.moveNext()) {
if (!comparer.compare(_thisIterator.current, _otherIterator.current)) {
return false;
}
} else {
return false;
}
}
if (_otherIterator.moveNext()) return false;
return true;
}