monoidal-containers-0.6.4.0: Containers with monoidal accumulation
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.HashMap.Monoidal

Description

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

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.

Synopsis

Documentation

newtype MonoidalHashMap k a Source #

A HashMap with monoidal accumulation

Constructors

MonoidalHashMap 

Instances

Instances details
(Eq k, Hashable k) => FoldableWithIndex k (MonoidalHashMap k) Source # 
Instance details

Defined in Data.HashMap.Monoidal

Methods

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

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

ifoldr :: (k -> a -> b -> b) -> b -> MonoidalHashMap k a -> b #

ifoldl :: (k -> b -> a -> b) -> b -> MonoidalHashMap k a -> b #

ifoldr' :: (k -> a -> b -> b) -> b -> MonoidalHashMap k a -> b #

ifoldl' :: (k -> b -> a -> b) -> b -> MonoidalHashMap k a -> b #

(Eq k, Hashable k) => FunctorWithIndex k (MonoidalHashMap k) Source # 
Instance details

Defined in Data.HashMap.Monoidal

Methods

imap :: (k -> a -> b) -> MonoidalHashMap k a -> MonoidalHashMap k b #

(Eq k, Hashable k) => TraversableWithIndex k (MonoidalHashMap k) Source # 
Instance details

Defined in Data.HashMap.Monoidal

Methods

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

Foldable (MonoidalHashMap k) Source # 
Instance details

Defined in Data.HashMap.Monoidal

Methods

fold :: Monoid m => MonoidalHashMap k m -> m #

foldMap :: Monoid m => (a -> m) -> MonoidalHashMap k a -> m #

foldMap' :: Monoid m => (a -> m) -> MonoidalHashMap k a -> m #

foldr :: (a -> b -> b) -> b -> MonoidalHashMap k a -> b #

foldr' :: (a -> b -> b) -> b -> MonoidalHashMap k a -> b #

foldl :: (b -> a -> b) -> b -> MonoidalHashMap k a -> b #

foldl' :: (b -> a -> b) -> b -> MonoidalHashMap k a -> b #

foldr1 :: (a -> a -> a) -> MonoidalHashMap k a -> a #

foldl1 :: (a -> a -> a) -> MonoidalHashMap k a -> a #

toList :: MonoidalHashMap k a -> [a] #

null :: MonoidalHashMap k a -> Bool #

length :: MonoidalHashMap k a -> Int #

elem :: Eq a => a -> MonoidalHashMap k a -> Bool #

maximum :: Ord a => MonoidalHashMap k a -> a #

minimum :: Ord a => MonoidalHashMap k a -> a #

sum :: Num a => MonoidalHashMap k a -> a #

product :: Num a => MonoidalHashMap k a -> a #

Eq k => Eq1 (MonoidalHashMap k) Source # 
Instance details

Defined in Data.HashMap.Monoidal

Methods

liftEq :: (a -> b -> Bool) -> MonoidalHashMap k a -> MonoidalHashMap k b -> Bool #

Traversable (MonoidalHashMap k) Source # 
Instance details

Defined in Data.HashMap.Monoidal

Methods

traverse :: Applicative f => (a -> f b) -> MonoidalHashMap k a -> f (MonoidalHashMap k b) #

sequenceA :: Applicative f => MonoidalHashMap k (f a) -> f (MonoidalHashMap k a) #

mapM :: Monad m => (a -> m b) -> MonoidalHashMap k a -> m (MonoidalHashMap k b) #

sequence :: Monad m => MonoidalHashMap k (m a) -> m (MonoidalHashMap k a) #

Functor (MonoidalHashMap k) Source # 
Instance details

Defined in Data.HashMap.Monoidal

Methods

fmap :: (a -> b) -> MonoidalHashMap k a -> MonoidalHashMap k b #

(<$) :: a -> MonoidalHashMap k b -> MonoidalHashMap k a #

Hashable k => Hashable1 (MonoidalHashMap k) Source # 
Instance details

Defined in Data.HashMap.Monoidal

Methods

liftHashWithSalt :: (Int -> a -> Int) -> Int -> MonoidalHashMap k a -> Int #

Hashable k => Align (MonoidalHashMap k) Source # 
Instance details

Defined in Data.HashMap.Monoidal

Methods

nil :: MonoidalHashMap k a #

Hashable k => Semialign (MonoidalHashMap k) Source # 
Instance details

Defined in Data.HashMap.Monoidal

Hashable k => Unalign (MonoidalHashMap k) Source # 
Instance details

Defined in Data.HashMap.Monoidal

Hashable k => Zip (MonoidalHashMap k) Source # 
Instance details

Defined in Data.HashMap.Monoidal

Methods

zip :: MonoidalHashMap k a -> MonoidalHashMap k b -> MonoidalHashMap k (a, b) #

zipWith :: (a -> b -> c) -> MonoidalHashMap k a -> MonoidalHashMap k b -> MonoidalHashMap k c #

Hashable k => Filterable (MonoidalHashMap k) Source # 
Instance details

Defined in Data.HashMap.Monoidal

(Eq k, Hashable k) => Witherable (MonoidalHashMap k) Source # 
Instance details

Defined in Data.HashMap.Monoidal

