monoidal-containers-0.6.5.0: Containers with monoidal accumulation

Safe Haskell | None
Language | Haskell2010

Data.HashMap.Monoidal

Contents

- Often-needed functions

Description

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

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

- newtype MonoidalHashMap k a = MonoidalHashMap {
  - getMonoidalHashMap :: HashMap k a
  }
- toList :: MonoidalHashMap k a -> [(k, a)]
- fromList :: (Eq k, Hashable k) => [(k, a)] -> MonoidalHashMap k a
- fromListWith :: (Eq k, Hashable k) => (a -> a -> a) -> [(k, a)] -> MonoidalHashMap k a
- singleton :: (Eq k, Hashable k) => k -> a -> MonoidalHashMap k a
- size :: MonoidalHashMap k a -> Int
- member :: (Eq k, Hashable k) => k -> MonoidalHashMap k a -> Bool
- notMember :: (Eq k, Hashable k) => k -> MonoidalHashMap k a -> Bool
- lookup :: (Eq k, Hashable k) => k -> MonoidalHashMap k v -> Maybe v
- lookupM :: (Eq k, Hashable k, Monoid v) => k -> MonoidalHashMap k v -> v
- elems :: MonoidalHashMap k a -> [a]
- keys :: MonoidalHashMap k a -> [k]
- delete :: (Eq k, Hashable k) => k -> MonoidalHashMap k a -> MonoidalHashMap k a
- mapKeys :: (Hashable k, Eq k, Hashable k', Eq k') => (k -> k') -> MonoidalHashMap k a -> MonoidalHashMap k' a
- insert :: (Hashable k, Eq k) => k -> a -> MonoidalHashMap k a -> MonoidalHashMap k a
- insertWith :: (Hashable k, Eq k) => (a -> a -> a) -> k -> a -> MonoidalHashMap k a -> MonoidalHashMap k a
- modify :: (Monoid a, Hashable k, Eq k) => (a -> a) -> k -> MonoidalHashMap k a -> MonoidalHashMap k a
- modifyDef :: (Hashable k, Eq k) => a -> (a -> a) -> k -> MonoidalHashMap k a -> MonoidalHashMap k a
- map :: (v1 -> v2) -> MonoidalHashMap k v1 -> MonoidalHashMap k v2
- filterWithKey :: (k -> v -> Bool) -> MonoidalHashMap k v -> MonoidalHashMap k v

# Documentation

newtype MonoidalHashMap k a #

A `HashMap` with monoidal accumulation

Constructors

MonoidalHashMap |

Fields

- getMonoidalHashMap :: HashMap k a

#### Instances

Instances details

(Eq k, Hashable k) => FoldableWithIndex k (MonoidalHashMap k) # |

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) # |
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) # |
Instance details Defined in Data.HashMap.Monoidal Methods itraverse :: Applicative f => (k -> a -> f b) -> MonoidalHashMap k a -> f (MonoidalHashMap k b) #
Eq k => Eq1 (MonoidalHashMap k) # |
Instance details Defined in Data.HashMap.Monoidal Methods liftEq :: (a -> b -> Bool) -> MonoidalHashMap k a -> MonoidalHashMap k b -> Bool #
Functor (MonoidalHashMap k) # |
Instance details Defined in Data.HashMap.Monoidal Methods fmap :: (a -> b) -> MonoidalHashMap k a -> MonoidalHashMap k b # (<$) :: a -> MonoidalHashMap k b -> MonoidalHashMap k a #
Foldable (MonoidalHashMap k) # |

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 #

Traversable (MonoidalHashMap k) # |
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) #
Hashable k => Hashable1 (MonoidalHashMap k) # |
Instance details Defined in Data.HashMap.Monoidal Methods liftHashWithSalt :: (Int -> a -> Int) -> Int -> MonoidalHashMap k a -> Int #
Hashable k => Align (MonoidalHashMap k) # |
Instance details Defined in Data.HashMap.Monoidal Methods nil :: MonoidalHashMap k a #
Hashable k => Semialign (MonoidalHashMap k) # |
Instance details Defined in Data.HashMap.Monoidal Methods align :: MonoidalHashMap k a -> MonoidalHashMap k b -> MonoidalHashMap k (These a b) # alignWith :: (These a b -> c) -> MonoidalHashMap k a -> MonoidalHashMap k b -> MonoidalHashMap k c #
Hashable k => Unalign (MonoidalHashMap k) # |
Instance details Defined in Data.HashMap.Monoidal Methods unalign :: MonoidalHashMap k (These a b) -> (MonoidalHashMap k a, MonoidalHashMap k b) # unalignWith :: (c -> These a b) -> MonoidalHashMap k c -> (MonoidalHashMap k a, MonoidalHashMap k b) #
Hashable k => Zip (MonoidalHashMap k) # |
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) # |
Instance details Defined in Data.HashMap.Monoidal Methods mapMaybe :: (a -> Maybe b) -> MonoidalHashMap k a -> MonoidalHashMap k b # catMaybes :: MonoidalHashMap k (Maybe a) -> MonoidalHashMap k a # filter :: (a -> Bool) -> MonoidalHashMap k a -> MonoidalHashMap k a # drain :: MonoidalHashMap k a -> MonoidalHashMap k b #
(Eq k, Hashable k) => Witherable (MonoidalHashMap k) # |

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 #

