MoreEnumerableGenerateTResult Method
Returns a sequence of values consecutively generated by a generator function.
Namespace: MoreLinqAssembly: MoreLinq (in MoreLinq.dll) Version: 3.4.0+b99a6a8cc504caf2d48372fe54a2f8116c59cd0c
public static IEnumerable<TResult> Generate<TResult>(
TResult initial,
Func<TResult, TResult> generator
)
Public Shared Function Generate(Of TResult) (
initial As TResult,
generator As Func(Of TResult, TResult)
) As IEnumerable(Of TResult)
public:
generic<typename TResult>
static IEnumerable<TResult>^ Generate(
TResult initial,
Func<TResult, TResult>^ generator
)
static member Generate :
initial : 'TResult *
generator : Func<'TResult, 'TResult> -> IEnumerable<'TResult>
- initial TResult
- Value of first element in sequence
- generator FuncTResult, TResult
-
Generator function which takes the previous series element and uses it to generate the next element.
- TResult
- Type of elements to generate.
IEnumerableTResultA sequence containing the generated values.
This function defers element generation until needed and streams the results.
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.