containsE method

bool containsE (T value, { EqualityComparer<T> comparer })

Returns true if the specified element exists in the enumerable and false otherwise.

Iterates over the entire enumerable and compares each element to the specified value. If the two are deemed to be equivalent, containsE returns true. If the iteration reaches the end of the enumerable without finding a match, containsE returns false.

Optionally, an EqualityComparer can be supplied to handle comparisons. If one is provided, the containsE method will use the comparer property in order to determine equivalency. If omitted, containsE will resort to strict equivalency (i.e. checking if (value == element)).

(For the containsE method, only the comparer property of the EqualityComparer need be supplied.)

The containsE method will short-circuit after receiving a true from any comparison and will not iterate further over the enumerable. In the worst case, it will iterate over the entire enumerable.

Implementation

bool containsE(T value, {EqualityComparer<T> comparer}) {
  if (comparer == null) comparer = EqualityComparer.forType<T>();

  final iterator = this.iterator;
  while (iterator.moveNext()) {
    if (comparer.compare(value, iterator.current)) return true;
  }
  return false;
}