ScanExtensionScanTSource, TState(IEnumerableTSource, TState, FuncTState, TSource, TState) Method

Like AggregateTSource(IEnumerableTSource, FuncTSource, TSource, TSource) except returns the sequence of intermediate results as well as the final one. An additional parameter specifies a seed.

Definition

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

Parameters

source  IEnumerableTSource
Source sequence
seed  TState
Initial state to seed
transformation  FuncTState, TSource, TState
Transformation operation

Type Parameters

TSource
Type of elements in source sequence
TState
Type of state

Return Value

IEnumerableTState
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 result.

Example

C#
var result = Enumerable.Range(1, 5).Scan(0, (a, b) => a + b);
When iterated, result will yield { 0, 1, 3, 6, 10, 15 }.

See Also