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
Maptype. All keyskmust satisfykeyFromText (keyToText k) == k.
- keyFromText
: Text -> k
Recover a key from its textual representation.
keyFromText xis allowed to fail whenever there is no keykwithkeyToText k == x. Whenever such akdoes exist, then it must satisfykeyFromText x == k.
Data Types¶
data Map k v
A
Map k vis an associative array data type composed of a collection of key/value pairs of key typekand value typevsuch 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
Mapfrom aTextMap.
- filter
: MapKey k => (v -> Bool) -> Map k v -> Map k v
Filter the
Mapusing 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
Mapusing 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 yappliesfto all key/value pairs whose key only appears inx,gto all pairs whose key only appears inyandhto all pairs whose key appears in bothxandy. In the end, all pairs yieldingSomeare collected as the result.