次の方法で共有


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

Parameters

  • mapping
    Type: 'T -> 'U

    The function to transform elements of the array.

  • array
    Type: 'T[]

    The input array.

Return Value

The array of transformed elements.

Remarks

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.

Example

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)|]

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

Reference

Collections.Array Module (F#)

Microsoft.FSharp.Collections Namespace (F#)