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

Creates a new collection whose elements are the results of applying the given function to each of the elements of the collection. The key passed to the function indicates the key of element being transformed.

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

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

// Signature:
Map.map : ('Key -> 'T -> 'U) -> Map<'Key,'T> -> Map<'Key,'U> (requires comparison)

// Usage:
Map.map mapping table

Parameters

  • mapping
    Type: 'Key -> 'T -> 'U

    The function to transform the key/value pairs.

  • table
    Type: Map<'Key,'T>

    The input map.

Return Value

The resulting map of keys and transformed values.

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 shows how to use Map.map.

let map1 = Map.ofList [ (1, "One"); (2, "Two"); (3, "Three") ]
let map2 = map1 |> Map.map (fun key value -> value.ToUpper())
let map3 = map1 |> Map.map (fun key value -> value.ToLower())
printfn "%A" map1
printfn "%A" map2
printfn "%A" map3

Output

map [(1, "One"); (2, "Two"); (3, "Three")]
map [(1, "ONE"); (2, "TWO"); (3, "THREE")]
map [(1, "one"); (2, "two"); (3, "three")]

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

Collections.Map Module (F#)

Microsoft.FSharp.Collections Namespace (F#)