map -package:base package:unordered-containers

O(n) Transform this map by applying a function to every value.
O(n) Transform this set by applying a function to every value. The resulting set may be smaller than the source.
>>> HashSet.map show (HashSet.fromList [1,2,3])
HashSet.fromList ["1","2","3"]
O(n). mapKeys f s is the map obtained by applying f to each key of s. The size of the result may be smaller if f maps two or more distinct keys to the same new key. In this case there is no guarantee which of the associated values is chosen for the conflicting key.
>>> mapKeys (+ 1) (fromList [(5,"a"), (3,"b")])
fromList [(4,"b"),(6,"a")]

>>> mapKeys (\ _ -> 1) (fromList [(1,"b"), (2,"a"), (3,"d"), (4,"c")])
fromList [(1,"c")]

>>> mapKeys (\ _ -> 3) (fromList [(1,"b"), (2,"a"), (3,"d"), (4,"c")])
fromList [(3,"c")]
O(n) Transform this map by applying a function to every value and retaining only some of them.
O(n) Transform this map by applying a function to every value and retaining only some of them.
O(n) Transform this map by applying a function to every value.
Strict version of map.
A map from keys to values. A map cannot contain duplicate keys; each key can map to at most one value.
Create a BitmapIndexed or Full node.
Common implementation for filterWithKey and mapMaybeWithKey, allowing the former to former to reuse terms.
O(n) Reduce the map by applying a function to each element and combining the results with a monoid operation.
O(n*log m) Inclusion of maps. A map is included in another map if the keys are subsets and the corresponding values are equal:
isSubmapOf m1 m2 = keys m1 `isSubsetOf` keys m2 &&
and [ v1 == v2 | (k1,v1) <- toList m1; let v2 = m2 ! k1 ]

Examples

>>> fromList [(1,'a')] `isSubmapOf` fromList [(1,'a'),(2,'b')]
True
>>> fromList [(1,'a'),(2,'b')] `isSubmapOf` fromList [(1,'a')]
False
O(n*log m) Inclusion of maps with value comparison. A map is included in another map if the keys are subsets and if the comparison function is true for the corresponding values:
isSubmapOfBy cmpV m1 m2 = keys m1 `isSubsetOf` keys m2 &&
and [ v1 `cmpV` v2 | (k1,v1) <- toList m1; let v2 = m2 ! k1 ]

Examples

>>> isSubmapOfBy (<=) (fromList [(1,'a')]) (fromList [(1,'b'),(2,'c')])
True
>>> isSubmapOfBy (<=) (fromList [(1,'b')]) (fromList [(1,'a'),(2,'c')])
False
O(1) Convert from the equivalent HashMap with () values.
>>> HashSet.fromMap (HashMap.singleton 1 ())
fromList [1]
O(1) Convert to set to the equivalent HashMap with () values.
>>> HashSet.toMap (HashSet.singleton 1)
fromList [(1,())]