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

Collections.Map<'Key,'Value> Class (F#)

Den Delimarsky|Last Updated: 8/18/2017
1 Contributor

Immutable maps. Keys are ordered by F# generic comparison.

Namespace/Module Path: Microsoft.FSharp.Collections

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


type Map<[<EqualityConditionalOnAttribute>] 'Key,[<ComparisonConditionalOnAttribute>] [<EqualityConditionalOnAttribute>] 'Value (requires comparison)> =
interface IEnumerable
interface IComparable
interface IEnumerable
interface ICollection
interface IDictionary
new Map : seq<'Key * 'Value> -> Map< 'Key, 'Value>
member this.Add : 'Key * 'Value -> Map<'Key, 'Value>
member this.ContainsKey : 'Key -> bool
member this.Remove : 'Key -> Map<'Key, 'Value>
member this.TryFind : 'Key -> 'Value option
member this.Count :  int
member this.IsEmpty :  bool
member this.Item ('Key) : 'Value


Maps based on generic comparison are efficient for small keys. They are not a suitable choice if keys are recursive data structures or if keys require bespoke comparison semantics. All members of this class are thread-safe and may be used concurrently from multiple threads.

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


newBuilds a map that contains the bindings of the given System.Collections.Generic.IEnumerable`1.

Instance Members

AddReturns a new map with the binding added to the given map.
ContainsKeyTests if an element is in the domain of the map.
CountThe number of bindings in the map.
IsEmptyReturns true if there are no bindings in the map.
ItemLookup an element in the map. Raise System.Collections.Generic.KeyNotFoundException if no binding exists in the map.
RemoveRemoves an element from the domain of the map. No exception is raised if the element is not present.
TryFindLookup an element in the map, returning a Some value if the element is in the domain of the map and None if not.


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

Microsoft.FSharp.Collections Namespace (F#)

© 2020 Microsoft