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

Map.Add<'Key,'Value> Method (F#)

Den Delimarsky|Last Updated: 8/18/2017
2 Contributors

Returns a new map from a given map, with an additional or replaced binding.

Namespace/Module Path: Microsoft.FSharp.Collections

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


// Signature:
member this.Add : 'Key * 'Value -> Map<'Key, 'Value> (requires comparison)

// Usage:
map.Add (key, value)


key Type: 'Key

The input key.

value Type: 'Value

The input value.

Return Value

The resulting map, in which the given key maps to the given value. If the key of the newly added key-value pair is present in the map this method was called on, the newly added pair replaces the old pair in the resulting map.


let map1 = Map.ofList [ (1, "one"); (2, "two") ]
let map2 = map1.Add(0, "zero")
let map3 = map2.Add(2, "twice")
map3 |> Map.iter (fun key value -> printfn "key: %d value: %s" key value)


key: 0 value: zero
key: 1 value: one
key: 2 value: twice


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.Map<'Key,'Value> Class (F#)

Microsoft.FSharp.Collections Namespace (F#)

© 2020 Microsoft