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
Parameters
initializer
Type: int -> 'TA function that generates an item in the sequence from a given index.
Return Value
The result sequence.
Remarks
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.
Thread Safety
The returned sequence may be passed between threads safely. However, individual IEnumerator values generated from the returned sequence should not be accessed concurrently.
Example
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; ...]
Platforms
Windows 7, Windows Vista SP2, Windows XP SP3, Windows XP x64 SP2, Windows Server 2008 R2, Windows Server 2008 SP2, Windows Server 2003 SP2
Version Information
F# Runtime
Supported in: 2.0, 4.0
Silverlight
Supported in: 3