monoidal-containers-0.6.3.0: Containers with monoidal accumulation
Safe Haskell None
Language Haskell2010

Data.Map.Monoidal.Strict

Description

This module provides a Map variant which uses the value's Monoid instance to accumulate conflicting entries when merging Map s.

While some functions mirroring those of Map are provided here for convenience, more specialized needs will likely want to use either the Newtype or Wrapped instances to manipulate the underlying Map .

Synopsis

Documentation

newtype MonoidalMap k a Source #

A Map with monoidal accumulation

Constructors

MonoidalMap

Instances

Instances details
FunctorWithIndex k ( MonoidalMap k) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

Methods

imap :: (k -> a -> b) -> MonoidalMap k a -> MonoidalMap k b Source #

FoldableWithIndex k ( MonoidalMap k) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

Methods

ifoldMap :: Monoid m => (k -> a -> m) -> MonoidalMap k a -> m Source #

ifoldMap' :: Monoid m => (k -> a -> m) -> MonoidalMap k a -> m Source #

ifoldr :: (k -> a -> b -> b) -> b -> MonoidalMap k a -> b Source #

ifoldl :: (k -> b -> a -> b) -> b -> MonoidalMap k a -> b Source #

ifoldr' :: (k -> a -> b -> b) -> b -> MonoidalMap k a -> b Source #

ifoldl' :: (k -> b -> a -> b) -> b -> MonoidalMap k a -> b Source #

TraversableWithIndex k ( MonoidalMap k) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

Methods

itraverse :: Applicative f => (k -> a -> f b) -> MonoidalMap k a -> f ( MonoidalMap k b) Source #

Ord k => TraverseMin k ( MonoidalMap k) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

Ord k => TraverseMax k ( MonoidalMap k) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

Functor ( MonoidalMap k) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

Foldable ( MonoidalMap k) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

Traversable ( MonoidalMap k) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

ToJSONKey k => ToJSON1 ( MonoidalMap k) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

( FromJSONKey k, Ord k) => FromJSON1 ( MonoidalMap k) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

Ord k => Eq1 ( MonoidalMap k) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

Ord k => Ord1 ( MonoidalMap k) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

Show k => Show1 ( MonoidalMap k) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

Ord k => Semialign ( MonoidalMap k) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

Ord k => Align ( MonoidalMap k) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

Ord k => Unalign ( MonoidalMap k) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

Ord k => Zip ( MonoidalMap k) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

Filterable ( MonoidalMap k) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

Ord k => Witherable ( MonoidalMap k) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

( Ord k, Semigroup a) => IsList ( MonoidalMap k a) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

Associated Types

type Item ( MonoidalMap k a) Source #

( Eq k, Eq a) => Eq ( MonoidalMap k a) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

( Data k, Data a, Ord k) => Data ( MonoidalMap k a) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

Methods

gfoldl :: ( forall d b. Data d => c (d -> b) -> d -> c b) -> ( forall g. g -> c g) -> MonoidalMap k a -> c ( MonoidalMap k a) Source #

gunfold :: ( forall b r. Data b => c (b -> r) -> c r) -> ( forall r. r -> c r) -> Constr -> c ( MonoidalMap k a) Source #

toConstr :: MonoidalMap k a -> Constr Source #

dataTypeOf :: MonoidalMap k a -> DataType Source #

dataCast1 :: Typeable t => ( forall d. Data d => c (t d)) -> Maybe (c ( MonoidalMap k a)) Source #

dataCast2 :: Typeable t => ( forall d e. ( Data d, Data e) => c (t d e)) -> Maybe (c ( MonoidalMap k a)) Source #

gmapT :: ( forall b. Data b => b -> b) -> MonoidalMap k a -> MonoidalMap k a Source #

