{-# LANGUAGE BangPatterns #-}
module Data.Map.Merge.Set.Strict
(
MS.SimpleWhenMissing
, Internal.SimpleWhenMissingSet
, Internal.SimpleWhenMatched
, Internal.merge
, Internal.dropMatched
, Internal.filterMatched
, mapMatched
, mapMaybeMatched
, MS.dropMissing
, MS.preserveMissing
, MS.mapMissing
, MS.filterMissing
, MS.mapMaybeMissing
, Internal.dropMissingSet
, generateMissingSet
, generateMaybeMissingSet
, MS.WhenMissing
, Internal.WhenMissingSet
, Internal.WhenMatched
, Internal.mergeA
, Internal.filterAMatched
, traverseMatched
, traverseMaybeMatched
, MS.filterAMissing
, MS.traverseMissing
, MS.traverseMaybeMissing
, M.whenMissing
, generateAMissingSet
, generateMaybeAMissingSet
, Internal.runWhenMatched
, Internal.runWhenMissingSet
) where
import qualified Data.Map.Strict.Internal as MS
import qualified Data.Map.Internal as M
import qualified Data.Map.Merge.Set.Internal as Internal
import Data.Map.Merge.Set.Internal (WhenMatched(..), WhenMissingSet(..))
mapMatched :: Applicative f => (k -> a -> b) -> WhenMatched f k a b
mapMatched :: forall (f :: * -> *) k a b.
Applicative f =>
(k -> a -> b) -> WhenMatched f k a b
mapMatched k -> a -> b
f = (k -> a -> f (Maybe b)) -> WhenMatched f k a b
forall (f :: * -> *) k a b.
(k -> a -> f (Maybe b)) -> WhenMatched f k a b
WhenMatched (\k
k a
x -> Maybe b -> f (Maybe b)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (b -> Maybe b
forall a. a -> Maybe a
Just (b -> Maybe b) -> b -> Maybe b
forall a b. (a -> b) -> a -> b
$! k -> a -> b
f k
k a
x))
{-# INLINE mapMatched #-}
mapMaybeMatched :: Applicative f => (k -> a -> Maybe b) -> WhenMatched f k a b
mapMaybeMatched :: forall (f :: * -> *) k a b.
Applicative f =>
(k -> a -> Maybe b) -> WhenMatched f k a b
mapMaybeMatched k -> a -> Maybe b
f = (k -> a -> f (Maybe b)) -> WhenMatched f k a b
forall (f :: * -> *) k a b.
(k -> a -> f (Maybe b)) -> WhenMatched f k a b
WhenMatched (\k
k a
x -> Maybe b -> f (Maybe b)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe b -> Maybe b
forall a. Maybe a -> Maybe a
forceMaybe (k -> a -> Maybe b
f k
k a
x)))
{-# INLINE mapMaybeMatched #-}
traverseMatched :: Functor f => (k -> a -> f b) -> WhenMatched f k a b
traverseMatched :: forall (f :: * -> *) k a b.
Functor f =>
(k -> a -> f b) -> WhenMatched f k a b
traverseMatched k -> a -> f b
f = (k -> a -> f (Maybe b)) -> WhenMatched f k a b
forall (f :: * -> *) k a b.
(k -> a -> f (Maybe b)) -> WhenMatched f k a b
WhenMatched (\k
k a
x -> (b -> Maybe b
forall a. a -> Maybe a
Just (b -> Maybe b) -> b -> Maybe b
forall a b. (a -> b) -> a -> b
$!) (b -> Maybe b) -> f b -> f (Maybe b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> k -> a -> f b
f k
k a
x)
{-# INLINE traverseMatched #-}
traverseMaybeMatched
:: Functor f => (k -> a -> f (Maybe b)) -> WhenMatched f k a b
traverseMaybeMatched :: forall (f :: * -> *) k a b.
Functor f =>
(k -> a -> f (Maybe b)) -> WhenMatched f k a b
traverseMaybeMatched k -> a -> f (Maybe b)
f = (k -> a -> f (Maybe b)) -> WhenMatched f k a b
forall (f :: * -> *) k a b.
(k -> a -> f (Maybe b)) -> WhenMatched f k a b
WhenMatched (\k
k a
x -> Maybe b -> Maybe b
forall a. Maybe a -> Maybe a
forceMaybe (Maybe b -> Maybe b) -> f (Maybe b) -> f (Maybe b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> k -> a -> f (Maybe b)
f k
k a
x)
{-# INLINE traverseMaybeMatched #-}
generateMissingSet :: Applicative f => (k -> a) -> WhenMissingSet f k a
generateMissingSet :: forall (f :: * -> *) k a.
Applicative f =>
(k -> a) -> WhenMissingSet f k a
generateMissingSet k -> a
f = WhenMissingSet
{ missingSubtree :: Set k -> f (Map k a)
missingSubtree = \Set k
s -> Map k a -> f (Map k a)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ((k -> a) -> Set k -> Map k a
forall k a. (k -> a) -> Set k -> Map k a
MS.fromSet k -> a
f Set k
s)
, missingKey :: k -> f (Maybe a)
missingKey = \k
k -> Maybe a -> f (Maybe a)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> a -> Maybe a
forall a b. (a -> b) -> a -> b
$! k -> a
f k
k)
}
{-# INLINE generateMissingSet #-}
generateAMissingSet :: Applicative f => (k -> f a) -> WhenMissingSet f k a
generateAMissingSet :: forall (f :: * -> *) k a.
Applicative f =>
(k -> f a) -> WhenMissingSet f k a
generateAMissingSet k -> f a
f = WhenMissingSet
{ missingSubtree :: Set k -> f (Map k a)
missingSubtree = (k -> f a) -> Set k -> f (Map k a)
forall (f :: * -> *) k a.
Applicative f =>
(k -> f a) -> Set k -> f (Map k a)
MS.fromSetA k -> f a
f
, missingKey :: k -> f (Maybe a)
missingKey = \k
k -> (a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> a -> Maybe a
forall a b. (a -> b) -> a -> b
$!) (a -> Maybe a) -> f a -> f (Maybe a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> k -> f a
f k
k
}
{-# INLINE generateAMissingSet #-}
generateMaybeMissingSet
:: Applicative f => (k -> Maybe a) -> WhenMissingSet f k a
generateMaybeMissingSet :: forall (f :: * -> *) k a.
Applicative f =>
(k -> Maybe a) -> WhenMissingSet f k a
generateMaybeMissingSet k -> Maybe a
f = WhenMissingSet
{ missingSubtree :: Set k -> f (Map k a)
missingSubtree = \Set k
s -> Map k a -> f (Map k a)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ((k -> Maybe a) -> Set k -> Map k a
forall k a. (k -> Maybe a) -> Set k -> Map k a
MS.fromSetMaybe k -> Maybe a
f Set k
s)
, missingKey :: k -> f (Maybe a)
missingKey = \k
k -> Maybe a -> f (Maybe a)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (k -> Maybe a
f k
k)
}
{-# INLINE generateMaybeMissingSet #-}
generateMaybeAMissingSet
:: Applicative f => (k -> f (Maybe a)) -> WhenMissingSet f k a
generateMaybeAMissingSet :: forall (f :: * -> *) k a.
Applicative f =>
(k -> f (Maybe a)) -> WhenMissingSet f k a
generateMaybeAMissingSet k -> f (Maybe a)
f = WhenMissingSet
{ missingSubtree :: Set k -> f (Map k a)
missingSubtree = (k -> f (Maybe a)) -> Set k -> f (Map k a)
forall (f :: * -> *) k a.
Applicative f =>
(k -> f (Maybe a)) -> Set k -> f (Map k a)
MS.fromSetMaybeA k -> f (Maybe a)
f
, missingKey :: k -> f (Maybe a)
missingKey = \k
k -> Maybe a -> Maybe a
forall a. Maybe a -> Maybe a
forceMaybe (Maybe a -> Maybe a) -> f (Maybe a) -> f (Maybe a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> k -> f (Maybe a)
f k
k
}
{-# INLINE generateMaybeAMissingSet #-}
forceMaybe :: Maybe a -> Maybe a
forceMaybe :: forall a. Maybe a -> Maybe a
forceMaybe Maybe a
Nothing = Maybe a
forall a. Maybe a
Nothing
forceMaybe m :: Maybe a
m@(Just !a
_) = Maybe a
m