Table of contents
TOC
Collapse the table of content
Expand the table of content

List.init<'T> Function (F#)

Den Delimarsky|Last Updated: 7/5/2016
|
1 Contributor

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)

Syntax

fsharp

// Signature:
List.init : int -> (int -> 'T) -> 'T list

// Usage:
List.init length initializer

Parameters

length Type: int

The length of the list to generate.

initializer Type: int-> 'T

The 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

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 8, Windows 7, Windows Server 2012, Windows Server 2008 R2

Version Information

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

See Also

Collections.List Module (F#)

Microsoft.FSharp.Collections Namespace (F#)

© 2016 Microsoft