List.init<'T> Function (F#)
Creates a list by calling the given generator on each index.
Namespace/Module Path: Microsoft.FSharp.Collections.List
Assembly: FSharp.Core (in FSharp.Core.dll)
// Signature:
List.init : int -> (int -> 'T) -> 'T list
// Usage:
List.init length initializer
Parameters
length
Type: intThe length of the list to generate.
initializer
Type: int -> 'TThe function to generate an element from an index.
Return Value
The list of generated elements.
Remarks
This function is named Initialize in compiled assemblies. If you are accessing the function from a language other than F#, or through reflection, use this name.
Example
The following code shows how to use List.init.
printfn "List of squares: %A" (List.init 10 (fun index -> index * index))
Output
List of squares: [0; 1; 4; 9; 16; 25; 36; 49; 64; 81]
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
See Also
Reference
Microsoft.FSharp.Collections Namespace (F#)
Change History
Date |
History |
Reason |
---|---|---|
August 2010 |
Added code example. |
Information enhancement. |