Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Map
utilities.
Synopsis
- alignWithKey :: Ord k => (k -> These a b -> c) -> Map k a -> Map k b -> Map k c
- bimap :: Ord a' => (a -> a') -> (b -> b') -> Map a b -> Map a' b'
- bitraverse :: (Applicative f, Ord a') => (a -> f a') -> (b -> f b') -> Map a b -> f (Map a' b')
- bitraversed :: (Ord a', Ord k') => Traversal k k' a a' -> Traversal v v' a a' -> Traversal (Map k v) (Map k' v') a a'
- deleteLookup :: Ord k => k -> Map k v -> (Maybe v, Map k v)
- deleteLookupJust :: (HasCallStack, Ord k) => k -> Map k v -> (v, Map k v)
- elemsSet :: Ord v => Map k v -> Set v
- foldM :: Monad m => (acc -> k -> v -> m acc) -> acc -> Map k v -> m acc
- foldMapM :: (Ord k, Monad m, Foldable t) => (a -> m (k, v)) -> t a -> m (Map k v)
- for_ :: Monad m => Map k v -> (k -> v -> m ()) -> m ()
- insertLookup :: Ord k => k -> v -> Map k v -> (Maybe v, Map k v)
- invert :: Ord v => Map k v -> Map v k
- mergeMap :: forall a b k m. (Monoid m, Ord k) => (k -> a -> m) -> (k -> b -> m) -> (k -> a -> b -> m) -> Map k a -> Map k b -> m
- unionWithM :: forall m k a. (Monad m, Ord k) => (a -> a -> m a) -> Map k a -> Map k a -> m (Map k a)
- remap :: Ord k1 => ((k0, v0) -> (k1, v1)) -> Map k0 v0 -> Map k1 v1
- traverseKeys :: (Applicative f, Ord k') => (k -> f k') -> Map k v -> f (Map k' v)
- traverseKeysWith :: (Applicative f, Ord k') => (v -> v -> v) -> (k -> f k') -> Map k v -> f (Map k' v)
- swap :: Ord b => Map a b -> Map b a
- upsert :: Ord k => (Maybe v -> v) -> k -> Map k v -> Map k v
- upsertF :: (Functor f, Ord k) => (Maybe v -> f v) -> k -> Map k v -> f (Map k v)
- upsertLookup :: Ord k => (Maybe v -> v) -> k -> Map k v -> (Maybe v, Map k v)
- valuesVector :: Map k v -> Vector v
- asList_ :: Ord k' => Traversal (Map k v) (Map k' v') [(k, v)] [(k', v')]
Documentation
alignWithKey :: Ord k => (k -> These a b -> c) -> Map k a -> Map k b -> Map k c Source #
A common case of Map.merge
. Like alignWith
, but includes the key.
bitraverse :: (Applicative f, Ord a') => (a -> f a') -> (b -> f b') -> Map a b -> f (Map a' b') Source #
bitraversed :: (Ord a', Ord k') => Traversal k k' a a' -> Traversal v v' a a' -> Traversal (Map k v) (Map k' v') a a' Source #
deleteLookup :: Ord k => k -> Map k v -> (Maybe v, Map k v) Source #
Like delete
, but returns the value as well.
deleteLookupJust :: (HasCallStack, Ord k) => k -> Map k v -> (v, Map k v) Source #
Like deleteLookup
, but asserts the value is in the map prior to deletion.
foldM :: Monad m => (acc -> k -> v -> m acc) -> acc -> Map k v -> m acc Source #
Like foldlWithKey'
, but with a monadic accumulator.
foldMapM :: (Ord k, Monad m, Foldable t) => (a -> m (k, v)) -> t a -> m (Map k v) Source #
Construct a map from a foldable container by mapping each element to monadic action that returns a key and a value.
The map is constructed from the left: if two elements map to the same key, the second will overwrite the first.
for_ :: Monad m => Map k v -> (k -> v -> m ()) -> m () Source #
Run a monadic action for each key/value pair in a map.
insertLookup :: Ord k => k -> v -> Map k v -> (Maybe v, Map k v) Source #
Like insert
, but returns the old value as well.
invert :: Ord v => Map k v -> Map v k Source #
Invert a map's keys and values. This probably only makes sense with injective maps, but otherwise, later key/value pairs (ordered by the original map's keys) overwrite earlier ones.
:: forall a b k m. (Monoid m, Ord k) | |
=> (k -> a -> m) | Function to apply when a key exists in the first map, but not the second. |
-> (k -> b -> m) | Function to apply when a key exists in the second map, but not the first. |
-> (k -> a -> b -> m) | Function to apply when a key exists in both maps. |
-> Map k a | |
-> Map k b | |
-> m |
mergeMap
is like a foldMap
version of merge
: summarize the merging of two maps together as a monoidal value.
unionWithM :: forall m k a. (Monad m, Ord k) => (a -> a -> m a) -> Map k a -> Map k a -> m (Map k a) Source #
remap :: Ord k1 => ((k0, v0) -> (k1, v1)) -> Map k0 v0 -> Map k1 v1 Source #
Reconstruct a map entirely, given a function from old keyvalue to new keyvalue.
remap f = Map.fromList . map f . Map.toList
traverseKeys :: (Applicative f, Ord k') => (k -> f k') -> Map k v -> f (Map k' v) Source #
traverseKeysWith :: (Applicative f, Ord k') => (v -> v -> v) -> (k -> f k') -> Map k v -> f (Map k' v) Source #
swap :: Ord b => Map a b -> Map b a Source #
swap
throws away data if the input contains duplicate values
upsertF :: (Functor f, Ord k) => (Maybe v -> f v) -> k -> Map k v -> f (Map k v) Source #
Upsert an element into a map.
upsertLookup :: Ord k => (Maybe v -> v) -> k -> Map k v -> (Maybe v, Map k v) Source #
Like upsert
, but returns the old value as well.
valuesVector :: Map k v -> Vector v Source #