ScanRightExtension.ScanRight<TSource>(IEnumerable<TSource>, Func<TSource, TSource, TSource>) Method

Performs a right-associative scan (inclusive prefix) on a sequence of elements. This operator is the right-associative version of the Scan<TSource>(IEnumerable<TSource>, Func<TSource, TSource, TSource>) LINQ operator.

Definition

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

Parameters

source  IEnumerable<TSource>
Source sequence.
func  Func<TSource, 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

IEnumerable<TSource>
The scanned sequence.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerable<TSource>. 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