Collections.Map Module (F#)
Functional programming operators related to the Map type.
Namespace/Module Path: Microsoft.FSharp.Collections
Assembly: FSharp.Core (in FSharp.Core.dll)
module Map
Values
Value |
Description |
---|---|
add : 'Key -> 'T -> Map<'Key,'T> -> Map<'Key,'T> |
Returns a new map with the binding added to the given map. |
containsKey : 'Key -> Map<'Key,'T> -> bool |
Tests if an element is in the domain of the map. |
empty : Map<'Key,'T> |
The empty map. |
exists : ('Key -> 'T -> bool) -> Map<'Key,'T> -> bool |
Returns true if the given predicate returns true for one of the bindings in the map. |
filter : ('Key -> 'T -> bool) -> Map<'Key,'T> -> Map<'Key,'T> |
Creates a new map containing only the bindings for which the given predicate returns true. |
find : 'Key -> Map<'Key,'T> -> 'T |
Looks up an element in the map. |
findKey : ('Key -> 'T -> bool) -> Map<'Key,'T> -> 'Key |
Evaluates the function on each mapping in the collection. Returns the key for the first mapping where the function returns true. |
fold : ('State -> 'Key -> 'T -> 'State) -> 'State -> Map<'Key,'T> -> 'State |
Folds over the bindings in the map |
foldBack : ('Key -> 'T -> 'State -> 'State) -> Map<'Key,'T> -> 'State -> 'State |
Folds over the bindings in the map. |
forall : ('Key -> 'T -> bool) -> Map<'Key,'T> -> bool |
Returns true if the given predicate returns true for all of the bindings in the map. |
isEmpty : Map<'Key,'T> -> bool |
Tests whether the map has any bindings. |
iter : ('Key -> 'T -> unit) -> Map<'Key,'T> -> unit |
Applies the given function to each binding in the dictionary |
map : ('Key -> 'T -> 'U) -> Map<'Key,'T> -> Map<'Key,'U> |
Creates a new collection whose elements are the results of applying the given function to each of the elements of the collection. The key passed to the function indicates the key of element being transformed. |
ofArray : ('Key * 'T) [] -> Map<'Key,'T> |
Returns a new map made from the given bindings. |
ofList : 'Key * 'T list -> Map<'Key,'T> |
Returns a new map made from the given bindings. |
ofSeq : seq<'Key * 'T> -> Map<'Key,'T> |
Returns a new map made from the given bindings. |
partition : ('Key -> 'T -> bool) -> Map<'Key,'T> -> Map<'Key,'T> * Map<'Key,'T> |
Creates two new maps, one containing the bindings for which the given predicate returns true, and the other the remaining bindings. |
pick : ('Key -> 'T -> 'U option) -> Map<'Key,'T> -> 'U |
Searches the map looking for the first element where the given function returns a Some value |
remove : 'Key -> Map<'Key,'T> -> Map<'Key,'T> |
Removes an element from the domain of the map. No exception is raised if the element is not present. |
toArray : Map<'Key,'T> -> ('Key * 'T) [] |
Returns an array of all key/value pairs in the mapping. The array will be ordered by the keys of the map. |
toList : Map<'Key,'T> -> ('Key * 'T) list |
Returns a list of all key/value pairs in the mapping. The list will be ordered by the keys of the map. |
toSeq : Map<'Key,'T> -> seq<'Key * 'T> |
Views the collection as an enumerable sequence of pairs. The sequence will be ordered by the keys of the map. |
tryFind : 'Key -> Map<'Key,'T> -> 'T option |
Looks up an element in the map, returning a Some value if the element is in the domain of the map, or None if not. |
tryFindKey : ('Key -> 'T -> bool) -> Map<'Key,'T> -> 'Key option |
Returns the key of the first mapping in the collection that satisfies the given predicate, or returns None if no such element exists. |
tryPick : ('Key -> 'T -> 'U option) -> Map<'Key,'T> -> 'U option |
Searches the map looking for the first element where the given function returns a Some value. |
Example
The following code example uses functions in the Map module to create a histogram of the occurrences of particular Unicode characters using a Microsoft.FSharp.Collections.Map.
let data = "The quick brown fox jumps over the lazy dog"
let histogram =
data.ToCharArray()
|> Seq.groupBy (fun c -> c)
|> Map.ofSeq
|> Map.map (fun k v -> Seq.length v)
for (KeyValue(c,n)) in histogram do
printfn "Number of '%c' characters = %d" c n
Number of ' ' characters = 8 Number of 'T' characters = 1 Number of 'a' characters = 1 Number of 'b' characters = 1 Number of 'c' characters = 1 Number of 'd' characters = 1 Number of 'e' characters = 3 Number of 'f' characters = 1 ...
Platforms
Windows 7, Windows Vista SP2, Windows XP SP3, Windows XP x64 SP2, Windows Server 2008 R2, Windows Server 2008 SP2, Windows Server 2003 SP2
Version Information
F# Runtime
Supported in: 2.0, 4.0
Silverlight
Supported in: 3