Click or drag to resize

MoreEnumerableGroupAdjacentTSource, TKey, TResult Method (IEnumerableTSource, FuncTSource, TKey, FuncTKey, IEnumerableTSource, TResult, IEqualityComparerTKey)

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.

Namespace:  MoreLinq
Assembly:  MoreLinq (in MoreLinq.dll) Version: 3.3.1+b77df70598ab84c28cd43dcf74594024b6d575e1
Syntax
public static IEnumerable<TResult> GroupAdjacent<TSource, TKey, TResult>(
	this IEnumerable<TSource> source,
	Func<TSource, TKey> keySelector,
	Func<TKey, IEnumerable<TSource>, TResult> resultSelector,
	IEqualityComparer<TKey> comparer
)

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.
resultSelector
Type: SystemFuncTKey, IEnumerableTSource, TResult
A function to map each key and associated source elements to a result object.
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.
TResult
The type of the elements in the resulting sequence.

Return Value

Type: IEnumerableTResult
A collection of elements of type TResult where each element represents a projection over a group and its key.

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