Immutable maps based on binary trees, where keys are ordered by F# generic comparison. By default comparison is the F# structural comparison function or uses implementations of the IComparable interface on key values.
See the Map module for further operations on maps. All members of this class are thread-safe and may be used concurrently from multiple threads.
Constructor | Description |
|
Example
Map [ (1, "a"); (2, "b") ] // evaluates to map [(1, "a"); (2, "b")] |
Instance member | Description | ||
![]() ![]() ![]() ![]() ![]() ![]() Returns a new map with the binding added to the given map. If a binding with the given key already exists in the input map, the existing binding is replaced by the new binding in the result map.
Example
let sample = Map [ (1, "a"); (2, "b") ] sample.Add (3, "c") // evaluates to map [(1, "a"); (2, "b"); (3, "c")] sample.Add (2, "aa") // evaluates to map [(1, "a"); (2, "aa")] |
|||
|
Example
let sample = Map [ (1, "a"); (2, "b") ] let f x = match x with | Some s -> Some (s + "z") | None -> None sample.Change (1, f) // evaluates to map [(1, "az"); (2, "b")] |
||
Full Usage:
this.ContainsKey
Parameters:
'Key
-
The input key.
Returns: bool
True if the map contains the given key.
|
Example
let sample = Map [ (1, "a"); (2, "b") ] sample.ContainsKey 1 // evaluates to true sample.ContainsKey 3 // evaluates to false |
||
|
Example
let sample = Map [ (1, "a"); (2, "b") ] sample.Count // evaluates to 2 |
||
|
Example
let emptyMap: Map<int, string> = Map.empty emptyMap.IsEmpty // evaluates to true let notEmptyMap = Map [ (1, "a"); (2, "b") ] notEmptyMap.IsEmpty // evaluates to false |
||
Full Usage:
this.[key]
Parameters:
'Key
-
The input key.
Returns: 'Value
The value mapped to the key.
|
Example
let sample = Map [ (1, "a"); (2, "b") ] sample.[1] // evaluates to "a" sample.[3] // throws KeyNotFoundException |
||
|
Example
let sample = Map [ (1, "a"); (2, "b") ] sample.Keys // evaluates to seq [1; 2] |
||
Full Usage:
this.Remove
Parameters:
'Key
-
The input key.
Returns: Map<'Key, 'Value>
The resulting map.
|
![]() ![]() ![]() ![]() ![]() ![]() Removes an element from the domain of the map. No exception is raised if the element is not present.
Example
let sample = Map [ (1, "a"); (2, "b") ] sample.Remove 1 // evaluates to map [(2, "b")] sample.Remove 3 // equal to sample |
||
Full Usage:
this.TryFind
Parameters:
'Key
-
The input key.
Returns: 'Value option
The mapped value, or None if the key is not in the map.
|
![]() ![]() ![]() ![]() ![]() ![]()
Lookup an element in the map, returning a
Example
let sample = Map [ (1, "a"); (2, "b") ] sample.TryFind 1 // evaluates to Some "a" sample.TryFind 3 // evaluates to None |
||
|
![]() ![]() ![]() ![]() ![]() ![]()
Lookup an element in the map, assigning to
Example
let sample = Map [ (1, "a"); (2, "b") ] sample.TryGetValue 1 // evaluates to (true, "a") sample.TryGetValue 3 // evaluates to (false, null) let mutable x = "" sample.TryGetValue (1, &x) // evaluates to true, x set to "a" let mutable y = "" sample.TryGetValue (3, &y) // evaluates to false, y unchanged |
||
|
![]() ![]() ![]() ![]() ![]() ![]() All the values in the map, including the duplicates. The sequence will be ordered by the keys of the map.
Example
let sample = Map [ (1, "a"); (2, "b") ] sample.Values // evaluates to seq ["a"; "b"] |