MoreEnumerableScanRightTSource, TAccumulate(IEnumerableTSource, TAccumulate, FuncTSource, TAccumulate, TAccumulate) Method

Performs a right-associative scan (inclusive prefix) on a sequence of elements. The specified seed value is used as the initial accumulator value. This operator is the right-associative version of the ScanTSource, TState(IEnumerableTSource, TState, FuncTState, TSource, TState) LINQ operator.

Definition

Namespace: MoreLinq
Assembly: MoreLinq (in MoreLinq.dll) Version: 3.4.0+b99a6a8cc504caf2d48372fe54a2f8116c59cd0c
C#
public static IEnumerable<TAccumulate> ScanRight<TSource, TAccumulate>(
	this IEnumerable<TSource> source,
	TAccumulate seed,
	Func<TSource, TAccumulate, TAccumulate> func
)

Parameters

source  IEnumerableTSource
Source sequence.
seed  TAccumulate
The initial accumulator value.
func  FuncTSource, TAccumulate, TAccumulate
A right-associative accumulator function to be invoked on each element.

Type Parameters

TSource
The type of the elements of source.
TAccumulate
The type of the accumulator value.

Return Value

IEnumerableTAccumulate
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, 4).ScanRight("5", (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