Module DA.Next.Map¶
Map - A Map
is an associative array data type composed of a
collection of key/value pairs such that each possible key appears
at most once in the collection.
Typeclasses¶
A class for types that can be used as keys for the
Map
type. All keysk
must satisfykeyFromText (keyToText k) == k
.
- keyFromText
: Text -> k
Recover a key from its textual representation.
keyFromText x
is allowed to fail whenever there is no keyk
withkeyToText k == x
. Whenever such ak
does exist, then it must satisfykeyFromText x == k
.
Data Types¶
data Map k v
A
Map k v
is an associative array data type composed of a collection of key/value pairs of key typek
and value typev
such that each possible key appears at most once in the collection.instance MapKey k => Monoid (Map k v)
instance MapKey k => Semigroup (Map k v)
instance MapKey k => Traversable (Map k)
instance MapKey k => Functor (Map k)
Functions¶
- fromListWith
: MapKey k => (v -> v -> v) -> [(k, v)] -> Map k v
Create a map from a list of key/value pairs with a combining function. Examples:
fromListWith (<>) [(5,"a"), (5,"b"), (3,"b"), (3,"a"), (5,"c")] == fromList [(3, "ba"), (5, "abc")] fromListWith (<>) [] == (empty : Map Int Text)
- toList
: MapKey k => Map k v -> [(k, v)]
Convert the map to a list of key/value pairs where the keys are in ascending order of their textual representation.
- fromTextMap
-
Create a
Map
from aTextMap
.
- filter
: MapKey k => (v -> Bool) -> Map k v -> Map k v
Filter the
Map
using a predicate: keep only the entries where the value satisfies the predicate.
- filterWithKey
: MapKey k => (k -> v -> Bool) -> Map k v -> Map k v
Filter the
Map
using a predicate: keep only the entries which satisfy the predicate.
- delete
: MapKey k => k -> Map k v -> Map k v
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
: MapKey k => k -> v -> Map k v -> Map k v
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.
- union
: MapKey k => Map k v -> Map k v -> Map k v
The union of two maps, preferring the first map when equal keys are encountered.
- merge
: MapKey k => (k -> a -> Optional c) -> (k -> b -> Optional c) -> (k -> a -> b -> Optional c) -> Map k a -> Map k b -> Map k c
Merge two maps.
merge f g h x y
appliesf
to all key/value pairs whose key only appears inx
,g
to all pairs whose key only appears iny
andh
to all pairs whose key appears in bothx
andy
. In the end, all pairs yieldingSome
are collected as the result.