HORIZON HASKELLDocslts/ghc-10.0.xfc4e5982026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · fc4e598 · 2026-10-11

Modulemonoidal-containers-0.6.8.0Haskell2010

Data.HashMap.Monoidal

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

While some functions mirroring those of Data.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.

  • 1 type
  • 19 values
newtypenewtype MonoidalHashMap k a
#

A HashMap with monoidal accumulation

Instances36FoldableWithIndex, FunctorWithIndex, TraversableWithIndex, Functor, Foldable, Traversable, …

Often-needed functions

19 declarations
valuetoList :: 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.

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

valuefromListWith
  1. :: (Eq k, Hashable k)
  2. => a -> a -> a
  3. -> [(k, a)]
  4. -> 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.

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

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

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

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

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