Note: This is only supported in Daml-LF 1.11 or later.
This module exports the generic map type
Map k v and associated
functions. This module should be imported qualified, for example:
import DA.Map (Map) import DA.Map qualified as M
This will give access to the
Map type, and the various operations
Map k v internally uses the built-in order for the type
This means that keys that contain functions are not comparable
and will result in runtime errors. To prevent this, the
instance is required for most map operations. It is recommended to
Map k v for key types that have an
Ord k instance
that is derived automatically using
data K = ... deriving (Eq, Ord)
This includes all built-in types that aren’t function types, such as
(a, b) assuming
b have default
Optional t and
t has a
Map k v assuming
Ord instances, and
Set k assuming
k has a
Create a map from a list of key/value pairs with a combining function. Examples:
>>> fromListWith (++) [("A", ), ("A", ), ("B", ), ("B", ), ("A", )] fromList [("A", [1, 2, 3]), ("B", [2, 1])] >>> fromListWith (++)  == (empty : Map Text [Int]) True
: Map k v -> [k]
Get the list of keys in the map. Keys are sorted according to the built-in order for the type
k, which matches the
Ord kinstance when using
>>> keys (fromList [("A", 1), ("C", 3), ("B", 2)]) ["A", "B", "C"]
: Map k v -> [v]
Get the list of values in the map. These will be in the same order as their respective keys from
>>> values (fromList [("A", 1), ("B", 2)]) [1, 2]
: Map k v -> [(k, v)]
Convert the map to a list of key/value pairs. These will be ordered by key, as in
Mapusing a predicate: keep only the entries where the value satisfies the predicate.
Mapusing a predicate: keep only the entries which satisfy the predicate.
Delete a key and its value from the map. When the key is not a member of the map, the original map is returned.
Insert a new key/value pair in the map. If the key is already present in the map, the associated value is replaced with the supplied value.
Update the value in
f, inserting or deleting as required.
fwill be called with either the value at
Somewith a new value to be inserted in
m(replacing the old value if there was one), or
Noneto remove any
Some implications of this behavior:
alter identity k = identity alter g k . alter f k = alter (g . f) k alter (_ -> Some v) k = insert k v alter (_ -> None) = delete
The union of two maps, preferring the first map when equal keys are encountered.
The union of two maps using the combining function to merge values that exist in both maps.