(NFData k, NFData a) => NFData (MonoidalHashMap k a) # |
Instance details Defined in Data.HashMap.Monoidal Methods rnf :: MonoidalHashMap k a -> () #
(Eq k, Hashable k, Semigroup a) => Monoid (MonoidalHashMap k a) # |
Instance details Defined in Data.HashMap.Monoidal Methods mempty :: MonoidalHashMap k a # mappend :: MonoidalHashMap k a -> MonoidalHashMap k a -> MonoidalHashMap k a # mconcat :: [MonoidalHashMap k a] -> MonoidalHashMap k a #
(Eq k, Hashable k, Semigroup a) => Semigroup (MonoidalHashMap k a) # |
Instance details Defined in Data.HashMap.Monoidal Methods (<>) :: MonoidalHashMap k a -> MonoidalHashMap k a -> MonoidalHashMap k a # sconcat :: NonEmpty (MonoidalHashMap k a) -> MonoidalHashMap k a # stimes :: Integral b => b -> MonoidalHashMap k a -> MonoidalHashMap k a #
(Data k, Data a, Hashable k) => Data (MonoidalHashMap k a) # |

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) => IsList (MonoidalHashMap k a) # |

Instance details

Defined in Data.HashMap.Monoidal

Associated Types

type Item (MonoidalHashMap k a) |
Instance details Defined in Data.HashMap.Monoidal type Item (MonoidalHashMap k a) = (k, a)

Methods

fromList :: [Item (MonoidalHashMap k a)] -> MonoidalHashMap k a #

fromListN :: Int -> [Item (MonoidalHashMap k a)] -> MonoidalHashMap k a #

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

(Hashable k, Read k, Read a) => Read (MonoidalHashMap k a) # |
Instance details Defined in Data.HashMap.Monoidal Methods readsPrec :: Int -> ReadS (MonoidalHashMap k a) # readList :: ReadS [MonoidalHashMap k a] # readPrec :: ReadPrec (MonoidalHashMap k a) # readListPrec :: ReadPrec [MonoidalHashMap k a] #
(Show k, Show a) => Show (MonoidalHashMap k a) # |
Instance details Defined in Data.HashMap.Monoidal Methods showsPrec :: Int -> MonoidalHashMap k a -> ShowS # show :: MonoidalHashMap k a -> String # showList :: [MonoidalHashMap k a] -> ShowS #
(Eq k, Eq a) => Eq (MonoidalHashMap k a) # |
Instance details Defined in Data.HashMap.Monoidal Methods (==) :: MonoidalHashMap k a -> MonoidalHashMap k a -> Bool # (/=) :: MonoidalHashMap k a -> MonoidalHashMap k a -> Bool #
(Hashable k, Hashable a) => Hashable (MonoidalHashMap k a) # |
Instance details Defined in Data.HashMap.Monoidal Methods hashWithSalt :: Int -> MonoidalHashMap k a -> Int # hash :: MonoidalHashMap k a -> Int #
(Eq k, Hashable k) => At (MonoidalHashMap k a) # |
Instance details Defined in Data.HashMap.Monoidal Methods at :: Index (MonoidalHashMap k a) -> Lens' (MonoidalHashMap k a) (Maybe (IxValue (MonoidalHashMap k a))) #
(Eq k, Hashable k) => Ixed (MonoidalHashMap k a) # |
Instance details Defined in Data.HashMap.Monoidal Methods ix :: Index (MonoidalHashMap k a) -> Traversal' (MonoidalHashMap k a) (IxValue (MonoidalHashMap k a)) #
AsEmpty (MonoidalHashMap k a) # |
Instance details Defined in Data.HashMap.Monoidal Methods _Empty :: Prism' (MonoidalHashMap k a) () #
Wrapped (MonoidalHashMap k a) # |

Instance details

Defined in Data.HashMap.Monoidal

Associated Types

type Unwrapped (MonoidalHashMap k a) |
Instance details Defined in Data.HashMap.Monoidal type Unwrapped (MonoidalHashMap k a) = HashMap k a

Methods

_Wrapped' :: Iso' (MonoidalHashMap k a) (Unwrapped (MonoidalHashMap k a)) #

(Eq k, Hashable k) => Rewrapped (MonoidalHashMap k a) (HashMap k a) # |
Instance details Defined in Data.HashMap.Monoidal
(Eq k, Hashable k) => Rewrapped (HashMap k a) (MonoidalHashMap k a) # |
Instance details Defined in Data.HashMap.Monoidal
Newtype (MonoidalHashMap k a) (HashMap k a) # |
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 # |
Instance details Defined in Data.HashMap.Monoidal Methods each :: Traversal (MonoidalHashMap k a) (MonoidalHashMap k b) a b #
type Item (MonoidalHashMap k a) # |
Instance details Defined in Data.HashMap.Monoidal type Item (MonoidalHashMap k a) = (k, a)
type Index (MonoidalHashMap k a) # |
Instance details Defined in Data.HashMap.Monoidal type Index (MonoidalHashMap k a) = k
type IxValue (MonoidalHashMap k a) # |
Instance details Defined in Data.HashMap.Monoidal type IxValue (MonoidalHashMap k a) = a
type Unwrapped (MonoidalHashMap k a) # |
Instance details Defined in Data.HashMap.Monoidal type Unwrapped (MonoidalHashMap k a) = HashMap k a

# Often-needed functions

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

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 #

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 #

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 #

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

size :: MonoidalHashMap k a -> Int #

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

member :: (Eq k, Hashable k) => k -> MonoidalHashMap k a -> Bool #

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

notMember :: (Eq k, Hashable k) => k -> MonoidalHashMap k a -> Bool #

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 #

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 #

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] #

O(n). Return a list of this map's values. The list is produced lazily.

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

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 #

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 #

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 #

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 #

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 #

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 #

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 #

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

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

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