module Data.Monoid.Map
( MonoidMap (..)
) where
import qualified Data.Map as M
import Stack.Prelude
newtype MonoidMap k a
= MonoidMap (Map k a)
deriving (MonoidMap k a -> MonoidMap k a -> Bool
(MonoidMap k a -> MonoidMap k a -> Bool)
-> (MonoidMap k a -> MonoidMap k a -> Bool) -> Eq (MonoidMap k a)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall k a. (Eq k, Eq a) => MonoidMap k a -> MonoidMap k a -> Bool
$c== :: forall k a. (Eq k, Eq a) => MonoidMap k a -> MonoidMap k a -> Bool
== :: MonoidMap k a -> MonoidMap k a -> Bool
$c/= :: forall k a. (Eq k, Eq a) => MonoidMap k a -> MonoidMap k a -> Bool
/= :: MonoidMap k a -> MonoidMap k a -> Bool
Eq, (forall a b. (a -> b) -> MonoidMap k a -> MonoidMap k b)
-> (forall a b. a -> MonoidMap k b -> MonoidMap k a)
-> Functor (MonoidMap k)
forall a b. a -> MonoidMap k b -> MonoidMap k a
forall a b. (a -> b) -> MonoidMap k a -> MonoidMap k b
forall k a b. a -> MonoidMap k b -> MonoidMap k a
forall k a b. (a -> b) -> MonoidMap k a -> MonoidMap k b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall k a b. (a -> b) -> MonoidMap k a -> MonoidMap k b
fmap :: forall a b. (a -> b) -> MonoidMap k a -> MonoidMap k b
$c<$ :: forall k a b. a -> MonoidMap k b -> MonoidMap k a
<$ :: forall a b. a -> MonoidMap k b -> MonoidMap k a
Functor, (forall x. MonoidMap k a -> Rep (MonoidMap k a) x)
-> (forall x. Rep (MonoidMap k a) x -> MonoidMap k a)
-> Generic (MonoidMap k a)
forall x. Rep (MonoidMap k a) x -> MonoidMap k a
forall x. MonoidMap k a -> Rep (MonoidMap k a) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall k a x. Rep (MonoidMap k a) x -> MonoidMap k a
forall k a x. MonoidMap k a -> Rep (MonoidMap k a) x
$cfrom :: forall k a x. MonoidMap k a -> Rep (MonoidMap k a) x
from :: forall x. MonoidMap k a -> Rep (MonoidMap k a) x
$cto :: forall k a x. Rep (MonoidMap k a) x -> MonoidMap k a
to :: forall x. Rep (MonoidMap k a) x -> MonoidMap k a
Generic, Eq (MonoidMap k a)
Eq (MonoidMap k a)
-> (MonoidMap k a -> MonoidMap k a -> Ordering)
-> (MonoidMap k a -> MonoidMap k a -> Bool)
-> (MonoidMap k a -> MonoidMap k a -> Bool)
-> (MonoidMap k a -> MonoidMap k a -> Bool)
-> (MonoidMap k a -> MonoidMap k a -> Bool)
-> (MonoidMap k a -> MonoidMap k a -> MonoidMap k a)
-> (MonoidMap k a -> MonoidMap k a -> MonoidMap k a)
-> Ord (MonoidMap k a)
MonoidMap k a -> MonoidMap k a -> Bool
MonoidMap k a -> MonoidMap k a -> Ordering
MonoidMap k a -> MonoidMap k a -> MonoidMap k a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {k} {a}. (Ord k, Ord a) => Eq (MonoidMap k a)
forall k a.
(Ord k, Ord a) =>
MonoidMap k a -> MonoidMap k a -> Bool
forall k a.
(Ord k, Ord a) =>
MonoidMap k a -> MonoidMap k a -> Ordering
forall k a.
(Ord k, Ord a) =>
MonoidMap k a -> MonoidMap k a -> MonoidMap k a
$ccompare :: forall k a.
(Ord k, Ord a) =>
MonoidMap k a -> MonoidMap k a -> Ordering
compare :: MonoidMap k a -> MonoidMap k a -> Ordering
$c< :: forall k a.
(Ord k, Ord a) =>
MonoidMap k a -> MonoidMap k a -> Bool
< :: MonoidMap k a -> MonoidMap k a -> Bool
$c<= :: forall k a.
(Ord k, Ord a) =>
MonoidMap k a -> MonoidMap k a -> Bool
<= :: MonoidMap k a -> MonoidMap k a -> Bool
$c> :: forall k a.
(Ord k, Ord a) =>
MonoidMap k a -> MonoidMap k a -> Bool
> :: MonoidMap k a -> MonoidMap k a -> Bool
$c>= :: forall k a.
(Ord k, Ord a) =>
MonoidMap k a -> MonoidMap k a -> Bool
>= :: MonoidMap k a -> MonoidMap k a -> Bool
$cmax :: forall k a.
(Ord k, Ord a) =>
MonoidMap k a -> MonoidMap k a -> MonoidMap k a
max :: MonoidMap k a -> MonoidMap k a -> MonoidMap k a
$cmin :: forall k a.
(Ord k, Ord a) =>
MonoidMap k a -> MonoidMap k a -> MonoidMap k a
min :: MonoidMap k a -> MonoidMap k a -> MonoidMap k a
Ord, ReadPrec [MonoidMap k a]
ReadPrec (MonoidMap k a)
Int -> ReadS (MonoidMap k a)
ReadS [MonoidMap k a]
(Int -> ReadS (MonoidMap k a))
-> ReadS [MonoidMap k a]
-> ReadPrec (MonoidMap k a)
-> ReadPrec [MonoidMap k a]
-> Read (MonoidMap k a)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall k a. (Ord k, Read k, Read a) => ReadPrec [MonoidMap k a]
forall k a. (Ord k, Read k, Read a) => ReadPrec (MonoidMap k a)
forall k a. (Ord k, Read k, Read a) => Int -> ReadS (MonoidMap k a)
forall k a. (Ord k, Read k, Read a) => ReadS [MonoidMap k a]
$creadsPrec :: forall k a. (Ord k, Read k, Read a) => Int -> ReadS (MonoidMap k a)
readsPrec :: Int -> ReadS (MonoidMap k a)
$creadList :: forall k a. (Ord k, Read k, Read a) => ReadS [MonoidMap k a]
readList :: ReadS [MonoidMap k a]
$creadPrec :: forall k a. (Ord k, Read k, Read a) => ReadPrec (MonoidMap k a)
readPrec :: ReadPrec (MonoidMap k a)
$creadListPrec :: forall k a. (Ord k, Read k, Read a) => ReadPrec [MonoidMap k a]
readListPrec :: ReadPrec [MonoidMap k a]
Read, Int -> MonoidMap k a -> ShowS
[MonoidMap k a] -> ShowS
MonoidMap k a -> String
(Int -> MonoidMap k a -> ShowS)
-> (MonoidMap k a -> String)
-> ([MonoidMap k a] -> ShowS)
-> Show (MonoidMap k a)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k a. (Show k, Show a) => Int -> MonoidMap k a -> ShowS
forall k a. (Show k, Show a) => [MonoidMap k a] -> ShowS
forall k a. (Show k, Show a) => MonoidMap k a -> String
$cshowsPrec :: forall k a. (Show k, Show a) => Int -> MonoidMap k a -> ShowS
showsPrec :: Int -> MonoidMap k a -> ShowS
$cshow :: forall k a. (Show k, Show a) => MonoidMap k a -> String
show :: MonoidMap k a -> String
$cshowList :: forall k a. (Show k, Show a) => [MonoidMap k a] -> ShowS
showList :: [MonoidMap k a] -> ShowS
Show)
instance (Ord k, Semigroup a) => Semigroup (MonoidMap k a) where
MonoidMap Map k a
mp1 <> :: MonoidMap k a -> MonoidMap k a -> MonoidMap k a
<> MonoidMap Map k a
mp2 = Map k a -> MonoidMap k a
forall k a. Map k a -> MonoidMap k a
MonoidMap ((a -> a -> a) -> Map k a -> Map k a -> Map k a
forall k a. Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
M.unionWith a -> a -> a
forall a. Semigroup a => a -> a -> a
(<>) Map k a
mp1 Map k a
mp2)
instance (Ord k, Semigroup a) => Monoid (MonoidMap k a) where
mappend :: MonoidMap k a -> MonoidMap k a -> MonoidMap k a
mappend = MonoidMap k a -> MonoidMap k a -> MonoidMap k a
forall a. Semigroup a => a -> a -> a
(<>)
mempty :: MonoidMap k a
mempty = Map k a -> MonoidMap k a
forall k a. Map k a -> MonoidMap k a
MonoidMap Map k a
forall a. Monoid a => a
mempty