Expand Minimize

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

length

Type: int

The length of the list to generate.

initializer

Type: int -> 'T

The function to generate an element from an index.

The list of generated elements.

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.

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]

Windows 8, Windows 7, Windows Server 2012, Windows Server 2008 R2

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft