equals method
Whether other has the same elements as this iterable. Length and order
dependent.
1,2,3,4 will match 1,2,3,4
but 4,1,2,1 will not match 1,1,2,4.
1,2,3,4 will not match 1,2,3
1,2,3, will not match 1,2,3,4.
Implementation
bool equals(Iterable<E>? other,
[bool Function(E, E) equals = _defaultEquals]) {
if (other == null) {
return false;
}
final iter1 = iterator;
final iter2 = other.iterator;
while (true) {
final iter1HasValue = iter1.moveNext();
final iter2HasValue = iter2.moveNext();
if (iter1HasValue != iter2HasValue) {
return false;
}
if (iter1HasValue && iter2HasValue) {
final iter1Value = iter1.current;
final iter2Value = iter2.current;
if (!equals(iter1Value, iter2Value)) {
return false;
}
continue;
}
// both are false
break;
}
return true;
}