MoreEnumerablePairwiseTSource, TResult Method

Returns a sequence resulting from applying a function to each element in the source sequence and its predecessor, with the exception of the first element which is only returned as the predecessor of the second element.

Definition

Namespace: MoreLinq
Assembly: MoreLinq (in MoreLinq.dll) Version: 3.4.0+b99a6a8cc504caf2d48372fe54a2f8116c59cd0c
C#
public static IEnumerable<TResult> Pairwise<TSource, TResult>(
	this IEnumerable<TSource> source,
	Func<TSource, TSource, TResult> resultSelector
)

Parameters

source  IEnumerableTSource
The source sequence.
resultSelector  FuncTSource, TSource, TResult
A transform function to apply to each pair of sequence.

Type Parameters

TSource
The type of the elements of source.
TResult
The type of the element of the returned sequence.

Return Value

IEnumerableTResult
Returns the resulting 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 operator uses deferred execution and streams its results.

Example

C#
var source = new[] { "a", "b", "c", "d" };
var result = source.Pairwise((a, b) => a + b);
The result variable, when iterated over, will yield "ab", "bc" and "cd", in turn.

See Also