Groups the adjacent elements of a sequence according to a
specified key selector function. The keys are compared by using
a comparer and each group's elements are projected by using a
specified function.
Declaration Syntax
C# | Visual Basic | Visual C++ |
public static IEnumerable<IGrouping<TKey, TElement>> GroupAdjacent<TSource, TKey, TElement>( this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer )
<ExtensionAttribute> _ Public Shared Function GroupAdjacent(Of TSource, TKey, TElement) ( _ source As IEnumerable(Of TSource), _ keySelector As Func(Of TSource, TKey), _ elementSelector As Func(Of TSource, TElement), _ comparer As IEqualityComparer(Of TKey) _ ) As IEnumerable(Of IGrouping(Of TKey, TElement))
public: [ExtensionAttribute] generic<typename TSource, typename TKey, typename TElement> static IEnumerable<IGrouping<TKey, TElement>^>^ GroupAdjacent( IEnumerable<TSource>^ source, Func<TSource, TKey>^ keySelector, Func<TSource, TElement>^ elementSelector, IEqualityComparer<TKey>^ comparer )
Generic Template Parameters
- TSource
- The type of the elements of source.
- TKey
- The type of the key returned by keySelector.
- TElement
- The type of the elements in the resulting groupings.
Parameters
- source (IEnumerable<(Of <(<'TSource>)>)>)
- A sequence whose elements to group.
- keySelector (Func<(Of <(<'TSource, TKey>)>)>)
- A function to extract the key for each element.
- elementSelector (Func<(Of <(<'TSource, TElement>)>)>)
- A function to map each source element to an element in the resulting grouping.
- comparer (IEqualityComparer<(Of <(<'TKey>)>)>)
- An IEqualityComparer<(Of <(<'T>)>)> to compare keys.
Return Value
A sequence of groupings where each grouping
(IGrouping<(Of <(<'TKey, TElement>)>)>) contains the key
and the adjacent elements (of type TElement)
in the same order as found in the source sequence.
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerable<(Of <(<'TSource>)>)>. When you use instance method syntax to call this method, omit the first parameter.
Remarks
This method is implemented by using deferred execution and
streams the groupings. The grouping elements, however, are
buffered. Each grouping is therefore yielded as soon as it
is complete and before the next grouping occurs.
Assembly: MoreLinq (Module: MoreLinq.dll) Version: 1.0.16006.0 (1.0.16006.1845)