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

Map.add<'Key,'T> Function (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.Map

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


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

// Usage:
Map.add key value table


key Type: 'Key

The input key.

value Type: 'T

The input value.

table Type: Map<'Key,'T>

The input map.

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 table, the newly added pair replaces the old pair in the resulting map.


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


Map.ofList [ (1, "one"); (2, "two") ]
|> Map.add 0 "zero"
|> Map.add 2 "twice"
|> 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 Module (F#)

Microsoft.FSharp.Collections Namespace (F#)

© 2020 Microsoft