GroupByValue<TKey, TValue> method
Groups the elements in the enumerable by a key and maps the elements to a new value.
After applying the GroupByValue method to an enumerable, the resulting
enumerable will be a series of groups of elements. Each group will consist
of all elements in the source enumerable that share a common key as defined
by passing the element to the keySelector
function with those elements
passed to the valueSelector
to retrieve the value stored under the key.
Optionally, an EqualityComparer can be supplied to handle key comparisons.
If one is provided, the GroupByValue method will use the comparer
and
hasher
properties in order to determine equivalency. If omitted,
GroupByValue will resort to strict equivalency (i.e. checking if (value == element)
).
(For the GroupByValue method, only the comparer
and hasher
properties of
the EqualityComparer need be supplied.)
The resulting enumerable will consist of a series of IGrouping
constructs
that contain the elements. If no two elements in the enumerable share a
common key, the resulting enumerable will consist of IGrouping
objects
(each containing a single element) of the same length as the source
enumerable.
Implementation
Enumerable<IGrouping<TKey, TValue>> GroupByValue<TKey, TValue>(
Selector<T, TKey> keySelector, Selector<T, TValue> valueSelector,
{EqualityComparer<TKey> keyComparer}) {
assert(keySelector != null && valueSelector != null);
return GroupByValueEnumerable<T, TKey, TValue>(
this, keySelector, valueSelector, keyComparer);
}