Intersect method

Enumerable<T> Intersect (Iterable<T> other, { EqualityComparer<T> comparer })

Returns the set intersection between the enumerable and the given collection.

After applying the Intersect method to an enumerable, the resulting enumerable will consist of all the elements in the source enumerable that are also present in the given other collection. This is equivalent to taking the set intersection of the two sequences.

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

(For the Intersect method, only the comparer and hasher properties of the EqualityComparer need be supplied.)

If all of the elements in the source enumerable match an element in the given other collection, the enumerable will be unchanged.

Implementation

Enumerable<T> Intersect(Iterable<T> other, {EqualityComparer<T> comparer}) {
  return IntersectEnumerable<T>(this, other, comparer);
}