{-# LANGUAGE CPP #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE DeriveDataTypeable #-}

-- | This module provides a 'Data.HashMap' variant which uses the value's
-- 'Monoid' instance to accumulate conflicting entries when merging
-- 'Map's.
--
-- 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'.

module Data.HashMap.Monoidal
    ( MonoidalHashMap(..)
      -- * Often-needed functions
    , toList
    , fromList
    , fromListWith
    , singleton
    , size
    , member
    , notMember
    , lookup
    , lookupM
    , elems
    , keys
    , delete
    , mapKeys
    , insert
    , insertWith
    , modify
    , modifyDef
    , map
    , filterWithKey
    ) where

import Prelude hiding (lookup, map)
import Data.Maybe (fromMaybe)
import Data.Semigroup
import Data.Foldable (Foldable)
import Control.Applicative (pure)
import Data.Data (Data)
import Data.Typeable (Typeable)

#if MIN_VERSION_base(4,7,0)
import qualified GHC.Exts as Exts
#endif

#if MIN_VERSION_base(4,9,0)
import Data.Functor.Classes (Eq1)
#endif

import Control.DeepSeq
import qualified Data.HashMap.Strict as M
import Data.Hashable (Hashable)
#if MIN_VERSION_unordered_containers(0,2,8)
import Data.Hashable.Lifted (Hashable1)
#endif
import Control.Lens
import Control.Newtype
import Data.Align
#ifdef MIN_VERSION_semialign
import Data.Semialign (Unalign)
#if MIN_VERSION_semialign(1,1,0)
import Data.Zip (Zip)
#endif
#endif
import qualified Witherable

-- | A 'HashMap' with monoidal accumulation
newtype MonoidalHashMap k a = MonoidalHashMap { forall k a. MonoidalHashMap k a -> HashMap k a
getMonoidalHashMap :: M.HashMap k a }
    deriving ( Int -> MonoidalHashMap k a -> ShowS
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k a. (Show k, Show a) => Int -> MonoidalHashMap k a -> ShowS
forall k a. (Show k, Show a) => [MonoidalHashMap k a] -> ShowS
forall k a. (Show k, Show a) => MonoidalHashMap k a -> String
showList :: [MonoidalHashMap k a] -> ShowS
$cshowList :: forall k a. (Show k, Show a) => [MonoidalHashMap k a] -> ShowS
show :: MonoidalHashMap k a -> String
$cshow :: forall k a. (Show k, Show a) => MonoidalHashMap k a -> String
showsPrec :: Int -> MonoidalHashMap k a -> ShowS
$cshowsPrec :: forall k a. (Show k, Show a) => Int -> MonoidalHashMap k a -> ShowS
Show, ReadPrec [MonoidalHashMap k a]
ReadPrec (MonoidalHashMap k a)
ReadS [MonoidalHashMap k a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall k a.
(Hashable k, Read k, Read a) =>
ReadPrec [MonoidalHashMap k a]
forall k a.
(Hashable k, Read k, Read a) =>
ReadPrec (MonoidalHashMap k a)
forall k a.
(Hashable k, Read k, Read a) =>
Int -> ReadS (MonoidalHashMap k a)
forall k a.
(Hashable k, Read k, Read a) =>
ReadS [MonoidalHashMap k a]
readListPrec :: ReadPrec [MonoidalHashMap k a]
$creadListPrec :: forall k a.
(Hashable k, Read k, Read a) =>
ReadPrec [MonoidalHashMap k a]
readPrec :: ReadPrec (MonoidalHashMap k a)
$creadPrec :: forall k a.
(Hashable k, Read k, Read a) =>
ReadPrec (MonoidalHashMap k a)
readList :: ReadS [MonoidalHashMap k a]
$creadList :: forall k a.
(Hashable k, Read k, Read a) =>
ReadS [MonoidalHashMap k a]
readsPrec :: Int -> ReadS (MonoidalHashMap k a)
$creadsPrec :: forall k a.
(Hashable k, Read k, Read a) =>
Int -> ReadS (MonoidalHashMap k a)
Read, forall a b. a -> MonoidalHashMap k b -> MonoidalHashMap k a
forall a b. (a -> b) -> MonoidalHashMap k a -> MonoidalHashMap k b
forall k a b. a -> MonoidalHashMap k b -> MonoidalHashMap k a
forall k a b.
(a -> b) -> MonoidalHashMap k a -> MonoidalHashMap k b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> MonoidalHashMap k b -> MonoidalHashMap k a
$c<$ :: forall k a b. a -> MonoidalHashMap k b -> MonoidalHashMap k a
fmap :: forall a b. (a -> b) -> MonoidalHashMap k a -> MonoidalHashMap k b
$cfmap :: forall k a b.
(a -> b) -> MonoidalHashMap k a -> MonoidalHashMap k b
Functor, MonoidalHashMap k a -> MonoidalHashMap k a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall k a.
(Eq k, Eq a) =>
MonoidalHashMap k a -> MonoidalHashMap k a -> Bool
/= :: MonoidalHashMap k a -> MonoidalHashMap k a -> Bool
$c/= :: forall k a.
(Eq k, Eq a) =>
MonoidalHashMap k a -> MonoidalHashMap k a -> Bool
== :: MonoidalHashMap k a -> MonoidalHashMap k a -> Bool
$c== :: forall k a.
(Eq k, Eq a) =>
MonoidalHashMap k a -> MonoidalHashMap k a -> Bool
Eq, MonoidalHashMap k a -> ()
forall a. (a -> ()) -> NFData a
forall k a. (NFData k, NFData a) => MonoidalHashMap k a -> ()
rnf :: MonoidalHashMap k a -> ()
$crnf :: forall k a. (NFData k, NFData a) => MonoidalHashMap k a -> ()
NFData
             , forall a. Eq a => a -> MonoidalHashMap k a -> Bool
forall a. Num a => MonoidalHashMap k a -> a
forall a. Ord a => MonoidalHashMap k a -> a
forall m. Monoid m => MonoidalHashMap k m -> m
forall a. MonoidalHashMap k a -> Bool
forall a. MonoidalHashMap k a -> Int
forall a. MonoidalHashMap k a -> [a]
forall a. (a -> a -> a) -> MonoidalHashMap k a -> a
forall k a. Eq a => a -> MonoidalHashMap k a -> Bool
forall k a. Num a => MonoidalHashMap k a -> a
forall k a. Ord a => MonoidalHashMap k a -> a
forall m a. Monoid m => (a -> m) -> MonoidalHashMap k a -> m
forall k m. Monoid m => MonoidalHashMap k m -> m
forall k a. MonoidalHashMap k a -> Bool
forall k a. MonoidalHashMap k a -> Int
forall k a. MonoidalHashMap k a -> [a]
forall b a. (b -> a -> b) -> b -> MonoidalHashMap k a -> b
forall a b. (a -> b -> b) -> b -> MonoidalHashMap k a -> b
forall k a. (a -> a -> a) -> MonoidalHashMap k a -> a
forall k m a. Monoid m => (a -> m) -> MonoidalHashMap k a -> m
forall k b a. (b -> a -> b) -> b -> MonoidalHashMap k a -> b
forall k a b. (a -> b -> b) -> b -> MonoidalHashMap k a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: forall a. Num a => MonoidalHashMap k a -> a
$cproduct :: forall k a. Num a => MonoidalHashMap k a -> a
sum :: forall a. Num a => MonoidalHashMap k a -> a
$csum :: forall k a. Num a => MonoidalHashMap k a -> a
minimum :: forall a. Ord a => MonoidalHashMap k a -> a
$cminimum :: forall k a. Ord a => MonoidalHashMap k a -> a
maximum :: forall a. Ord a => MonoidalHashMap k a -> a
$cmaximum :: forall k a. Ord a => MonoidalHashMap k a -> a
elem :: forall a. Eq a => a -> MonoidalHashMap k a -> Bool
$celem :: forall k a. Eq a => a -> MonoidalHashMap k a -> Bool
length :: forall a. MonoidalHashMap k a -> Int
$clength :: forall k a. MonoidalHashMap k a -> Int
null :: forall a. MonoidalHashMap k a -> Bool
$cnull :: forall k a. MonoidalHashMap k a -> Bool
toList :: forall a. MonoidalHashMap k a -> [a]
$ctoList :: forall k a. MonoidalHashMap k a -> [a]
foldl1 :: forall a. (a -> a -> a) -> MonoidalHashMap k a -> a
$cfoldl1 :: forall k a. (a -> a -> a) -> MonoidalHashMap k a -> a
foldr1 :: forall a. (a -> a -> a) -> MonoidalHashMap k a -> a
$cfoldr1 :: forall k a. (a -> a -> a) -> MonoidalHashMap k a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> MonoidalHashMap k a -> b
$cfoldl' :: forall k b a. (b -> a -> b) -> b -> MonoidalHashMap k a -> b
foldl :: forall b a. (b -> a -> b) -> b -> MonoidalHashMap k a -> b
$cfoldl :: forall k b a. (b -> a -> b) -> b -> MonoidalHashMap k a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> MonoidalHashMap k a -> b
$cfoldr' :: forall k a b. (a -> b -> b) -> b -> MonoidalHashMap k a -> b
foldr :: forall a b. (a -> b -> b) -> b -> MonoidalHashMap k a -> b
$cfoldr :: forall k a b. (a -> b -> b) -> b -> MonoidalHashMap k a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> MonoidalHashMap k a -> m
$cfoldMap' :: forall k m a. Monoid m => (a -> m) -> MonoidalHashMap k a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> MonoidalHashMap k a -> m
$cfoldMap :: forall k m a. Monoid m => (a -> m) -> MonoidalHashMap k a -> m
fold :: forall m. Monoid m => MonoidalHashMap k m -> m
$cfold :: forall k m. Monoid m => MonoidalHashMap k m -> m
Foldable, forall k. Functor (MonoidalHashMap k)
forall k. Foldable (MonoidalHashMap k)
forall k (m :: * -> *) a.
Monad m =>
MonoidalHashMap k (m a) -> m (MonoidalHashMap k a)
forall k (f :: * -> *) a.
Applicative f =>
MonoidalHashMap k (f a) -> f (MonoidalHashMap k a)
forall k (m :: * -> *) a b.
Monad m =>
(a -> m b) -> MonoidalHashMap k a -> m (MonoidalHashMap k b)
forall k (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> MonoidalHashMap k a -> f (MonoidalHashMap k b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> MonoidalHashMap k a -> f (MonoidalHashMap k b)
sequence :: forall (m :: * -> *) a.
Monad m =>
MonoidalHashMap k (m a) -> m (MonoidalHashMap k a)
$csequence :: forall k (m :: * -> *) a.
Monad m =>
MonoidalHashMap k (m a) -> m (MonoidalHashMap k a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> MonoidalHashMap k a -> m (MonoidalHashMap k b)
$cmapM :: forall k (m :: * -> *) a b.
Monad m =>
(a -> m b) -> MonoidalHashMap k a -> m (MonoidalHashMap k b)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
MonoidalHashMap k (f a) -> f (MonoidalHashMap k a)
$csequenceA :: forall k (f :: * -> *) a.
Applicative f =>
MonoidalHashMap k (f a) -> f (MonoidalHashMap k a)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> MonoidalHashMap k a -> f (MonoidalHashMap k b)
$ctraverse :: forall k (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> MonoidalHashMap k a -> f (MonoidalHashMap k b)
Traversable, MonoidalHashMap k a -> DataType
MonoidalHashMap k a -> Constr
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall {k} {a}.
(Data k, Data a, Hashable k) =>
Typeable (MonoidalHashMap k a)
forall k a.
(Data k, Data a, Hashable k) =>
MonoidalHashMap k a -> DataType
forall k a.
(Data k, Data a, Hashable k) =>
MonoidalHashMap k a -> Constr
forall k a.
(Data k, Data a, Hashable k) =>
(forall b. Data b => b -> b)
-> MonoidalHashMap k a -> MonoidalHashMap k a
forall k a u.
(Data k, Data a, Hashable k) =>
Int -> (forall d. Data d => d -> u) -> MonoidalHashMap k a -> u
forall k a u.
(Data k, Data a, Hashable k) =>
(forall d. Data d => d -> u) -> MonoidalHashMap k a -> [u]
forall k a r r'.
(Data k, Data a, Hashable k) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> MonoidalHashMap k a -> r
forall k a r r'.
(Data k, Data a, Hashable k) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> MonoidalHashMap k a -> r
forall k a (m :: * -> *).
(Data k, Data a, Hashable k, Monad m) =>
(forall d. Data d => d -> m d)
-> MonoidalHashMap k a -> m (MonoidalHashMap k a)
forall k a (m :: * -> *).
(Data k, Data a, Hashable k, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> MonoidalHashMap k a -> m (MonoidalHashMap k a)
forall k a (c :: * -> *).
(Data k, Data a, Hashable k) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (MonoidalHashMap k a)
forall k a (c :: * -> *).
(Data k, Data a, Hashable k) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> MonoidalHashMap k a
-> c (MonoidalHashMap k a)
forall k a (t :: * -> *) (c :: * -> *).
(Data k, Data a, Hashable k, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (MonoidalHashMap k a))
forall k a (t :: * -> * -> *) (c :: * -> *).
(Data k, Data a, Hashable k, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (MonoidalHashMap k a))
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (MonoidalHashMap k a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> MonoidalHashMap k a
-> c (MonoidalHashMap k a)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (MonoidalHashMap k a))
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> MonoidalHashMap k a -> m (MonoidalHashMap k a)
$cgmapMo :: forall k a (m :: * -> *).
(Data k, Data a, Hashable k, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> MonoidalHashMap k a -> m (MonoidalHashMap k a)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> MonoidalHashMap k a -> m (MonoidalHashMap k a)
$cgmapMp :: forall k a (m :: * -> *).
(Data k, Data a, Hashable k, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> MonoidalHashMap k a -> m (MonoidalHashMap k a)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> MonoidalHashMap k a -> m (MonoidalHashMap k a)
$cgmapM :: forall k a (m :: * -> *).
(Data k, Data a, Hashable k, Monad m) =>
(forall d. Data d => d -> m d)
-> MonoidalHashMap k a -> m (MonoidalHashMap k a)
gmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> MonoidalHashMap k a -> u
$cgmapQi :: forall k a u.
(Data k, Data a, Hashable k) =>
Int -> (forall d. Data d => d -> u) -> MonoidalHashMap k a -> u
gmapQ :: forall u.
(forall d. Data d => d -> u) -> MonoidalHashMap k a -> [u]
$cgmapQ :: forall k a u.
(Data k, Data a, Hashable k) =>
(forall d. Data d => d -> u) -> MonoidalHashMap k a -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> MonoidalHashMap k a -> r
$cgmapQr :: forall k a r r'.
(Data k, Data a, Hashable k) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> MonoidalHashMap k a -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> MonoidalHashMap k a -> r
$cgmapQl :: forall k a r r'.
(Data k, Data a, Hashable k) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> MonoidalHashMap k a -> r
gmapT :: (forall b. Data b => b -> b)
-> MonoidalHashMap k a -> MonoidalHashMap k a
$cgmapT :: forall k a.
(Data k, Data a, Hashable k) =>
(forall b. Data b => b -> b)
-> MonoidalHashMap k a -> MonoidalHashMap k a
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (MonoidalHashMap k a))
$cdataCast2 :: forall k a (t :: * -> * -> *) (c :: * -> *).
(Data k, Data a, Hashable k, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (MonoidalHashMap k a))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (MonoidalHashMap k a))
$cdataCast1 :: forall k a (t :: * -> *) (c :: * -> *).
(Data k, Data a, Hashable k, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (MonoidalHashMap k a))
dataTypeOf :: MonoidalHashMap k a -> DataType
$cdataTypeOf :: forall k a.
(Data k, Data a, Hashable k) =>
MonoidalHashMap k a -> DataType
toConstr :: MonoidalHashMap k a -> Constr
$ctoConstr :: forall k a.
(Data k, Data a, Hashable k) =>
MonoidalHashMap k a -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (MonoidalHashMap k a)
$cgunfold :: forall k a (c :: * -> *).
(Data k, Data a, Hashable k) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (MonoidalHashMap k a)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> MonoidalHashMap k a
-> c (MonoidalHashMap k a)
$cgfoldl :: forall k a (c :: * -> *).
(Data k, Data a, Hashable k) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> MonoidalHashMap k a
-> c (MonoidalHashMap k a)
Data, Typeable, Int -> MonoidalHashMap k a -> Int
MonoidalHashMap k a -> Int
forall a. Eq a -> (Int -> a -> Int) -> (a -> Int) -> Hashable a
forall {k} {a}.
(Hashable k, Hashable a) =>
Eq (MonoidalHashMap k a)
forall k a.
(Hashable k, Hashable a) =>
Int -> MonoidalHashMap k a -> Int
forall k a. (Hashable k, Hashable a) => MonoidalHashMap k a -> Int
hash :: MonoidalHashMap k a -> Int
$chash :: forall k a. (Hashable k, Hashable a) => MonoidalHashMap k a -> Int
hashWithSalt :: Int -> MonoidalHashMap k a -> Int
$chashWithSalt :: forall k a.
(Hashable k, Hashable a) =>
Int -> MonoidalHashMap k a -> Int
Hashable, forall a. MonoidalHashMap k a
forall {k}. Hashable k => Semialign (MonoidalHashMap k)
forall k a. Hashable k => MonoidalHashMap k a
forall (f :: * -> *). Semialign f -> (forall a. f a) -> Align f
nil :: forall a. MonoidalHashMap k a
$cnil :: forall k a. Hashable k => MonoidalHashMap k a
Align
#if MIN_VERSION_base(4,9,0)
             , forall k a b.
Eq k =>
(a -> b -> Bool)
-> MonoidalHashMap k a -> MonoidalHashMap k b -> Bool
forall a b.
(a -> b -> Bool)
-> MonoidalHashMap k a -> MonoidalHashMap k b -> Bool
forall (f :: * -> *).
(forall a b. (a -> b -> Bool) -> f a -> f b -> Bool) -> Eq1 f
liftEq :: forall a b.
(a -> b -> Bool)
-> MonoidalHashMap k a -> MonoidalHashMap k b -> Bool
$cliftEq :: forall k a b.
Eq k =>
(a -> b -> Bool)
-> MonoidalHashMap k a -> MonoidalHashMap k b -> Bool
Eq1
#endif
#if MIN_VERSION_unordered_containers(0,2,8)
             , forall {k}. Hashable k => Eq1 (MonoidalHashMap k)
forall k a.
Hashable k =>
(Int -> a -> Int) -> Int -> MonoidalHashMap k a -> Int
forall a. (Int -> a -> Int) -> Int -> MonoidalHashMap k a -> Int
forall (t :: * -> *).
Eq1 t
-> (forall a. (Int -> a -> Int) -> Int -> t a -> Int)
-> Hashable1 t
liftHashWithSalt :: forall a. (Int -> a -> Int) -> Int -> MonoidalHashMap k a -> Int
$cliftHashWithSalt :: forall k a.
Hashable k =>
(Int -> a -> Int) -> Int -> MonoidalHashMap k a -> Int
Hashable1
#endif
#if MIN_VERSION_these(0,8,0)
             , forall {k}. Hashable k => Functor (MonoidalHashMap k)
forall k a b.
Hashable k =>
MonoidalHashMap k a
-> MonoidalHashMap k b -> MonoidalHashMap k (These a b)
forall k a b c.
Hashable k =>
(These a b -> c)
-> MonoidalHashMap k a
-> MonoidalHashMap k b
-> MonoidalHashMap k c
forall a b.
MonoidalHashMap k a
-> MonoidalHashMap k b -> MonoidalHashMap k (These a b)
forall a b c.
(These a b -> c)
-> MonoidalHashMap k a
-> MonoidalHashMap k b
-> MonoidalHashMap k c
forall (f :: * -> *).
Functor f
-> (forall a b. f a -> f b -> f (These a b))
-> (forall a b c. (These a b -> c) -> f a -> f b -> f c)
-> Semialign f
alignWith :: forall a b c.
(These a b -> c)
-> MonoidalHashMap k a
-> MonoidalHashMap k b
-> MonoidalHashMap k c
$calignWith :: forall k a b c.
Hashable k =>
(These a b -> c)
-> MonoidalHashMap k a
-> MonoidalHashMap k b
-> MonoidalHashMap k c
align :: forall a b.
MonoidalHashMap k a
-> MonoidalHashMap k b -> MonoidalHashMap k (These a b)
$calign :: forall k a b.
Hashable k =>
MonoidalHashMap k a
-> MonoidalHashMap k b -> MonoidalHashMap k (These a b)
Semialign
#endif
#ifdef MIN_VERSION_semialign
             , forall {k}. Hashable k => Semialign (MonoidalHashMap k)
forall k a b.
Hashable k =>
MonoidalHashMap k (These a b)
-> (MonoidalHashMap k a, MonoidalHashMap k b)
forall k c a b.
Hashable k =>
(c -> These a b)
-> MonoidalHashMap k c
-> (MonoidalHashMap k a, MonoidalHashMap k b)
forall a b.
MonoidalHashMap k (These a b)
-> (MonoidalHashMap k a, MonoidalHashMap k b)
forall c a b.
(c -> These a b)
-> MonoidalHashMap k c
-> (MonoidalHashMap k a, MonoidalHashMap k b)
forall (f :: * -> *).
Semialign f
-> (forall a b. f (These a b) -> (f a, f b))
-> (forall c a b. (c -> These a b) -> f c -> (f a, f b))
-> Unalign f
unalignWith :: forall c a b.
(c -> These a b)
-> MonoidalHashMap k c
-> (MonoidalHashMap k a, MonoidalHashMap k b)
$cunalignWith :: forall k c a b.
Hashable k =>
(c -> These a b)
-> MonoidalHashMap k c
-> (MonoidalHashMap k a, MonoidalHashMap k b)
unalign :: forall a b.
MonoidalHashMap k (These a b)
-> (MonoidalHashMap k a, MonoidalHashMap k b)
$cunalign :: forall k a b.
Hashable k =>
MonoidalHashMap k (These a b)
-> (MonoidalHashMap k a, MonoidalHashMap k b)
Unalign
#if MIN_VERSION_semialign(1,1,0)
             , forall {k}. Hashable k => Semialign (MonoidalHashMap k)
forall k a b.
Hashable k =>
MonoidalHashMap k a
-> MonoidalHashMap k b -> MonoidalHashMap k (a, b)
forall k a b c.
Hashable k =>
(a -> b -> c)
-> MonoidalHashMap k a
-> MonoidalHashMap k b
-> MonoidalHashMap k c
forall a b.
MonoidalHashMap k a
-> MonoidalHashMap k b -> MonoidalHashMap k (a, b)
forall a b c.
(a -> b -> c)
-> MonoidalHashMap k a
-> MonoidalHashMap k b
-> MonoidalHashMap k c
forall (f :: * -> *).
Semialign f
-> (forall a b. f a -> f b -> f (a, b))
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> Zip f
zipWith :: forall a b c.
(a -> b -> c)
-> MonoidalHashMap k a
-> MonoidalHashMap k b
-> MonoidalHashMap k c
$czipWith :: forall k a b c.
Hashable k =>
(a -> b -> c)
-> MonoidalHashMap k a
-> MonoidalHashMap k b
-> MonoidalHashMap k c
zip :: forall a b.
MonoidalHashMap k a
-> MonoidalHashMap k b -> MonoidalHashMap k (a, b)
$czip :: forall k a b.
Hashable k =>
MonoidalHashMap k a
-> MonoidalHashMap k b -> MonoidalHashMap k (a, b)
Zip
#endif
#endif
             , forall {k}. Hashable k => Functor (MonoidalHashMap k)
forall k a.
Hashable k =>
MonoidalHashMap k (Maybe a) -> MonoidalHashMap k a
forall k a.
Hashable k =>
(a -> Bool) -> MonoidalHashMap k a -> MonoidalHashMap k a
forall k a b.
Hashable k =>
(a -> Maybe b) -> MonoidalHashMap k a -> MonoidalHashMap k b
forall a. MonoidalHashMap k (Maybe a) -> MonoidalHashMap k a
forall a. (a -> Bool) -> MonoidalHashMap k a -> MonoidalHashMap k a
forall a b.
(a -> Maybe b) -> MonoidalHashMap k a -> MonoidalHashMap k b
forall (f :: * -> *).
Functor f
-> (forall a b. (a -> Maybe b) -> f a -> f b)
-> (forall a. f (Maybe a) -> f a)
-> (forall a. (a -> Bool) -> f a -> f a)
-> Filterable f
filter :: forall a. (a -> Bool) -> MonoidalHashMap k a -> MonoidalHashMap k a
$cfilter :: forall k a.
Hashable k =>
(a -> Bool) -> MonoidalHashMap k a -> MonoidalHashMap k a
catMaybes :: forall a. MonoidalHashMap k (Maybe a) -> MonoidalHashMap k a
$ccatMaybes :: forall k a.
Hashable k =>
MonoidalHashMap k (Maybe a) -> MonoidalHashMap k a
mapMaybe :: forall a b.
(a -> Maybe b) -> MonoidalHashMap k a -> MonoidalHashMap k b
$cmapMaybe :: forall k a b.
Hashable k =>
(a -> Maybe b) -> MonoidalHashMap k a -> MonoidalHashMap k b
Witherable.Filterable
             )

type instance Index (MonoidalHashMap k a) = k
type instance IxValue (MonoidalHashMap k a) = a
instance (Eq k, Hashable k) => Ixed (MonoidalHashMap k a) where
    ix :: Index (MonoidalHashMap k a)
-> Traversal' (MonoidalHashMap k a) (IxValue (MonoidalHashMap k a))
ix Index (MonoidalHashMap k a)
k IxValue (MonoidalHashMap k a) -> f (IxValue (MonoidalHashMap k a))
f (MonoidalHashMap HashMap k a
m) = case forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
M.lookup Index (MonoidalHashMap k a)
k HashMap k a
m of
      Just a
v  -> IxValue (MonoidalHashMap k a) -> f (IxValue (MonoidalHashMap k a))
f a
v forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \a
v' -> forall k a. HashMap k a -> MonoidalHashMap k a
MonoidalHashMap (forall k v.
(Eq k, Hashable k) =>
k -> v -> HashMap k v -> HashMap k v
M.insert Index (MonoidalHashMap k a)
k a
v' HashMap k a
m)
      Maybe a
Nothing -> forall (f :: * -> *) a. Applicative f => a -> f a
pure (forall k a. HashMap k a -> MonoidalHashMap k a
MonoidalHashMap HashMap k a
m)
    {-# INLINE ix #-}

instance (Eq k, Hashable k) => At (MonoidalHashMap k a) where
    at :: Index (MonoidalHashMap k a)
-> Lens'
     (MonoidalHashMap k a) (Maybe (IxValue (MonoidalHashMap k a)))
at Index (MonoidalHashMap k a)
k Maybe (IxValue (MonoidalHashMap k a))
-> f (Maybe (IxValue (MonoidalHashMap k a)))
f (MonoidalHashMap HashMap k a
m) = Maybe (IxValue (MonoidalHashMap k a))
-> f (Maybe (IxValue (MonoidalHashMap k a)))
f Maybe a
mv forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \Maybe a
r -> case Maybe a
r of
      Maybe a
Nothing -> forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall k a. HashMap k a -> MonoidalHashMap k a
MonoidalHashMap HashMap k a
m) (forall a b. a -> b -> a
const (forall k a. HashMap k a -> MonoidalHashMap k a
MonoidalHashMap forall a b. (a -> b) -> a -> b
$ forall k v. (Eq k, Hashable k) => k -> HashMap k v -> HashMap k v
M.delete Index (MonoidalHashMap k a)
k HashMap k a
m)) Maybe a
mv
      Just a
v' -> forall k a. HashMap k a -> MonoidalHashMap k a
MonoidalHashMap forall a b. (a -> b) -> a -> b
$ forall k v.
(Eq k, Hashable k) =>
k -> v -> HashMap k v -> HashMap k v
M.insert Index (MonoidalHashMap k a)
k a
v' HashMap k a
m
      where mv :: Maybe a
mv = forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
M.lookup Index (MonoidalHashMap k a)
k HashMap k a
m
    {-# INLINE at #-}

instance Each (MonoidalHashMap k a) (MonoidalHashMap k b) a b

instance (Eq k, Hashable k) => FunctorWithIndex k (MonoidalHashMap k)
instance (Eq k, Hashable k) => FoldableWithIndex k (MonoidalHashMap k)
instance (Eq k, Hashable k) => TraversableWithIndex k (MonoidalHashMap k) where
    itraverse :: forall (f :: * -> *) a b.
Applicative f =>
(k -> a -> f b) -> MonoidalHashMap k a -> f (MonoidalHashMap k b)
itraverse k -> a -> f b
f (MonoidalHashMap HashMap k a
m) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall k a. HashMap k a -> MonoidalHashMap k a
MonoidalHashMap forall a b. (a -> b) -> a -> b
$ forall i (t :: * -> *) (f :: * -> *) a b.
(TraversableWithIndex i t, Applicative f) =>
(i -> a -> f b) -> t a -> f (t b)
itraverse k -> a -> f b
f HashMap k a
m
    {-# INLINE itraverse #-}

instance AsEmpty (MonoidalHashMap k a) where
    _Empty :: Prism' (MonoidalHashMap k a) ()
_Empty = forall a. a -> (a -> Bool) -> Prism' a ()
nearly (forall k a. HashMap k a -> MonoidalHashMap k a
MonoidalHashMap forall k v. HashMap k v
M.empty) (forall k v. HashMap k v -> Bool
M.null forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall n o. Newtype n o => n -> o
unpack)
    {-# INLINE _Empty #-}

instance Wrapped (MonoidalHashMap k a) where
    type Unwrapped (MonoidalHashMap k a) = M.HashMap k a
    _Wrapped' :: Iso' (MonoidalHashMap k a) (Unwrapped (MonoidalHashMap k a))
_Wrapped' = forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso forall n o. Newtype n o => n -> o
unpack forall n o. Newtype n o => o -> n
pack
    {-# INLINE _Wrapped' #-}

instance (Eq k, Hashable k) => Rewrapped (M.HashMap k a) (MonoidalHashMap k a)

instance (Eq k, Hashable k) => Rewrapped (MonoidalHashMap k a) (M.HashMap k a)

instance (Eq k, Hashable k, Semigroup a) => Semigroup (MonoidalHashMap k a) where
    MonoidalHashMap HashMap k a
a <> :: MonoidalHashMap k a -> MonoidalHashMap k a -> MonoidalHashMap k a
<> MonoidalHashMap HashMap k a
b = forall k a. HashMap k a -> MonoidalHashMap k a
MonoidalHashMap forall a b. (a -> b) -> a -> b
$ forall k v.
(Eq k, Hashable k) =>
(v -> v -> v) -> HashMap k v -> HashMap k v -> HashMap k v
M.unionWith forall a. Semigroup a => a -> a -> a
(<>) HashMap k a
a HashMap k a
b
    {-# INLINE (<>) #-}

instance (Eq k, Hashable k, Semigroup a) => Monoid (MonoidalHashMap k a) where
    mempty :: MonoidalHashMap k a
mempty = forall k a. HashMap k a -> MonoidalHashMap k a
MonoidalHashMap forall a. Monoid a => a
mempty
    {-# INLINE mempty #-}
#if !(MIN_VERSION_base(4,11,0))
    mappend (MonoidalHashMap a) (MonoidalHashMap b) = MonoidalHashMap $ M.unionWith (<>) a b
    {-# INLINE mappend #-}
#endif

instance Newtype (MonoidalHashMap k a) (M.HashMap k a) where
    pack :: HashMap k a -> MonoidalHashMap k a
pack = forall k a. HashMap k a -> MonoidalHashMap k a
MonoidalHashMap
    {-# INLINE pack #-}
    unpack :: MonoidalHashMap k a -> HashMap k a
unpack (MonoidalHashMap HashMap k a
a) = HashMap k a
a
    {-# INLINE unpack #-}

#if MIN_VERSION_base(4,7,0)
instance (Eq k, Hashable k, Semigroup a) => Exts.IsList (MonoidalHashMap k a) where
    type Item (MonoidalHashMap k a) = (k, a)
    fromList :: [Item (MonoidalHashMap k a)] -> MonoidalHashMap k a
fromList = forall k a. HashMap k a -> MonoidalHashMap k a
MonoidalHashMap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
M.fromList
    {-# INLINE fromList #-}
    toList :: MonoidalHashMap k a -> [Item (MonoidalHashMap k a)]
toList = forall k v. HashMap k v -> [(k, v)]
M.toList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall n o. Newtype n o => n -> o
unpack
    {-# INLINE toList #-}
#endif

instance (Eq k, Hashable k) => Witherable.Witherable (MonoidalHashMap k)

-- | /O(1)/. A map with a single element.
singleton :: (Eq k, Hashable k) => k -> a -> MonoidalHashMap k a
singleton :: forall k a. (Eq k, Hashable k) => k -> a -> MonoidalHashMap k a
singleton k
k a
a = forall k a. HashMap k a -> MonoidalHashMap k a
MonoidalHashMap forall a b. (a -> b) -> a -> b
$ forall k v. Hashable k => k -> v -> HashMap k v
M.singleton k
k a
a
{-# INLINE singleton #-}

-- | /O(1)/. The number of elements in the map.
size :: MonoidalHashMap k a -> Int
size :: forall k a. MonoidalHashMap k a -> Int
size = forall k v. HashMap k v -> Int
M.size forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall n o. Newtype n o => n -> o
unpack
{-# INLINE size #-}

-- | /O(log n)/. Is the key a member of the map? See also 'notMember'.
member :: (Eq k, Hashable k) => k -> MonoidalHashMap k a -> Bool
member :: forall k a. (Eq k, Hashable k) => k -> MonoidalHashMap k a -> Bool
member k
k = forall k a. (Eq k, Hashable k) => k -> HashMap k a -> Bool
M.member k
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall n o. Newtype n o => n -> o
unpack
{-# INLINE member #-}

-- | /O(log n)/. Is the key not a member of the map? See also 'member'.
notMember :: (Eq k, Hashable k) => k -> MonoidalHashMap k a -> Bool
notMember :: forall k a. (Eq k, Hashable k) => k -> MonoidalHashMap k a -> Bool
notMember k
k = Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k a. (Eq k, Hashable k) => k -> HashMap k a -> Bool
M.member k
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall n o. Newtype n o => n -> o
unpack
{-# INLINE notMember #-}

-- | /O(log n)/ Return the value to which the specified key is mapped,
-- or 'Nothing' if this map contains no mapping for the key.
lookup :: (Eq k, Hashable k) => k -> MonoidalHashMap k v -> Maybe v
lookup :: forall k v.
(Eq k, Hashable k) =>
k -> MonoidalHashMap k v -> Maybe v
lookup k
k = forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
M.lookup k
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall n o. Newtype n o => n -> o
unpack
{-# INLINE lookup #-}

-- | /O(log n)/ Return the value to which the specified key is mapped,
-- or mempty if this map contains no mapping for the key.
lookupM :: (Eq k, Hashable k, Monoid v) => k -> MonoidalHashMap k v -> v
lookupM :: forall k v.
(Eq k, Hashable k, Monoid v) =>
k -> MonoidalHashMap k v -> v
lookupM k
k = forall a. a -> Maybe a -> a
fromMaybe forall a. Monoid a => a
mempty forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
M.lookup k
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall n o. Newtype n o => n -> o
unpack
{-# INLINE lookupM #-}

-- | /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.
delete :: (Eq k, Hashable k) => k -> MonoidalHashMap k a -> MonoidalHashMap k a
delete :: forall k a.
(Eq k, Hashable k) =>
k -> MonoidalHashMap k a -> MonoidalHashMap k a
delete k
k = forall s. Wrapped s => (Unwrapped s -> s) -> Iso' s (Unwrapped s)
_Wrapping' forall k a. HashMap k a -> MonoidalHashMap k a
MonoidalHashMap forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ forall k v. (Eq k, Hashable k) => k -> HashMap k v -> HashMap k v
M.delete k
k
{-# INLINE delete #-}

-- | /O(n)/.
-- Return a list of this map's values. The list is produced lazily.
elems :: MonoidalHashMap k a -> [a]
elems :: forall k a. MonoidalHashMap k a -> [a]
elems = forall k v. HashMap k v -> [v]
M.elems forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall n o. Newtype n o => n -> o
unpack
{-# INLINE elems #-}

-- | /O(n)/. Return all keys of the map in ascending order. Subject to list
-- fusion.
keys :: MonoidalHashMap k a -> [k]
keys :: forall k a. MonoidalHashMap k a -> [k]
keys = forall k v. HashMap k v -> [k]
M.keys forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall n o. Newtype n o => n -> o
unpack
{-# INLINE keys #-}

-- | /O(n*log n)/. Construct a map with the supplied mappings. If the list
-- contains duplicate mappings, values will be replaced.
fromList :: (Eq k, Hashable k) => [(k,a)] -> MonoidalHashMap k a
fromList :: forall k a. (Eq k, Hashable k) => [(k, a)] -> MonoidalHashMap k a
fromList = forall n o. Newtype n o => o -> n
pack forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
M.fromList
{-# INLINE fromList #-}

-- | /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.
fromListWith :: (Eq k, Hashable k) => (a -> a -> a) -> [(k,a)] -> MonoidalHashMap k a
fromListWith :: forall k a.
(Eq k, Hashable k) =>
(a -> a -> a) -> [(k, a)] -> MonoidalHashMap k a
fromListWith a -> a -> a
f = forall n o. Newtype n o => o -> n
pack forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k v.
(Eq k, Hashable k) =>
(v -> v -> v) -> [(k, v)] -> HashMap k v
M.fromListWith a -> a -> a
f
{-# INLINE fromListWith #-}


-- | /O(n*log n)/.  Return a list of this map's elements. The list is produced
-- lazily. The order of its elements is unspecified.
toList :: MonoidalHashMap k a -> [(k,a)]
toList :: forall k a. MonoidalHashMap k a -> [(k, a)]
toList = forall k v. HashMap k v -> [(k, v)]
M.toList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall n o. Newtype n o => n -> o
unpack
{-# INLINE toList #-}

-- | /O(log n)/. Insert a value on some key, if it exists replace the value.
insert :: (Hashable k, Eq k)
       => k
       -> a
       -> MonoidalHashMap k a
       -> MonoidalHashMap k a
insert :: forall k a.
(Hashable k, Eq k) =>
k -> a -> MonoidalHashMap k a -> MonoidalHashMap k a
insert k
k a
x = forall n o. Newtype n o => o -> n
pack
           forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k v.
(Eq k, Hashable k) =>
k -> v -> HashMap k v -> HashMap k v
M.insert k
k a
x
           forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall n o. Newtype n o => n -> o
unpack

-- | /O(log n)/. Insert a value on some key, if it exists apply the combining function.
insertWith :: (Hashable k, Eq k)
       => (a -> a -> a)
       -> k
       -> a
       -> MonoidalHashMap k a
       -> MonoidalHashMap k a
insertWith :: forall k a.
(Hashable k, Eq k) =>
(a -> a -> a)
-> k -> a -> MonoidalHashMap k a -> MonoidalHashMap k a
insertWith a -> a -> a
f k
k a
x = forall n o. Newtype n o => o -> n
pack
           forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k v.
(Eq k, Hashable k) =>
(v -> v -> v) -> k -> v -> HashMap k v -> HashMap k v
M.insertWith a -> a -> a
f k
k a
x
           forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall n o. Newtype n o => n -> o
unpack

-- | /O(log n)/. Modify a value on some key with a function, if value
-- under key doesn't exist -- use mempty.
modify :: (Monoid a, Hashable k, Eq k)
       => (a -> a)
       -> k -> MonoidalHashMap k a
       -> MonoidalHashMap k a
modify :: forall a k.
(Monoid a, Hashable k, Eq k) =>
(a -> a) -> k -> MonoidalHashMap k a -> MonoidalHashMap k a
modify a -> a
f k
k = forall n o. Newtype n o => o -> n
pack
           forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k v.
(Eq k, Hashable k) =>
(v -> v -> v) -> k -> v -> HashMap k v -> HashMap k v
M.insertWith (\a
_ a
old -> a -> a
f a
old) k
k (a -> a
f forall a. Monoid a => a
mempty)
           forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall n o. Newtype n o => n -> o
unpack
{-# INLINE modify #-}

-- | /O(log n)/. Modify a value on some key with a function, providing
-- a default value if that key doesn't exist.
modifyDef :: (Hashable k, Eq k)
          => a -> (a -> a)
          -> k -> MonoidalHashMap k a
          -> MonoidalHashMap k a
modifyDef :: forall k a.
(Hashable k, Eq k) =>
a -> (a -> a) -> k -> MonoidalHashMap k a -> MonoidalHashMap k a
modifyDef a
d a -> a
f k
k = forall n o. Newtype n o => o -> n
pack
                forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k v.
(Eq k, Hashable k) =>
(v -> v -> v) -> k -> v -> HashMap k v -> HashMap k v
M.insertWith (\a
_ a
old -> a -> a
f a
old) k
k a
d
                forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall n o. Newtype n o => n -> o
unpack
{-# INLINE modifyDef #-}

-- | /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
mapKeys :: (Hashable k, Eq k, Hashable k', Eq k')
        => (k -> k') -> MonoidalHashMap k a -> MonoidalHashMap k' a
mapKeys :: forall k k' a.
(Hashable k, Eq k, Hashable k', Eq k') =>
(k -> k') -> MonoidalHashMap k a -> MonoidalHashMap k' a
mapKeys k -> k'
f = forall k a. (Eq k, Hashable k) => [(k, a)] -> MonoidalHashMap k a
fromList
          forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (\(k
k, a
v) -> (k -> k'
f k
k, a
v))
          forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k a. MonoidalHashMap k a -> [(k, a)]
toList
{-# INLINE mapKeys #-}

-- | /O(n)/ Filter this map by retaining only elements satisfying a
-- predicate.
filterWithKey :: (k -> v -> Bool) -> MonoidalHashMap k v -> MonoidalHashMap k v
filterWithKey :: forall k v.
(k -> v -> Bool) -> MonoidalHashMap k v -> MonoidalHashMap k v
filterWithKey k -> v -> Bool
pred = forall n o. Newtype n o => o -> n
pack forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k v. (k -> v -> Bool) -> HashMap k v -> HashMap k v
M.filterWithKey k -> v -> Bool
pred forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall n o. Newtype n o => n -> o
unpack
{-# INLINE filterWithKey #-}

-- | /O(n)/ Transform this map by applying a function to every value.
map :: (v1 -> v2) -> MonoidalHashMap k v1 -> MonoidalHashMap k v2
map :: forall v1 v2 k.
(v1 -> v2) -> MonoidalHashMap k v1 -> MonoidalHashMap k v2
map v1 -> v2
f = forall n o. Newtype n o => o -> n
pack forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall v1 v2 k. (v1 -> v2) -> HashMap k v1 -> HashMap k v2
M.map v1 -> v2
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall n o. Newtype n o => n -> o
unpack
{-# INLINE map #-}