Union method
Returns the set union between the enumerable and the given collection.
After applying the Union method to an enumerable, the resulting
enumerable will consist of all the distinct elements in the source
enumerable as well as the distinct elements in the given other
collection. This is equivalent to taking the set union of the two
sequences.
Optionally, an EqualityComparer can be supplied to handle comparisons. If
one is provided, the Union method will use the comparer
and hasher
properties in
order to determine equivalency. If omitted, Union will resort to strict
equivalency (i.e. checking if (value == element)
).
(For the Union method, only the comparer
and hasher
properties of the
EqualityComparer need be supplied.)
Due to the nature of set unions, the resulting enumerable will be as though Distinct was applied to it, so duplicate elements after the first found will be discarded. If the intention is to combine elements of two enumerables/collections, use Concat instead.
Implementation
Enumerable<T> Union(Iterable<T> other, {EqualityComparer<T> comparer}) {
return UnionEnumerable<T>(this, other, comparer);
}