gmapQl :: (r -> r' -> r) -> r -> ( forall d. Data d => d -> r') -> MonoidalMap k a -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> ( forall d. Data d => d -> r') -> MonoidalMap k a -> r Source #

gmapQ :: ( forall d. Data d => d -> u) -> MonoidalMap k a -> [u] Source #

gmapQi :: Int -> ( forall d. Data d => d -> u) -> MonoidalMap k a -> u Source #

gmapM :: Monad m => ( forall d. Data d => d -> m d) -> MonoidalMap k a -> m ( MonoidalMap k a) Source #

gmapMp :: MonadPlus m => ( forall d. Data d => d -> m d) -> MonoidalMap k a -> m ( MonoidalMap k a) Source #

gmapMo :: MonadPlus m => ( forall d. Data d => d -> m d) -> MonoidalMap k a -> m ( MonoidalMap k a) Source #

( Ord k, Ord a) => Ord ( MonoidalMap k a) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

( Ord k, Read k, Read a) => Read ( MonoidalMap k a) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

( Show k, Show a) => Show ( MonoidalMap k a) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

( Ord k, Semigroup a) => Semigroup ( MonoidalMap k a) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

( Ord k, Semigroup a) => Monoid ( MonoidalMap k a) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

( ToJSON a, ToJSONKey k) => ToJSON ( MonoidalMap k a) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

( FromJSONKey k, Ord k, FromJSON a) => FromJSON ( MonoidalMap k a) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

( NFData k, NFData a) => NFData ( MonoidalMap k a) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

Ord k => Ixed ( MonoidalMap k a) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

Ord k => At ( MonoidalMap k a) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

Wrapped ( MonoidalMap k a) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

Associated Types

type Unwrapped ( MonoidalMap k a) Source #

AsEmpty ( MonoidalMap k a) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

Ord k => Rewrapped ( Map k a) ( MonoidalMap k a) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

Ord k => Rewrapped ( MonoidalMap k a) ( Map k a) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

Newtype ( MonoidalMap k a) ( Map k a) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

Each ( MonoidalMap k a) ( MonoidalMap k b) a b Source #
Instance details

Defined in Data.Map.Monoidal.Strict

type Item ( MonoidalMap k a) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

type Item ( MonoidalMap k a) = (k, a)
type Index ( MonoidalMap k a) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

type Index ( MonoidalMap k a) = k
type IxValue ( MonoidalMap k a) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

type IxValue ( MonoidalMap k a) = a
type Unwrapped ( MonoidalMap k a) Source #
Instance details

Defined in Data.Map.Monoidal.Strict

Often-needed functions

singleton :: k -> a -> MonoidalMap k a Source #

O(1) . A map with a single element.

size :: MonoidalMap k a -> Int Source #

O(1) . The number of elements in the map.

member :: Ord k => k -> MonoidalMap k a -> Bool Source #

O(log n) . Is the key a member of the map? See also notMember .

notMember :: Ord k => k -> MonoidalMap k a -> Bool Source #

O(log n) . Is the key not a member of the map? See also member .

findWithDefault :: Ord k => a -> k -> MonoidalMap k a -> a Source #

O(log n) . The expression ( findWithDefault def k map) returns the value at key k or returns default value def when the key is not in the map.

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

O(n) . Return all elements of the map and their keys

elems :: MonoidalMap k a -> [a] Source #

O(n) . Return all elements of the map in the ascending order of their keys. Subject to list fusion.

keys :: MonoidalMap k a -> [k] Source #

O(n) . Return all keys of the map in ascending order. Subject to list fusion.

(!?) :: forall k a. Ord k => MonoidalMap k a -> k -> Maybe a infixl 9 Source #

(!) :: forall k a. Ord k => MonoidalMap k a -> k -> a infixl 9 Source #

(\\) :: forall k a b. Ord k => MonoidalMap k a -> MonoidalMap k b -> MonoidalMap k a infixl 9 Source #

adjust :: forall k a. Ord k => (a -> a) -> k -> MonoidalMap k a -> MonoidalMap k a Source #

adjustWithKey :: forall k a. Ord k => (k -> a -> a) -> k -> MonoidalMap k a -> MonoidalMap k a Source #

alter :: forall k a. Ord k => ( Maybe a -> Maybe a) -> k -> MonoidalMap k a -> MonoidalMap k a Source #

delete :: Ord k => k -> MonoidalMap k a -> MonoidalMap 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.

differenceWithKey :: forall k a b. Ord k => (k -> a -> b -> Maybe a) -> MonoidalMap k a -> MonoidalMap k b -> MonoidalMap k a Source #

elemAt :: forall k a. Int -> MonoidalMap k a -> (k, a) Source #

findMax :: forall k a. MonoidalMap k a -> (k, a) Source #

findMin :: forall k a. MonoidalMap k a -> (k, a) Source #

foldMapWithKey :: forall k a m. Monoid m => (k -> a -> m) -> MonoidalMap k a -> m Source #

foldl :: forall k a b. (a -> b -> a) -> a -> MonoidalMap k b -> a Source #

foldl' :: forall k a b. (a -> b -> a) -> a -> MonoidalMap k b -> a Source #

foldlWithKey :: forall k a b. (a -> k -> b -> a) -> a -> MonoidalMap k b -> a Source #

foldlWithKey' :: forall k a b. (a -> k -> b -> a) -> a -> MonoidalMap k b -> a Source #

foldr :: forall k a b. (a -> b -> b) -> b -> MonoidalMap k a -> b Source #

foldr' :: forall k a b. (a -> b -> b) -> b -> MonoidalMap k a -> b Source #

foldrWithKey :: forall k a b. (k -> a -> b -> b) -> b -> MonoidalMap k a -> b Source #

foldrWithKey' :: forall k a b. (k -> a -> b -> b) -> b -> MonoidalMap k a -> b Source #

fromAscList :: forall k a. Eq k => [(k, a)] -> MonoidalMap k a Source #

fromAscListWith :: forall k a. Eq k => (a -> a -> a) -> [(k, a)] -> MonoidalMap k a Source #

fromAscListWithKey :: forall k a. Eq k => (k -> a -> a -> a) -> [(k, a)] -> MonoidalMap k a Source #

fromDistinctList :: forall k a. Ord k => [(k, a)] -> MonoidalMap k a Source #

fromDescList :: forall k a. Eq k => [(k, a)] -> MonoidalMap k a Source #

fromDescListWith :: forall k a. Eq k => (a -> a -> a) -> [(k, a)] -> MonoidalMap k a Source #

fromDescListWithKey :: forall k a. Eq k => (k -> a -> a -> a) -> [(k, a)] -> MonoidalMap k a Source #

fromList :: forall k a. Ord k => [(k, a)] -> MonoidalMap k a Source #

fromListWith :: forall k a. Ord k => (a -> a -> a) -> [(k, a)] -> MonoidalMap k a Source #

fromListWithKey :: forall k a. Ord k => (k -> a -> a -> a) -> [(k, a)] -> MonoidalMap k a Source #

fromSet :: forall k a. (k -> a) -> Set k -> MonoidalMap k a Source #

insert :: forall k a. Ord k => k -> a -> MonoidalMap k a -> MonoidalMap k a Source #

insertLookupWithKey :: forall k a. Ord k => (k -> a -> a -> a) -> k -> a -> MonoidalMap k a -> ( Maybe a, MonoidalMap k a) Source #

insertWith :: forall k a. Ord k => (a -> a -> a) -> k -> a -> MonoidalMap k a -> MonoidalMap k a Source #

insertWithKey :: forall k a. Ord k => (k -> a -> a -> a) -> k -> a -> MonoidalMap k a -> MonoidalMap k a Source #

intersectionWith :: forall k a b c. Ord k => (a -> b -> c) -> MonoidalMap k a -> MonoidalMap k b -> MonoidalMap k c Source #

intersectionWithKey :: forall k a b c. Ord k => (k -> a -> b -> c) -> MonoidalMap k a -> MonoidalMap k b -> MonoidalMap k c Source #

lookupGE :: forall k a. Ord k => k -> MonoidalMap k a -> Maybe (k, a) Source #

lookupGT :: forall k a. Ord k => k -> MonoidalMap k a -> Maybe (k, a) Source #

lookupLE :: forall k a. Ord k => k -> MonoidalMap k a -> Maybe (k, a) Source #

lookupLT :: forall k a. Ord k => k -> MonoidalMap k a -> Maybe (k, a) Source #

mapAccum :: forall k a b c. (a -> b -> (a, c)) -> a -> MonoidalMap k b -> (a, MonoidalMap k c) Source #

mapAccumRWithKey :: forall k a b c. (a -> k -> b -> (a, c)) -> a -> MonoidalMap k b -> (a, MonoidalMap k c) Source #

mapAccumWithKey :: forall k a b c. (a -> k -> b -> (a, c)) -> a -> MonoidalMap k b -> (a, MonoidalMap k c) Source #

mapEither :: forall k a b c. (a -> Either b c) -> MonoidalMap k a -> ( MonoidalMap k b, MonoidalMap k c) Source #

mapEitherWithKey :: forall k a b c. (k -> a -> Either b c) -> MonoidalMap k a -> ( MonoidalMap k b, MonoidalMap k c) Source #

mapKeys :: forall k1 k2 a. Ord k2 => (k1 -> k2) -> MonoidalMap k1 a -> MonoidalMap k2 a Source #

mapKeysMonotonic :: forall k1 k2 a. (k1 -> k2) -> MonoidalMap k1 a -> MonoidalMap k2 a Source #

O(n) . mapKeysMonotonic f s == mapKeys f s , but works only when f is strictly increasing (both monotonic and injective). That is, for any values x and y , if x < y then f x < f y and f is injective (i.e. it never maps two input keys to the same output key). The precondition is not checked. Semi-formally, we have:

and [x < y ==> f x < f y | x <- ls, y <- ls]
                    ==> mapKeysMonotonic f s == mapKeys f s
    where ls = keys s

This means that f maps distinct original keys to distinct resulting keys. This function has better performance than mapKeys .

mapKeysMonotonic (\ k -> k * 2) (fromList [(5,"a"), (3,"b")]) == fromList [(6, "b"), (10, "a")]
valid (mapKeysMonotonic (\ k -> k * 2) (fromList [(5,"a"), (3,"b")])) == True
valid (mapKeysMonotonic (\ _ -> 1)     (fromList [(5,"a"), (3,"b")])) == False

mapKeysWith :: forall k1 k2 a. Ord k2 => (a -> a -> a) -> (k1 -> k2) -> MonoidalMap k1 a -> MonoidalMap k2 a Source #

mapWithKey :: forall k a b. (k -> a -> b) -> MonoidalMap k a -> MonoidalMap k b Source #

mergeWithKey :: forall k a b c. Ord k => (k -> a -> b -> Maybe c) -> ( MonoidalMap k a -> MonoidalMap k c) -> ( MonoidalMap k b -> MonoidalMap k c) -> MonoidalMap k a -> MonoidalMap k b -> MonoidalMap k c Source #

toAscList :: forall k a. MonoidalMap k a -> [(k, a)] Source #

toDescList :: forall k a. MonoidalMap k a -> [(k, a)] Source #

toList :: forall k a. MonoidalMap k a -> [(k, a)] Source #

traverseMaybeWithKey :: forall f k a b. Applicative f => (k -> a -> f ( Maybe b)) -> MonoidalMap k a -> f ( MonoidalMap k b) Source #

unionWith :: forall k a. Ord k => (a -> a -> a) -> MonoidalMap k a -> MonoidalMap k a -> MonoidalMap k a Source #

unionWithKey :: forall k a. Ord k => (k -> a -> a -> a) -> MonoidalMap k a -> MonoidalMap k a -> MonoidalMap k a Source #

unionsWith :: forall k a. Ord k => (a -> a -> a) -> [ MonoidalMap k a] -> MonoidalMap k a Source #

update :: forall k a. Ord k => (a -> Maybe a) -> k -> MonoidalMap k a -> MonoidalMap k a Source #

updateAt :: forall k a. (k -> a -> Maybe a) -> Int -> MonoidalMap k a -> MonoidalMap k a Source #

updateLookupWithKey :: forall k a. Ord k => (k -> a -> Maybe a) -> k -> MonoidalMap k a -> ( Maybe a, MonoidalMap k a) Source #

updateWithKey :: forall k a. Ord k => (k -> a -> Maybe a) -> k -> MonoidalMap k a -> MonoidalMap k a Source #