MoreEnumerableGroupAdjacentTSource, TKey Method (IEnumerableTSource, FuncTSource, TKey, IEqualityComparerTKey) |
Groups the adjacent elements of a sequence according to a
specified key selector function and compares the keys by using a
specified comparer.
Namespace:
MoreLinq
Assembly:
MoreLinq (in MoreLinq.dll) Version: 2.4.0
Syntax public static IEnumerable<IGrouping<TKey, TSource>> GroupAdjacent<TSource, TKey>(
this IEnumerable<TSource> source,
Func<TSource, TKey> keySelector,
IEqualityComparer<TKey> comparer
)
<ExtensionAttribute>
Public Shared Function GroupAdjacent(Of TSource, TKey) (
source As IEnumerable(Of TSource),
keySelector As Func(Of TSource, TKey),
comparer As IEqualityComparer(Of TKey)
) As IEnumerable(Of IGrouping(Of TKey, TSource))
public:
[ExtensionAttribute]
generic<typename TSource, typename TKey>
static IEnumerable<IGrouping<TKey, TSource>^>^ GroupAdjacent(
IEnumerable<TSource>^ source,
Func<TSource, TKey>^ keySelector,
IEqualityComparer<TKey>^ comparer
)
[<ExtensionAttribute>]
static member GroupAdjacent :
source : IEnumerable<'TSource> *
keySelector : Func<'TSource, 'TKey> *
comparer : IEqualityComparer<'TKey> -> IEnumerable<IGrouping<'TKey, 'TSource>>
Parameters
- source
- Type: System.Collections.GenericIEnumerableTSource
A sequence whose elements to group. - keySelector
- Type: SystemFuncTSource, TKey
A function to extract the key for each
element. - comparer
- Type: System.Collections.GenericIEqualityComparerTKey
An IEqualityComparerT to
compare keys.
Type Parameters
- TSource
- The type of the elements of
source.
- TKey
- The type of the key returned by
keySelector.
Return Value
Type:
IEnumerableIGroupingTKey,
TSourceA sequence of groupings where each grouping
(
IGroupingTKey, TElement) contains the key
and the adjacent elements 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
IEnumerableTSource. When you use instance method syntax to call this method, omit the first parameter. For more information, see
Extension Methods (Visual Basic) or
Extension Methods (C# Programming Guide).
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.
See Also