-- | Class of key-value maps
--
-- See 'StaticMap' and 'Map'.
module Data.Map.Class where

import Control.Applicative hiding (Alternative (..))
import Control.Arrow
import Data.Either.Both
import Data.Filtrable
import qualified Data.Foldable as Foldable
import Data.Function (on)
import Data.Functor.Classes
import Data.Functor.Compose
import Data.Functor.Identity
import Data.Functor.Product
import Data.IntMap (IntMap)
import qualified Data.IntMap as Int
import qualified Data.Map as M
import qualified Data.Map.Merge.Lazy as M
import Data.Monoid (Dual (..), Last (..))
import Util ((∘), (∘∘), compose2, bind2)
import Util.Private (Endo (..))

-- | Class of key-value maps
--
-- Laws:
--
-- * @'adjustA' 'pure' _ = 'pure'@
--
-- * @'adjustA' 'Const' k '<=<' 'traverseWithKey' f = 'fmap' 'Const' '.' f k '<=<' 'getConst' '.' 'adjustA' 'Const' k@
class Traversable map => StaticMap map where
    type Key map
    -- | Modify the value of the key in the map. If the key is absent, the map is returned unmodified.
    adjustA :: Applicative p => (a -> p a) -> Key map -> map a -> p (map a)
    -- | Traverse a function over each value in the map.
    traverseWithKey :: (Applicative p) => (Key map -> a -> p b) -> map a -> p (map b)

