PairwiseExtensionPairwiseTSource, 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.
Namespace: MoreLinq.ExtensionsAssembly: MoreLinq (in MoreLinq.dll) Version: 4.1.0+0e154ef592f33ce0f6f3d534a9eedee273f0ce72
public static IEnumerable<TResult> Pairwise<TSource, TResult>(
this IEnumerable<TSource> source,
Func<TSource, TSource, TResult> resultSelector
)
<ExtensionAttribute>
Public Shared Function Pairwise(Of TSource, TResult) (
source As IEnumerable(Of TSource),
resultSelector As Func(Of TSource, TSource, TResult)
) As IEnumerable(Of TResult)
public:
[ExtensionAttribute]
generic<typename TSource, typename TResult>
static IEnumerable<TResult>^ Pairwise(
IEnumerable<TSource>^ source,
Func<TSource, TSource, TResult>^ resultSelector
)
[<ExtensionAttribute>]
static member Pairwise :
source : IEnumerable<'TSource> *
resultSelector : Func<'TSource, 'TSource, 'TResult> -> IEnumerable<'TResult>
- source IEnumerableTSource
- The source sequence.
- resultSelector FuncTSource, TSource, TResult
- A transform function to apply to
each pair of sequence.
- TSource
- The type of the elements of source.
- TResult
- The type of the element of the returned sequence.
IEnumerableTResult
Returns the resulting sequence.
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).
This operator uses deferred execution and streams its results.
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.