Note: This is only supported in Daml-LF 1.11 or later.
Daml
ModuleDA.Map
Latest release3.7.5
Functions
fromList
fromList : Ordk => [(k, v)] -> MapkvCreate a map from a list of key/value pairs.
fromListWithL
fromListWithL : Ordk => (v -> v -> v) -> [(k, v)] -> MapkvCreate a map from a list of key/value pairs with a combining
function. The combining function is only used when a key appears multiple
times in the list and it takes two arguments: the first one is the new value
being inserted at that key and the second one is the value accumulated so
far at that key.
Examples:
fromListWithR : Ordk => (v -> v -> v) -> [(k, v)] -> MapkvCreate a map from a list of key/value pairs like fromListWithL
with the combining function flipped. Examples:
fromListWith : Ordk => (v -> v -> v) -> [(k, v)] -> Mapkv
Deprecated: Daml compatibility helper, use ‘fromListWithR’ instead of ‘fromListWith’
keys
keys : Mapkv -> [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 k instance
when using deriving Ord.
lookup : Ordk => k -> Mapkv -> OptionalvLookup the value at a key in the map.
member
member : Ordk => k -> Mapkv -> BoolIs the key a member of the map?
filter
filter : Ordk => (v -> Bool) -> Mapkv -> MapkvFilter the Map using a predicate: keep only the entries where the
value satisfies the predicate.
filterWithKey
filterWithKey : Ordk => (k -> v -> Bool) -> Mapkv -> MapkvFilter the Map using a predicate: keep only the entries which
satisfy the predicate.
delete
delete : Ordk => k -> Mapkv -> MapkvDelete a key and its value from the map. When the key is not a
member of the map, the original map is returned.
singleton
singleton : Ordk => k -> v -> MapkvCreate a singleton map.
insert
insert : Ordk => k -> v -> Mapkv -> MapkvInsert 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.
insertWith
insertWith : Ordk => (v -> v -> v) -> k -> v -> Mapkv -> MapkvInsert a new key/value pair in the map. If the key is already
present in the map, it is combined with the previous value using the given function
f new_value old_value.
alter
alter : Ordk => (Optionalv -> Optionalv) -> k -> Mapkv -> MapkvUpdate the value in m at k with f, inserting or deleting as
required. f will be called with either the value at k, or None
if absent; f can return Some with a new value to be inserted in
m (replacing the old value if there was one), or None to remove
any k association m may have.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
union
union : Ordk => Mapkv -> Mapkv -> MapkvThe union of two maps, preferring the first map when equal
keys are encountered.
unionWith
unionWith : Ordk => (v -> v -> v) -> Mapkv -> Mapkv -> MapkvThe union of two maps using the combining function to merge values that
exist in both maps.
merge
merge : Ordk => (k -> a -> Optionalc) -> (k -> b -> Optionalc) -> (k -> a -> b -> Optionalc) -> Mapka -> Mapkb -> MapkcCombine two maps, using separate functions based on whether
a key appears only in the first map, only in the second map,
or appears in both maps.