- data MultiMap k a
- fromList :: Ord k => [(k, [a])] -> MultiMap k a
- toList :: MultiMap k a -> [(k, [a])]
- empty :: MultiMap k a
- singleton :: k -> a -> MultiMap k a
- insert :: Ord k => k -> a -> MultiMap k a -> MultiMap k a
- insertMany :: Ord k => [(k, a)] -> MultiMap k a -> MultiMap k a
- insertList :: Ord k => k -> [a] -> MultiMap k a -> MultiMap k a
- insertManyLists :: Ord k => [(k, [a])] -> MultiMap k a -> MultiMap k a
- null :: MultiMap k a -> Bool
- lookup :: Ord k => k -> MultiMap k a -> [a]
- deleteList :: Ord k => k -> MultiMap k a -> MultiMap k a
- extractList :: Ord k => k -> MultiMap k a -> ([a], MultiMap k a)
- extractEachListWithKey :: Ord k => MultiMap k a -> [((k, [a]), MultiMap k a)]
- alter :: Ord k => ([a] -> [a]) -> k -> MultiMap k a -> MultiMap k a
- maxView :: MultiMap k a -> Maybe (a, MultiMap k a)
- elems :: MultiMap k a -> [a]
- descElems :: MultiMap k a -> [a]
- assocs :: MultiMap k a -> [(k, a)]
- descAssocs :: MultiMap k a -> [(k, a)]

# Documentation

fromList :: Ord k => [(k, [a])] -> MultiMap k aSource

Converts an association list into a multimap. If the association list contains duplicate keys, then the corresponding lists of values become concatenated.

`>>>`

fromList [(1,"abaac"),(2,"b"),(4,"dca")]`fromList [(4, "dca"), (1, "aba"), (2, "b"), (1, "ac"), (3, "")]`

toList :: MultiMap k a -> [(k, [a])]Source

Converts a multimap into an association list, with the keys in ascending order.

`>>>`

[(1,"abaac"),(2,"b"),(4,"dca")]`toList $ fromList [(4, "dca"), (1, "aba"), (2, "b"), (1, "ac"), (3, "")]`

insert :: Ord k => k -> a -> MultiMap k a -> MultiMap k aSource

Inserts a new key-value pair. If other entries already exist with the same key, then the new entry is inserted just before them.

`>>>`

fromList [(1,"efg"),(2,"ajzw"),(3,"abc")]`insert 2 'a' $ fromList [(1, "efg"), (2, "jzw"), (3, "abc")]`

insertMany :: Ord k => [(k, a)] -> MultiMap k a -> MultiMap k aSource

Passes down the list from left to right, inserting each entry into the multimap.

`>>>`

fromList [(1,"baa"),(5,"a")]`insertMany [(1, 'a'), (5, 'a'), (1, 'a'), (1, 'b')] empty`

insertList :: Ord k => k -> [a] -> MultiMap k a -> MultiMap k aSource

Prepends a list of values onto the entry with the given key.

`>>>`

fromList [(5,"ab"),(7,"helloefg")]`insertList 7 "hello" $ fromList [(5, "ab"), (7, "efg")]`

insertManyLists :: Ord k => [(k, [a])] -> MultiMap k a -> MultiMap k aSource

Passes down the given list from left to right invoking `insertList`

.

lookup :: Ord k => k -> MultiMap k a -> [a]Source

Returns the list of values associated with the given key.

`>>>`

"aagf"`lookup 5 $ fromList [(1, "abc"), (5, "aagf"), (6, "c")]`

deleteList :: Ord k => k -> MultiMap k a -> MultiMap k aSource

Deletes all the values associated with the given key.

extractList :: Ord k => k -> MultiMap k a -> ([a], MultiMap k a)Source

Simultaneous lookup and deleteList.

extractEachListWithKey :: Ord k => MultiMap k a -> [((k, [a]), MultiMap k a)]Source

For each key that maps to a non-empty list of values, returns that key and its corresponding values as well as the multimap with those values removed. The keys are enumerated in ascending order.

alter :: Ord k => ([a] -> [a]) -> k -> MultiMap k a -> MultiMap k aSource

Modifies the list of values associated with a given key.

maxView :: MultiMap k a -> Maybe (a, MultiMap k a)Source

Returns `Nothing`

if the multimap is empty, otherwise returns the
first value associated with the maximal key of the multimap, and
the multimap stripped of that value.

`>>>`

Just ('e',fromList [(1,"ab"),(2,"fg")])`maxView $ fromList [(1, "ab"), (2, "efg")]`

elems :: MultiMap k a -> [a]Source

Returns all of the values in the multimap in ascending order of their keys.

`>>>`

"abaadfz"`elems $ fromList [(1, "aba"), (2, "adf"), (3, "z")]`

descElems :: MultiMap k a -> [a]Source

Returns all of the values in the multimap in descending order of
their keys. The values are enumerated in the same order as with `maxView`

.

`>>>`

"zadfaba"`descElems $ fromList [(1, "aba"), (2, "adf"), (3, "z")]`

assocs :: MultiMap k a -> [(k, a)]Source

Returns all of the key-value pairs in the multimap in ascending order of keys.

`>>>`

[(1,'a'),(1,'b'),(4,'c'),(4,'d'),(4,'a')]`assocs $ fromList [(1, "ab"), (4, "cda")]`

descAssocs :: MultiMap k a -> [(k, a)]Source

Returns all of the key-value pairs in the multimap in descending order
of keys. The values are enumerated in the same order as with `maxView`

.

`>>>`

[(4,'c'),(4,'d'),(4,'a'),(1,'a'),(1,'b')]`descAssocs (fromList [(1, "ab"), (4, "cda")])`