canton-network-docs
DA.Map
DA.Map - Canton Network Docs
Skip to main content
This will give access to the
This includes all built-in types that aren’t function types, such as
Create a map from a list of key/value pairs.
Create 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:
Create a map from a list of key/value pairs like
Get the list of keys in the map. Keys are sorted according to the
built-in order for the type
Get the list of values in the map. These will be in the same order as
their respective keys from
Convert the map to a list of key/value pairs. These will be ordered
by key, as in
The empty map.
Number of elements in the map.
Is the map empty?
Lookup the value at a key in the map.
Is the key a member of the map?
Filter the
Filter the
Delete a key and its value from the map. When the key is not a
member of the map, the original map is returned.
Create a singleton map.
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.
Insert 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
Update the value in
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.
Combine 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.
Documentation Index
Fetch the complete documentation index at: https://docs.canton.network/llms.txt
Use this file to discover all available pages before exploring further.
DA.Map
Note: This is only supported in Daml-LF 1.11 or later. This module exports the generic map typeMap k v and associated
functions. This module should be imported qualified, for example:
Map type, and the various operations
as M.lookup, M.insert, M.fromList, etc.
Map k v internally uses the built-in order for the type k.
This means that keys that contain functions are not comparable
and will result in runtime errors. To prevent this, the Ord k
instance is required for most map operations. It is recommended to
only use Map k v for key types that have an Ord k instance
that is derived automatically using deriving:
Int, Text, Bool, (a, b) assuming a and b have default
Ord instances, Optional t and [t] assuming t has a
default Ord instance, Map k v assuming k and v have
default Ord instances, and Set k assuming k has a
default Ord instance.
Module Snapshot
Lifecycle
Stable.
Notices
Status:
active
Introduced in: 3.4.9
Removed in: -
Warnings: 0
Deprecations: 0
Deprecated since: -Functions
fromList
fromListWithL
fromListWithR
fromListWithL
with the combining function flipped. Examples:
fromListWith
keys
k, which matches the Ord k instance
when using deriving Ord.
values
M.keys.
toList
M.keys.
empty
size
null
lookup
member
filter
Map using a predicate: keep only the entries where the
value satisfies the predicate.
filterWithKey
Map using a predicate: keep only the entries which
satisfy the predicate.
delete
singleton
insert
insertWith
f new_value old_value.
alter
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
unionWith
merge
Orphan Typeclass Instances
-
instance (Show k, Show v) => Show (Map k v) -
instance (Ord k, Eq v) => Eq (Map k v) -
instance (Ord k, Ord v) => Ord (Map k v) -
instance Ord k => Semigroup (Map k v) -
instance Ord k => Monoid (Map k v) -
instance Ord k => Functor (Map k) -
instance Ord k => Foldable (Map k) -
instance Ord k => Traversable (Map k)