Partager via


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

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

Namespace/Module Path: Microsoft.FSharp.Collections

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

[<Sealed>]
type Map<[<EqualityConditionalOnAttribute>] 'Key,[<ComparisonConditionalOnAttribute>] [<EqualityConditionalOnAttribute>] 'Value (requires comparison)> =
 class
  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
 end

Remarks

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.

Constructors

Member

Description

new

Builds a map that contains the bindings of the given IEnumerable.

Instance Members

Member

Description

Add

Returns a new map with the binding added to the given map.

ContainsKey

Tests if an element is in the domain of the map.

Count

The number of bindings in the map.

IsEmpty

Returns true if there are no bindings in the map.

Item

Lookup an element in the map. Raise KeyNotFoundException if no binding exists in the map.

Remove

Removes an element from the domain of the map. No exception is raised if the element is not present.

TryFind

Lookup an element in the map, returning a Some value if the element is in the domain of the map and None if not.

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

Microsoft.FSharp.Collections Namespace (F#)