Click or drag to resize

MoreEnumerableGenerateTResult Method

Returns a sequence of values consecutively generated by a generator function.

Namespace:  MoreLinq
Assembly:  MoreLinq (in MoreLinq.dll) Version: 3.3.1+b77df70598ab84c28cd43dcf74594024b6d575e1
Syntax
public static IEnumerable<TResult> Generate<TResult>(
	TResult initial,
	Func<TResult, TResult> generator
)

Parameters

initial
Type: TResult
Value of first element in sequence
generator
Type: SystemFuncTResult, TResult
Generator function which takes the previous series element and uses it to generate the next element.

Type Parameters

TResult
Type of elements to generate.

Return Value

Type: IEnumerableTResult
A sequence containing the generated values.
Remarks
This function defers element generation until needed and streams the results.
Examples
var result = MoreEnumerable.Generate(2, n => n * n).Take(5);
The result variable, when iterated over, will yield 2, 4, 16, 256, and 65536, in turn.
See Also