Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module provides a HashMap
variant which uses the value's
Monoid
instance to accumulate conflicting entries when merging
Map
s.
While some functions mirroring those of HashMap
are provided
here for convenience, more specialized needs will likely want to use
either the Newtype
or Wrapped
instances to manipulate the
underlying Map
.
- data MonoidalHashMap k a
- singleton :: (Eq k, Hashable k) => k -> a -> MonoidalHashMap k a
- size :: MonoidalHashMap k a -> Int
- member :: (Eq k, Hashable k) => k -> MonoidalHashMap k a -> Bool
- notMember :: (Eq k, Hashable k) => k -> MonoidalHashMap k a -> Bool
- lookup :: (Eq k, Hashable k) => k -> MonoidalHashMap k v -> Maybe v
- lookupM :: (Eq k, Hashable k, Monoid v) => k -> MonoidalHashMap k v -> v
- elems :: MonoidalHashMap k a -> [a]
- keys :: MonoidalHashMap k a -> [k]
- delete :: (Eq k, Hashable k) => k -> MonoidalHashMap k a -> MonoidalHashMap k a
- mapKeys :: (Monoid a, Hashable k, Eq k, Hashable k', Eq k') => (k -> k') -> MonoidalHashMap k a -> MonoidalHashMap k' a
- modify :: (Monoid a, Hashable k, Eq k) => (a -> a) -> k -> MonoidalHashMap k a -> MonoidalHashMap k a
- modifyDef :: (Monoid a, Hashable k, Eq k) => a -> (a -> a) -> k -> MonoidalHashMap k a -> MonoidalHashMap k a
Documentation
data MonoidalHashMap k a Source
A HashMap
with monoidal accumulation
Often-needed functions
singleton :: (Eq k, Hashable k) => k -> a -> MonoidalHashMap k a Source
O(1). A map with a single element.
size :: MonoidalHashMap k a -> Int Source
O(1). The number of elements in the map.
member :: (Eq k, Hashable k) => k -> MonoidalHashMap k a -> Bool Source
O(log n). Is the key a member of the map? See also notMember
.
notMember :: (Eq k, Hashable k) => k -> MonoidalHashMap k a -> Bool Source
O(log n). Is the key not a member of the map? See also member
.
lookup :: (Eq k, Hashable k) => k -> MonoidalHashMap k v -> Maybe v Source
O(log n) Return the value to which the specified key is mapped,
or Nothing
if this map contains no mapping for the key.
lookupM :: (Eq k, Hashable k, Monoid v) => k -> MonoidalHashMap k v -> v Source
O(log n) Return the value to which the specified key is mapped, or mempty if this map contains no mapping for the key.
elems :: MonoidalHashMap k a -> [a] Source
O(n). Return all elements of the map in the ascending order of their keys. Subject to list fusion.
keys :: MonoidalHashMap k a -> [k] Source
O(n). Return all keys of the map in ascending order. Subject to list fusion.
delete :: (Eq k, Hashable k) => k -> MonoidalHashMap k a -> MonoidalHashMap k a Source
O(log n). Delete a key and its value from the map. When the key is not a member of the map, the original map is returned.
mapKeys :: (Monoid a, Hashable k, Eq k, Hashable k', Eq k') => (k -> k') -> MonoidalHashMap k a -> MonoidalHashMap k' a Source
O(n). Map a function to each key of a map
modify :: (Monoid a, Hashable k, Eq k) => (a -> a) -> k -> MonoidalHashMap k a -> MonoidalHashMap k a Source
O(log n). Modify a value on some key with a function, if value under key doesn't exist -- use mempty.
modifyDef :: (Monoid a, Hashable k, Eq k) => a -> (a -> a) -> k -> MonoidalHashMap k a -> MonoidalHashMap k a Source
O(log n). Modify a value on some key with a function, providing a default value if that key doesn't exist.