Seq.initInfinite<'T> Function (F#)
Generates a new sequence which, when iterated, will return successive elements by calling the given function.
Namespace/Module Path: Microsoft.FSharp.Collections.Seq
Assembly: FSharp.Core (in FSharp.Core.dll)
// Signature: Seq.initInfinite : (int -> 'T) -> seq<'T> // Usage: Seq.initInfinite initializer
The results of calling the function will not be saved, that is the function will be reapplied as necessary to regenerate the elements. The function is passed the index of the item being generated.
Iteration can continue up to Int32.MaxValue.
This function is named InitializeInfinite in compiled assemblies. If you are accessing the function from a language other than F#, or through reflection, use this name.
The following example shows the use of Seq.initInfinite to create a sequence 1/n^2, with alternating signs.
let seqInfinite = Seq.initInfinite (fun index -> let n = float( index + 1 ) 1.0 / (n * n * (if ((index + 1) % 2 = 0) then 1.0 else -1.0))) printfn "%A" seqInfinite
seq [-1.0; 0.25; -0.1111111111; 0.0625; ...]