Methods

wither :: Applicative f => (a -> f (Maybe b)) -> MonoidalHashMap k a -> f (MonoidalHashMap k b) #

witherM :: Monad m => (a -> m (Maybe b)) -> MonoidalHashMap k a -> m (MonoidalHashMap k b) #

filterA :: Applicative f => (a -> f Bool) -> MonoidalHashMap k a -> f (MonoidalHashMap k a) #

witherMap :: Applicative m => (MonoidalHashMap k b -> r) -> (a -> m (Maybe b)) -> MonoidalHashMap k a -> m r #

(Data k, Data a, Hashable k) => Data (MonoidalHashMap k a) Source # 
Instance details

Defined in Data.HashMap.Monoidal

Methods

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

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

toConstr :: MonoidalHashMap k a -> Constr #

dataTypeOf :: MonoidalHashMap k a -> DataType #

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

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

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

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

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

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

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

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

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

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

(Eq k, Hashable k, Semigroup a) => Monoid (MonoidalHashMap k a) Source # 
Instance details

Defined in Data.HashMap.Monoidal

(Eq k, Hashable k, Semigroup a) => Semigroup (MonoidalHashMap k a) Source # 
Instance details

Defined in Data.HashMap.Monoidal

(Eq k, Hashable k, Semigroup a) => IsList (MonoidalHashMap k a) Source # 
Instance details

Defined in Data.HashMap.Monoidal

Associated Types

type Item (MonoidalHashMap k a) #

(Hashable k, Read k, Read a) => Read (MonoidalHashMap k a) Source # 
Instance details

Defined in Data.HashMap.Monoidal

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

Defined in Data.HashMap.Monoidal

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

Defined in Data.HashMap.Monoidal

Methods

rnf :: MonoidalHashMap k a -> () #

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

Defined in Data.HashMap.Monoidal

(Hashable k, Hashable a) => Hashable (MonoidalHashMap k a) Source # 
Instance details

Defined in Data.HashMap.Monoidal

(Eq k, Hashable k) => At (MonoidalHashMap k a) Source # 
Instance details

Defined in Data.HashMap.Monoidal

(Eq k, Hashable k) => Ixed (MonoidalHashMap k a) Source # 
Instance details

Defined in Data.HashMap.Monoidal

AsEmpty (MonoidalHashMap k a) Source # 
Instance details

Defined in Data.HashMap.Monoidal

Methods

_Empty :: Prism' (MonoidalHashMap k a) () #

Wrapped (MonoidalHashMap k a) Source # 
Instance details

Defined in Data.HashMap.Monoidal

Associated Types

type Unwrapped (MonoidalHashMap k a) #

(Eq k, Hashable k) => Rewrapped (MonoidalHashMap k a) (HashMap k a) Source # 
Instance details

Defined in Data.HashMap.Monoidal

(Eq k, Hashable k) => Rewrapped (HashMap k a) (MonoidalHashMap k a) Source # 
Instance details

Defined in Data.HashMap.Monoidal

Newtype (MonoidalHashMap k a) (HashMap k a) Source # 
Instance details

Defined in Data.HashMap.Monoidal

Methods

pack :: HashMap k a -> MonoidalHashMap k a #

unpack :: MonoidalHashMap k a -> HashMap k a #

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

Defined in Data.HashMap.Monoidal

Methods

each :: Traversal (MonoidalHashMap k a) (MonoidalHashMap k b) a b #

type Item (MonoidalHashMap k a) Source # 
Instance details

Defined in Data.HashMap.Monoidal

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

Defined in Data.HashMap.Monoidal

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

Defined in Data.HashMap.Monoidal

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

Defined in Data.HashMap.Monoidal

Often-needed functions

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

O(n*log n). Return a list of this map's elements. The list is produced lazily. The order of its elements is unspecified.

fromList :: (Eq k, Hashable k) => [(k, a)] -> MonoidalHashMap k a Source #

O(n*log n). Construct a map with the supplied mappings. If the list contains duplicate mappings, values will be replaced.

fromListWith :: (Eq k, Hashable k) => (a -> a -> a) -> [(k, a)] -> MonoidalHashMap k a Source #

O(n*log n). Construct a map with the supplied mappings. If the list contains duplicate mappings, values will be merged using the provided combining function.

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 a list of this map's values. The list is produced lazily.

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 :: (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, if it will result in duplicated mappings, their values will be merged in unspecified order

insert :: (Hashable k, Eq k) => k -> a -> MonoidalHashMap k a -> MonoidalHashMap k a Source #

O(log n). Insert a value on some key, if it exists replace the value.

insertWith :: (Hashable k, Eq k) => (a -> a -> a) -> k -> a -> MonoidalHashMap k a -> MonoidalHashMap k a Source #

O(log n). Insert a value on some key, if it exists apply the combining function.

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

map :: (v1 -> v2) -> MonoidalHashMap k v1 -> MonoidalHashMap k v2 Source #

O(n) Transform this map by applying a function to every value.

filterWithKey :: (k -> v -> Bool) -> MonoidalHashMap k v -> MonoidalHashMap k v Source #

O(n) Filter this map by retaining only elements satisfying a predicate.