unison-prelude-0.0.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Unison.Util.Map

Description

Map utilities.

Synopsis

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.

bimap :: Ord a' => (a -> a') -> (b -> b') -> Map a b -> Map a' b' Source #

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.

elemsSet :: Ord v => Map k v -> Set v Source #

Like elems, but return the values as a set.

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.

mergeMap Source #

Arguments

:: 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

upsert :: Ord k => (Maybe v -> v) -> k -> Map k v -> Map k v Source #

Upsert an element into a map.

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.

asList_ :: Ord k' => Traversal (Map k v) (Map k' v') [(k, v)] [(k', v')] Source #

Traverse a map as a list of key-value pairs. Note: This can have unexpected results if the result contains duplicate keys.