Export (0) Print
Expand All
Expand Minimize

Array.map<'T,'U> Function (F#)

Builds a new array whose elements are the results of applying the given function to each of the elements of the array.

Namespace/Module Path: Microsoft.FSharp.Collections.Array

Assembly: FSharp.Core (in FSharp.Core.dll)

// Signature:
Array.map : ('T -> 'U) -> 'T [] -> 'U []

// Usage:
Array.map mapping array

mapping

Type: 'T -> 'U

The function to transform elements of the array.

array

Type: 'T []

The input array.

The array of transformed elements.

This function is named Map in compiled assemblies. If you are accessing the function from a language other than F#, or through reflection, use this name.

The following code example shows how to use Array.map.


let data = [| 1; 2; 3; 4 |]
let r1 = data |> Array.map (fun x -> x + 1)
printfn "Adding '1' using map = %A" r1
let r2 = data |> Array.map string
printfn "Converting to strings by using map = %A" r2
let r3 = data |> Array.map (fun x -> (x, x))
printfn "Converting to tupels by using map = %A" r3


Output

Adding '1' using map = [|2; 3; 4; 5|]
Converting to strings by using map = [|"1"; "2"; "3"; "4"|]
Converting to tuples by using map = [|(1, 1); (2, 2); (3, 3); (4, 4)|]

Windows 7, Windows Vista SP2, Windows XP SP3, Windows XP x64 SP2, Windows Server 2008 R2, Windows Server 2008 SP2, Windows Server 2003 SP2

F# Runtime

Supported in: 2.0, 4.0

Silverlight

Supported in: 3

Community Additions

ADD
Show:
© 2014 Microsoft