ScanRightExtensionScanRightTSource(IEnumerableTSource, FuncTSource, TSource, TSource) Method

Performs a right-associative scan (inclusive prefix) on a sequence of elements. This operator is the right-associative version of the ScanTSource(IEnumerableTSource, FuncTSource, TSource, TSource) LINQ operator.

Definition

Namespace: MoreLinq.Extensions
Assembly: MoreLinq (in MoreLinq.dll) Version: 4.1.0+0e154ef592f33ce0f6f3d534a9eedee273f0ce72
C#
public static IEnumerable<TSource> ScanRight<TSource>(
	this IEnumerable<TSource> source,
	Func<TSource, TSource, TSource> func
)

Parameters

source  IEnumerableTSource
Source sequence.
func  FuncTSource, TSource, TSource
A right-associative accumulator function to be invoked on each element. Its first argument is the current value in the sequence; second argument is the previous accumulator value.

Type Parameters

TSource
Type of elements in source sequence.

Return Value

IEnumerableTSource
The scanned 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. Source sequence is consumed greedily when an iteration of the resulting sequence begins.

Example

C#
var result = Enumerable.Range(1, 5).Select(i => i.ToString()).ScanRight((a, b) => $"({a}+{b})");
The result variable will contain [ "(1+(2+(3+(4+5))))", "(2+(3+(4+5)))", "(3+(4+5))", "(4+5)", "5" ].

See Also