-- | Class of key-value maps with variable structure
class (Filtrable map, StaticMap map) => Map map where
    -- | The empty map
    empty :: map a
    -- | Modify the value of the key in the map, or insert the key and its value into the map, or delete the key and its value from the map, functorially.
    --
    -- @fmap ('!?' k) . 'alterF' f k = f . ('!?' k)@
    --
    -- This is the most general operation on a given key in the map.
    alterF :: Functor f => (Maybe a -> f (Maybe a)) -> Key map -> map a -> f (map a)
    -- | Combine two maps with the given function, which is called once for each key present in either map, inclusive.
    mergeA :: Applicative p => (Key map -> Either' a b -> p (Maybe c)) -> map a -> map b -> p (map c)
    -- | Traverse a function over each value in the map, gathering the 'Just' values and forgetting the 'Nothing'.
    mapMaybeWithKeyA :: Applicative p => (Key map -> a -> p (Maybe b)) -> map a -> p (map b)
    -- | Traverse a function over each value in the map, gathering the 'Left' and 'Right' values separately.
    mapEitherWithKeyA :: Applicative p => (Key map -> a -> p (Either b c)) -> map a -> p (map b, map c)
    mapEitherWithKeyA f :: Key map -> a -> p (Either b c)
f = (map b -> map c -> (map b, map c))
-> p (map b) -> p (map c) -> p (map b, map c)
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (,) (p (map b) -> p (map c) -> p (map b, map c))
-> (map a -> p (map b)) -> map a -> p (map c) -> p (map b, map c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Key map -> a -> p (Maybe b)) -> map a -> p (map b)
forall (map :: * -> *) (p :: * -> *) a b.
(Map map, Applicative p) =>
(Key map -> a -> p (Maybe b)) -> map a -> p (map b)
mapMaybeWithKeyA ((Either b c -> Maybe b) -> p (Either b c) -> p (Maybe b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (b -> Maybe b
forall a. a -> Maybe a
Just (b -> Maybe b) -> (c -> Maybe b) -> Either b c -> Maybe b
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
`either` Maybe b -> c -> Maybe b
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe b
forall a. Maybe a
Nothing) (p (Either b c) -> p (Maybe b))
-> (Key map -> a -> p (Either b c)) -> Key map -> a -> p (Maybe b)
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ Key map -> a -> p (Either b c)
f)
                                     (map a -> p (map c) -> p (map b, map c))
-> (map a -> p (map c)) -> map a -> p (map b, map c)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Key map -> a -> p (Maybe c)) -> map a -> p (map c)
forall (map :: * -> *) (p :: * -> *) a b.
(Map map, Applicative p) =>
(Key map -> a -> p (Maybe b)) -> map a -> p (map b)
mapMaybeWithKeyA ((Either b c -> Maybe c) -> p (Either b c) -> p (Maybe c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Maybe c -> b -> Maybe c
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe c
forall a. Maybe a
Nothing (b -> Maybe c) -> (c -> Maybe c) -> Either b c -> Maybe c
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
`either` c -> Maybe c
forall a. a -> Maybe a
Just) (p (Either b c) -> p (Maybe c))
-> (Key map -> a -> p (Either b c)) -> Key map -> a -> p (Maybe c)
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ Key map -> a -> p (Either b c)
f)

-- | Default implementation of `adjustA` in terms of `Map` methods
defaultAdjustA :: (Map map, Applicative p) => (a -> p a) -> Key map -> map a -> p (map a)
defaultAdjustA :: (a -> p a) -> Key map -> map a -> p (map a)
defaultAdjustA f :: a -> p a
f = (Maybe a -> p (Maybe a)) -> Key map -> map a -> p (map a)
forall (map :: * -> *) (f :: * -> *) a.
(Map map, Functor f) =>
(Maybe a -> f (Maybe a)) -> Key map -> map a -> f (map a)
alterF ((a -> p a) -> Maybe a -> p (Maybe a)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse a -> p a
f)

-- | Default implementation of `traverseWithKey` in terms of `Map` methods
defaultTraverseWithKey :: (Map map, Applicative p) => (Key map -> a -> p b) -> map a -> p (map b)
defaultTraverseWithKey :: (Key map -> a -> p b) -> map a -> p (map b)
defaultTraverseWithKey f :: Key map -> a -> p b
f = (Key map -> a -> p (Maybe b)) -> map a -> p (map b)
forall (map :: * -> *) (p :: * -> *) a b.
(Map map, Applicative p) =>
(Key map -> a -> p (Maybe b)) -> map a -> p (map b)
mapMaybeWithKeyA ((b -> Maybe b) -> p b -> p (Maybe b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> Maybe b
forall a. a -> Maybe a
Just (p b -> p (Maybe b))
-> (Key map -> a -> p b) -> Key map -> a -> p (Maybe b)
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ Key map -> a -> p b
f)

instance Filtrable IntMap where
    mapMaybe :: (a -> Maybe b) -> IntMap a -> IntMap b
mapMaybe = (a -> Maybe b) -> IntMap a -> IntMap b
forall a b. (a -> Maybe b) -> IntMap a -> IntMap b
Int.mapMaybe

instance Filtrable (M.Map key) where
    mapMaybe :: (a -> Maybe b) -> Map key a -> Map key b
mapMaybe = (a -> Maybe b) -> Map key a -> Map key b
forall a b k. (a -> Maybe b) -> Map k a -> Map k b
M.mapMaybe

instance StaticMap Maybe where
    type Key Maybe = ()
    adjustA :: (a -> p a) -> Key Maybe -> Maybe a -> p (Maybe a)
adjustA f :: a -> p a
f () = (a -> p a) -> Maybe a -> p (Maybe a)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse a -> p a
f
    traverseWithKey :: (Key Maybe -> a -> p b) -> Maybe a -> p (Maybe b)
traverseWithKey f :: Key Maybe -> a -> p b
f = (a -> p b) -> Maybe a -> p (Maybe b)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Key Maybe -> a -> p b
f ())

instance StaticMap IntMap where
    type Key IntMap = Int
    adjustA :: (a -> p a) -> Key IntMap -> IntMap a -> p (IntMap a)
adjustA = (a -> p a) -> Key IntMap -> IntMap a -> p (IntMap a)
forall (map :: * -> *) (p :: * -> *) a.
(Map map, Applicative p) =>
(a -> p a) -> Key map -> map a -> p (map a)
defaultAdjustA
    traverseWithKey :: (Key IntMap -> a -> p b) -> IntMap a -> p (IntMap b)
traverseWithKey = (Key IntMap -> a -> p b) -> IntMap a -> p (IntMap b)
forall (map :: * -> *) (p :: * -> *) a b.
(Map map, Applicative p) =>
(Key map -> a -> p b) -> map a -> p (map b)
defaultTraverseWithKey

instance Ord key => StaticMap (M.Map key) where
    type Key (M.Map key) = key
    adjustA :: (a -> p a) -> Key (Map key) -> Map key a -> p (Map key a)
adjustA = (a -> p a) -> Key (Map key) -> Map key a -> p (Map key a)
forall (map :: * -> *) (p :: * -> *) a.
(Map map, Applicative p) =>
(a -> p a) -> Key map -> map a -> p (map a)
defaultAdjustA
    traverseWithKey :: (Key (Map key) -> a -> p b) -> Map key a -> p (Map key b)
traverseWithKey = (Key (Map key) -> a -> p b) -> Map key a -> p (Map key b)
forall (map :: * -> *) (p :: * -> *) a b.
(Map map, Applicative p) =>
(Key map -> a -> p b) -> map a -> p (map b)
defaultTraverseWithKey

instance (StaticMap m, StaticMap n) => StaticMap (Compose m n) where
    type Key (Compose m n) = (Key m, Key n)
    adjustA :: (a -> p a)
-> Key (Compose m n) -> Compose m n a -> p (Compose m n a)
adjustA f :: a -> p a
f (i, j) = (m (n a) -> Compose m n a) -> p (m (n a)) -> p (Compose m n a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap m (n a) -> Compose m n a
forall k k1 (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose (p (m (n a)) -> p (Compose m n a))
-> (Compose m n a -> p (m (n a)))
-> Compose m n a
-> p (Compose m n a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (n a -> p (n a)) -> Key m -> m (n a) -> p (m (n a))
forall (map :: * -> *) (p :: * -> *) a.
(StaticMap map, Applicative p) =>
(a -> p a) -> Key map -> map a -> p (map a)
adjustA ((a -> p a) -> Key n -> n a -> p (n a)
forall (map :: * -> *) (p :: * -> *) a.
(StaticMap map, Applicative p) =>
(a -> p a) -> Key map -> map a -> p (map a)
adjustA a -> p a
f Key n
j) Key m
i (m (n a) -> p (m (n a)))
-> (Compose m n a -> m (n a)) -> Compose m n a -> p (m (n a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Compose m n a -> m (n a)
forall k1 (f :: k1 -> *) k2 (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose
    traverseWithKey :: (Key (Compose m n) -> a -> p b)
-> Compose m n a -> p (Compose m n b)
traverseWithKey f :: Key (Compose m n) -> a -> p b
f = (m (n b) -> Compose m n b) -> p (m (n b)) -> p (Compose m n b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap m (n b) -> Compose m n b
forall k k1 (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose (p (m (n b)) -> p (Compose m n b))
-> (Compose m n a -> p (m (n b)))
-> Compose m n a
-> p (Compose m n b)
forall (p :: * -> * -> *) b c a.
Category p =>
p b c -> p a b -> p a c
 (Key m -> n a -> p (n b)) -> m (n a) -> p (m (n b))
forall (map :: * -> *) (p :: * -> *) a b.
(StaticMap map, Applicative p) =>
(Key map -> a -> p b) -> map a -> p (map b)
traverseWithKey (\ i :: Key m
i -> (Key n -> a -> p b) -> n a -> p (n b)
forall (map :: * -> *) (p :: * -> *) a b.
(StaticMap map, Applicative p) =>
(Key map -> a -> p b) -> map a -> p (map b)
traverseWithKey (\ j :: Key n
j -> Key (Compose m n) -> a -> p b
f (Key m
i, Key n
j))) (m (n a) -> p (m (n b)))
-> (Compose m n a -> m (n a)) -> Compose m n a -> p (m (n b))
forall (p :: * -> * -> *) b c a.
Category p =>
p b c -> p a b -> p a c
 Compose m n a -> m (n a)
forall k1 (f :: k1 -> *) k2 (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose

instance (StaticMap m, StaticMap n) => StaticMap (Product m n) where
    type Key (Product m n) = Either (Key m) (Key n)
    adjustA :: (a -> p a)
-> Key (Product m n) -> Product m n a -> p (Product m n a)
adjustA f :: a -> p a
f k :: Key (Product m n)
k (Pair a :: m a
a b :: n a
b) = case Key (Product m n)
k of
        Left  i -> (m a -> n a -> Product m n a) -> n a -> m a -> Product m n a
forall a b c. (a -> b -> c) -> b -> a -> c
flip m a -> n a -> Product m n a
forall k (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Pair n a
b (m a -> Product m n a) -> p (m a) -> p (Product m n a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a -> p a) -> Key m -> m a -> p (m a)
forall (map :: * -> *) (p :: * -> *) a.
(StaticMap map, Applicative p) =>
(a -> p a) -> Key map -> map a -> p (map a)
adjustA a -> p a
f Key m
i m a
a
        Right j -> (m a -> n a -> Product m n a) -> m a -> n a -> Product m n a
forall a. a -> a
id   m a -> n a -> Product m n a
forall k (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Pair m a
a (n a -> Product m n a) -> p (n a) -> p (Product m n a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a -> p a) -> Key n -> n a -> p (n a)
forall (map :: * -> *) (p :: * -> *) a.
(StaticMap map, Applicative p) =>
(a -> p a) -> Key map -> map a -> p (map a)
adjustA a -> p a
f Key n
j n a
b
    traverseWithKey :: (Key (Product m n) -> a -> p b)
-> Product m n a -> p (Product m n b)
traverseWithKey f :: Key (Product m n) -> a -> p b
f (Pair a :: m a
a b :: n a
b) =
        m b -> n b -> Product m n b
forall k (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Pair (m b -> n b -> Product m n b)
-> p (m b) -> p (n b -> Product m n b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Key m -> a -> p b) -> m a -> p (m b)
forall (map :: * -> *) (p :: * -> *) a b.
(StaticMap map, Applicative p) =>
(Key map -> a -> p b) -> map a -> p (map b)
traverseWithKey (Either (Key m) (Key n) -> a -> p b
Key (Product m n) -> a -> p b
f (Either (Key m) (Key n) -> a -> p b)
-> (Key m -> Either (Key m) (Key n)) -> Key m -> a -> p b
forall (p :: * -> * -> *) b c a.
Category p =>
p b c -> p a b -> p a c
 Key m -> Either (Key m) (Key n)
forall a b. a -> Either a b
Left) m a
a p (n b -> Product m n b) -> p (n b) -> p (Product m n b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Key n -> a -> p b) -> n a -> p (n b)
forall (map :: * -> *) (p :: * -> *) a b.
(StaticMap map, Applicative p) =>
(Key map -> a -> p b) -> map a -> p (map b)
traverseWithKey (Either (Key m) (Key n) -> a -> p b
Key (Product m n) -> a -> p b
f (Either (Key m) (Key n) -> a -> p b)
-> (Key n -> Either (Key m) (Key n)) -> Key n -> a -> p b
forall (p :: * -> * -> *) b c a.
Category p =>
p b c -> p a b -> p a c
 Key n -> Either (Key m) (Key n)
forall a b. b -> Either a b
Right) n a
b

instance Map Maybe where
    empty :: Maybe a
empty = Maybe a
forall a. Maybe a
Nothing
    alterF :: (Maybe a -> f (Maybe a)) -> Key Maybe -> Maybe a -> f (Maybe a)
alterF = (Maybe a -> f (Maybe a)) -> Key Maybe -> Maybe a -> f (Maybe a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure
    mergeA :: (Key Maybe -> Either' a b -> p (Maybe c))
-> Maybe a -> Maybe b -> p (Maybe c)
mergeA f :: Key Maybe -> Either' a b -> p (Maybe c)
f = (Key Maybe -> Either' a b -> p (Maybe c))
-> Maybe (Either' a b) -> p (Maybe c)
forall (map :: * -> *) (p :: * -> *) a b.
(Map map, Applicative p) =>
(Key map -> a -> p (Maybe b)) -> map a -> p (map b)
mapMaybeWithKeyA Key Maybe -> Either' a b -> p (Maybe c)
f (Maybe (Either' a b) -> p (Maybe c))
-> (Maybe a -> Maybe b -> Maybe (Either' a b))
-> Maybe a
-> Maybe b
-> p (Maybe c)
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ Maybe a -> Maybe b -> Maybe (Either' a b)
forall a b. Maybe a -> Maybe b -> Maybe (Either' a b)
fromMaybes
    mapMaybeWithKeyA :: (Key Maybe -> a -> p (Maybe b)) -> Maybe a -> p (Maybe b)
mapMaybeWithKeyA f :: Key Maybe -> a -> p (Maybe b)
f = (a -> p (Maybe b)) -> Maybe a -> p (Maybe b)
forall (f :: * -> *) (p :: * -> *) a b.
(Filtrable f, Traversable f, Applicative p) =>
(a -> p (Maybe b)) -> f a -> p (f b)
mapMaybeA (Key Maybe -> a -> p (Maybe b)
f ())

instance Map IntMap where
    empty :: IntMap a
empty = IntMap a
forall a. IntMap a
Int.empty
    alterF :: (Maybe a -> f (Maybe a)) -> Key IntMap -> IntMap a -> f (IntMap a)
alterF = (Maybe a -> f (Maybe a)) -> Key IntMap -> IntMap a -> f (IntMap a)
forall (f :: * -> *) a.
Functor f =>
(Maybe a -> f (Maybe a)) -> Key -> IntMap a -> f (IntMap a)
Int.alterF
    mergeA :: (Key IntMap -> Either' a b -> p (Maybe c))
-> IntMap a -> IntMap b -> p (IntMap c)
mergeA f :: Key IntMap -> Either' a b -> p (Maybe c)
f = (Key IntMap -> Either' a b -> p (Maybe c))
-> IntMap (Either' a b) -> p (IntMap c)
forall (map :: * -> *) (p :: * -> *) a b.
(Map map, Applicative p) =>
(Key map -> a -> p (Maybe b)) -> map a -> p (map b)
mapMaybeWithKeyA Key IntMap -> Either' a b -> p (Maybe c)
f (IntMap (Either' a b) -> p (IntMap c))
-> (IntMap a -> IntMap b -> IntMap (Either' a b))
-> IntMap a
-> IntMap b
-> p (IntMap c)
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘
               (Key -> a -> b -> Maybe (Either' a b))
-> (IntMap a -> IntMap (Either' a b))
-> (IntMap b -> IntMap (Either' a b))
-> IntMap a
-> IntMap b
-> IntMap (Either' a b)
forall a b c.
(Key -> a -> b -> Maybe c)
-> (IntMap a -> IntMap c)
-> (IntMap b -> IntMap c)
-> IntMap a
-> IntMap b
-> IntMap c
Int.mergeWithKey ((a -> b -> Maybe (Either' a b))
-> Key -> a -> b -> Maybe (Either' a b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure ((a -> b -> Maybe (Either' a b))
 -> Key -> a -> b -> Maybe (Either' a b))
-> (a -> b -> Maybe (Either' a b))
-> Key
-> a
-> b
-> Maybe (Either' a b)
forall a b. (a -> b) -> a -> b
$ Either' a b -> Maybe (Either' a b)
forall a. a -> Maybe a
Just (Either' a b -> Maybe (Either' a b))
-> (a -> b -> Either' a b) -> a -> b -> Maybe (Either' a b)
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ a -> b -> Either' a b
forall a b. a -> b -> Either' a b
Both) ((a -> Either' a b) -> IntMap a -> IntMap (Either' a b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> Either' a b
forall a b. a -> Either' a b
JustLeft) ((b -> Either' a b) -> IntMap b -> IntMap (Either' a b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> Either' a b
forall a b. b -> Either' a b
JustRight)
    mapMaybeWithKeyA :: (Key IntMap -> a -> p (Maybe b)) -> IntMap a -> p (IntMap b)
mapMaybeWithKeyA f :: Key IntMap -> a -> p (Maybe b)
f = (IntMap (Maybe b) -> IntMap b)
-> p (IntMap (Maybe b)) -> p (IntMap b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap IntMap (Maybe b) -> IntMap b
forall (f :: * -> *) a. Filtrable f => f (Maybe a) -> f a
catMaybes (p (IntMap (Maybe b)) -> p (IntMap b))
-> (IntMap a -> p (IntMap (Maybe b))) -> IntMap a -> p (IntMap b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Key -> a -> p (Maybe b)) -> IntMap a -> p (IntMap (Maybe b))
forall (t :: * -> *) a b.
Applicative t =>
(Key -> a -> t b) -> IntMap a -> t (IntMap b)
Int.traverseWithKey Key -> a -> p (Maybe b)
Key IntMap -> a -> p (Maybe b)
f
    mapEitherWithKeyA :: (Key IntMap -> a -> p (Either b c))
-> IntMap a -> p (IntMap b, IntMap c)
mapEitherWithKeyA f :: Key IntMap -> a -> p (Either b c)
f = (IntMap (Either b c) -> (IntMap b, IntMap c))
-> p (IntMap (Either b c)) -> p (IntMap b, IntMap c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap IntMap (Either b c) -> (IntMap b, IntMap c)
forall (f :: * -> *) a b.
Filtrable f =>
f (Either a b) -> (f a, f b)
partitionEithers (p (IntMap (Either b c)) -> p (IntMap b, IntMap c))
-> (IntMap a -> p (IntMap (Either b c)))
-> IntMap a
-> p (IntMap b, IntMap c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Key -> a -> p (Either b c)) -> IntMap a -> p (IntMap (Either b c))
forall (t :: * -> *) a b.
Applicative t =>
(Key -> a -> t b) -> IntMap a -> t (IntMap b)
Int.traverseWithKey Key -> a -> p (Either b c)
Key IntMap -> a -> p (Either b c)
f

instance Ord key => Map (M.Map key) where
    empty :: Map key a
empty = Map key a
forall k a. Map k a
M.empty
    alterF :: (Maybe a -> f (Maybe a))
-> Key (Map key) -> Map key a -> f (Map key a)
alterF = (Maybe a -> f (Maybe a))
-> Key (Map key) -> Map key a -> f (Map key a)
forall (f :: * -> *) k a.
(Functor f, Ord k) =>
(Maybe a -> f (Maybe a)) -> k -> Map k a -> f (Map k a)
M.alterF
    mergeA :: (Key (Map key) -> Either' a b -> p (Maybe c))
-> Map key a -> Map key b -> p (Map key c)
mergeA f :: Key (Map key) -> Either' a b -> p (Maybe c)
f = WhenMissing p key a c
-> WhenMissing p key b c
-> WhenMatched p key a b c
-> Map key a
-> Map key b
-> p (Map key c)
forall (f :: * -> *) k a c b.
(Applicative f, Ord k) =>
WhenMissing f k a c
-> WhenMissing f k b c
-> WhenMatched f k a b c
-> Map k a
-> Map k b
-> f (Map k c)
M.mergeA ((key -> a -> p (Maybe c)) -> WhenMissing p key a c
forall (f :: * -> *) k x y.
Applicative f =>
(k -> x -> f (Maybe y)) -> WhenMissing f k x y
M.traverseMaybeMissing ((key -> a -> p (Maybe c)) -> WhenMissing p key a c)
-> (key -> a -> p (Maybe c)) -> WhenMissing p key a c
forall a b. (a -> b) -> a -> b
$ \ k :: key
k a :: a
a -> Key (Map key) -> Either' a b -> p (Maybe c)
f key
Key (Map key)
k (a -> Either' a b
forall a b. a -> Either' a b
JustLeft a
a))
                        ((key -> b -> p (Maybe c)) -> WhenMissing p key b c
forall (f :: * -> *) k x y.
Applicative f =>
(k -> x -> f (Maybe y)) -> WhenMissing f k x y
M.traverseMaybeMissing ((key -> b -> p (Maybe c)) -> WhenMissing p key b c)
-> (key -> b -> p (Maybe c)) -> WhenMissing p key b c
forall a b. (a -> b) -> a -> b
$ \ k :: key
k b :: b
b -> Key (Map key) -> Either' a b -> p (Maybe c)
f key
Key (Map key)
k (b -> Either' a b
forall a b. b -> Either' a b
JustRight b
b))
                        ((key -> a -> b -> p (Maybe c)) -> WhenMatched p key a b c
forall k x y (f :: * -> *) z.
(k -> x -> y -> f (Maybe z)) -> WhenMatched f k x y z
M.zipWithMaybeAMatched ((key -> a -> b -> p (Maybe c)) -> WhenMatched p key a b c)
-> (key -> a -> b -> p (Maybe c)) -> WhenMatched p key a b c
forall a b. (a -> b) -> a -> b
$ \ k :: key
k a :: a
a b :: b
b -> Key (Map key) -> Either' a b -> p (Maybe c)
f key
Key (Map key)
k (a -> b -> Either' a b
forall a b. a -> b -> Either' a b
Both a
a b
b))
    mapMaybeWithKeyA :: (Key (Map key) -> a -> p (Maybe b)) -> Map key a -> p (Map key b)
mapMaybeWithKeyA f :: Key (Map key) -> a -> p (Maybe b)
f = (Map key (Maybe b) -> Map key b)
-> p (Map key (Maybe b)) -> p (Map key b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Map key (Maybe b) -> Map key b
forall (f :: * -> *) a. Filtrable f => f (Maybe a) -> f a
catMaybes (p (Map key (Maybe b)) -> p (Map key b))
-> (Map key a -> p (Map key (Maybe b)))
-> Map key a
-> p (Map key b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (key -> a -> p (Maybe b)) -> Map key a -> p (Map key (Maybe b))
forall (t :: * -> *) k a b.
Applicative t =>
(k -> a -> t b) -> Map k a -> t (Map k b)
M.traverseWithKey key -> a -> p (Maybe b)
Key (Map key) -> a -> p (Maybe b)
f
    mapEitherWithKeyA :: (Key (Map key) -> a -> p (Either b c))
-> Map key a -> p (Map key b, Map key c)
mapEitherWithKeyA f :: Key (Map key) -> a -> p (Either b c)
f = (Map key (Either b c) -> (Map key b, Map key c))
-> p (Map key (Either b c)) -> p (Map key b, Map key c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Map key (Either b c) -> (Map key b, Map key c)
forall (f :: * -> *) a b.
Filtrable f =>
f (Either a b) -> (f a, f b)
partitionEithers (p (Map key (Either b c)) -> p (Map key b, Map key c))
-> (Map key a -> p (Map key (Either b c)))
-> Map key a
-> p (Map key b, Map key c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (key -> a -> p (Either b c))
-> Map key a -> p (Map key (Either b c))
forall (t :: * -> *) k a b.
Applicative t =>
(k -> a -> t b) -> Map k a -> t (Map k b)
M.traverseWithKey key -> a -> p (Either b c)
Key (Map key) -> a -> p (Either b c)
f

instance (Map m, Map n) => Map (Compose m n) where
    empty :: Compose m n a
empty = m (n a) -> Compose m n a
forall k k1 (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose m (n a)
forall (map :: * -> *) a. Map map => map a
empty
    alterF :: (Maybe a -> f (Maybe a))
-> Key (Compose m n) -> Compose m n a -> f (Compose m n a)
alterF f :: Maybe a -> f (Maybe a)
f (i, j) = (m (n a) -> Compose m n a) -> f (m (n a)) -> f (Compose m n a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap m (n a) -> Compose m n a
forall k k1 (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose (f (m (n a)) -> f (Compose m n a))
-> (Compose m n a -> f (m (n a)))
-> Compose m n a
-> f (Compose m n a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe (n a) -> f (Maybe (n a))) -> Key m -> m (n a) -> f (m (n a))
forall (map :: * -> *) (f :: * -> *) a.
(Map map, Functor f) =>
(Maybe a -> f (Maybe a)) -> Key map -> map a -> f (map a)
alterF (f (Maybe (n a))
-> (n a -> f (Maybe (n a))) -> Maybe (n a) -> f (Maybe (n a))
forall b a. b -> (a -> b) -> Maybe a -> b
maybe ((a -> n a) -> Maybe a -> Maybe (n a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Key n -> a -> n a
forall (map :: * -> *) a. Map map => Key map -> a -> map a
singleton Key n
j) (Maybe a -> Maybe (n a)) -> f (Maybe a) -> f (Maybe (n a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe a -> f (Maybe a)
f Maybe a
forall a. Maybe a
Nothing) ((n a -> Maybe (n a)) -> f (n a) -> f (Maybe (n a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap n a -> Maybe (n a)
forall a. a -> Maybe a
Just (f (n a) -> f (Maybe (n a)))
-> (n a -> f (n a)) -> n a -> f (Maybe (n a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe a -> f (Maybe a)) -> Key n -> n a -> f (n a)
forall (map :: * -> *) (f :: * -> *) a.
(Map map, Functor f) =>
(Maybe a -> f (Maybe a)) -> Key map -> map a -> f (map a)
alterF Maybe a -> f (Maybe a)
f Key n
j)) Key m
i (m (n a) -> f (m (n a)))
-> (Compose m n a -> m (n a)) -> Compose m n a -> f (m (n a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Compose m n a -> m (n a)
forall k1 (f :: k1 -> *) k2 (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose
    mergeA :: (Key (Compose m n) -> Either' a b -> p (Maybe c))
-> Compose m n a -> Compose m n b -> p (Compose m n c)
mergeA f :: Key (Compose m n) -> Either' a b -> p (Maybe c)
f =
        (m (n c) -> Compose m n c) -> p (m (n c)) -> p (Compose m n c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap m (n c) -> Compose m n c
forall k k1 (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose (p (m (n c)) -> p (Compose m n c))
-> (Compose m n a -> Compose m n b -> p (m (n c)))
-> Compose m n a
-> Compose m n b
-> p (Compose m n c)
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘
        (m (n a) -> m (n b) -> p (m (n c)))
-> (Compose m n a -> m (n a))
-> (Compose m n b -> m (n b))
-> Compose m n a
-> Compose m n b
-> p (m (n c))
forall a' b' c a b.
(a' -> b' -> c) -> (a -> a') -> (b -> b') -> a -> b -> c
compose2 ((Key m -> Either' (n a) (n b) -> p (Maybe (n c)))
-> m (n a) -> m (n b) -> p (m (n c))
forall (map :: * -> *) (p :: * -> *) a b c.
(Map map, Applicative p) =>
(Key map -> Either' a b -> p (Maybe c))
-> map a -> map b -> p (map c)
mergeA ((Key m -> Either' (n a) (n b) -> p (Maybe (n c)))
 -> m (n a) -> m (n b) -> p (m (n c)))
-> (Key m -> Either' (n a) (n b) -> p (Maybe (n c)))
-> m (n a)
-> m (n b)
-> p (m (n c))
forall a b. (a -> b) -> a -> b
$ \ i :: Key m
i ->
                  (n c -> Maybe (n c)) -> p (n c) -> p (Maybe (n c))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap n c -> Maybe (n c)
forall a. a -> Maybe a
Just (p (n c) -> p (Maybe (n c)))
-> (Either' (n a) (n b) -> p (n c))
-> Either' (n a) (n b)
-> p (Maybe (n c))
forall (p :: * -> * -> *) b c a.
Category p =>
p b c -> p a b -> p a c
 (n a -> p (n c))
-> (n b -> p (n c))
-> (n a -> n b -> p (n c))
-> Either' (n a) (n b)
-> p (n c)
forall a c b.
(a -> c) -> (b -> c) -> (a -> b -> c) -> Either' a b -> c
either' ((Key n -> a -> p (Maybe c)) -> n a -> p (n c)
forall (map :: * -> *) (p :: * -> *) a b.
(Map map, Applicative p) =>
(Key map -> a -> p (Maybe b)) -> map a -> p (map b)
mapMaybeWithKeyA ((Key n -> a -> p (Maybe c)) -> n a -> p (n c))
-> (Key n -> a -> p (Maybe c)) -> n a -> p (n c)
forall a b. (a -> b) -> a -> b
$ \ j :: Key n
j -> Key (Compose m n) -> Either' a b -> p (Maybe c)
f (Key m
i, Key n
j) (Either' a b -> p (Maybe c))
-> (a -> Either' a b) -> a -> p (Maybe c)
forall (p :: * -> * -> *) b c a.
Category p =>
p b c -> p a b -> p a c
 a -> Either' a b
forall a b. a -> Either' a b
JustLeft)
                                      ((Key n -> b -> p (Maybe c)) -> n b -> p (n c)
forall (map :: * -> *) (p :: * -> *) a b.
(Map map, Applicative p) =>
(Key map -> a -> p (Maybe b)) -> map a -> p (map b)
mapMaybeWithKeyA ((Key n -> b -> p (Maybe c)) -> n b -> p (n c))
-> (Key n -> b -> p (Maybe c)) -> n b -> p (n c)
forall a b. (a -> b) -> a -> b
$ \ j :: Key n
j -> Key (Compose m n) -> Either' a b -> p (Maybe c)
f (Key m
i, Key n
j) (Either' a b -> p (Maybe c))
-> (b -> Either' a b) -> b -> p (Maybe c)
forall (p :: * -> * -> *) b c a.
Category p =>
p b c -> p a b -> p a c
 b -> Either' a b
forall a b. b -> Either' a b
JustRight)
                                      ((Key n -> Either' a b -> p (Maybe c)) -> n a -> n b -> p (n c)
forall (map :: * -> *) (p :: * -> *) a b c.
(Map map, Applicative p) =>
(Key map -> Either' a b -> p (Maybe c))
-> map a -> map b -> p (map c)
mergeA ((Key n -> Either' a b -> p (Maybe c)) -> n a -> n b -> p (n c))
-> (Key n -> Either' a b -> p (Maybe c)) -> n a -> n b -> p (n c)
forall a b. (a -> b) -> a -> b
$ \ j :: Key n
j -> Key (Compose m n) -> Either' a b -> p (Maybe c)
f (Key m
i, Key n
j))) Compose m n a -> m (n a)
forall k1 (f :: k1 -> *) k2 (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose Compose m n b -> m (n b)
forall k1 (f :: k1 -> *) k2 (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose
    mapMaybeWithKeyA :: (Key (Compose m n) -> a -> p (Maybe b))
-> Compose m n a -> p (Compose m n b)
mapMaybeWithKeyA f :: Key (Compose m n) -> a -> p (Maybe b)
f = (m (n b) -> Compose m n b) -> p (m (n b)) -> p (Compose m n b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap m (n b) -> Compose m n b
forall k k1 (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose (p (m (n b)) -> p (Compose m n b))
-> (Compose m n a -> p (m (n b)))
-> Compose m n a
-> p (Compose m n b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Key m -> n a -> p (Maybe (n b))) -> m (n a) -> p (m (n b))
forall (map :: * -> *) (p :: * -> *) a b.
(Map map, Applicative p) =>
(Key map -> a -> p (Maybe b)) -> map a -> p (map b)
mapMaybeWithKeyA (\ i :: Key m
i -> (n b -> Maybe (n b)) -> p (n b) -> p (Maybe (n b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap n b -> Maybe (n b)
forall a. a -> Maybe a
Just (p (n b) -> p (Maybe (n b)))
-> (n a -> p (n b)) -> n a -> p (Maybe (n b))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Key n -> a -> p (Maybe b)) -> n a -> p (n b)
forall (map :: * -> *) (p :: * -> *) a b.
(Map map, Applicative p) =>
(Key map -> a -> p (Maybe b)) -> map a -> p (map b)
mapMaybeWithKeyA (\ j :: Key n
j -> Key (Compose m n) -> a -> p (Maybe b)
f (Key m
i, Key n
j))) (m (n a) -> p (m (n b)))
-> (Compose m n a -> m (n a)) -> Compose m n a -> p (m (n b))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Compose m n a -> m (n a)
forall k1 (f :: k1 -> *) k2 (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose

instance (Map m, Map n) => Map (Product m n) where
    empty :: Product m n a
empty = m a -> n a -> Product m n a
forall k (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Pair m a
forall (map :: * -> *) a. Map map => map a
empty n a
forall (map :: * -> *) a. Map map => map a
empty
    alterF :: (Maybe a -> f (Maybe a))
-> Key (Product m n) -> Product m n a -> f (Product m n a)
alterF f :: Maybe a -> f (Maybe a)
f k :: Key (Product m n)
k (Pair a :: m a
a b :: n a
b) = case Key (Product m n)
k of
        Left  i -> (m a -> n a -> Product m n a) -> n a -> m a -> Product m n a
forall a b c. (a -> b -> c) -> b -> a -> c
flip m a -> n a -> Product m n a
forall k (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Pair n a
b (m a -> Product m n a) -> f (m a) -> f (Product m n a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Maybe a -> f (Maybe a)) -> Key m -> m a -> f (m a)
forall (map :: * -> *) (f :: * -> *) a.
(Map map, Functor f) =>
(Maybe a -> f (Maybe a)) -> Key map -> map a -> f (map a)
alterF Maybe a -> f (Maybe a)
f Key m
i m a
a
        Right j -> (m a -> n a -> Product m n a) -> m a -> n a -> Product m n a
forall a. a -> a
id   m a -> n a -> Product m n a
forall k (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Pair m a
a (n a -> Product m n a) -> f (n a) -> f (Product m n a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Maybe a -> f (Maybe a)) -> Key n -> n a -> f (n a)
forall (map :: * -> *) (f :: * -> *) a.
(Map map, Functor f) =>
(Maybe a -> f (Maybe a)) -> Key map -> map a -> f (map a)
alterF Maybe a -> f (Maybe a)
f Key n
j n a
b
    mergeA :: (Key (Product m n) -> Either' a b -> p (Maybe c))
-> Product m n a -> Product m n b -> p (Product m n c)
mergeA f :: Key (Product m n) -> Either' a b -> p (Maybe c)
f (Pair a₀ :: m a
a₀ b₀ :: n a
b₀) (Pair a₁ :: m b
a₁ b₁ :: n b
b₁) = m c -> n c -> Product m n c
forall k (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Pair (m c -> n c -> Product m n c)
-> p (m c) -> p (n c -> Product m n c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Key m -> Either' a b -> p (Maybe c)) -> m a -> m b -> p (m c)
forall (map :: * -> *) (p :: * -> *) a b c.
(Map map, Applicative p) =>
(Key map -> Either' a b -> p (Maybe c))
-> map a -> map b -> p (map c)
mergeA (Either (Key m) (Key n) -> Either' a b -> p (Maybe c)
Key (Product m n) -> Either' a b -> p (Maybe c)
f (Either (Key m) (Key n) -> Either' a b -> p (Maybe c))
-> (Key m -> Either (Key m) (Key n))
-> Key m
-> Either' a b
-> p (Maybe c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Key m -> Either (Key m) (Key n)
forall a b. a -> Either a b
Left) m a
a₀ m b
a₁ p (n c -> Product m n c) -> p (n c) -> p (Product m n c)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Key n -> Either' a b -> p (Maybe c)) -> n a -> n b -> p (n c)
forall (map :: * -> *) (p :: * -> *) a b c.
(Map map, Applicative p) =>
(Key map -> Either' a b -> p (Maybe c))
-> map a -> map b -> p (map c)
mergeA (Either (Key m) (Key n) -> Either' a b -> p (Maybe c)
Key (Product m n) -> Either' a b -> p (Maybe c)
f (Either (Key m) (Key n) -> Either' a b -> p (Maybe c))
-> (Key n -> Either (Key m) (Key n))
-> Key n
-> Either' a b
-> p (Maybe c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Key n -> Either (Key m) (Key n)
forall a b. b -> Either a b
Right) n a
b₀ n b
b₁
    mapMaybeWithKeyA :: (Key (Product m n) -> a -> p (Maybe b))
-> Product m n a -> p (Product m n b)
mapMaybeWithKeyA f :: Key (Product m n) -> a -> p (Maybe b)
f (Pair a :: m a
a b :: n a
b) = m b -> n b -> Product m n b
forall k (f :: k -> *) (g :: k -> *) (a :: k).
f a -> g a -> Product f g a
Pair (m b -> n b -> Product m n b)
-> p (m b) -> p (n b -> Product m n b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Key m -> a -> p (Maybe b)) -> m a -> p (m b)
forall (map :: * -> *) (p :: * -> *) a b.
(Map map, Applicative p) =>
(Key map -> a -> p (Maybe b)) -> map a -> p (map b)
mapMaybeWithKeyA (Either (Key m) (Key n) -> a -> p (Maybe b)
Key (Product m n) -> a -> p (Maybe b)
f (Either (Key m) (Key n) -> a -> p (Maybe b))
-> (Key m -> Either (Key m) (Key n)) -> Key m -> a -> p (Maybe b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Key m -> Either (Key m) (Key n)
forall a b. a -> Either a b
Left) m a
a p (n b -> Product m n b) -> p (n b) -> p (Product m n b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Key n -> a -> p (Maybe b)) -> n a -> p (n b)
forall (map :: * -> *) (p :: * -> *) a b.
(Map map, Applicative p) =>
(Key map -> a -> p (Maybe b)) -> map a -> p (map b)
mapMaybeWithKeyA (Either (Key m) (Key n) -> a -> p (Maybe b)
Key (Product m n) -> a -> p (Maybe b)
f (Either (Key m) (Key n) -> a -> p (Maybe b))
-> (Key n -> Either (Key m) (Key n)) -> Key n -> a -> p (Maybe b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Key n -> Either (Key m) (Key n)
forall a b. b -> Either a b
Right) n a
b

-- | Look up the key in the map.
infix 9 !?
(!?) :: StaticMap map => map a -> Key map -> Maybe a
!? :: map a -> Key map -> Maybe a
(!?) = (Key map -> map a -> Maybe a) -> map a -> Key map -> Maybe a
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((Key map -> map a -> Maybe a) -> map a -> Key map -> Maybe a)
-> (Key map -> map a -> Maybe a) -> map a -> Key map -> Maybe a
forall a b. (a -> b) -> a -> b
$ Last a -> Maybe a
forall a. Last a -> Maybe a
getLast (Last a -> Maybe a)
-> (Key map -> map a -> Last a) -> Key map -> map a -> Maybe a
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ (Last a, map a) -> Last a
forall a b. (a, b) -> a
fst ((Last a, map a) -> Last a)
-> (Key map -> map a -> (Last a, map a))
-> Key map
-> map a
-> Last a
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ (a -> (Last a, a)) -> Key map -> map a -> (Last a, map a)
forall (map :: * -> *) (p :: * -> *) a.
(StaticMap map, Applicative p) =>
(a -> p a) -> Key map -> map a -> p (map a)
adjustA ((,) (Last a -> a -> (Last a, a))
-> (a -> Last a) -> a -> a -> (Last a, a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe a -> Last a
forall a. Maybe a -> Last a
Last (Maybe a -> Last a) -> (a -> Maybe a) -> a -> Last a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Maybe a
forall a. a -> Maybe a
Just (a -> a -> (Last a, a)) -> (a -> a) -> a -> (Last a, a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> a -> a
forall a. a -> a
id)

-- | Insert a key and new value into the map, the new value clobbering the old if the key is already present.
-- @'insert' = 'insertWith' 'pure'@
insert :: Map map => Key map -> a -> map a -> map a
insert :: Key map -> a -> map a -> map a
insert = (a -> a -> a) -> Key map -> a -> map a -> map a
forall (map :: * -> *) a.
Map map =>
(a -> a -> a) -> Key map -> a -> map a -> map a
insertWith a -> a -> a
forall (f :: * -> *) a. Applicative f => a -> f a
pure

-- | Insert a key and new value into the map, combining the old and new values with the given function if the key is already present.
insertWith :: Map map => (a -> a -> a) -> Key map -> a -> map a -> map a
insertWith :: (a -> a -> a) -> Key map -> a -> map a -> map a
insertWith f :: a -> a -> a
f = (a -> Key map -> map a -> map a) -> Key map -> a -> map a -> map a
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((a -> Key map -> map a -> map a)
 -> Key map -> a -> map a -> map a)
-> (a -> Key map -> map a -> map a)
-> Key map
-> a
-> map a
-> map a
forall a b. (a -> b) -> a -> b
$ \ a :: a
a -> (Maybe a -> Maybe a) -> Key map -> map a -> map a
forall (map :: * -> *) a.
Map map =>
(Maybe a -> Maybe a) -> Key map -> map a -> map a
alter (a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> (Maybe a -> a) -> Maybe a -> Maybe a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> (a -> a) -> Maybe a -> a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe a
a (a -> a -> a
f a
a))

-- | Insert a key and new value into the map, looking up the old value if the key is already present.
insertLookup :: Map map => Key map -> a -> map a -> (Maybe a, map a)
insertLookup :: Key map -> a -> map a -> (Maybe a, map a)
insertLookup = (a -> a -> a) -> Key map -> a -> map a -> (Maybe a, map a)
forall (map :: * -> *) a.
Map map =>
(a -> a -> a) -> Key map -> a -> map a -> (Maybe a, map a)
insertLookupWith a -> a -> a
forall (f :: * -> *) a. Applicative f => a -> f a
pure

-- | Insert a key and new value into the map, looking up the old value and combining the old and new values with the given function if the key is already present.
insertLookupWith :: Map map => (a -> a -> a) -> Key map -> a -> map a -> (Maybe a, map a)
insertLookupWith :: (a -> a -> a) -> Key map -> a -> map a -> (Maybe a, map a)
insertLookupWith f :: a -> a -> a
f = (a -> Key map -> map a -> (Maybe a, map a))
-> Key map -> a -> map a -> (Maybe a, map a)
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((a -> Key map -> map a -> (Maybe a, map a))
 -> Key map -> a -> map a -> (Maybe a, map a))
-> (a -> Key map -> map a -> (Maybe a, map a))
-> Key map
-> a
-> map a
-> (Maybe a, map a)
forall a b. (a -> b) -> a -> b
$ \ a :: a
a -> (Maybe a -> Maybe a) -> Key map -> map a -> (Maybe a, map a)
forall (map :: * -> *) a.
Map map =>
(Maybe a -> Maybe a) -> Key map -> map a -> (Maybe a, map a)
alterLookup (a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> (Maybe a -> a) -> Maybe a -> Maybe a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> (a -> a) -> Maybe a -> a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe a
a (a -> a -> a
f a
a))

-- | Delete a key and its value from the map. If the key is absent, the map is returned unmodified.
delete :: Map map => Key map -> map a -> map a
delete :: Key map -> map a -> map a
delete = (Maybe a -> Maybe a) -> Key map -> map a -> map a
forall (map :: * -> *) a.
Map map =>
(Maybe a -> Maybe a) -> Key map -> map a -> map a
alter (Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe a
forall a. Maybe a
Nothing)

-- | Modify the value of the key in the map. If the key is absent, the map is returned unmodified.
adjust :: StaticMap map => (a -> a) -> Key map -> map a -> map a
adjust :: (a -> a) -> Key map -> map a -> map a
adjust f :: a -> a
f = Identity (map a) -> map a
forall a. Identity a -> a
runIdentity (Identity (map a) -> map a)
-> (Key map -> map a -> Identity (map a))
-> Key map
-> map a
-> map a
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ (a -> Identity a) -> Key map -> map a -> Identity (map a)
forall (map :: * -> *) (p :: * -> *) a.
(StaticMap map, Applicative p) =>
(a -> p a) -> Key map -> map a -> p (map a)
adjustA (a -> Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> Identity a) -> (a -> a) -> a -> Identity a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> a
f)

-- | Modify the value of the key in the map, or delete the key and its value from the map, if the given function returns 'Just' or 'Nothing', in turn. If the key is absent, the map is returned unmodified.
update :: Map map => (a -> Maybe a) -> Key map -> map a -> map a
update :: (a -> Maybe a) -> Key map -> map a -> map a
update f :: a -> Maybe a
f = (Maybe a -> Maybe a) -> Key map -> map a -> map a
forall (map :: * -> *) a.
Map map =>
(Maybe a -> Maybe a) -> Key map -> map a -> map a
alter (Maybe a -> (a -> Maybe a) -> Maybe a
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= a -> Maybe a
f)

-- | Modify the value of the key in the map, or delete the key and its value from the map, if the given function returns 'Just' or 'Nothing', in turn, looking up the old value if the key is already present. If the key is absent, the map is returned unmodified.
updateLookup :: Map map => (a -> Maybe a) -> Key map -> map a -> (Maybe a, map a)
updateLookup :: (a -> Maybe a) -> Key map -> map a -> (Maybe a, map a)
updateLookup f :: a -> Maybe a
f = (Maybe a -> Maybe a) -> Key map -> map a -> (Maybe a, map a)
forall (map :: * -> *) a.
Map map =>
(Maybe a -> Maybe a) -> Key map -> map a -> (Maybe a, map a)
alterLookup (Maybe a -> (a -> Maybe a) -> Maybe a
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= a -> Maybe a
f)

-- | Modify the value of the key in the map, or insert the key and its value into the map, or delete the key and its value from the map.
alter :: Map map => (Maybe a -> Maybe a) -> Key map -> map a -> map a
alter :: (Maybe a -> Maybe a) -> Key map -> map a -> map a
alter f :: Maybe a -> Maybe a
f = Identity (map a) -> map a
forall a. Identity a -> a
runIdentity (Identity (map a) -> map a)
-> (Key map -> map a -> Identity (map a))
-> Key map
-> map a
-> map a
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ (Maybe a -> Identity (Maybe a))
-> Key map -> map a -> Identity (map a)
forall (map :: * -> *) (f :: * -> *) a.
(Map map, Functor f) =>
(Maybe a -> f (Maybe a)) -> Key map -> map a -> f (map a)
alterF (Maybe a -> Identity (Maybe a)
forall a. a -> Identity a
Identity (Maybe a -> Identity (Maybe a))
-> (Maybe a -> Maybe a) -> Maybe a -> Identity (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe a -> Maybe a
f)

-- | Modify the value of the key in the map, or insert the key and its value into the map, or delete the key and its value from the map, looking up the old value if the key is already present.
alterLookup :: Map map => (Maybe a -> Maybe a) -> Key map -> map a -> (Maybe a, map a)
alterLookup :: (Maybe a -> Maybe a) -> Key map -> map a -> (Maybe a, map a)
alterLookup f :: Maybe a -> Maybe a
f = (Maybe a -> (Maybe a, Maybe a))
-> Key map -> map a -> (Maybe a, map a)
forall (map :: * -> *) (f :: * -> *) a.
(Map map, Functor f) =>
(Maybe a -> f (Maybe a)) -> Key map -> map a -> f (map a)
alterF ((,) (Maybe a -> Maybe a -> (Maybe a, Maybe a))
-> (Maybe a -> Maybe a) -> Maybe a -> (Maybe a, Maybe a)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe a -> Maybe a
f)

-- | Modify the value of the key in the map, or insert the key and its value into the map, or delete the key and its value from the map, looking up the old value if the key is already present, functorially.
--
-- This is no more general than `alterF`, but is defined for convenience.
alterLookupF :: (Map map, Functor f) => (Maybe a -> f (Maybe a)) -> Key map -> map a -> f (Maybe a, map a)
alterLookupF :: (Maybe a -> f (Maybe a)) -> Key map -> map a -> f (Maybe a, map a)
alterLookupF f :: Maybe a -> f (Maybe a)
f = Compose f ((,) (Maybe a)) (map a) -> f (Maybe a, map a)
forall k1 (f :: k1 -> *) k2 (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose (Compose f ((,) (Maybe a)) (map a) -> f (Maybe a, map a))
-> (Key map -> map a -> Compose f ((,) (Maybe a)) (map a))
-> Key map
-> map a
-> f (Maybe a, map a)
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ (Maybe a -> Compose f ((,) (Maybe a)) (Maybe a))
-> Key map -> map a -> Compose f ((,) (Maybe a)) (map a)
forall (map :: * -> *) (f :: * -> *) a.
(Map map, Functor f) =>
(Maybe a -> f (Maybe a)) -> Key map -> map a -> f (map a)
alterF (f (Maybe a, Maybe a) -> Compose f ((,) (Maybe a)) (Maybe a)
forall k k1 (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose (f (Maybe a, Maybe a) -> Compose f ((,) (Maybe a)) (Maybe a))
-> (Maybe a -> f (Maybe a, Maybe a))
-> Maybe a
-> Compose f ((,) (Maybe a)) (Maybe a)
forall (p :: * -> * -> *) b c a.
Category p =>
p b c -> p a b -> p a c
 ((Maybe a -> (Maybe a, Maybe a))
 -> f (Maybe a) -> f (Maybe a, Maybe a))
-> (Maybe a -> Maybe a -> (Maybe a, Maybe a))
-> (Maybe a -> f (Maybe a))
-> Maybe a
-> f (Maybe a, Maybe a)
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (Maybe a -> (Maybe a, Maybe a))
-> f (Maybe a) -> f (Maybe a, Maybe a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (,) Maybe a -> f (Maybe a)
f)

-- | Map a function over each value in the map.
mapWithKey :: StaticMap map => (Key map -> a -> b) -> map a -> map b
mapWithKey :: (Key map -> a -> b) -> map a -> map b
mapWithKey f :: Key map -> a -> b
f = Identity (map b) -> map b
forall a. Identity a -> a
runIdentity (Identity (map b) -> map b)
-> (map a -> Identity (map b)) -> map a -> map b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Key map -> a -> Identity b) -> map a -> Identity (map b)
forall (map :: * -> *) (p :: * -> *) a b.
(StaticMap map, Applicative p) =>
(Key map -> a -> p b) -> map a -> p (map b)
traverseWithKey (b -> Identity b
forall a. a -> Identity a
Identity (b -> Identity b)
-> (Key map -> a -> b) -> Key map -> a -> Identity b
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ Key map -> a -> b
f)

-- | Map a function over each value in the map, gathering the 'Just' values and forgetting the 'Nothing'.
mapMaybeWithKey :: Map map => (Key map -> a -> Maybe b) -> map a -> map b
mapMaybeWithKey :: (Key map -> a -> Maybe b) -> map a -> map b
mapMaybeWithKey f :: Key map -> a -> Maybe b
f = Identity (map b) -> map b
forall a. Identity a -> a
runIdentity (Identity (map b) -> map b)
-> (map a -> Identity (map b)) -> map a -> map b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Key map -> a -> Identity (Maybe b)) -> map a -> Identity (map b)
forall (map :: * -> *) (p :: * -> *) a b.
(Map map, Applicative p) =>
(Key map -> a -> p (Maybe b)) -> map a -> p (map b)
mapMaybeWithKeyA (Maybe b -> Identity (Maybe b)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe b -> Identity (Maybe b))
-> (Key map -> a -> Maybe b) -> Key map -> a -> Identity (Maybe b)
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ Key map -> a -> Maybe b
f)

-- | Map a function over each value in the map, gathering the 'Left' and 'Right' separately.
mapEitherWithKey :: Map map => (Key map -> a -> Either b c) -> map a -> (map b, map c)
mapEitherWithKey :: (Key map -> a -> Either b c) -> map a -> (map b, map c)
mapEitherWithKey f :: Key map -> a -> Either b c
f = Identity (map b, map c) -> (map b, map c)
forall a. Identity a -> a
runIdentity (Identity (map b, map c) -> (map b, map c))
-> (map a -> Identity (map b, map c)) -> map a -> (map b, map c)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Key map -> a -> Identity (Either b c))
-> map a -> Identity (map b, map c)
forall (map :: * -> *) (p :: * -> *) a b c.
(Map map, Applicative p) =>
(Key map -> a -> p (Either b c)) -> map a -> p (map b, map c)
mapEitherWithKeyA (Either b c -> Identity (Either b c)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either b c -> Identity (Either b c))
-> (Key map -> a -> Either b c)
-> Key map
-> a
-> Identity (Either b c)
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ Key map -> a -> Either b c
f)

foldMapWithKeyA :: (StaticMap map, Applicative p, Monoid b) => (Key map -> a -> p b) -> map a -> p b
foldMapWithKeyA :: (Key map -> a -> p b) -> map a -> p b
foldMapWithKeyA f :: Key map -> a -> p b
f = (Const b (map Any) -> b) -> p (Const b (map Any)) -> p b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Const b (map Any) -> b
forall a k (b :: k). Const a b -> a
getConst (p (Const b (map Any)) -> p b)
-> (map a -> p (Const b (map Any))) -> map a -> p b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Compose p (Const b) (map Any) -> p (Const b (map Any))
forall k1 (f :: k1 -> *) k2 (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose (Compose p (Const b) (map Any) -> p (Const b (map Any)))
-> (map a -> Compose p (Const b) (map Any))
-> map a
-> p (Const b (map Any))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Key map -> a -> Compose p (Const b) Any)
-> map a -> Compose p (Const b) (map Any)
forall (map :: * -> *) (p :: * -> *) a b.
(StaticMap map, Applicative p) =>
(Key map -> a -> p b) -> map a -> p (map b)
traverseWithKey (p (Const b Any) -> Compose p (Const b) Any
forall k k1 (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose (p (Const b Any) -> Compose p (Const b) Any)
-> (Key map -> a -> p (Const b Any))
-> Key map
-> a
-> Compose p (Const b) Any
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ (b -> Const b Any) -> p b -> p (Const b Any)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> Const b Any
forall k a (b :: k). a -> Const a b
Const (p b -> p (Const b Any))
-> (Key map -> a -> p b) -> Key map -> a -> p (Const b Any)
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ Key map -> a -> p b
f)

foldrWithKeyM :: (StaticMap map, Monad m) => (Key map -> a -> b -> m b) -> b -> map a -> m b
foldrWithKeyM :: (Key map -> a -> b -> m b) -> b -> map a -> m b
foldrWithKeyM f :: Key map -> a -> b -> m b
f = (map a -> b -> m b) -> b -> map a -> m b
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((map a -> b -> m b) -> b -> map a -> m b)
-> (map a -> b -> m b) -> b -> map a -> m b
forall a b. (a -> b) -> a -> b
$ Kleisli m b b -> b -> m b
forall (m :: * -> *) a b. Kleisli m a b -> a -> m b
runKleisli (Kleisli m b b -> b -> m b)
-> (map a -> Kleisli m b b) -> map a -> b -> m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Endo (Kleisli m) b -> Kleisli m b b
forall k (s :: k -> k -> *) (a :: k). Endo s a -> s a a
appEndo (Endo (Kleisli m) b -> Kleisli m b b)
-> (map a -> Endo (Kleisli m) b) -> map a -> Kleisli m b b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Key map -> a -> Endo (Kleisli m) b) -> map a -> Endo (Kleisli m) b
forall (map :: * -> *) b a.
(StaticMap map, Monoid b) =>
(Key map -> a -> b) -> map a -> b
foldMapWithKey (Kleisli m b b -> Endo (Kleisli m) b
forall k (s :: k -> k -> *) (a :: k). s a a -> Endo s a
Endo (Kleisli m b b -> Endo (Kleisli m) b)
-> (Key map -> a -> Kleisli m b b)
-> Key map
-> a
-> Endo (Kleisli m) b
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ (b -> m b) -> Kleisli m b b
forall (m :: * -> *) a b. (a -> m b) -> Kleisli m a b
Kleisli ((b -> m b) -> Kleisli m b b)
-> (Key map -> a -> b -> m b) -> Key map -> a -> Kleisli m b b
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ Key map -> a -> b -> m b
f)

foldlWithKeyM :: (StaticMap map, Monad m) => (b -> Key map -> a -> m b) -> b -> map a -> m b
foldlWithKeyM :: (b -> Key map -> a -> m b) -> b -> map a -> m b
foldlWithKeyM f :: b -> Key map -> a -> m b
f = (map a -> b -> m b) -> b -> map a -> m b
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((map a -> b -> m b) -> b -> map a -> m b)
-> (map a -> b -> m b) -> b -> map a -> m b
forall a b. (a -> b) -> a -> b
$ Kleisli m b b -> b -> m b
forall (m :: * -> *) a b. Kleisli m a b -> a -> m b
runKleisli (Kleisli m b b -> b -> m b)
-> (map a -> Kleisli m b b) -> map a -> b -> m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Endo (Kleisli m) b -> Kleisli m b b
forall k (s :: k -> k -> *) (a :: k). Endo s a -> s a a
appEndo (Endo (Kleisli m) b -> Kleisli m b b)
-> (map a -> Endo (Kleisli m) b) -> map a -> Kleisli m b b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dual (Endo (Kleisli m) b) -> Endo (Kleisli m) b
forall a. Dual a -> a
getDual (Dual (Endo (Kleisli m) b) -> Endo (Kleisli m) b)
-> (map a -> Dual (Endo (Kleisli m) b))
-> map a
-> Endo (Kleisli m) b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Key map -> a -> Dual (Endo (Kleisli m) b))
-> map a -> Dual (Endo (Kleisli m) b)
forall (map :: * -> *) b a.
(StaticMap map, Monoid b) =>
(Key map -> a -> b) -> map a -> b
foldMapWithKey (Endo (Kleisli m) b -> Dual (Endo (Kleisli m) b)
forall a. a -> Dual a
Dual (Endo (Kleisli m) b -> Dual (Endo (Kleisli m) b))
-> (Key map -> a -> Endo (Kleisli m) b)
-> Key map
-> a
-> Dual (Endo (Kleisli m) b)
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ Kleisli m b b -> Endo (Kleisli m) b
forall k (s :: k -> k -> *) (a :: k). s a a -> Endo s a
Endo (Kleisli m b b -> Endo (Kleisli m) b)
-> (Key map -> a -> Kleisli m b b)
-> Key map
-> a
-> Endo (Kleisli m) b
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ (b -> m b) -> Kleisli m b b
forall (m :: * -> *) a b. (a -> m b) -> Kleisli m a b
Kleisli ((b -> m b) -> Kleisli m b b)
-> (Key map -> a -> b -> m b) -> Key map -> a -> Kleisli m b b
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ \ k :: Key map
k a :: a
a b :: b
b -> b -> Key map -> a -> m b
f b
b Key map
k a
a)

foldMapWithKey :: (StaticMap map, Monoid b) => (Key map -> a -> b) -> map a -> b
foldMapWithKey :: (Key map -> a -> b) -> map a -> b
foldMapWithKey f :: Key map -> a -> b
f = Identity b -> b
forall a. Identity a -> a
runIdentity (Identity b -> b) -> (map a -> Identity b) -> map a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Key map -> a -> Identity b) -> map a -> Identity b
forall (map :: * -> *) (p :: * -> *) b a.
(StaticMap map, Applicative p, Monoid b) =>
(Key map -> a -> p b) -> map a -> p b
foldMapWithKeyA (b -> Identity b
forall (f :: * -> *) a. Applicative f => a -> f a
pure (b -> Identity b)
-> (Key map -> a -> b) -> Key map -> a -> Identity b
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ Key map -> a -> b
f)

foldrWithKey :: StaticMap map => (Key map -> a -> b -> b) -> b -> map a -> b
foldrWithKey :: (Key map -> a -> b -> b) -> b -> map a -> b
foldrWithKey f :: Key map -> a -> b -> b
f = (map a -> b -> b) -> b -> map a -> b
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((map a -> b -> b) -> b -> map a -> b)
-> (map a -> b -> b) -> b -> map a -> b
forall a b. (a -> b) -> a -> b
$ Endo (->) b -> b -> b
forall k (s :: k -> k -> *) (a :: k). Endo s a -> s a a
appEndo (Endo (->) b -> b -> b)
-> (map a -> Endo (->) b) -> map a -> b -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Key map -> a -> Endo (->) b) -> map a -> Endo (->) b
forall (map :: * -> *) b a.
(StaticMap map, Monoid b) =>
(Key map -> a -> b) -> map a -> b
foldMapWithKey ((b -> b) -> Endo (->) b
forall k (s :: k -> k -> *) (a :: k). s a a -> Endo s a
Endo ((b -> b) -> Endo (->) b)
-> (Key map -> a -> b -> b) -> Key map -> a -> Endo (->) b
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ Key map -> a -> b -> b
f)

foldlWithKey :: StaticMap map => (b -> Key map -> a -> b) -> b -> map a -> b
foldlWithKey :: (b -> Key map -> a -> b) -> b -> map a -> b
foldlWithKey f :: b -> Key map -> a -> b
f = (map a -> b -> b) -> b -> map a -> b
forall a b c. (a -> b -> c) -> b -> a -> c
flip ((map a -> b -> b) -> b -> map a -> b)
-> (map a -> b -> b) -> b -> map a -> b
forall a b. (a -> b) -> a -> b
$ Endo (->) b -> b -> b
forall k (s :: k -> k -> *) (a :: k). Endo s a -> s a a
appEndo (Endo (->) b -> b -> b)
-> (map a -> Endo (->) b) -> map a -> b -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dual (Endo (->) b) -> Endo (->) b
forall a. Dual a -> a
getDual (Dual (Endo (->) b) -> Endo (->) b)
-> (map a -> Dual (Endo (->) b)) -> map a -> Endo (->) b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Key map -> a -> Dual (Endo (->) b)) -> map a -> Dual (Endo (->) b)
forall (map :: * -> *) b a.
(StaticMap map, Monoid b) =>
(Key map -> a -> b) -> map a -> b
foldMapWithKey (Endo (->) b -> Dual (Endo (->) b)
forall a. a -> Dual a
Dual (Endo (->) b -> Dual (Endo (->) b))
-> (Key map -> a -> Endo (->) b)
-> Key map
-> a
-> Dual (Endo (->) b)
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ (b -> b) -> Endo (->) b
forall k (s :: k -> k -> *) (a :: k). s a a -> Endo s a
Endo ((b -> b) -> Endo (->) b)
-> (Key map -> a -> b -> b) -> Key map -> a -> Endo (->) b
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ \ k :: Key map
k a :: a
a b :: b
b -> b -> Key map -> a -> b
f b
b Key map
k a
a)

fromList :: Map map => [(Key map, a)] -> map a
fromList :: [(Key map, a)] -> map a
fromList = (a -> a -> a) -> [(Key map, a)] -> map a
forall (map :: * -> *) a.
Map map =>
(a -> a -> a) -> [(Key map, a)] -> map a
fromListWith a -> a -> a
forall (f :: * -> *) a. Applicative f => a -> f a
pure

fromListWith :: Map map => (a -> a -> a) -> [(Key map, a)] -> map a
fromListWith :: (a -> a -> a) -> [(Key map, a)] -> map a
fromListWith = (Key map -> a -> a -> a) -> [(Key map, a)] -> map a
forall (map :: * -> *) a.
Map map =>
(Key map -> a -> a -> a) -> [(Key map, a)] -> map a
fromListWithKey ((Key map -> a -> a -> a) -> [(Key map, a)] -> map a)
-> ((a -> a -> a) -> Key map -> a -> a -> a)
-> (a -> a -> a)
-> [(Key map, a)]
-> map a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> a -> a) -> Key map -> a -> a -> a
forall (f :: * -> *) a. Applicative f => a -> f a
pure

fromListWithKey :: Map map => (Key map -> a -> a -> a) -> [(Key map, a)] -> map a
fromListWithKey :: (Key map -> a -> a -> a) -> [(Key map, a)] -> map a
fromListWithKey f :: Key map -> a -> a -> a
f = (map a -> (Key map, a) -> map a)
-> map a -> [(Key map, a)] -> map a
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
Foldable.foldl' (((Key map, a) -> map a -> map a) -> map a -> (Key map, a) -> map a
forall a b c. (a -> b -> c) -> b -> a -> c
flip (((Key map, a) -> map a -> map a)
 -> map a -> (Key map, a) -> map a)
-> ((Key map -> a -> map a -> map a)
    -> (Key map, a) -> map a -> map a)
-> (Key map -> a -> map a -> map a)
-> map a
-> (Key map, a)
-> map a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Key map -> a -> map a -> map a) -> (Key map, a) -> map a -> map a
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry ((Key map -> a -> map a -> map a)
 -> map a -> (Key map, a) -> map a)
-> (Key map -> a -> map a -> map a)
-> map a
-> (Key map, a)
-> map a
forall a b. (a -> b) -> a -> b
$ (a -> a -> a) -> Key map -> a -> map a -> map a
forall (map :: * -> *) a.
Map map =>
(a -> a -> a) -> Key map -> a -> map a -> map a
insertWith ((a -> a -> a) -> Key map -> a -> map a -> map a)
-> (Key map -> a -> a -> a) -> Key map -> a -> map a -> map a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Key map -> a -> a -> a
f) map a
forall (map :: * -> *) a. Map map => map a
empty

fromListWithM :: (Map map, Monad m) => (a -> a -> m a) -> [(Key map, a)] -> m (map a)
fromListWithM :: (a -> a -> m a) -> [(Key map, a)] -> m (map a)
fromListWithM = (Key map -> a -> a -> m a) -> [(Key map, a)] -> m (map a)
forall (map :: * -> *) (m :: * -> *) a.
(Map map, Monad m) =>
(Key map -> a -> a -> m a) -> [(Key map, a)] -> m (map a)
fromListWithKeyM ((Key map -> a -> a -> m a) -> [(Key map, a)] -> m (map a))
-> ((a -> a -> m a) -> Key map -> a -> a -> m a)
-> (a -> a -> m a)
-> [(Key map, a)]
-> m (map a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> a -> m a) -> Key map -> a -> a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure

fromListWithKeyM :: (Map map, Monad m) => (Key map -> a -> a -> m a) -> [(Key map, a)] -> m (map a)
fromListWithKeyM :: (Key map -> a -> a -> m a) -> [(Key map, a)] -> m (map a)
fromListWithKeyM f :: Key map -> a -> a -> m a
f = map (m a) -> m (map a)
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA (map (m a) -> m (map a))
-> ([(Key map, a)] -> map (m a)) -> [(Key map, a)] -> m (map a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Key map -> m a -> m a -> m a) -> [(Key map, m a)] -> map (m a)
forall (map :: * -> *) a.
Map map =>
(Key map -> a -> a -> a) -> [(Key map, a)] -> map a
fromListWithKey ((a -> a -> m a) -> m a -> m a -> m a
forall (m :: * -> *) a b c.
Monad m =>
(a -> b -> m c) -> m a -> m b -> m c
bind2 ((a -> a -> m a) -> m a -> m a -> m a)
-> (Key map -> a -> a -> m a) -> Key map -> m a -> m a -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Key map -> a -> a -> m a
f) ([(Key map, m a)] -> map (m a))
-> ([(Key map, a)] -> [(Key map, m a)])
-> [(Key map, a)]
-> map (m a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (((Key map, a) -> (Key map, m a))
-> [(Key map, a)] -> [(Key map, m a)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (((Key map, a) -> (Key map, m a))
 -> [(Key map, a)] -> [(Key map, m a)])
-> ((a -> m a) -> (Key map, a) -> (Key map, m a))
-> (a -> m a)
-> [(Key map, a)]
-> [(Key map, m a)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> m a) -> (Key map, a) -> (Key map, m a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap) a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure

-- | Modify the value of the key in the map, looking up the old value if the key is already present. If the key is absent, the map is returned unmodified.
adjustLookupA :: (StaticMap map, Applicative p) => (a -> p a) -> Key map -> map a -> p (Maybe a, map a)
adjustLookupA :: (a -> p a) -> Key map -> map a -> p (Maybe a, map a)
adjustLookupA f :: a -> p a
f = (Maybe a, p (map a)) -> p (Maybe a, map a)
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA ((Maybe a, p (map a)) -> p (Maybe a, map a))
-> (Key map -> map a -> (Maybe a, p (map a)))
-> Key map
-> map a
-> p (Maybe a, map a)
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ (Last a -> Maybe a
forall a. Last a -> Maybe a
getLast (Last a -> Maybe a)
-> (p (map a) -> p (map a))
-> (Last a, p (map a))
-> (Maybe a, p (map a))
forall (a :: * -> * -> *) b c b' c'.
Arrow a =>
a b c -> a b' c' -> a (b, b') (c, c')
*** p (map a) -> p (map a)
forall a. a -> a
id ((Last a, p (map a)) -> (Maybe a, p (map a)))
-> (Compose ((,) (Last a)) p (map a) -> (Last a, p (map a)))
-> Compose ((,) (Last a)) p (map a)
-> (Maybe a, p (map a))
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
<<< Compose ((,) (Last a)) p (map a) -> (Last a, p (map a))
forall k1 (f :: k1 -> *) k2 (g :: k2 -> k1) (a :: k2).
Compose f g a -> f (g a)
getCompose) (Compose ((,) (Last a)) p (map a) -> (Maybe a, p (map a)))
-> (Key map -> map a -> Compose ((,) (Last a)) p (map a))
-> Key map
-> map a
-> (Maybe a, p (map a))
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ (a -> Compose ((,) (Last a)) p a)
-> Key map -> map a -> Compose ((,) (Last a)) p (map a)
forall (map :: * -> *) (p :: * -> *) a.
(StaticMap map, Applicative p) =>
(a -> p a) -> Key map -> map a -> p (map a)
adjustA (\ a :: a
a -> (Last a, p a) -> Compose ((,) (Last a)) p a
forall k k1 (f :: k -> *) (g :: k1 -> k) (a :: k1).
f (g a) -> Compose f g a
Compose (a -> Last a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a
a, a -> p a
f a
a))

-- | Map with a single element
singleton :: Map map => Key map -> a -> map a
singleton :: Key map -> a -> map a
singleton k :: Key map
k a :: a
a = [(Key map, a)] -> map a
forall (map :: * -> *) a. Map map => [(Key map, a)] -> map a
fromList [(Key map
k, a
a)]

-- | Union of two maps, combining values of the same key with the given function
unionWith :: Map map => (Key map -> a -> a -> a) -> map a -> map a -> map a
unionWith :: (Key map -> a -> a -> a) -> map a -> map a -> map a
unionWith f :: Key map -> a -> a -> a
f = Identity (map a) -> map a
forall a. Identity a -> a
runIdentity (Identity (map a) -> map a)
-> (map a -> map a -> Identity (map a)) -> map a -> map a -> map a
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ (Key map -> a -> a -> Identity a)
-> map a -> map a -> Identity (map a)
forall (map :: * -> *) (p :: * -> *) a.
(Map map, Applicative p) =>
(Key map -> a -> a -> p a) -> map a -> map a -> p (map a)
unionWithA (\ k :: Key map
k -> a -> Identity a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> Identity a) -> (a -> a -> a) -> a -> a -> Identity a
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ Key map -> a -> a -> a
f Key map
k)

-- | Intersection of two maps, combining values of the same key with the given function
intersectionWith :: Map map => (Key map -> a -> b -> c) -> map a -> map b -> map c
intersectionWith :: (Key map -> a -> b -> c) -> map a -> map b -> map c
intersectionWith f :: Key map -> a -> b -> c
f = Identity (map c) -> map c
forall a. Identity a -> a
runIdentity (Identity (map c) -> map c)
-> (map a -> map b -> Identity (map c)) -> map a -> map b -> map c
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ (Key map -> a -> b -> Identity c)
-> map a -> map b -> Identity (map c)
forall (map :: * -> *) (p :: * -> *) a b c.
(Map map, Applicative p) =>
(Key map -> a -> b -> p c) -> map a -> map b -> p (map c)
intersectionWithA (\ k :: Key map
k -> c -> Identity c
forall (f :: * -> *) a. Applicative f => a -> f a
pure (c -> Identity c) -> (a -> b -> c) -> a -> b -> Identity c
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ Key map -> a -> b -> c
f Key map
k)

-- | Combine two maps with the given function, which is called once for each key present in either map, inclusive.
merge :: Map map => (Key map -> Either' a b -> Maybe c) -> map a -> map b -> map c
merge :: (Key map -> Either' a b -> Maybe c) -> map a -> map b -> map c
merge f :: Key map -> Either' a b -> Maybe c
f = Identity (map c) -> map c
forall a. Identity a -> a
runIdentity (Identity (map c) -> map c)
-> (map a -> map b -> Identity (map c)) -> map a -> map b -> map c
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ (Key map -> Either' a b -> Identity (Maybe c))
-> map a -> map b -> Identity (map c)
forall (map :: * -> *) (p :: * -> *) a b c.
(Map map, Applicative p) =>
(Key map -> Either' a b -> p (Maybe c))
-> map a -> map b -> p (map c)
mergeA (Maybe c -> Identity (Maybe c)
forall a. a -> Identity a
Identity (Maybe c -> Identity (Maybe c))
-> (Key map -> Either' a b -> Maybe c)
-> Key map
-> Either' a b
-> Identity (Maybe c)
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ Key map -> Either' a b -> Maybe c
f)

-- | Union of two maps, combining values of the same key with the given function
unionWithA :: (Map map, Applicative p) => (Key map -> a -> a -> p a) -> map a -> map a -> p (map a)
unionWithA :: (Key map -> a -> a -> p a) -> map a -> map a -> p (map a)
unionWithA f :: Key map -> a -> a -> p a
f = (Key map -> Either' a a -> p (Maybe a))
-> map a -> map a -> p (map a)
forall (map :: * -> *) (p :: * -> *) a b c.
(Map map, Applicative p) =>
(Key map -> Either' a b -> p (Maybe c))
-> map a -> map b -> p (map c)
mergeA (\ k :: Key map
k -> \ case JustLeft a :: a
a -> Maybe a -> p (Maybe a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> Maybe a
forall a. a -> Maybe a
Just a
a); JustRight a :: a
a -> Maybe a -> p (Maybe a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> Maybe a
forall a. a -> Maybe a
Just a
a); Both a :: a
a b :: a
b -> a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> p a -> p (Maybe a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Key map -> a -> a -> p a
f Key map
k a
a a
b)

-- | Intersection of two maps, combining values of the same key with the given function
intersectionWithA :: (Map map, Applicative p) => (Key map -> a -> b -> p c) -> map a -> map b -> p (map c)
intersectionWithA :: (Key map -> a -> b -> p c) -> map a -> map b -> p (map c)
intersectionWithA f :: Key map -> a -> b -> p c
f = (Key map -> Either' a b -> p (Maybe c))
-> map a -> map b -> p (map c)
forall (map :: * -> *) (p :: * -> *) a b c.
(Map map, Applicative p) =>
(Key map -> Either' a b -> p (Maybe c))
-> map a -> map b -> p (map c)
mergeA (\ k :: Key map
k -> \ case Both a :: a
a b :: b
b -> c -> Maybe c
forall a. a -> Maybe a
Just (c -> Maybe c) -> p c -> p (Maybe c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Key map -> a -> b -> p c
f Key map
k a
a b
b; _ -> Maybe c -> p (Maybe c)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe c
forall a. Maybe a
Nothing)

-- | Difference of two maps, which contains exactly the keys present in the first map but absent in the second
difference :: Map map => map a -> map b -> map a
difference :: map a -> map b -> map a
difference = (Key map -> Either' a b -> Maybe a) -> map a -> map b -> map a
forall (map :: * -> *) a b c.
Map map =>
(Key map -> Either' a b -> Maybe c) -> map a -> map b -> map c
merge ((Key map -> Either' a b -> Maybe a) -> map a -> map b -> map a)
-> (Key map -> Either' a b -> Maybe a) -> map a -> map b -> map a
forall a b. (a -> b) -> a -> b
$ (Either' a b -> Maybe a) -> Key map -> Either' a b -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ((Either' a b -> Maybe a) -> Key map -> Either' a b -> Maybe a)
-> (Either' a b -> Maybe a) -> Key map -> Either' a b -> Maybe a
forall a b. (a -> b) -> a -> b
$ (a -> Maybe a)
-> (b -> Maybe a) -> (a -> b -> Maybe a) -> Either' a b -> Maybe a
forall a c b.
(a -> c) -> (b -> c) -> (a -> b -> c) -> Either' a b -> c
either' a -> Maybe a
forall a. a -> Maybe a
Just (Maybe a -> b -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe a
forall a. Maybe a
Nothing) ((a -> b -> Maybe a) -> Either' a b -> Maybe a)
-> (a -> b -> Maybe a) -> Either' a b -> Maybe a
forall a b. (a -> b) -> a -> b
$ \ _ _ -> Maybe a
forall a. Maybe a
Nothing

-- | Symmetric difference of two maps, which contains exactly the keys present in the either map but absent in the other
symmetricDifference :: Map map => map a -> map a -> map a
symmetricDifference :: map a -> map a -> map a
symmetricDifference = (Key map -> Either' a a -> Maybe a) -> map a -> map a -> map a
forall (map :: * -> *) a b c.
Map map =>
(Key map -> Either' a b -> Maybe c) -> map a -> map b -> map c
merge ((Key map -> Either' a a -> Maybe a) -> map a -> map a -> map a)
-> (Key map -> Either' a a -> Maybe a) -> map a -> map a -> map a
forall a b. (a -> b) -> a -> b
$ (Either' a a -> Maybe a) -> Key map -> Either' a a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ((Either' a a -> Maybe a) -> Key map -> Either' a a -> Maybe a)
-> (Either' a a -> Maybe a) -> Key map -> Either' a a -> Maybe a
forall a b. (a -> b) -> a -> b
$ (a -> Maybe a)
-> (a -> Maybe a) -> (a -> a -> Maybe a) -> Either' a a -> Maybe a
forall a c b.
(a -> c) -> (b -> c) -> (a -> b -> c) -> Either' a b -> c
either' a -> Maybe a
forall a. a -> Maybe a
Just a -> Maybe a
forall a. a -> Maybe a
Just ((a -> a -> Maybe a) -> Either' a a -> Maybe a)
-> (a -> a -> Maybe a) -> Either' a a -> Maybe a
forall a b. (a -> b) -> a -> b
$ \ _ _ -> Maybe a
forall a. Maybe a
Nothing

-- | Map a function over each key in the map.
mapKeys :: (StaticMap m, Map n) => (Key m -> Key n) -> m a -> n a
mapKeys :: (Key m -> Key n) -> m a -> n a
mapKeys f :: Key m -> Key n
f = (Key m -> a -> n a -> n a) -> n a -> m a -> n a
forall (map :: * -> *) a b.
StaticMap map =>
(Key map -> a -> b -> b) -> b -> map a -> b
foldrWithKey (Key n -> a -> n a -> n a
forall (map :: * -> *) a. Map map => Key map -> a -> map a -> map a
insert (Key n -> a -> n a -> n a)
-> (Key m -> Key n) -> Key m -> a -> n a -> n a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Key m -> Key n
f) n a
forall (map :: * -> *) a. Map map => map a
empty

-- | Map a function over each key in the map, combining values of keys which collide with the given function.
mapKeysWith :: (StaticMap m, Map n) => (a -> a -> a) -> (Key m -> Key n) -> m a -> n a
mapKeysWith :: (a -> a -> a) -> (Key m -> Key n) -> m a -> n a
mapKeysWith combine :: a -> a -> a
combine f :: Key m -> Key n
f = (Key m -> a -> n a -> n a) -> n a -> m a -> n a
forall (map :: * -> *) a b.
StaticMap map =>
(Key map -> a -> b -> b) -> b -> map a -> b
foldrWithKey ((a -> a -> a) -> Key n -> a -> n a -> n a
forall (map :: * -> *) a.
Map map =>
(a -> a -> a) -> Key map -> a -> map a -> map a
insertWith a -> a -> a
combine (Key n -> a -> n a -> n a)
-> (Key m -> Key n) -> Key m -> a -> n a -> n a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Key m -> Key n
f) n a
forall (map :: * -> *) a. Map map => map a
empty

-- | Traverse a function over each key in the map.
traverseKeys :: (StaticMap m, Map n, Applicative p) => (Key m -> p (Key n)) -> m a -> p (n a)
traverseKeys :: (Key m -> p (Key n)) -> m a -> p (n a)
traverseKeys f :: Key m -> p (Key n)
f = (Endo (->) (n a) -> n a) -> p (Endo (->) (n a)) -> p (n a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Endo (->) (n a) -> n a -> n a) -> n a -> Endo (->) (n a) -> n a
forall a b c. (a -> b -> c) -> b -> a -> c
flip Endo (->) (n a) -> n a -> n a
forall k (s :: k -> k -> *) (a :: k). Endo s a -> s a a
appEndo n a
forall (map :: * -> *) a. Map map => map a
empty) (p (Endo (->) (n a)) -> p (n a))
-> (m a -> p (Endo (->) (n a))) -> m a -> p (n a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Key m -> a -> p (Endo (->) (n a))) -> m a -> p (Endo (->) (n a))
forall (map :: * -> *) (p :: * -> *) b a.
(StaticMap map, Applicative p, Monoid b) =>
(Key map -> a -> p b) -> map a -> p b
foldMapWithKeyA (\ i :: Key m
i a :: a
a -> (\ j :: Key n
j -> (n a -> n a) -> Endo (->) (n a)
forall k (s :: k -> k -> *) (a :: k). s a a -> Endo s a
Endo ((n a -> n a) -> Endo (->) (n a))
-> (n a -> n a) -> Endo (->) (n a)
forall a b. (a -> b) -> a -> b
$ Key n -> a -> n a -> n a
forall (map :: * -> *) a. Map map => Key map -> a -> map a -> map a
insert Key n
j a
a) (Key n -> Endo (->) (n a)) -> p (Key n) -> p (Endo (->) (n a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Key m -> p (Key n)
f Key m
i)

-- | Traverse a function over each key in the map, combining values of keys which collide with the given function.
traverseKeysWith :: (StaticMap m, Map n, Applicative p) => (a -> a -> a) -> (Key m -> p (Key n)) -> m a -> p (n a)
traverseKeysWith :: (a -> a -> a) -> (Key m -> p (Key n)) -> m a -> p (n a)
traverseKeysWith combine :: a -> a -> a
combine f :: Key m -> p (Key n)
f = (Endo (->) (n a) -> n a) -> p (Endo (->) (n a)) -> p (n a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Endo (->) (n a) -> n a -> n a) -> n a -> Endo (->) (n a) -> n a
forall a b c. (a -> b -> c) -> b -> a -> c
flip Endo (->) (n a) -> n a -> n a
forall k (s :: k -> k -> *) (a :: k). Endo s a -> s a a
appEndo n a
forall (map :: * -> *) a. Map map => map a
empty) (p (Endo (->) (n a)) -> p (n a))
-> (m a -> p (Endo (->) (n a))) -> m a -> p (n a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Key m -> a -> p (Endo (->) (n a))) -> m a -> p (Endo (->) (n a))
forall (map :: * -> *) (p :: * -> *) b a.
(StaticMap map, Applicative p, Monoid b) =>
(Key map -> a -> p b) -> map a -> p b
foldMapWithKeyA (\ i :: Key m
i a :: a
a -> (\ j :: Key n
j -> (n a -> n a) -> Endo (->) (n a)
forall k (s :: k -> k -> *) (a :: k). s a a -> Endo s a
Endo ((n a -> n a) -> Endo (->) (n a))
-> (n a -> n a) -> Endo (->) (n a)
forall a b. (a -> b) -> a -> b
$ (a -> a -> a) -> Key n -> a -> n a -> n a
forall (map :: * -> *) a.
Map map =>
(a -> a -> a) -> Key map -> a -> map a -> map a
insertWith a -> a -> a
combine Key n
j a
a) (Key n -> Endo (->) (n a)) -> p (Key n) -> p (Endo (->) (n a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Key m -> p (Key n)
f Key m
i)

-- | Map a function over each key in the map, gathering the 'Just' values and forgetting the 'Nothing'.
mapKeysMaybe :: (StaticMap m, Map n) => (Key m -> Maybe (Key n)) -> m a -> n a
mapKeysMaybe :: (Key m -> Maybe (Key n)) -> m a -> n a
mapKeysMaybe f :: Key m -> Maybe (Key n)
f = Identity (n a) -> n a
forall a. Identity a -> a
runIdentity (Identity (n a) -> n a) -> (m a -> Identity (n a)) -> m a -> n a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Key m -> Identity (Maybe (Key n))) -> m a -> Identity (n a)
forall (m :: * -> *) (n :: * -> *) (p :: * -> *) a.
(StaticMap m, Map n, Applicative p) =>
(Key m -> p (Maybe (Key n))) -> m a -> p (n a)
traverseKeysMaybe (Maybe (Key n) -> Identity (Maybe (Key n))
forall a. a -> Identity a
Identity (Maybe (Key n) -> Identity (Maybe (Key n)))
-> (Key m -> Maybe (Key n)) -> Key m -> Identity (Maybe (Key n))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Key m -> Maybe (Key n)
f)

-- | Map a function over each key in the map, gathering the 'Just' values and forgetting the 'Nothing', combining values of keys which collide with the given function.
mapKeysMaybeWith :: (StaticMap m, Map n) => (a -> a -> a) -> (Key m -> Maybe (Key n)) -> m a -> n a
mapKeysMaybeWith :: (a -> a -> a) -> (Key m -> Maybe (Key n)) -> m a -> n a
mapKeysMaybeWith combine :: a -> a -> a
combine f :: Key m -> Maybe (Key n)
f = Identity (n a) -> n a
forall a. Identity a -> a
runIdentity (Identity (n a) -> n a) -> (m a -> Identity (n a)) -> m a -> n a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> a -> a)
-> (Key m -> Identity (Maybe (Key n))) -> m a -> Identity (n a)
forall (m :: * -> *) (n :: * -> *) (p :: * -> *) a.
(StaticMap m, Map n, Applicative p) =>
(a -> a -> a) -> (Key m -> p (Maybe (Key n))) -> m a -> p (n a)
traverseKeysMaybeWith a -> a -> a
combine (Maybe (Key n) -> Identity (Maybe (Key n))
forall a. a -> Identity a
Identity (Maybe (Key n) -> Identity (Maybe (Key n)))
-> (Key m -> Maybe (Key n)) -> Key m -> Identity (Maybe (Key n))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Key m -> Maybe (Key n)
f)

-- | Traverse a function over each key in the map, gathering the 'Just' values and forgetting the 'Nothing'.
traverseKeysMaybe :: (StaticMap m, Map n, Applicative p) => (Key m -> p (Maybe (Key n))) -> m a -> p (n a)
traverseKeysMaybe :: (Key m -> p (Maybe (Key n))) -> m a -> p (n a)
traverseKeysMaybe f :: Key m -> p (Maybe (Key n))
f = (Endo (->) (n a) -> n a) -> p (Endo (->) (n a)) -> p (n a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Endo (->) (n a) -> n a -> n a) -> n a -> Endo (->) (n a) -> n a
forall a b c. (a -> b -> c) -> b -> a -> c
flip Endo (->) (n a) -> n a -> n a
forall k (s :: k -> k -> *) (a :: k). Endo s a -> s a a
appEndo n a
forall (map :: * -> *) a. Map map => map a
empty) (p (Endo (->) (n a)) -> p (n a))
-> (m a -> p (Endo (->) (n a))) -> m a -> p (n a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Key m -> a -> p (Endo (->) (n a))) -> m a -> p (Endo (->) (n a))
forall (map :: * -> *) (p :: * -> *) b a.
(StaticMap map, Applicative p, Monoid b) =>
(Key map -> a -> p b) -> map a -> p b
foldMapWithKeyA (\ i :: Key m
i a :: a
a -> (Key n -> Endo (->) (n a)) -> Maybe (Key n) -> Endo (->) (n a)
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (\ j :: Key n
j -> (n a -> n a) -> Endo (->) (n a)
forall k (s :: k -> k -> *) (a :: k). s a a -> Endo s a
Endo ((n a -> n a) -> Endo (->) (n a))
-> (n a -> n a) -> Endo (->) (n a)
forall a b. (a -> b) -> a -> b
$ Key n -> a -> n a -> n a
forall (map :: * -> *) a. Map map => Key map -> a -> map a -> map a
insert Key n
j a
a) (Maybe (Key n) -> Endo (->) (n a))
-> p (Maybe (Key n)) -> p (Endo (->) (n a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Key m -> p (Maybe (Key n))
f Key m
i)

-- | Traverse a function over each key in the map, gathering the 'Just' values and forgetting the 'Nothing', combining values of keys which collide with the given function.
traverseKeysMaybeWith :: (StaticMap m, Map n, Applicative p) => (a -> a -> a) -> (Key m -> p (Maybe (Key n))) -> m a -> p (n a)
traverseKeysMaybeWith :: (a -> a -> a) -> (Key m -> p (Maybe (Key n))) -> m a -> p (n a)
traverseKeysMaybeWith combine :: a -> a -> a
combine f :: Key m -> p (Maybe (Key n))
f = (Endo (->) (n a) -> n a) -> p (Endo (->) (n a)) -> p (n a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Endo (->) (n a) -> n a -> n a) -> n a -> Endo (->) (n a) -> n a
forall a b c. (a -> b -> c) -> b -> a -> c
flip Endo (->) (n a) -> n a -> n a
forall k (s :: k -> k -> *) (a :: k). Endo s a -> s a a
appEndo n a
forall (map :: * -> *) a. Map map => map a
empty) (p (Endo (->) (n a)) -> p (n a))
-> (m a -> p (Endo (->) (n a))) -> m a -> p (n a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Key m -> a -> p (Endo (->) (n a))) -> m a -> p (Endo (->) (n a))
forall (map :: * -> *) (p :: * -> *) b a.
(StaticMap map, Applicative p, Monoid b) =>
(Key map -> a -> p b) -> map a -> p b
foldMapWithKeyA (\ i :: Key m
i a :: a
a -> (Key n -> Endo (->) (n a)) -> Maybe (Key n) -> Endo (->) (n a)
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (\ j :: Key n
j -> (n a -> n a) -> Endo (->) (n a)
forall k (s :: k -> k -> *) (a :: k). s a a -> Endo s a
Endo ((n a -> n a) -> Endo (->) (n a))
-> (n a -> n a) -> Endo (->) (n a)
forall a b. (a -> b) -> a -> b
$ (a -> a -> a) -> Key n -> a -> n a -> n a
forall (map :: * -> *) a.
Map map =>
(a -> a -> a) -> Key map -> a -> map a -> map a
insertWith a -> a -> a
combine Key n
j a
a) (Maybe (Key n) -> Endo (->) (n a))
-> p (Maybe (Key n)) -> p (Endo (->) (n a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Key m -> p (Maybe (Key n))
f Key m
i)

-- | Keys of the map
--
-- @'keys' as '!?' k = k '<$' (as '!?' k)@
keys :: StaticMap map => map a -> map (Key map)
keys :: map a -> map (Key map)
keys = (Key map -> a -> Key map) -> map a -> map (Key map)
forall (map :: * -> *) a b.
StaticMap map =>
(Key map -> a -> b) -> map a -> map b
mapWithKey Key map -> a -> Key map
forall (f :: * -> *) a. Applicative f => a -> f a
pure

-- | Wrapper of a 'Map' whose semigroup operation is the union, combining values elementwise, and ergo whose monoidal unit is empty
newtype Union map a = Union { Union map a -> map a
unUnion :: map a }
  deriving (a -> Union map b -> Union map a
(a -> b) -> Union map a -> Union map b
(forall a b. (a -> b) -> Union map a -> Union map b)
-> (forall a b. a -> Union map b -> Union map a)
-> Functor (Union map)
forall a b. a -> Union map b -> Union map a
forall a b. (a -> b) -> Union map a -> Union map b
forall (map :: * -> *) a b.
Functor map =>
a -> Union map b -> Union map a
forall (map :: * -> *) a b.
Functor map =>
(a -> b) -> Union map a -> Union map b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> Union map b -> Union map a
$c<$ :: forall (map :: * -> *) a b.
Functor map =>
a -> Union map b -> Union map a
fmap :: (a -> b) -> Union map a -> Union map b
$cfmap :: forall (map :: * -> *) a b.
Functor map =>
(a -> b) -> Union map a -> Union map b
Functor, Union map a -> Bool
(a -> m) -> Union map a -> m
(a -> b -> b) -> b -> Union map a -> b
(forall m. Monoid m => Union map m -> m)
-> (forall m a. Monoid m => (a -> m) -> Union map a -> m)
-> (forall m a. Monoid m => (a -> m) -> Union map a -> m)
-> (forall a b. (a -> b -> b) -> b -> Union map a -> b)
-> (forall a b. (a -> b -> b) -> b -> Union map a -> b)
-> (forall b a. (b -> a -> b) -> b -> Union map a -> b)
-> (forall b a. (b -> a -> b) -> b -> Union map a -> b)
-> (forall a. (a -> a -> a) -> Union map a -> a)
-> (forall a. (a -> a -> a) -> Union map a -> a)
-> (forall a. Union map a -> [a])
-> (forall a. Union map a -> Bool)
-> (forall a. Union map a -> Key)
-> (forall a. Eq a => a -> Union map a -> Bool)
-> (forall a. Ord a => Union map a -> a)
-> (forall a. Ord a => Union map a -> a)
-> (forall a. Num a => Union map a -> a)
-> (forall a. Num a => Union map a -> a)
-> Foldable (Union map)
forall a. Eq a => a -> Union map a -> Bool
forall a. Num a => Union map a -> a
forall a. Ord a => Union map a -> a
forall m. Monoid m => Union map m -> m
forall a. Union map a -> Bool
forall a. Union map a -> Key
forall a. Union map a -> [a]
forall a. (a -> a -> a) -> Union map a -> a
forall m a. Monoid m => (a -> m) -> Union map a -> m
forall b a. (b -> a -> b) -> b -> Union map a -> b
forall a b. (a -> b -> b) -> b -> Union map a -> b
forall (map :: * -> *) a.
(Foldable map, Eq a) =>
a -> Union map a -> Bool
forall (map :: * -> *) a. (Foldable map, Num a) => Union map a -> a
forall (map :: * -> *) a. (Foldable map, Ord a) => Union map a -> a
forall (map :: * -> *) m.
(Foldable map, Monoid m) =>
Union map m -> m
forall (map :: * -> *) a. Foldable map => Union map a -> Bool
forall (map :: * -> *) a. Foldable map => Union map a -> Key
forall (map :: * -> *) a. Foldable map => Union map a -> [a]
forall (map :: * -> *) a.
Foldable map =>
(a -> a -> a) -> Union map a -> a
forall (map :: * -> *) m a.
(Foldable map, Monoid m) =>
(a -> m) -> Union map a -> m
forall (map :: * -> *) b a.
Foldable map =>
(b -> a -> b) -> b -> Union map a -> b
forall (map :: * -> *) a b.
Foldable map =>
(a -> b -> b) -> b -> Union map 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 -> Key)
-> (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 :: Union map a -> a
$cproduct :: forall (map :: * -> *) a. (Foldable map, Num a) => Union map a -> a
sum :: Union map a -> a
$csum :: forall (map :: * -> *) a. (Foldable map, Num a) => Union map a -> a
minimum :: Union map a -> a
$cminimum :: forall (map :: * -> *) a. (Foldable map, Ord a) => Union map a -> a
maximum :: Union map a -> a
$cmaximum :: forall (map :: * -> *) a. (Foldable map, Ord a) => Union map a -> a
elem :: a -> Union map a -> Bool
$celem :: forall (map :: * -> *) a.
(Foldable map, Eq a) =>
a -> Union map a -> Bool
length :: Union map a -> Key
$clength :: forall (map :: * -> *) a. Foldable map => Union map a -> Key
null :: Union map a -> Bool
$cnull :: forall (map :: * -> *) a. Foldable map => Union map a -> Bool
toList :: Union map a -> [a]
$ctoList :: forall (map :: * -> *) a. Foldable map => Union map a -> [a]
foldl1 :: (a -> a -> a) -> Union map a -> a
$cfoldl1 :: forall (map :: * -> *) a.
Foldable map =>
(a -> a -> a) -> Union map a -> a
foldr1 :: (a -> a -> a) -> Union map a -> a
$cfoldr1 :: forall (map :: * -> *) a.
Foldable map =>
(a -> a -> a) -> Union map a -> a
foldl' :: (b -> a -> b) -> b -> Union map a -> b
$cfoldl' :: forall (map :: * -> *) b a.
Foldable map =>
(b -> a -> b) -> b -> Union map a -> b
foldl :: (b -> a -> b) -> b -> Union map a -> b
$cfoldl :: forall (map :: * -> *) b a.
Foldable map =>
(b -> a -> b) -> b -> Union map a -> b
foldr' :: (a -> b -> b) -> b -> Union map a -> b
$cfoldr' :: forall (map :: * -> *) a b.
Foldable map =>
(a -> b -> b) -> b -> Union map a -> b
foldr :: (a -> b -> b) -> b -> Union map a -> b
$cfoldr :: forall (map :: * -> *) a b.
Foldable map =>
(a -> b -> b) -> b -> Union map a -> b
foldMap' :: (a -> m) -> Union map a -> m
$cfoldMap' :: forall (map :: * -> *) m a.
(Foldable map, Monoid m) =>
(a -> m) -> Union map a -> m
foldMap :: (a -> m) -> Union map a -> m
$cfoldMap :: forall (map :: * -> *) m a.
(Foldable map, Monoid m) =>
(a -> m) -> Union map a -> m
fold :: Union map m -> m
$cfold :: forall (map :: * -> *) m.
(Foldable map, Monoid m) =>
Union map m -> m
Foldable, Functor (Union map)
Foldable (Union map)
(Functor (Union map), Foldable (Union map)) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> Union map a -> f (Union map b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    Union map (f a) -> f (Union map a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> Union map a -> m (Union map b))
-> (forall (m :: * -> *) a.
    Monad m =>
    Union map (m a) -> m (Union map a))
-> Traversable (Union map)
(a -> f b) -> Union map a -> f (Union map 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 (map :: * -> *). Traversable map => Functor (Union map)
forall (map :: * -> *). Traversable map => Foldable (Union map)
forall (map :: * -> *) (m :: * -> *) a.
(Traversable map, Monad m) =>
Union map (m a) -> m (Union map a)
forall (map :: * -> *) (f :: * -> *) a.
(Traversable map, Applicative f) =>
Union map (f a) -> f (Union map a)
forall (map :: * -> *) (m :: * -> *) a b.
(Traversable map, Monad m) =>
(a -> m b) -> Union map a -> m (Union map b)
forall (map :: * -> *) (f :: * -> *) a b.
(Traversable map, Applicative f) =>
(a -> f b) -> Union map a -> f (Union map b)
forall (m :: * -> *) a.
Monad m =>
Union map (m a) -> m (Union map a)
forall (f :: * -> *) a.
Applicative f =>
Union map (f a) -> f (Union map a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Union map a -> m (Union map b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Union map a -> f (Union map b)
sequence :: Union map (m a) -> m (Union map a)
$csequence :: forall (map :: * -> *) (m :: * -> *) a.
(Traversable map, Monad m) =>
Union map (m a) -> m (Union map a)
mapM :: (a -> m b) -> Union map a -> m (Union map b)
$cmapM :: forall (map :: * -> *) (m :: * -> *) a b.
(Traversable map, Monad m) =>
(a -> m b) -> Union map a -> m (Union map b)
sequenceA :: Union map (f a) -> f (Union map a)
$csequenceA :: forall (map :: * -> *) (f :: * -> *) a.
(Traversable map, Applicative f) =>
Union map (f a) -> f (Union map a)
traverse :: (a -> f b) -> Union map a -> f (Union map b)
$ctraverse :: forall (map :: * -> *) (f :: * -> *) a b.
(Traversable map, Applicative f) =>
(a -> f b) -> Union map a -> f (Union map b)
$cp2Traversable :: forall (map :: * -> *). Traversable map => Foldable (Union map)
$cp1Traversable :: forall (map :: * -> *). Traversable map => Functor (Union map)
Traversable)
  deriving (Union map a -> Union map a -> Bool
(Union map a -> Union map a -> Bool)
-> (Union map a -> Union map a -> Bool) -> Eq (Union map a)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall k (map :: k -> *) (a :: k).
Eq (map a) =>
Union map a -> Union map a -> Bool
/= :: Union map a -> Union map a -> Bool
$c/= :: forall k (map :: k -> *) (a :: k).
Eq (map a) =>
Union map a -> Union map a -> Bool
== :: Union map a -> Union map a -> Bool
$c== :: forall k (map :: k -> *) (a :: k).
Eq (map a) =>
Union map a -> Union map a -> Bool
Eq, Eq (Union map a)
Eq (Union map a) =>
(Union map a -> Union map a -> Ordering)
-> (Union map a -> Union map a -> Bool)
-> (Union map a -> Union map a -> Bool)
-> (Union map a -> Union map a -> Bool)
-> (Union map a -> Union map a -> Bool)
-> (Union map a -> Union map a -> Union map a)
-> (Union map a -> Union map a -> Union map a)
-> Ord (Union map a)
Union map a -> Union map a -> Bool
Union map a -> Union map a -> Ordering
Union map a -> Union map a -> Union map 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 (map :: k -> *) (a :: k). Ord (map a) => Eq (Union map a)
forall k (map :: k -> *) (a :: k).
Ord (map a) =>
Union map a -> Union map a -> Bool
forall k (map :: k -> *) (a :: k).
Ord (map a) =>
Union map a -> Union map a -> Ordering
forall k (map :: k -> *) (a :: k).
Ord (map a) =>
Union map a -> Union map a -> Union map a
min :: Union map a -> Union map a -> Union map a
$cmin :: forall k (map :: k -> *) (a :: k).
Ord (map a) =>
Union map a -> Union map a -> Union map a
max :: Union map a -> Union map a -> Union map a
$cmax :: forall k (map :: k -> *) (a :: k).
Ord (map a) =>
Union map a -> Union map a -> Union map a
>= :: Union map a -> Union map a -> Bool
$c>= :: forall k (map :: k -> *) (a :: k).
Ord (map a) =>
Union map a -> Union map a -> Bool
> :: Union map a -> Union map a -> Bool
$c> :: forall k (map :: k -> *) (a :: k).
Ord (map a) =>
Union map a -> Union map a -> Bool
<= :: Union map a -> Union map a -> Bool
$c<= :: forall k (map :: k -> *) (a :: k).
Ord (map a) =>
Union map a -> Union map a -> Bool
< :: Union map a -> Union map a -> Bool
$c< :: forall k (map :: k -> *) (a :: k).
Ord (map a) =>
Union map a -> Union map a -> Bool
compare :: Union map a -> Union map a -> Ordering
$ccompare :: forall k (map :: k -> *) (a :: k).
Ord (map a) =>
Union map a -> Union map a -> Ordering
$cp1Ord :: forall k (map :: k -> *) (a :: k). Ord (map a) => Eq (Union map a)
Ord, ReadPrec [Union map a]
ReadPrec (Union map a)
Key -> ReadS (Union map a)
ReadS [Union map a]
(Key -> ReadS (Union map a))
-> ReadS [Union map a]
-> ReadPrec (Union map a)
-> ReadPrec [Union map a]
-> Read (Union map a)
forall a.
(Key -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall k (map :: k -> *) (a :: k).
Read (map a) =>
ReadPrec [Union map a]
forall k (map :: k -> *) (a :: k).
Read (map a) =>
ReadPrec (Union map a)
forall k (map :: k -> *) (a :: k).
Read (map a) =>
Key -> ReadS (Union map a)
forall k (map :: k -> *) (a :: k).
Read (map a) =>
ReadS [Union map a]
readListPrec :: ReadPrec [Union map a]
$creadListPrec :: forall k (map :: k -> *) (a :: k).
Read (map a) =>
ReadPrec [Union map a]
readPrec :: ReadPrec (Union map a)
$creadPrec :: forall k (map :: k -> *) (a :: k).
Read (map a) =>
ReadPrec (Union map a)
readList :: ReadS [Union map a]
$creadList :: forall k (map :: k -> *) (a :: k).
Read (map a) =>
ReadS [Union map a]
readsPrec :: Key -> ReadS (Union map a)
$creadsPrec :: forall k (map :: k -> *) (a :: k).
Read (map a) =>
Key -> ReadS (Union map a)
Read, Key -> Union map a -> ShowS
[Union map a] -> ShowS
Union map a -> String
(Key -> Union map a -> ShowS)
-> (Union map a -> String)
-> ([Union map a] -> ShowS)
-> Show (Union map a)
forall a.
(Key -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (map :: k -> *) (a :: k).
Show (map a) =>
Key -> Union map a -> ShowS
forall k (map :: k -> *) (a :: k).
Show (map a) =>
[Union map a] -> ShowS
forall k (map :: k -> *) (a :: k).
Show (map a) =>
Union map a -> String
showList :: [Union map a] -> ShowS
$cshowList :: forall k (map :: k -> *) (a :: k).
Show (map a) =>
[Union map a] -> ShowS
show :: Union map a -> String
$cshow :: forall k (map :: k -> *) (a :: k).
Show (map a) =>
Union map a -> String
showsPrec :: Key -> Union map a -> ShowS
$cshowsPrec :: forall k (map :: k -> *) (a :: k).
Show (map a) =>
Key -> Union map a -> ShowS
Show) via map a
  deriving ((a -> b -> Bool) -> Union map a -> Union map b -> Bool
(forall a b.
 (a -> b -> Bool) -> Union map a -> Union map b -> Bool)
-> Eq1 (Union map)
forall a b. (a -> b -> Bool) -> Union map a -> Union map b -> Bool
forall (map :: * -> *) a b.
Eq1 map =>
(a -> b -> Bool) -> Union map a -> Union map b -> Bool
forall (f :: * -> *).
(forall a b. (a -> b -> Bool) -> f a -> f b -> Bool) -> Eq1 f
liftEq :: (a -> b -> Bool) -> Union map a -> Union map b -> Bool
$cliftEq :: forall (map :: * -> *) a b.
Eq1 map =>
(a -> b -> Bool) -> Union map a -> Union map b -> Bool
Eq1, Eq1 (Union map)
Eq1 (Union map) =>
(forall a b.
 (a -> b -> Ordering) -> Union map a -> Union map b -> Ordering)
-> Ord1 (Union map)
(a -> b -> Ordering) -> Union map a -> Union map b -> Ordering
forall a b.
(a -> b -> Ordering) -> Union map a -> Union map b -> Ordering
forall (f :: * -> *).
Eq1 f =>
(forall a b. (a -> b -> Ordering) -> f a -> f b -> Ordering)
-> Ord1 f
forall (map :: * -> *). Ord1 map => Eq1 (Union map)
forall (map :: * -> *) a b.
Ord1 map =>
(a -> b -> Ordering) -> Union map a -> Union map b -> Ordering
liftCompare :: (a -> b -> Ordering) -> Union map a -> Union map b -> Ordering
$cliftCompare :: forall (map :: * -> *) a b.
Ord1 map =>
(a -> b -> Ordering) -> Union map a -> Union map b -> Ordering
$cp1Ord1 :: forall (map :: * -> *). Ord1 map => Eq1 (Union map)
Ord1, ReadPrec a -> ReadPrec [a] -> ReadPrec (Union map a)
ReadPrec a -> ReadPrec [a] -> ReadPrec [Union map a]
(Key -> ReadS a) -> ReadS [a] -> Key -> ReadS (Union map a)
(Key -> ReadS a) -> ReadS [a] -> ReadS [Union map a]
(forall a.
 (Key -> ReadS a) -> ReadS [a] -> Key -> ReadS (Union map a))
-> (forall a. (Key -> ReadS a) -> ReadS [a] -> ReadS [Union map a])
-> (forall a. ReadPrec a -> ReadPrec [a] -> ReadPrec (Union map a))
-> (forall a. ReadPrec a -> ReadPrec [a] -> ReadPrec [Union map a])
-> Read1 (Union map)
forall a. ReadPrec a -> ReadPrec [a] -> ReadPrec [Union map a]
forall a. ReadPrec a -> ReadPrec [a] -> ReadPrec (Union map a)
forall a.
(Key -> ReadS a) -> ReadS [a] -> Key -> ReadS (Union map a)
forall a. (Key -> ReadS a) -> ReadS [a] -> ReadS [Union map a]
forall (map :: * -> *) a.
Read1 map =>
ReadPrec a -> ReadPrec [a] -> ReadPrec [Union map a]
forall (map :: * -> *) a.
Read1 map =>
ReadPrec a -> ReadPrec [a] -> ReadPrec (Union map a)
forall (map :: * -> *) a.
Read1 map =>
(Key -> ReadS a) -> ReadS [a] -> Key -> ReadS (Union map a)
forall (map :: * -> *) a.
Read1 map =>
(Key -> ReadS a) -> ReadS [a] -> ReadS [Union map a]
forall (f :: * -> *).
(forall a. (Key -> ReadS a) -> ReadS [a] -> Key -> ReadS (f a))
-> (forall a. (Key -> ReadS a) -> ReadS [a] -> ReadS [f a])
-> (forall a. ReadPrec a -> ReadPrec [a] -> ReadPrec (f a))
-> (forall a. ReadPrec a -> ReadPrec [a] -> ReadPrec [f a])
-> Read1 f
liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [Union map a]
$cliftReadListPrec :: forall (map :: * -> *) a.
Read1 map =>
ReadPrec a -> ReadPrec [a] -> ReadPrec [Union map a]
liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (Union map a)
$cliftReadPrec :: forall (map :: * -> *) a.
Read1 map =>
ReadPrec a -> ReadPrec [a] -> ReadPrec (Union map a)
liftReadList :: (Key -> ReadS a) -> ReadS [a] -> ReadS [Union map a]
$cliftReadList :: forall (map :: * -> *) a.
Read1 map =>
(Key -> ReadS a) -> ReadS [a] -> ReadS [Union map a]
liftReadsPrec :: (Key -> ReadS a) -> ReadS [a] -> Key -> ReadS (Union map a)
$cliftReadsPrec :: forall (map :: * -> *) a.
Read1 map =>
(Key -> ReadS a) -> ReadS [a] -> Key -> ReadS (Union map a)
Read1, (Key -> a -> ShowS)
-> ([a] -> ShowS) -> Key -> Union map a -> ShowS
(Key -> a -> ShowS) -> ([a] -> ShowS) -> [Union map a] -> ShowS
(forall a.
 (Key -> a -> ShowS)
 -> ([a] -> ShowS) -> Key -> Union map a -> ShowS)
-> (forall a.
    (Key -> a -> ShowS) -> ([a] -> ShowS) -> [Union map a] -> ShowS)
-> Show1 (Union map)
forall a.
(Key -> a -> ShowS)
-> ([a] -> ShowS) -> Key -> Union map a -> ShowS
forall a.
(Key -> a -> ShowS) -> ([a] -> ShowS) -> [Union map a] -> ShowS
forall (map :: * -> *) a.
Show1 map =>
(Key -> a -> ShowS)
-> ([a] -> ShowS) -> Key -> Union map a -> ShowS
forall (map :: * -> *) a.
Show1 map =>
(Key -> a -> ShowS) -> ([a] -> ShowS) -> [Union map a] -> ShowS
forall (f :: * -> *).
(forall a.
 (Key -> a -> ShowS) -> ([a] -> ShowS) -> Key -> f a -> ShowS)
-> (forall a.
    (Key -> a -> ShowS) -> ([a] -> ShowS) -> [f a] -> ShowS)
-> Show1 f
liftShowList :: (Key -> a -> ShowS) -> ([a] -> ShowS) -> [Union map a] -> ShowS
$cliftShowList :: forall (map :: * -> *) a.
Show1 map =>
(Key -> a -> ShowS) -> ([a] -> ShowS) -> [Union map a] -> ShowS
liftShowsPrec :: (Key -> a -> ShowS)
-> ([a] -> ShowS) -> Key -> Union map a -> ShowS
$cliftShowsPrec :: forall (map :: * -> *) a.
Show1 map =>
(Key -> a -> ShowS)
-> ([a] -> ShowS) -> Key -> Union map a -> ShowS
Show1) via map

instance Filtrable map => Filtrable (Union map) where
    mapMaybe :: (a -> Maybe b) -> Union map a -> Union map b
mapMaybe f :: a -> Maybe b
f = map b -> Union map b
forall k (map :: k -> *) (a :: k). map a -> Union map a
Union (map b -> Union map b)
-> (Union map a -> map b) -> Union map a -> Union map b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Maybe b) -> map a -> map b
forall (f :: * -> *) a b.
Filtrable f =>
(a -> Maybe b) -> f a -> f b
mapMaybe a -> Maybe b
f (map a -> map b) -> (Union map a -> map a) -> Union map a -> map b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Union map a -> map a
forall k (map :: k -> *) (a :: k). Union map a -> map a
unUnion

instance StaticMap map => StaticMap (Union map) where
    type Key (Union map) = Key map
    adjustA :: (a -> p a) -> Key (Union map) -> Union map a -> p (Union map a)
adjustA f :: a -> p a
f k :: Key (Union map)
k = (map a -> Union map a) -> p (map a) -> p (Union map a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap map a -> Union map a
forall k (map :: k -> *) (a :: k). map a -> Union map a
Union (p (map a) -> p (Union map a))
-> (Union map a -> p (map a)) -> Union map a -> p (Union map a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> p a) -> Key map -> map a -> p (map a)
forall (map :: * -> *) (p :: * -> *) a.
(StaticMap map, Applicative p) =>
(a -> p a) -> Key map -> map a -> p (map a)
adjustA a -> p a
f Key map
Key (Union map)
k (map a -> p (map a))
-> (Union map a -> map a) -> Union map a -> p (map a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Union map a -> map a
forall k (map :: k -> *) (a :: k). Union map a -> map a
unUnion
    traverseWithKey :: (Key (Union map) -> a -> p b) -> Union map a -> p (Union map b)
traverseWithKey f :: Key (Union map) -> a -> p b
f = (map b -> Union map b) -> p (map b) -> p (Union map b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap map b -> Union map b
forall k (map :: k -> *) (a :: k). map a -> Union map a
Union (p (map b) -> p (Union map b))
-> (Union map a -> p (map b)) -> Union map a -> p (Union map b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Key map -> a -> p b) -> map a -> p (map b)
forall (map :: * -> *) (p :: * -> *) a b.
(StaticMap map, Applicative p) =>
(Key map -> a -> p b) -> map a -> p (map b)
traverseWithKey Key map -> a -> p b
Key (Union map) -> a -> p b
f (map a -> p (map b))
-> (Union map a -> map a) -> Union map a -> p (map b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Union map a -> map a
forall k (map :: k -> *) (a :: k). Union map a -> map a
unUnion

instance Map map => Map (Union map) where
    empty :: Union map a
empty = map a -> Union map a
forall k (map :: k -> *) (a :: k). map a -> Union map a
Union map a
forall (map :: * -> *) a. Map map => map a
empty
    alterF :: (Maybe a -> f (Maybe a))
-> Key (Union map) -> Union map a -> f (Union map a)
alterF f :: Maybe a -> f (Maybe a)
f k :: Key (Union map)
k = (map a -> Union map a) -> f (map a) -> f (Union map a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap map a -> Union map a
forall k (map :: k -> *) (a :: k). map a -> Union map a
Union (f (map a) -> f (Union map a))
-> (Union map a -> f (map a)) -> Union map a -> f (Union map a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe a -> f (Maybe a)) -> Key map -> map a -> f (map a)
forall (map :: * -> *) (f :: * -> *) a.
(Map map, Functor f) =>
(Maybe a -> f (Maybe a)) -> Key map -> map a -> f (map a)
alterF Maybe a -> f (Maybe a)
f Key map
Key (Union map)
k (map a -> f (map a))
-> (Union map a -> map a) -> Union map a -> f (map a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Union map a -> map a
forall k (map :: k -> *) (a :: k). Union map a -> map a
unUnion
    mergeA :: (Key (Union map) -> Either' a b -> p (Maybe c))
-> Union map a -> Union map b -> p (Union map c)
mergeA f :: Key (Union map) -> Either' a b -> p (Maybe c)
f = (map c -> Union map c) -> p (map c) -> p (Union map c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap map c -> Union map c
forall k (map :: k -> *) (a :: k). map a -> Union map a
Union (p (map c) -> p (Union map c))
-> (Union map a -> Union map b -> p (map c))
-> Union map a
-> Union map b
-> p (Union map c)
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ (map a -> map b -> p (map c))
-> (Union map a -> map a)
-> (Union map b -> map b)
-> Union map a
-> Union map b
-> p (map c)
forall a' b' c a b.
(a' -> b' -> c) -> (a -> a') -> (b -> b') -> a -> b -> c
compose2 ((Key map -> Either' a b -> p (Maybe c))
-> map a -> map b -> p (map c)
forall (map :: * -> *) (p :: * -> *) a b c.
(Map map, Applicative p) =>
(Key map -> Either' a b -> p (Maybe c))
-> map a -> map b -> p (map c)
mergeA Key map -> Either' a b -> p (Maybe c)
Key (Union map) -> Either' a b -> p (Maybe c)
f) Union map a -> map a
forall k (map :: k -> *) (a :: k). Union map a -> map a
unUnion Union map b -> map b
forall k (map :: k -> *) (a :: k). Union map a -> map a
unUnion
    mapMaybeWithKeyA :: (Key (Union map) -> a -> p (Maybe b))
-> Union map a -> p (Union map b)
mapMaybeWithKeyA f :: Key (Union map) -> a -> p (Maybe b)
f = (map b -> Union map b) -> p (map b) -> p (Union map b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap map b -> Union map b
forall k (map :: k -> *) (a :: k). map a -> Union map a
Union (p (map b) -> p (Union map b))
-> (Union map a -> p (map b)) -> Union map a -> p (Union map b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Key map -> a -> p (Maybe b)) -> map a -> p (map b)
forall (map :: * -> *) (p :: * -> *) a b.
(Map map, Applicative p) =>
(Key map -> a -> p (Maybe b)) -> map a -> p (map b)
mapMaybeWithKeyA Key map -> a -> p (Maybe b)
Key (Union map) -> a -> p (Maybe b)
f (map a -> p (map b))
-> (Union map a -> map a) -> Union map a -> p (map b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Union map a -> map a
forall k (map :: k -> *) (a :: k). Union map a -> map a
unUnion

instance (Map map, Semigroup a) => Semigroup (Union map a) where
    <> :: Union map a -> Union map a -> Union map a
(<>) = map a -> Union map a
forall k (map :: k -> *) (a :: k). map a -> Union map a
Union (map a -> Union map a)
-> (map a -> map a -> map a) -> map a -> map a -> Union map a
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ (Key map -> a -> a -> a) -> map a -> map a -> map a
forall (map :: * -> *) a.
Map map =>
(Key map -> a -> a -> a) -> map a -> map a -> map a
unionWith ((a -> a -> a) -> Key map -> a -> a -> a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a -> a -> a
forall a. Semigroup a => a -> a -> a
(<>)) (map a -> map a -> Union map a)
-> (Union map a -> map a)
-> Union map a
-> Union map a
-> Union map a
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` Union map a -> map a
forall k (map :: k -> *) (a :: k). Union map a -> map a
unUnion

instance (Map map, Semigroup a) => Monoid (Union map a) where
    mempty :: Union map a
mempty = map a -> Union map a
forall k (map :: k -> *) (a :: k). map a -> Union map a
Union map a
forall (map :: * -> *) a. Map map => map a
empty

-- | Wrapper of a 'Map' whose semigroup operation is the intersection, combining values elementwise
newtype Intersection map a = Intersection { Intersection map a -> map a
unIntersection :: map a }
  deriving (a -> Intersection map b -> Intersection map a
(a -> b) -> Intersection map a -> Intersection map b
(forall a b. (a -> b) -> Intersection map a -> Intersection map b)
-> (forall a b. a -> Intersection map b -> Intersection map a)
-> Functor (Intersection map)
forall a b. a -> Intersection map b -> Intersection map a
forall a b. (a -> b) -> Intersection map a -> Intersection map b
forall (map :: * -> *) a b.
Functor map =>
a -> Intersection map b -> Intersection map a
forall (map :: * -> *) a b.
Functor map =>
(a -> b) -> Intersection map a -> Intersection map b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> Intersection map b -> Intersection map a
$c<$ :: forall (map :: * -> *) a b.
Functor map =>
a -> Intersection map b -> Intersection map a
fmap :: (a -> b) -> Intersection map a -> Intersection map b
$cfmap :: forall (map :: * -> *) a b.
Functor map =>
(a -> b) -> Intersection map a -> Intersection map b
Functor, Intersection map a -> Bool
(a -> m) -> Intersection map a -> m
(a -> b -> b) -> b -> Intersection map a -> b
(forall m. Monoid m => Intersection map m -> m)
-> (forall m a. Monoid m => (a -> m) -> Intersection map a -> m)
-> (forall m a. Monoid m => (a -> m) -> Intersection map a -> m)
-> (forall a b. (a -> b -> b) -> b -> Intersection map a -> b)
-> (forall a b. (a -> b -> b) -> b -> Intersection map a -> b)
-> (forall b a. (b -> a -> b) -> b -> Intersection map a -> b)
-> (forall b a. (b -> a -> b) -> b -> Intersection map a -> b)
-> (forall a. (a -> a -> a) -> Intersection map a -> a)
-> (forall a. (a -> a -> a) -> Intersection map a -> a)
-> (forall a. Intersection map a -> [a])
-> (forall a. Intersection map a -> Bool)
-> (forall a. Intersection map a -> Key)
-> (forall a. Eq a => a -> Intersection map a -> Bool)
-> (forall a. Ord a => Intersection map a -> a)
-> (forall a. Ord a => Intersection map a -> a)
-> (forall a. Num a => Intersection map a -> a)
-> (forall a. Num a => Intersection map a -> a)
-> Foldable (Intersection map)
forall a. Eq a => a -> Intersection map a -> Bool
forall a. Num a => Intersection map a -> a
forall a. Ord a => Intersection map a -> a
forall m. Monoid m => Intersection map m -> m
forall a. Intersection map a -> Bool
forall a. Intersection map a -> Key
forall a. Intersection map a -> [a]
forall a. (a -> a -> a) -> Intersection map a -> a
forall m a. Monoid m => (a -> m) -> Intersection map a -> m
forall b a. (b -> a -> b) -> b -> Intersection map a -> b
forall a b. (a -> b -> b) -> b -> Intersection map a -> b
forall (map :: * -> *) a.
(Foldable map, Eq a) =>
a -> Intersection map a -> Bool
forall (map :: * -> *) a.
(Foldable map, Num a) =>
Intersection map a -> a
forall (map :: * -> *) a.
(Foldable map, Ord a) =>
Intersection map a -> a
forall (map :: * -> *) m.
(Foldable map, Monoid m) =>
Intersection map m -> m
forall (map :: * -> *) a.
Foldable map =>
Intersection map a -> Bool
forall (map :: * -> *) a. Foldable map => Intersection map a -> Key
forall (map :: * -> *) a. Foldable map => Intersection map a -> [a]
forall (map :: * -> *) a.
Foldable map =>
(a -> a -> a) -> Intersection map a -> a
forall (map :: * -> *) m a.
(Foldable map, Monoid m) =>
(a -> m) -> Intersection map a -> m
forall (map :: * -> *) b a.
Foldable map =>
(b -> a -> b) -> b -> Intersection map a -> b
forall (map :: * -> *) a b.
Foldable map =>
(a -> b -> b) -> b -> Intersection map 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 -> Key)
-> (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 :: Intersection map a -> a
$cproduct :: forall (map :: * -> *) a.
(Foldable map, Num a) =>
Intersection map a -> a
sum :: Intersection map a -> a
$csum :: forall (map :: * -> *) a.
(Foldable map, Num a) =>
Intersection map a -> a
minimum :: Intersection map a -> a
$cminimum :: forall (map :: * -> *) a.
(Foldable map, Ord a) =>
Intersection map a -> a
maximum :: Intersection map a -> a
$cmaximum :: forall (map :: * -> *) a.
(Foldable map, Ord a) =>
Intersection map a -> a
elem :: a -> Intersection map a -> Bool
$celem :: forall (map :: * -> *) a.
(Foldable map, Eq a) =>
a -> Intersection map a -> Bool
length :: Intersection map a -> Key
$clength :: forall (map :: * -> *) a. Foldable map => Intersection map a -> Key
null :: Intersection map a -> Bool
$cnull :: forall (map :: * -> *) a.
Foldable map =>
Intersection map a -> Bool
toList :: Intersection map a -> [a]
$ctoList :: forall (map :: * -> *) a. Foldable map => Intersection map a -> [a]
foldl1 :: (a -> a -> a) -> Intersection map a -> a
$cfoldl1 :: forall (map :: * -> *) a.
Foldable map =>
(a -> a -> a) -> Intersection map a -> a
foldr1 :: (a -> a -> a) -> Intersection map a -> a
$cfoldr1 :: forall (map :: * -> *) a.
Foldable map =>
(a -> a -> a) -> Intersection map a -> a
foldl' :: (b -> a -> b) -> b -> Intersection map a -> b
$cfoldl' :: forall (map :: * -> *) b a.
Foldable map =>
(b -> a -> b) -> b -> Intersection map a -> b
foldl :: (b -> a -> b) -> b -> Intersection map a -> b
$cfoldl :: forall (map :: * -> *) b a.
Foldable map =>
(b -> a -> b) -> b -> Intersection map a -> b
foldr' :: (a -> b -> b) -> b -> Intersection map a -> b
$cfoldr' :: forall (map :: * -> *) a b.
Foldable map =>
(a -> b -> b) -> b -> Intersection map a -> b
foldr :: (a -> b -> b) -> b -> Intersection map a -> b
$cfoldr :: forall (map :: * -> *) a b.
Foldable map =>
(a -> b -> b) -> b -> Intersection map a -> b
foldMap' :: (a -> m) -> Intersection map a -> m
$cfoldMap' :: forall (map :: * -> *) m a.
(Foldable map, Monoid m) =>
(a -> m) -> Intersection map a -> m
foldMap :: (a -> m) -> Intersection map a -> m
$cfoldMap :: forall (map :: * -> *) m a.
(Foldable map, Monoid m) =>
(a -> m) -> Intersection map a -> m
fold :: Intersection map m -> m
$cfold :: forall (map :: * -> *) m.
(Foldable map, Monoid m) =>
Intersection map m -> m
Foldable, Functor (Intersection map)
Foldable (Intersection map)
(Functor (Intersection map), Foldable (Intersection map)) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b) -> Intersection map a -> f (Intersection map b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    Intersection map (f a) -> f (Intersection map a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> Intersection map a -> m (Intersection map b))
-> (forall (m :: * -> *) a.
    Monad m =>
    Intersection map (m a) -> m (Intersection map a))
-> Traversable (Intersection map)
(a -> f b) -> Intersection map a -> f (Intersection map 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 (map :: * -> *).
Traversable map =>
Functor (Intersection map)
forall (map :: * -> *).
Traversable map =>
Foldable (Intersection map)
forall (map :: * -> *) (m :: * -> *) a.
(Traversable map, Monad m) =>
Intersection map (m a) -> m (Intersection map a)
forall (map :: * -> *) (f :: * -> *) a.
(Traversable map, Applicative f) =>
Intersection map (f a) -> f (Intersection map a)
forall (map :: * -> *) (m :: * -> *) a b.
(Traversable map, Monad m) =>
(a -> m b) -> Intersection map a -> m (Intersection map b)
forall (map :: * -> *) (f :: * -> *) a b.
(Traversable map, Applicative f) =>
(a -> f b) -> Intersection map a -> f (Intersection map b)
forall (m :: * -> *) a.
Monad m =>
Intersection map (m a) -> m (Intersection map a)
forall (f :: * -> *) a.
Applicative f =>
Intersection map (f a) -> f (Intersection map a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Intersection map a -> m (Intersection map b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Intersection map a -> f (Intersection map b)
sequence :: Intersection map (m a) -> m (Intersection map a)
$csequence :: forall (map :: * -> *) (m :: * -> *) a.
(Traversable map, Monad m) =>
Intersection map (m a) -> m (Intersection map a)
mapM :: (a -> m b) -> Intersection map a -> m (Intersection map b)
$cmapM :: forall (map :: * -> *) (m :: * -> *) a b.
(Traversable map, Monad m) =>
(a -> m b) -> Intersection map a -> m (Intersection map b)
sequenceA :: Intersection map (f a) -> f (Intersection map a)
$csequenceA :: forall (map :: * -> *) (f :: * -> *) a.
(Traversable map, Applicative f) =>
Intersection map (f a) -> f (Intersection map a)
traverse :: (a -> f b) -> Intersection map a -> f (Intersection map b)
$ctraverse :: forall (map :: * -> *) (f :: * -> *) a b.
(Traversable map, Applicative f) =>
(a -> f b) -> Intersection map a -> f (Intersection map b)
$cp2Traversable :: forall (map :: * -> *).
Traversable map =>
Foldable (Intersection map)
$cp1Traversable :: forall (map :: * -> *).
Traversable map =>
Functor (Intersection map)
Traversable)
  deriving (Intersection map a -> Intersection map a -> Bool
(Intersection map a -> Intersection map a -> Bool)
-> (Intersection map a -> Intersection map a -> Bool)
-> Eq (Intersection map a)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall k (map :: k -> *) (a :: k).
Eq (map a) =>
Intersection map a -> Intersection map a -> Bool
/= :: Intersection map a -> Intersection map a -> Bool
$c/= :: forall k (map :: k -> *) (a :: k).
Eq (map a) =>
Intersection map a -> Intersection map a -> Bool
== :: Intersection map a -> Intersection map a -> Bool
$c== :: forall k (map :: k -> *) (a :: k).
Eq (map a) =>
Intersection map a -> Intersection map a -> Bool
Eq, Eq (Intersection map a)
Eq (Intersection map a) =>
(Intersection map a -> Intersection map a -> Ordering)
-> (Intersection map a -> Intersection map a -> Bool)
-> (Intersection map a -> Intersection map a -> Bool)
-> (Intersection map a -> Intersection map a -> Bool)
-> (Intersection map a -> Intersection map a -> Bool)
-> (Intersection map a -> Intersection map a -> Intersection map a)
-> (Intersection map a -> Intersection map a -> Intersection map a)
-> Ord (Intersection map a)
Intersection map a -> Intersection map a -> Bool
Intersection map a -> Intersection map a -> Ordering
Intersection map a -> Intersection map a -> Intersection map 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 (map :: k -> *) (a :: k).
Ord (map a) =>
Eq (Intersection map a)
forall k (map :: k -> *) (a :: k).
Ord (map a) =>
Intersection map a -> Intersection map a -> Bool
forall k (map :: k -> *) (a :: k).
Ord (map a) =>
Intersection map a -> Intersection map a -> Ordering
forall k (map :: k -> *) (a :: k).
Ord (map a) =>
Intersection map a -> Intersection map a -> Intersection map a
min :: Intersection map a -> Intersection map a -> Intersection map a
$cmin :: forall k (map :: k -> *) (a :: k).
Ord (map a) =>
Intersection map a -> Intersection map a -> Intersection map a
max :: Intersection map a -> Intersection map a -> Intersection map a
$cmax :: forall k (map :: k -> *) (a :: k).
Ord (map a) =>
Intersection map a -> Intersection map a -> Intersection map a
>= :: Intersection map a -> Intersection map a -> Bool
$c>= :: forall k (map :: k -> *) (a :: k).
Ord (map a) =>
Intersection map a -> Intersection map a -> Bool
> :: Intersection map a -> Intersection map a -> Bool
$c> :: forall k (map :: k -> *) (a :: k).
Ord (map a) =>
Intersection map a -> Intersection map a -> Bool
<= :: Intersection map a -> Intersection map a -> Bool
$c<= :: forall k (map :: k -> *) (a :: k).
Ord (map a) =>
Intersection map a -> Intersection map a -> Bool
< :: Intersection map a -> Intersection map a -> Bool
$c< :: forall k (map :: k -> *) (a :: k).
Ord (map a) =>
Intersection map a -> Intersection map a -> Bool
compare :: Intersection map a -> Intersection map a -> Ordering
$ccompare :: forall k (map :: k -> *) (a :: k).
Ord (map a) =>
Intersection map a -> Intersection map a -> Ordering
$cp1Ord :: forall k (map :: k -> *) (a :: k).
Ord (map a) =>
Eq (Intersection map a)
Ord, ReadPrec [Intersection map a]
ReadPrec (Intersection map a)
Key -> ReadS (Intersection map a)
ReadS [Intersection map a]
(Key -> ReadS (Intersection map a))
-> ReadS [Intersection map a]
-> ReadPrec (Intersection map a)
-> ReadPrec [Intersection map a]
-> Read (Intersection map a)
forall a.
(Key -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall k (map :: k -> *) (a :: k).
Read (map a) =>
ReadPrec [Intersection map a]
forall k (map :: k -> *) (a :: k).
Read (map a) =>
ReadPrec (Intersection map a)
forall k (map :: k -> *) (a :: k).
Read (map a) =>
Key -> ReadS (Intersection map a)
forall k (map :: k -> *) (a :: k).
Read (map a) =>
ReadS [Intersection map a]
readListPrec :: ReadPrec [Intersection map a]
$creadListPrec :: forall k (map :: k -> *) (a :: k).
Read (map a) =>
ReadPrec [Intersection map a]
readPrec :: ReadPrec (Intersection map a)
$creadPrec :: forall k (map :: k -> *) (a :: k).
Read (map a) =>
ReadPrec (Intersection map a)
readList :: ReadS [Intersection map a]
$creadList :: forall k (map :: k -> *) (a :: k).
Read (map a) =>
ReadS [Intersection map a]
readsPrec :: Key -> ReadS (Intersection map a)
$creadsPrec :: forall k (map :: k -> *) (a :: k).
Read (map a) =>
Key -> ReadS (Intersection map a)
Read, Key -> Intersection map a -> ShowS
[Intersection map a] -> ShowS
Intersection map a -> String
(Key -> Intersection map a -> ShowS)
-> (Intersection map a -> String)
-> ([Intersection map a] -> ShowS)
-> Show (Intersection map a)
forall a.
(Key -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (map :: k -> *) (a :: k).
Show (map a) =>
Key -> Intersection map a -> ShowS
forall k (map :: k -> *) (a :: k).
Show (map a) =>
[Intersection map a] -> ShowS
forall k (map :: k -> *) (a :: k).
Show (map a) =>
Intersection map a -> String
showList :: [Intersection map a] -> ShowS
$cshowList :: forall k (map :: k -> *) (a :: k).
Show (map a) =>
[Intersection map a] -> ShowS
show :: Intersection map a -> String
$cshow :: forall k (map :: k -> *) (a :: k).
Show (map a) =>
Intersection map a -> String
showsPrec :: Key -> Intersection map a -> ShowS
$cshowsPrec :: forall k (map :: k -> *) (a :: k).
Show (map a) =>
Key -> Intersection map a -> ShowS
Show) via map a
  deriving ((a -> b -> Bool)
-> Intersection map a -> Intersection map b -> Bool
(forall a b.
 (a -> b -> Bool)
 -> Intersection map a -> Intersection map b -> Bool)
-> Eq1 (Intersection map)
forall a b.
(a -> b -> Bool)
-> Intersection map a -> Intersection map b -> Bool
forall (map :: * -> *) a b.
Eq1 map =>
(a -> b -> Bool)
-> Intersection map a -> Intersection map b -> Bool
forall (f :: * -> *).
(forall a b. (a -> b -> Bool) -> f a -> f b -> Bool) -> Eq1 f
liftEq :: (a -> b -> Bool)
-> Intersection map a -> Intersection map b -> Bool
$cliftEq :: forall (map :: * -> *) a b.
Eq1 map =>
(a -> b -> Bool)
-> Intersection map a -> Intersection map b -> Bool
Eq1, Eq1 (Intersection map)
Eq1 (Intersection map) =>
(forall a b.
 (a -> b -> Ordering)
 -> Intersection map a -> Intersection map b -> Ordering)
-> Ord1 (Intersection map)
(a -> b -> Ordering)
-> Intersection map a -> Intersection map b -> Ordering
forall a b.
(a -> b -> Ordering)
-> Intersection map a -> Intersection map b -> Ordering
forall (f :: * -> *).
Eq1 f =>
(forall a b. (a -> b -> Ordering) -> f a -> f b -> Ordering)
-> Ord1 f
forall (map :: * -> *). Ord1 map => Eq1 (Intersection map)
forall (map :: * -> *) a b.
Ord1 map =>
(a -> b -> Ordering)
-> Intersection map a -> Intersection map b -> Ordering
liftCompare :: (a -> b -> Ordering)
-> Intersection map a -> Intersection map b -> Ordering
$cliftCompare :: forall (map :: * -> *) a b.
Ord1 map =>
(a -> b -> Ordering)
-> Intersection map a -> Intersection map b -> Ordering
$cp1Ord1 :: forall (map :: * -> *). Ord1 map => Eq1 (Intersection map)
Ord1, ReadPrec a -> ReadPrec [a] -> ReadPrec (Intersection map a)
ReadPrec a -> ReadPrec [a] -> ReadPrec [Intersection map a]
(Key -> ReadS a) -> ReadS [a] -> Key -> ReadS (Intersection map a)
(Key -> ReadS a) -> ReadS [a] -> ReadS [Intersection map a]
(forall a.
 (Key -> ReadS a) -> ReadS [a] -> Key -> ReadS (Intersection map a))
-> (forall a.
    (Key -> ReadS a) -> ReadS [a] -> ReadS [Intersection map a])
-> (forall a.
    ReadPrec a -> ReadPrec [a] -> ReadPrec (Intersection map a))
-> (forall a.
    ReadPrec a -> ReadPrec [a] -> ReadPrec [Intersection map a])
-> Read1 (Intersection map)
forall a.
ReadPrec a -> ReadPrec [a] -> ReadPrec [Intersection map a]
forall a.
ReadPrec a -> ReadPrec [a] -> ReadPrec (Intersection map a)
forall a.
(Key -> ReadS a) -> ReadS [a] -> Key -> ReadS (Intersection map a)
forall a.
(Key -> ReadS a) -> ReadS [a] -> ReadS [Intersection map a]
forall (map :: * -> *) a.
Read1 map =>
ReadPrec a -> ReadPrec [a] -> ReadPrec [Intersection map a]
forall (map :: * -> *) a.
Read1 map =>
ReadPrec a -> ReadPrec [a] -> ReadPrec (Intersection map a)
forall (map :: * -> *) a.
Read1 map =>
(Key -> ReadS a) -> ReadS [a] -> Key -> ReadS (Intersection map a)
forall (map :: * -> *) a.
Read1 map =>
(Key -> ReadS a) -> ReadS [a] -> ReadS [Intersection map a]
forall (f :: * -> *).
(forall a. (Key -> ReadS a) -> ReadS [a] -> Key -> ReadS (f a))
-> (forall a. (Key -> ReadS a) -> ReadS [a] -> ReadS [f a])
-> (forall a. ReadPrec a -> ReadPrec [a] -> ReadPrec (f a))
-> (forall a. ReadPrec a -> ReadPrec [a] -> ReadPrec [f a])
-> Read1 f
liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [Intersection map a]
$cliftReadListPrec :: forall (map :: * -> *) a.
Read1 map =>
ReadPrec a -> ReadPrec [a] -> ReadPrec [Intersection map a]
liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (Intersection map a)
$cliftReadPrec :: forall (map :: * -> *) a.
Read1 map =>
ReadPrec a -> ReadPrec [a] -> ReadPrec (Intersection map a)
liftReadList :: (Key -> ReadS a) -> ReadS [a] -> ReadS [Intersection map a]
$cliftReadList :: forall (map :: * -> *) a.
Read1 map =>
(Key -> ReadS a) -> ReadS [a] -> ReadS [Intersection map a]
liftReadsPrec :: (Key -> ReadS a) -> ReadS [a] -> Key -> ReadS (Intersection map a)
$cliftReadsPrec :: forall (map :: * -> *) a.
Read1 map =>
(Key -> ReadS a) -> ReadS [a] -> Key -> ReadS (Intersection map a)
Read1, (Key -> a -> ShowS)
-> ([a] -> ShowS) -> Key -> Intersection map a -> ShowS
(Key -> a -> ShowS)
-> ([a] -> ShowS) -> [Intersection map a] -> ShowS
(forall a.
 (Key -> a -> ShowS)
 -> ([a] -> ShowS) -> Key -> Intersection map a -> ShowS)
-> (forall a.
    (Key -> a -> ShowS)
    -> ([a] -> ShowS) -> [Intersection map a] -> ShowS)
-> Show1 (Intersection map)
forall a.
(Key -> a -> ShowS)
-> ([a] -> ShowS) -> Key -> Intersection map a -> ShowS
forall a.
(Key -> a -> ShowS)
-> ([a] -> ShowS) -> [Intersection map a] -> ShowS
forall (map :: * -> *) a.
Show1 map =>
(Key -> a -> ShowS)
-> ([a] -> ShowS) -> Key -> Intersection map a -> ShowS
forall (map :: * -> *) a.
Show1 map =>
(Key -> a -> ShowS)
-> ([a] -> ShowS) -> [Intersection map a] -> ShowS
forall (f :: * -> *).
(forall a.
 (Key -> a -> ShowS) -> ([a] -> ShowS) -> Key -> f a -> ShowS)
-> (forall a.
    (Key -> a -> ShowS) -> ([a] -> ShowS) -> [f a] -> ShowS)
-> Show1 f
liftShowList :: (Key -> a -> ShowS)
-> ([a] -> ShowS) -> [Intersection map a] -> ShowS
$cliftShowList :: forall (map :: * -> *) a.
Show1 map =>
(Key -> a -> ShowS)
-> ([a] -> ShowS) -> [Intersection map a] -> ShowS
liftShowsPrec :: (Key -> a -> ShowS)
-> ([a] -> ShowS) -> Key -> Intersection map a -> ShowS
$cliftShowsPrec :: forall (map :: * -> *) a.
Show1 map =>
(Key -> a -> ShowS)
-> ([a] -> ShowS) -> Key -> Intersection map a -> ShowS
Show1) via map

instance Filtrable map => Filtrable (Intersection map) where
    mapMaybe :: (a -> Maybe b) -> Intersection map a -> Intersection map b
mapMaybe f :: a -> Maybe b
f = map b -> Intersection map b
forall k (map :: k -> *) (a :: k). map a -> Intersection map a
Intersection (map b -> Intersection map b)
-> (Intersection map a -> map b)
-> Intersection map a
-> Intersection map b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Maybe b) -> map a -> map b
forall (f :: * -> *) a b.
Filtrable f =>
(a -> Maybe b) -> f a -> f b
mapMaybe a -> Maybe b
f (map a -> map b)
-> (Intersection map a -> map a) -> Intersection map a -> map b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Intersection map a -> map a
forall k (map :: k -> *) (a :: k). Intersection map a -> map a
unIntersection

instance StaticMap map => StaticMap (Intersection map) where
    type Key (Intersection map) = Key map
    adjustA :: (a -> p a)
-> Key (Intersection map)
-> Intersection map a
-> p (Intersection map a)
adjustA f :: a -> p a
f k :: Key (Intersection map)
k = (map a -> Intersection map a)
-> p (map a) -> p (Intersection map a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap map a -> Intersection map a
forall k (map :: k -> *) (a :: k). map a -> Intersection map a
Intersection (p (map a) -> p (Intersection map a))
-> (Intersection map a -> p (map a))
-> Intersection map a
-> p (Intersection map a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> p a) -> Key map -> map a -> p (map a)
forall (map :: * -> *) (p :: * -> *) a.
(StaticMap map, Applicative p) =>
(a -> p a) -> Key map -> map a -> p (map a)
adjustA a -> p a
f Key map
Key (Intersection map)
k (map a -> p (map a))
-> (Intersection map a -> map a) -> Intersection map a -> p (map a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Intersection map a -> map a
forall k (map :: k -> *) (a :: k). Intersection map a -> map a
unIntersection
    traverseWithKey :: (Key (Intersection map) -> a -> p b)
-> Intersection map a -> p (Intersection map b)
traverseWithKey f :: Key (Intersection map) -> a -> p b
f = (map b -> Intersection map b)
-> p (map b) -> p (Intersection map b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap map b -> Intersection map b
forall k (map :: k -> *) (a :: k). map a -> Intersection map a
Intersection (p (map b) -> p (Intersection map b))
-> (Intersection map a -> p (map b))
-> Intersection map a
-> p (Intersection map b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Key map -> a -> p b) -> map a -> p (map b)
forall (map :: * -> *) (p :: * -> *) a b.
(StaticMap map, Applicative p) =>
(Key map -> a -> p b) -> map a -> p (map b)
traverseWithKey Key map -> a -> p b
Key (Intersection map) -> a -> p b
f (map a -> p (map b))
-> (Intersection map a -> map a) -> Intersection map a -> p (map b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Intersection map a -> map a
forall k (map :: k -> *) (a :: k). Intersection map a -> map a
unIntersection

instance Map map => Map (Intersection map) where
    empty :: Intersection map a
empty = map a -> Intersection map a
forall k (map :: k -> *) (a :: k). map a -> Intersection map a
Intersection map a
forall (map :: * -> *) a. Map map => map a
empty
    alterF :: (Maybe a -> f (Maybe a))
-> Key (Intersection map)
-> Intersection map a
-> f (Intersection map a)
alterF f :: Maybe a -> f (Maybe a)
f k :: Key (Intersection map)
k = (map a -> Intersection map a)
-> f (map a) -> f (Intersection map a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap map a -> Intersection map a
forall k (map :: k -> *) (a :: k). map a -> Intersection map a
Intersection (f (map a) -> f (Intersection map a))
-> (Intersection map a -> f (map a))
-> Intersection map a
-> f (Intersection map a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe a -> f (Maybe a)) -> Key map -> map a -> f (map a)
forall (map :: * -> *) (f :: * -> *) a.
(Map map, Functor f) =>
(Maybe a -> f (Maybe a)) -> Key map -> map a -> f (map a)
alterF Maybe a -> f (Maybe a)
f Key map
Key (Intersection map)
k (map a -> f (map a))
-> (Intersection map a -> map a) -> Intersection map a -> f (map a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Intersection map a -> map a
forall k (map :: k -> *) (a :: k). Intersection map a -> map a
unIntersection
    mergeA :: (Key (Intersection map) -> Either' a b -> p (Maybe c))
-> Intersection map a
-> Intersection map b
-> p (Intersection map c)
mergeA f :: Key (Intersection map) -> Either' a b -> p (Maybe c)
f = (map c -> Intersection map c)
-> p (map c) -> p (Intersection map c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap map c -> Intersection map c
forall k (map :: k -> *) (a :: k). map a -> Intersection map a
Intersection (p (map c) -> p (Intersection map c))
-> (Intersection map a -> Intersection map b -> p (map c))
-> Intersection map a
-> Intersection map b
-> p (Intersection map c)
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ (map a -> map b -> p (map c))
-> (Intersection map a -> map a)
-> (Intersection map b -> map b)
-> Intersection map a
-> Intersection map b
-> p (map c)
forall a' b' c a b.
(a' -> b' -> c) -> (a -> a') -> (b -> b') -> a -> b -> c
compose2 ((Key map -> Either' a b -> p (Maybe c))
-> map a -> map b -> p (map c)
forall (map :: * -> *) (p :: * -> *) a b c.
(Map map, Applicative p) =>
(Key map -> Either' a b -> p (Maybe c))
-> map a -> map b -> p (map c)
mergeA Key map -> Either' a b -> p (Maybe c)
Key (Intersection map) -> Either' a b -> p (Maybe c)
f) Intersection map a -> map a
forall k (map :: k -> *) (a :: k). Intersection map a -> map a
unIntersection Intersection map b -> map b
forall k (map :: k -> *) (a :: k). Intersection map a -> map a
unIntersection
    mapMaybeWithKeyA :: (Key (Intersection map) -> a -> p (Maybe b))
-> Intersection map a -> p (Intersection map b)
mapMaybeWithKeyA f :: Key (Intersection map) -> a -> p (Maybe b)
f = (map b -> Intersection map b)
-> p (map b) -> p (Intersection map b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap map b -> Intersection map b
forall k (map :: k -> *) (a :: k). map a -> Intersection map a
Intersection (p (map b) -> p (Intersection map b))
-> (Intersection map a -> p (map b))
-> Intersection map a
-> p (Intersection map b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Key map -> a -> p (Maybe b)) -> map a -> p (map b)
forall (map :: * -> *) (p :: * -> *) a b.
(Map map, Applicative p) =>
(Key map -> a -> p (Maybe b)) -> map a -> p (map b)
mapMaybeWithKeyA Key map -> a -> p (Maybe b)
Key (Intersection map) -> a -> p (Maybe b)
f (map a -> p (map b))
-> (Intersection map a -> map a) -> Intersection map a -> p (map b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Intersection map a -> map a
forall k (map :: k -> *) (a :: k). Intersection map a -> map a
unIntersection

instance (Map map, Semigroup a) => Semigroup (Intersection map a) where
    <> :: Intersection map a -> Intersection map a -> Intersection map a
(<>) = map a -> Intersection map a
forall k (map :: k -> *) (a :: k). map a -> Intersection map a
Intersection (map a -> Intersection map a)
-> (map a -> map a -> map a)
-> map a
-> map a
-> Intersection map a
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ (Key map -> a -> a -> a) -> map a -> map a -> map a
forall (map :: * -> *) a b c.
Map map =>
(Key map -> a -> b -> c) -> map a -> map b -> map c
intersectionWith ((a -> a -> a) -> Key map -> a -> a -> a
forall (f :: * -> *) a. Applicative f => a -> f a
pure a -> a -> a
forall a. Semigroup a => a -> a -> a
(<>)) (map a -> map a -> Intersection map a)
-> (Intersection map a -> map a)
-> Intersection map a
-> Intersection map a
-> Intersection map a
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` Intersection map a -> map a
forall k (map :: k -> *) (a :: k). Intersection map a -> map a
unIntersection

-- | Wrapper of a 'Map' whose semigroup operation is the symmetric difference, and ergo whose monoidal unit is empty
newtype SymmetricDifference map a = SymmetricDifference { SymmetricDifference map a -> map a
unSymmetricDifference :: map a }
  deriving (a -> SymmetricDifference map b -> SymmetricDifference map a
(a -> b) -> SymmetricDifference map a -> SymmetricDifference map b
(forall a b.
 (a -> b) -> SymmetricDifference map a -> SymmetricDifference map b)
-> (forall a b.
    a -> SymmetricDifference map b -> SymmetricDifference map a)
-> Functor (SymmetricDifference map)
forall a b.
a -> SymmetricDifference map b -> SymmetricDifference map a
forall a b.
(a -> b) -> SymmetricDifference map a -> SymmetricDifference map b
forall (map :: * -> *) a b.
Functor map =>
a -> SymmetricDifference map b -> SymmetricDifference map a
forall (map :: * -> *) a b.
Functor map =>
(a -> b) -> SymmetricDifference map a -> SymmetricDifference map b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> SymmetricDifference map b -> SymmetricDifference map a
$c<$ :: forall (map :: * -> *) a b.
Functor map =>
a -> SymmetricDifference map b -> SymmetricDifference map a
fmap :: (a -> b) -> SymmetricDifference map a -> SymmetricDifference map b
$cfmap :: forall (map :: * -> *) a b.
Functor map =>
(a -> b) -> SymmetricDifference map a -> SymmetricDifference map b
Functor, SymmetricDifference map a -> Bool
(a -> m) -> SymmetricDifference map a -> m
(a -> b -> b) -> b -> SymmetricDifference map a -> b
(forall m. Monoid m => SymmetricDifference map m -> m)
-> (forall m a.
    Monoid m =>
    (a -> m) -> SymmetricDifference map a -> m)
-> (forall m a.
    Monoid m =>
    (a -> m) -> SymmetricDifference map a -> m)
-> (forall a b.
    (a -> b -> b) -> b -> SymmetricDifference map a -> b)
-> (forall a b.
    (a -> b -> b) -> b -> SymmetricDifference map a -> b)
-> (forall b a.
    (b -> a -> b) -> b -> SymmetricDifference map a -> b)
-> (forall b a.
    (b -> a -> b) -> b -> SymmetricDifference map a -> b)
-> (forall a. (a -> a -> a) -> SymmetricDifference map a -> a)
-> (forall a. (a -> a -> a) -> SymmetricDifference map a -> a)
-> (forall a. SymmetricDifference map a -> [a])
-> (forall a. SymmetricDifference map a -> Bool)
-> (forall a. SymmetricDifference map a -> Key)
-> (forall a. Eq a => a -> SymmetricDifference map a -> Bool)
-> (forall a. Ord a => SymmetricDifference map a -> a)
-> (forall a. Ord a => SymmetricDifference map a -> a)
-> (forall a. Num a => SymmetricDifference map a -> a)
-> (forall a. Num a => SymmetricDifference map a -> a)
-> Foldable (SymmetricDifference map)
forall a. Eq a => a -> SymmetricDifference map a -> Bool
forall a. Num a => SymmetricDifference map a -> a
forall a. Ord a => SymmetricDifference map a -> a
forall m. Monoid m => SymmetricDifference map m -> m
forall a. SymmetricDifference map a -> Bool
forall a. SymmetricDifference map a -> Key
forall a. SymmetricDifference map a -> [a]
forall a. (a -> a -> a) -> SymmetricDifference map a -> a
forall m a. Monoid m => (a -> m) -> SymmetricDifference map a -> m
forall b a. (b -> a -> b) -> b -> SymmetricDifference map a -> b
forall a b. (a -> b -> b) -> b -> SymmetricDifference map a -> b
forall (map :: * -> *) a.
(Foldable map, Eq a) =>
a -> SymmetricDifference map a -> Bool
forall (map :: * -> *) a.
(Foldable map, Num a) =>
SymmetricDifference map a -> a
forall (map :: * -> *) a.
(Foldable map, Ord a) =>
SymmetricDifference map a -> a
forall (map :: * -> *) m.
(Foldable map, Monoid m) =>
SymmetricDifference map m -> m
forall (map :: * -> *) a.
Foldable map =>
SymmetricDifference map a -> Bool
forall (map :: * -> *) a.
Foldable map =>
SymmetricDifference map a -> Key
forall (map :: * -> *) a.
Foldable map =>
SymmetricDifference map a -> [a]
forall (map :: * -> *) a.
Foldable map =>
(a -> a -> a) -> SymmetricDifference map a -> a
forall (map :: * -> *) m a.
(Foldable map, Monoid m) =>
(a -> m) -> SymmetricDifference map a -> m
forall (map :: * -> *) b a.
Foldable map =>
(b -> a -> b) -> b -> SymmetricDifference map a -> b
forall (map :: * -> *) a b.
Foldable map =>
(a -> b -> b) -> b -> SymmetricDifference map 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 -> Key)
-> (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 :: SymmetricDifference map a -> a
$cproduct :: forall (map :: * -> *) a.
(Foldable map, Num a) =>
SymmetricDifference map a -> a
sum :: SymmetricDifference map a -> a
$csum :: forall (map :: * -> *) a.
(Foldable map, Num a) =>
SymmetricDifference map a -> a
minimum :: SymmetricDifference map a -> a
$cminimum :: forall (map :: * -> *) a.
(Foldable map, Ord a) =>
SymmetricDifference map a -> a
maximum :: SymmetricDifference map a -> a
$cmaximum :: forall (map :: * -> *) a.
(Foldable map, Ord a) =>
SymmetricDifference map a -> a
elem :: a -> SymmetricDifference map a -> Bool
$celem :: forall (map :: * -> *) a.
(Foldable map, Eq a) =>
a -> SymmetricDifference map a -> Bool
length :: SymmetricDifference map a -> Key
$clength :: forall (map :: * -> *) a.
Foldable map =>
SymmetricDifference map a -> Key
null :: SymmetricDifference map a -> Bool
$cnull :: forall (map :: * -> *) a.
Foldable map =>
SymmetricDifference map a -> Bool
toList :: SymmetricDifference map a -> [a]
$ctoList :: forall (map :: * -> *) a.
Foldable map =>
SymmetricDifference map a -> [a]
foldl1 :: (a -> a -> a) -> SymmetricDifference map a -> a
$cfoldl1 :: forall (map :: * -> *) a.
Foldable map =>
(a -> a -> a) -> SymmetricDifference map a -> a
foldr1 :: (a -> a -> a) -> SymmetricDifference map a -> a
$cfoldr1 :: forall (map :: * -> *) a.
Foldable map =>
(a -> a -> a) -> SymmetricDifference map a -> a
foldl' :: (b -> a -> b) -> b -> SymmetricDifference map a -> b
$cfoldl' :: forall (map :: * -> *) b a.
Foldable map =>
(b -> a -> b) -> b -> SymmetricDifference map a -> b
foldl :: (b -> a -> b) -> b -> SymmetricDifference map a -> b
$cfoldl :: forall (map :: * -> *) b a.
Foldable map =>
(b -> a -> b) -> b -> SymmetricDifference map a -> b
foldr' :: (a -> b -> b) -> b -> SymmetricDifference map a -> b
$cfoldr' :: forall (map :: * -> *) a b.
Foldable map =>
(a -> b -> b) -> b -> SymmetricDifference map a -> b
foldr :: (a -> b -> b) -> b -> SymmetricDifference map a -> b
$cfoldr :: forall (map :: * -> *) a b.
Foldable map =>
(a -> b -> b) -> b -> SymmetricDifference map a -> b
foldMap' :: (a -> m) -> SymmetricDifference map a -> m
$cfoldMap' :: forall (map :: * -> *) m a.
(Foldable map, Monoid m) =>
(a -> m) -> SymmetricDifference map a -> m
foldMap :: (a -> m) -> SymmetricDifference map a -> m
$cfoldMap :: forall (map :: * -> *) m a.
(Foldable map, Monoid m) =>
(a -> m) -> SymmetricDifference map a -> m
fold :: SymmetricDifference map m -> m
$cfold :: forall (map :: * -> *) m.
(Foldable map, Monoid m) =>
SymmetricDifference map m -> m
Foldable, Functor (SymmetricDifference map)
Foldable (SymmetricDifference map)
(Functor (SymmetricDifference map),
 Foldable (SymmetricDifference map)) =>
(forall (f :: * -> *) a b.
 Applicative f =>
 (a -> f b)
 -> SymmetricDifference map a -> f (SymmetricDifference map b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    SymmetricDifference map (f a) -> f (SymmetricDifference map a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b)
    -> SymmetricDifference map a -> m (SymmetricDifference map b))
-> (forall (m :: * -> *) a.
    Monad m =>
    SymmetricDifference map (m a) -> m (SymmetricDifference map a))
-> Traversable (SymmetricDifference map)
(a -> f b)
-> SymmetricDifference map a -> f (SymmetricDifference map 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 (map :: * -> *).
Traversable map =>
Functor (SymmetricDifference map)
forall (map :: * -> *).
Traversable map =>
Foldable (SymmetricDifference map)
forall (map :: * -> *) (m :: * -> *) a.
(Traversable map, Monad m) =>
SymmetricDifference map (m a) -> m (SymmetricDifference map a)
forall (map :: * -> *) (f :: * -> *) a.
(Traversable map, Applicative f) =>
SymmetricDifference map (f a) -> f (SymmetricDifference map a)
forall (map :: * -> *) (m :: * -> *) a b.
(Traversable map, Monad m) =>
(a -> m b)
-> SymmetricDifference map a -> m (SymmetricDifference map b)
forall (map :: * -> *) (f :: * -> *) a b.
(Traversable map, Applicative f) =>
(a -> f b)
-> SymmetricDifference map a -> f (SymmetricDifference map b)
forall (m :: * -> *) a.
Monad m =>
SymmetricDifference map (m a) -> m (SymmetricDifference map a)
forall (f :: * -> *) a.
Applicative f =>
SymmetricDifference map (f a) -> f (SymmetricDifference map a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b)
-> SymmetricDifference map a -> m (SymmetricDifference map b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> SymmetricDifference map a -> f (SymmetricDifference map b)
sequence :: SymmetricDifference map (m a) -> m (SymmetricDifference map a)
$csequence :: forall (map :: * -> *) (m :: * -> *) a.
(Traversable map, Monad m) =>
SymmetricDifference map (m a) -> m (SymmetricDifference map a)
mapM :: (a -> m b)
-> SymmetricDifference map a -> m (SymmetricDifference map b)
$cmapM :: forall (map :: * -> *) (m :: * -> *) a b.
(Traversable map, Monad m) =>
(a -> m b)
-> SymmetricDifference map a -> m (SymmetricDifference map b)
sequenceA :: SymmetricDifference map (f a) -> f (SymmetricDifference map a)
$csequenceA :: forall (map :: * -> *) (f :: * -> *) a.
(Traversable map, Applicative f) =>
SymmetricDifference map (f a) -> f (SymmetricDifference map a)
traverse :: (a -> f b)
-> SymmetricDifference map a -> f (SymmetricDifference map b)
$ctraverse :: forall (map :: * -> *) (f :: * -> *) a b.
(Traversable map, Applicative f) =>
(a -> f b)
-> SymmetricDifference map a -> f (SymmetricDifference map b)
$cp2Traversable :: forall (map :: * -> *).
Traversable map =>
Foldable (SymmetricDifference map)
$cp1Traversable :: forall (map :: * -> *).
Traversable map =>
Functor (SymmetricDifference map)
Traversable)
  deriving (SymmetricDifference map a -> SymmetricDifference map a -> Bool
(SymmetricDifference map a -> SymmetricDifference map a -> Bool)
-> (SymmetricDifference map a -> SymmetricDifference map a -> Bool)
-> Eq (SymmetricDifference map a)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall k (map :: k -> *) (a :: k).
Eq (map a) =>
SymmetricDifference map a -> SymmetricDifference map a -> Bool
/= :: SymmetricDifference map a -> SymmetricDifference map a -> Bool
$c/= :: forall k (map :: k -> *) (a :: k).
Eq (map a) =>
SymmetricDifference map a -> SymmetricDifference map a -> Bool
== :: SymmetricDifference map a -> SymmetricDifference map a -> Bool
$c== :: forall k (map :: k -> *) (a :: k).
Eq (map a) =>
SymmetricDifference map a -> SymmetricDifference map a -> Bool
Eq, Eq (SymmetricDifference map a)
Eq (SymmetricDifference map a) =>
(SymmetricDifference map a
 -> SymmetricDifference map a -> Ordering)
-> (SymmetricDifference map a -> SymmetricDifference map a -> Bool)
-> (SymmetricDifference map a -> SymmetricDifference map a -> Bool)
-> (SymmetricDifference map a -> SymmetricDifference map a -> Bool)
-> (SymmetricDifference map a -> SymmetricDifference map a -> Bool)
-> (SymmetricDifference map a
    -> SymmetricDifference map a -> SymmetricDifference map a)
-> (SymmetricDifference map a
    -> SymmetricDifference map a -> SymmetricDifference map a)
-> Ord (SymmetricDifference map a)
SymmetricDifference map a -> SymmetricDifference map a -> Bool
SymmetricDifference map a -> SymmetricDifference map a -> Ordering
SymmetricDifference map a
-> SymmetricDifference map a -> SymmetricDifference map 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 (map :: k -> *) (a :: k).
Ord (map a) =>
Eq (SymmetricDifference map a)
forall k (map :: k -> *) (a :: k).
Ord (map a) =>
SymmetricDifference map a -> SymmetricDifference map a -> Bool
forall k (map :: k -> *) (a :: k).
Ord (map a) =>
SymmetricDifference map a -> SymmetricDifference map a -> Ordering
forall k (map :: k -> *) (a :: k).
Ord (map a) =>
SymmetricDifference map a
-> SymmetricDifference map a -> SymmetricDifference map a
min :: SymmetricDifference map a
-> SymmetricDifference map a -> SymmetricDifference map a
$cmin :: forall k (map :: k -> *) (a :: k).
Ord (map a) =>
SymmetricDifference map a
-> SymmetricDifference map a -> SymmetricDifference map a
max :: SymmetricDifference map a
-> SymmetricDifference map a -> SymmetricDifference map a
$cmax :: forall k (map :: k -> *) (a :: k).
Ord (map a) =>
SymmetricDifference map a
-> SymmetricDifference map a -> SymmetricDifference map a
>= :: SymmetricDifference map a -> SymmetricDifference map a -> Bool
$c>= :: forall k (map :: k -> *) (a :: k).
Ord (map a) =>
SymmetricDifference map a -> SymmetricDifference map a -> Bool
> :: SymmetricDifference map a -> SymmetricDifference map a -> Bool
$c> :: forall k (map :: k -> *) (a :: k).
Ord (map a) =>
SymmetricDifference map a -> SymmetricDifference map a -> Bool
<= :: SymmetricDifference map a -> SymmetricDifference map a -> Bool
$c<= :: forall k (map :: k -> *) (a :: k).
Ord (map a) =>
SymmetricDifference map a -> SymmetricDifference map a -> Bool
< :: SymmetricDifference map a -> SymmetricDifference map a -> Bool
$c< :: forall k (map :: k -> *) (a :: k).
Ord (map a) =>
SymmetricDifference map a -> SymmetricDifference map a -> Bool
compare :: SymmetricDifference map a -> SymmetricDifference map a -> Ordering
$ccompare :: forall k (map :: k -> *) (a :: k).
Ord (map a) =>
SymmetricDifference map a -> SymmetricDifference map a -> Ordering
$cp1Ord :: forall k (map :: k -> *) (a :: k).
Ord (map a) =>
Eq (SymmetricDifference map a)
Ord, ReadPrec [SymmetricDifference map a]
ReadPrec (SymmetricDifference map a)
Key -> ReadS (SymmetricDifference map a)
ReadS [SymmetricDifference map a]
(Key -> ReadS (SymmetricDifference map a))
-> ReadS [SymmetricDifference map a]
-> ReadPrec (SymmetricDifference map a)
-> ReadPrec [SymmetricDifference map a]
-> Read (SymmetricDifference map a)
forall a.
(Key -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall k (map :: k -> *) (a :: k).
Read (map a) =>
ReadPrec [SymmetricDifference map a]
forall k (map :: k -> *) (a :: k).
Read (map a) =>
ReadPrec (SymmetricDifference map a)
forall k (map :: k -> *) (a :: k).
Read (map a) =>
Key -> ReadS (SymmetricDifference map a)
forall k (map :: k -> *) (a :: k).
Read (map a) =>
ReadS [SymmetricDifference map a]
readListPrec :: ReadPrec [SymmetricDifference map a]
$creadListPrec :: forall k (map :: k -> *) (a :: k).
Read (map a) =>
ReadPrec [SymmetricDifference map a]
readPrec :: ReadPrec (SymmetricDifference map a)
$creadPrec :: forall k (map :: k -> *) (a :: k).
Read (map a) =>
ReadPrec (SymmetricDifference map a)
readList :: ReadS [SymmetricDifference map a]
$creadList :: forall k (map :: k -> *) (a :: k).
Read (map a) =>
ReadS [SymmetricDifference map a]
readsPrec :: Key -> ReadS (SymmetricDifference map a)
$creadsPrec :: forall k (map :: k -> *) (a :: k).
Read (map a) =>
Key -> ReadS (SymmetricDifference map a)
Read, Key -> SymmetricDifference map a -> ShowS
[SymmetricDifference map a] -> ShowS
SymmetricDifference map a -> String
(Key -> SymmetricDifference map a -> ShowS)
-> (SymmetricDifference map a -> String)
-> ([SymmetricDifference map a] -> ShowS)
-> Show (SymmetricDifference map a)
forall a.
(Key -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (map :: k -> *) (a :: k).
Show (map a) =>
Key -> SymmetricDifference map a -> ShowS
forall k (map :: k -> *) (a :: k).
Show (map a) =>
[SymmetricDifference map a] -> ShowS
forall k (map :: k -> *) (a :: k).
Show (map a) =>
SymmetricDifference map a -> String
showList :: [SymmetricDifference map a] -> ShowS
$cshowList :: forall k (map :: k -> *) (a :: k).
Show (map a) =>
[SymmetricDifference map a] -> ShowS
show :: SymmetricDifference map a -> String
$cshow :: forall k (map :: k -> *) (a :: k).
Show (map a) =>
SymmetricDifference map a -> String
showsPrec :: Key -> SymmetricDifference map a -> ShowS
$cshowsPrec :: forall k (map :: k -> *) (a :: k).
Show (map a) =>
Key -> SymmetricDifference map a -> ShowS
Show) via map a
  deriving ((a -> b -> Bool)
-> SymmetricDifference map a -> SymmetricDifference map b -> Bool
(forall a b.
 (a -> b -> Bool)
 -> SymmetricDifference map a -> SymmetricDifference map b -> Bool)
-> Eq1 (SymmetricDifference map)
forall a b.
(a -> b -> Bool)
-> SymmetricDifference map a -> SymmetricDifference map b -> Bool
forall (map :: * -> *) a b.
Eq1 map =>
(a -> b -> Bool)
-> SymmetricDifference map a -> SymmetricDifference map b -> Bool
forall (f :: * -> *).
(forall a b. (a -> b -> Bool) -> f a -> f b -> Bool) -> Eq1 f
liftEq :: (a -> b -> Bool)
-> SymmetricDifference map a -> SymmetricDifference map b -> Bool
$cliftEq :: forall (map :: * -> *) a b.
Eq1 map =>
(a -> b -> Bool)
-> SymmetricDifference map a -> SymmetricDifference map b -> Bool
Eq1, Eq1 (SymmetricDifference map)
Eq1 (SymmetricDifference map) =>
(forall a b.
 (a -> b -> Ordering)
 -> SymmetricDifference map a
 -> SymmetricDifference map b
 -> Ordering)
-> Ord1 (SymmetricDifference map)
(a -> b -> Ordering)
-> SymmetricDifference map a
-> SymmetricDifference map b
-> Ordering
forall a b.
(a -> b -> Ordering)
-> SymmetricDifference map a
-> SymmetricDifference map b
-> Ordering
forall (f :: * -> *).
Eq1 f =>
(forall a b. (a -> b -> Ordering) -> f a -> f b -> Ordering)
-> Ord1 f
forall (map :: * -> *). Ord1 map => Eq1 (SymmetricDifference map)
forall (map :: * -> *) a b.
Ord1 map =>
(a -> b -> Ordering)
-> SymmetricDifference map a
-> SymmetricDifference map b
-> Ordering
liftCompare :: (a -> b -> Ordering)
-> SymmetricDifference map a
-> SymmetricDifference map b
-> Ordering
$cliftCompare :: forall (map :: * -> *) a b.
Ord1 map =>
(a -> b -> Ordering)
-> SymmetricDifference map a
-> SymmetricDifference map b
-> Ordering
$cp1Ord1 :: forall (map :: * -> *). Ord1 map => Eq1 (SymmetricDifference map)
Ord1, ReadPrec a -> ReadPrec [a] -> ReadPrec (SymmetricDifference map a)
ReadPrec a -> ReadPrec [a] -> ReadPrec [SymmetricDifference map a]
(Key -> ReadS a)
-> ReadS [a] -> Key -> ReadS (SymmetricDifference map a)
(Key -> ReadS a) -> ReadS [a] -> ReadS [SymmetricDifference map a]
(forall a.
 (Key -> ReadS a)
 -> ReadS [a] -> Key -> ReadS (SymmetricDifference map a))
-> (forall a.
    (Key -> ReadS a) -> ReadS [a] -> ReadS [SymmetricDifference map a])
-> (forall a.
    ReadPrec a -> ReadPrec [a] -> ReadPrec (SymmetricDifference map a))
-> (forall a.
    ReadPrec a -> ReadPrec [a] -> ReadPrec [SymmetricDifference map a])
-> Read1 (SymmetricDifference map)
forall a.
ReadPrec a -> ReadPrec [a] -> ReadPrec [SymmetricDifference map a]
forall a.
ReadPrec a -> ReadPrec [a] -> ReadPrec (SymmetricDifference map a)
forall a.
(Key -> ReadS a)
-> ReadS [a] -> Key -> ReadS (SymmetricDifference map a)
forall a.
(Key -> ReadS a) -> ReadS [a] -> ReadS [SymmetricDifference map a]
forall (map :: * -> *) a.
Read1 map =>
ReadPrec a -> ReadPrec [a] -> ReadPrec [SymmetricDifference map a]
forall (map :: * -> *) a.
Read1 map =>
ReadPrec a -> ReadPrec [a] -> ReadPrec (SymmetricDifference map a)
forall (map :: * -> *) a.
Read1 map =>
(Key -> ReadS a)
-> ReadS [a] -> Key -> ReadS (SymmetricDifference map a)
forall (map :: * -> *) a.
Read1 map =>
(Key -> ReadS a) -> ReadS [a] -> ReadS [SymmetricDifference map a]
forall (f :: * -> *).
(forall a. (Key -> ReadS a) -> ReadS [a] -> Key -> ReadS (f a))
-> (forall a. (Key -> ReadS a) -> ReadS [a] -> ReadS [f a])
-> (forall a. ReadPrec a -> ReadPrec [a] -> ReadPrec (f a))
-> (forall a. ReadPrec a -> ReadPrec [a] -> ReadPrec [f a])
-> Read1 f
liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [SymmetricDifference map a]
$cliftReadListPrec :: forall (map :: * -> *) a.
Read1 map =>
ReadPrec a -> ReadPrec [a] -> ReadPrec [SymmetricDifference map a]
liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (SymmetricDifference map a)
$cliftReadPrec :: forall (map :: * -> *) a.
Read1 map =>
ReadPrec a -> ReadPrec [a] -> ReadPrec (SymmetricDifference map a)
liftReadList :: (Key -> ReadS a) -> ReadS [a] -> ReadS [SymmetricDifference map a]
$cliftReadList :: forall (map :: * -> *) a.
Read1 map =>
(Key -> ReadS a) -> ReadS [a] -> ReadS [SymmetricDifference map a]
liftReadsPrec :: (Key -> ReadS a)
-> ReadS [a] -> Key -> ReadS (SymmetricDifference map a)
$cliftReadsPrec :: forall (map :: * -> *) a.
Read1 map =>
(Key -> ReadS a)
-> ReadS [a] -> Key -> ReadS (SymmetricDifference map a)
Read1, (Key -> a -> ShowS)
-> ([a] -> ShowS) -> Key -> SymmetricDifference map a -> ShowS
(Key -> a -> ShowS)
-> ([a] -> ShowS) -> [SymmetricDifference map a] -> ShowS
(forall a.
 (Key -> a -> ShowS)
 -> ([a] -> ShowS) -> Key -> SymmetricDifference map a -> ShowS)
-> (forall a.
    (Key -> a -> ShowS)
    -> ([a] -> ShowS) -> [SymmetricDifference map a] -> ShowS)
-> Show1 (SymmetricDifference map)
forall a.
(Key -> a -> ShowS)
-> ([a] -> ShowS) -> Key -> SymmetricDifference map a -> ShowS
forall a.
(Key -> a -> ShowS)
-> ([a] -> ShowS) -> [SymmetricDifference map a] -> ShowS
forall (map :: * -> *) a.
Show1 map =>
(Key -> a -> ShowS)
-> ([a] -> ShowS) -> Key -> SymmetricDifference map a -> ShowS
forall (map :: * -> *) a.
Show1 map =>
(Key -> a -> ShowS)
-> ([a] -> ShowS) -> [SymmetricDifference map a] -> ShowS
forall (f :: * -> *).
(forall a.
 (Key -> a -> ShowS) -> ([a] -> ShowS) -> Key -> f a -> ShowS)
-> (forall a.
    (Key -> a -> ShowS) -> ([a] -> ShowS) -> [f a] -> ShowS)
-> Show1 f
liftShowList :: (Key -> a -> ShowS)
-> ([a] -> ShowS) -> [SymmetricDifference map a] -> ShowS
$cliftShowList :: forall (map :: * -> *) a.
Show1 map =>
(Key -> a -> ShowS)
-> ([a] -> ShowS) -> [SymmetricDifference map a] -> ShowS
liftShowsPrec :: (Key -> a -> ShowS)
-> ([a] -> ShowS) -> Key -> SymmetricDifference map a -> ShowS
$cliftShowsPrec :: forall (map :: * -> *) a.
Show1 map =>
(Key -> a -> ShowS)
-> ([a] -> ShowS) -> Key -> SymmetricDifference map a -> ShowS
Show1) via map

instance Filtrable map => Filtrable (SymmetricDifference map) where
    mapMaybe :: (a -> Maybe b)
-> SymmetricDifference map a -> SymmetricDifference map b
mapMaybe f :: a -> Maybe b
f = map b -> SymmetricDifference map b
forall k (map :: k -> *) (a :: k).
map a -> SymmetricDifference map a
SymmetricDifference (map b -> SymmetricDifference map b)
-> (SymmetricDifference map a -> map b)
-> SymmetricDifference map a
-> SymmetricDifference map b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Maybe b) -> map a -> map b
forall (f :: * -> *) a b.
Filtrable f =>
(a -> Maybe b) -> f a -> f b
mapMaybe a -> Maybe b
f (map a -> map b)
-> (SymmetricDifference map a -> map a)
-> SymmetricDifference map a
-> map b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SymmetricDifference map a -> map a
forall k (map :: k -> *) (a :: k).
SymmetricDifference map a -> map a
unSymmetricDifference

instance StaticMap map => StaticMap (SymmetricDifference map) where
    type Key (SymmetricDifference map) = Key map
    adjustA :: (a -> p a)
-> Key (SymmetricDifference map)
-> SymmetricDifference map a
-> p (SymmetricDifference map a)
adjustA f :: a -> p a
f k :: Key (SymmetricDifference map)
k = (map a -> SymmetricDifference map a)
-> p (map a) -> p (SymmetricDifference map a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap map a -> SymmetricDifference map a
forall k (map :: k -> *) (a :: k).
map a -> SymmetricDifference map a
SymmetricDifference (p (map a) -> p (SymmetricDifference map a))
-> (SymmetricDifference map a -> p (map a))
-> SymmetricDifference map a
-> p (SymmetricDifference map a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> p a) -> Key map -> map a -> p (map a)
forall (map :: * -> *) (p :: * -> *) a.
(StaticMap map, Applicative p) =>
(a -> p a) -> Key map -> map a -> p (map a)
adjustA a -> p a
f Key map
Key (SymmetricDifference map)
k (map a -> p (map a))
-> (SymmetricDifference map a -> map a)
-> SymmetricDifference map a
-> p (map a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SymmetricDifference map a -> map a
forall k (map :: k -> *) (a :: k).
SymmetricDifference map a -> map a
unSymmetricDifference
    traverseWithKey :: (Key (SymmetricDifference map) -> a -> p b)
-> SymmetricDifference map a -> p (SymmetricDifference map b)
traverseWithKey f :: Key (SymmetricDifference map) -> a -> p b
f = (map b -> SymmetricDifference map b)
-> p (map b) -> p (SymmetricDifference map b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap map b -> SymmetricDifference map b
forall k (map :: k -> *) (a :: k).
map a -> SymmetricDifference map a
SymmetricDifference (p (map b) -> p (SymmetricDifference map b))
-> (SymmetricDifference map a -> p (map b))
-> SymmetricDifference map a
-> p (SymmetricDifference map b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Key map -> a -> p b) -> map a -> p (map b)
forall (map :: * -> *) (p :: * -> *) a b.
(StaticMap map, Applicative p) =>
(Key map -> a -> p b) -> map a -> p (map b)
traverseWithKey Key map -> a -> p b
Key (SymmetricDifference map) -> a -> p b
f (map a -> p (map b))
-> (SymmetricDifference map a -> map a)
-> SymmetricDifference map a
-> p (map b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SymmetricDifference map a -> map a
forall k (map :: k -> *) (a :: k).
SymmetricDifference map a -> map a
unSymmetricDifference

instance Map map => Map (SymmetricDifference map) where
    empty :: SymmetricDifference map a
empty = map a -> SymmetricDifference map a
forall k (map :: k -> *) (a :: k).
map a -> SymmetricDifference map a
SymmetricDifference map a
forall (map :: * -> *) a. Map map => map a
empty
    alterF :: (Maybe a -> f (Maybe a))
-> Key (SymmetricDifference map)
-> SymmetricDifference map a
-> f (SymmetricDifference map a)
alterF f :: Maybe a -> f (Maybe a)
f k :: Key (SymmetricDifference map)
k = (map a -> SymmetricDifference map a)
-> f (map a) -> f (SymmetricDifference map a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap map a -> SymmetricDifference map a
forall k (map :: k -> *) (a :: k).
map a -> SymmetricDifference map a
SymmetricDifference (f (map a) -> f (SymmetricDifference map a))
-> (SymmetricDifference map a -> f (map a))
-> SymmetricDifference map a
-> f (SymmetricDifference map a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe a -> f (Maybe a)) -> Key map -> map a -> f (map a)
forall (map :: * -> *) (f :: * -> *) a.
(Map map, Functor f) =>
(Maybe a -> f (Maybe a)) -> Key map -> map a -> f (map a)
alterF Maybe a -> f (Maybe a)
f Key map
Key (SymmetricDifference map)
k (map a -> f (map a))
-> (SymmetricDifference map a -> map a)
-> SymmetricDifference map a
-> f (map a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SymmetricDifference map a -> map a
forall k (map :: k -> *) (a :: k).
SymmetricDifference map a -> map a
unSymmetricDifference
    mergeA :: (Key (SymmetricDifference map) -> Either' a b -> p (Maybe c))
-> SymmetricDifference map a
-> SymmetricDifference map b
-> p (SymmetricDifference map c)
mergeA f :: Key (SymmetricDifference map) -> Either' a b -> p (Maybe c)
f = (map c -> SymmetricDifference map c)
-> p (map c) -> p (SymmetricDifference map c)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap map c -> SymmetricDifference map c
forall k (map :: k -> *) (a :: k).
map a -> SymmetricDifference map a
SymmetricDifference (p (map c) -> p (SymmetricDifference map c))
-> (SymmetricDifference map a
    -> SymmetricDifference map b -> p (map c))
-> SymmetricDifference map a
-> SymmetricDifference map b
-> p (SymmetricDifference map c)
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ (map a -> map b -> p (map c))
-> (SymmetricDifference map a -> map a)
-> (SymmetricDifference map b -> map b)
-> SymmetricDifference map a
-> SymmetricDifference map b
-> p (map c)
forall a' b' c a b.
(a' -> b' -> c) -> (a -> a') -> (b -> b') -> a -> b -> c
compose2 ((Key map -> Either' a b -> p (Maybe c))
-> map a -> map b -> p (map c)
forall (map :: * -> *) (p :: * -> *) a b c.
(Map map, Applicative p) =>
(Key map -> Either' a b -> p (Maybe c))
-> map a -> map b -> p (map c)
mergeA Key map -> Either' a b -> p (Maybe c)
Key (SymmetricDifference map) -> Either' a b -> p (Maybe c)
f) SymmetricDifference map a -> map a
forall k (map :: k -> *) (a :: k).
SymmetricDifference map a -> map a
unSymmetricDifference SymmetricDifference map b -> map b
forall k (map :: k -> *) (a :: k).
SymmetricDifference map a -> map a
unSymmetricDifference
    mapMaybeWithKeyA :: (Key (SymmetricDifference map) -> a -> p (Maybe b))
-> SymmetricDifference map a -> p (SymmetricDifference map b)
mapMaybeWithKeyA f :: Key (SymmetricDifference map) -> a -> p (Maybe b)
f = (map b -> SymmetricDifference map b)
-> p (map b) -> p (SymmetricDifference map b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap map b -> SymmetricDifference map b
forall k (map :: k -> *) (a :: k).
map a -> SymmetricDifference map a
SymmetricDifference (p (map b) -> p (SymmetricDifference map b))
-> (SymmetricDifference map a -> p (map b))
-> SymmetricDifference map a
-> p (SymmetricDifference map b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Key map -> a -> p (Maybe b)) -> map a -> p (map b)
forall (map :: * -> *) (p :: * -> *) a b.
(Map map, Applicative p) =>
(Key map -> a -> p (Maybe b)) -> map a -> p (map b)
mapMaybeWithKeyA Key map -> a -> p (Maybe b)
Key (SymmetricDifference map) -> a -> p (Maybe b)
f (map a -> p (map b))
-> (SymmetricDifference map a -> map a)
-> SymmetricDifference map a
-> p (map b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SymmetricDifference map a -> map a
forall k (map :: k -> *) (a :: k).
SymmetricDifference map a -> map a
unSymmetricDifference

instance Map map => Semigroup (SymmetricDifference map a) where
    <> :: SymmetricDifference map a
-> SymmetricDifference map a -> SymmetricDifference map a
(<>) = map a -> SymmetricDifference map a
forall k (map :: k -> *) (a :: k).
map a -> SymmetricDifference map a
SymmetricDifference (map a -> SymmetricDifference map a)
-> (map a -> map a -> map a)
-> map a
-> map a
-> SymmetricDifference map a
forall c d a b. (c -> d) -> (a -> b -> c) -> a -> b -> d
∘∘ map a -> map a -> map a
forall (map :: * -> *) a. Map map => map a -> map a -> map a
symmetricDifference (map a -> map a -> SymmetricDifference map a)
-> (SymmetricDifference map a -> map a)
-> SymmetricDifference map a
-> SymmetricDifference map a
-> SymmetricDifference map a
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`on` SymmetricDifference map a -> map a
forall k (map :: k -> *) (a :: k).
SymmetricDifference map a -> map a
unSymmetricDifference

instance Map map => Monoid (SymmetricDifference map a) where
    mempty :: SymmetricDifference map a
mempty = map a -> SymmetricDifference map a
forall k (map :: k -> *) (a :: k).
map a -> SymmetricDifference map a
SymmetricDifference map a
forall (map :: * -> *) a. Map map => map a
empty