equals method Null safety

  1. @override
bool equals(
  1. Iterable<E>? elements1,
  2. Iterable<E>? elements2
)
override

Compare two elements for being equal.

This should be a proper equality relation.

Implementation

@override
bool equals(Iterable<E>? elements1, Iterable<E>? elements2) {
  if (identical(elements1, elements2)) return true;
  if (elements1 == null || elements2 == null) return false;
  var it1 = elements1.iterator;
  var it2 = elements2.iterator;
  while (true) {
    var hasNext = it1.moveNext();
    if (hasNext != it2.moveNext()) return false;
    if (!hasNext) return true;
    if (!_elementEquality.equals(it1.current, it2.current)) return false;
  }
}