{-# OPTIONS_GHC -fno-warn-redundant-constraints #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
module Data.MonoidMap.Internal
(
MonoidMap (..)
, NonNull (..)
, empty
, fromList
, fromListWith
, fromMap
, singleton
, toList
, toMap
, get
, set
, adjust
, nullify
, null
, nullKey
, nonNull
, nonNullCount
, nonNullKey
, nonNullKeys
, take
, drop
, splitAt
, filter
, filterKeys
, filterWithKey
, partition
, partitionKeys
, partitionWithKey
, map
, mapKeys
, mapKeysWith
, foldl
, foldr
, foldlWithKey
, foldrWithKey
, foldMapWithKey
, foldl'
, foldr'
, foldlWithKey'
, foldrWithKey'
, append
, minus
, minusMaybe
, monus
, invert
, power
, isSubmapOf
, isSubmapOfBy
, disjoint
, disjointBy
, intersection
, intersectionWith
, intersectionWithA
, union
, unionWith
, unionWithA
, isPrefixOf
, stripPrefix
, commonPrefix
, stripCommonPrefix
, isSuffixOf
, stripSuffix
, commonSuffix
, stripCommonSuffix
, overlap
, stripPrefixOverlap
, stripSuffixOverlap
, stripOverlap
)
where
import Prelude hiding
( drop
, filter
, foldl
, foldl'
, foldr
, lookup
, map
, null
, splitAt
, subtract
, take
)
import Control.DeepSeq
( NFData )
import Data.Bifoldable
( Bifoldable )
import Data.Coerce
( coerce )
import Data.Function
( (&) )
import Data.Functor.Classes
( Eq1, Eq2, Show1, Show2 )
import Data.Functor.Identity
( Identity (..) )
import Data.Group
( Abelian, Group )
import Data.Map.Strict
( Map, lookup )
import Data.Maybe
( fromMaybe, isJust )
import Data.Monoid.GCD
( DistributiveGCDMonoid
, GCDMonoid
, LeftDistributiveGCDMonoid
, LeftGCDMonoid
, OverlappingGCDMonoid
, RightDistributiveGCDMonoid
, RightGCDMonoid
)
import Data.Monoid.LCM
( DistributiveLCMMonoid, LCMMonoid )
import Data.Monoid.Monus
( Monus (..) )
import Data.Monoid.Null
( MonoidNull, PositiveMonoid )
import Data.Semigroup
( stimes )
import Data.Semigroup.Cancellative
( Cancellative
, Commutative
, LeftCancellative
, LeftReductive
, Reductive (..)
, RightCancellative
, RightReductive
)
import Data.Set
( Set )
import GHC.Exts
( IsList (Item) )
import NoThunks.Class
( NoThunks )
import Text.Read
( Read (..) )
import qualified Data.Bifunctor as B
import qualified Data.Foldable as F
import qualified Data.List as L
import qualified Data.List.NonEmpty as NE
import qualified Data.Map.Merge.Strict as Map
import qualified Data.Map.Strict as Map
import qualified Data.Set as Set
import qualified GHC.Exts as GHC
import qualified Data.Group as C
import qualified Data.Monoid.GCD as C
import qualified Data.Monoid.LCM as C
import qualified Data.Monoid.Null as C
import qualified Data.Semigroup.Cancellative as C
newtype MonoidMap k v = MonoidMap (Map k (NonNull v))
deriving (MonoidMap k v -> MonoidMap k v -> Bool
(MonoidMap k v -> MonoidMap k v -> Bool)
-> (MonoidMap k v -> MonoidMap k v -> Bool) -> Eq (MonoidMap k v)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall k v. (Eq k, Eq v) => MonoidMap k v -> MonoidMap k v -> Bool
$c== :: forall k v. (Eq k, Eq v) => MonoidMap k v -> MonoidMap k v -> Bool
== :: MonoidMap k v -> MonoidMap k v -> Bool
$c/= :: forall k v. (Eq k, Eq v) => MonoidMap k v -> MonoidMap k v -> Bool
/= :: MonoidMap k v -> MonoidMap k v -> Bool
Eq, Int -> MonoidMap k v -> ShowS
[MonoidMap k v] -> ShowS
MonoidMap k v -> String
(Int -> MonoidMap k v -> ShowS)
-> (MonoidMap k v -> String)
-> ([MonoidMap k v] -> ShowS)
-> Show (MonoidMap k v)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k v. (Show k, Show v) => Int -> MonoidMap k v -> ShowS
forall k v. (Show k, Show v) => [MonoidMap k v] -> ShowS
forall k v. (Show k, Show v) => MonoidMap k v -> String
$cshowsPrec :: forall k v. (Show k, Show v) => Int -> MonoidMap k v -> ShowS
showsPrec :: Int -> MonoidMap k v -> ShowS
$cshow :: forall k v. (Show k, Show v) => MonoidMap k v -> String
show :: MonoidMap k v -> String
$cshowList :: forall k v. (Show k, Show v) => [MonoidMap k v] -> ShowS
showList :: [MonoidMap k v] -> ShowS
Show, MonoidMap k v -> ()
(MonoidMap k v -> ()) -> NFData (MonoidMap k v)
forall a. (a -> ()) -> NFData a
forall k v. (NFData k, NFData v) => MonoidMap k v -> ()
$crnf :: forall k v. (NFData k, NFData v) => MonoidMap k v -> ()
rnf :: MonoidMap k v -> ()
NFData, Context -> MonoidMap k v -> IO (Maybe ThunkInfo)
Proxy (MonoidMap k v) -> String
(Context -> MonoidMap k v -> IO (Maybe ThunkInfo))
-> (Context -> MonoidMap k v -> IO (Maybe ThunkInfo))
-> (Proxy (MonoidMap k v) -> String)
-> NoThunks (MonoidMap k v)
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
forall k v.
(NoThunks k, NoThunks v) =>
Context -> MonoidMap k v -> IO (Maybe ThunkInfo)
forall k v.
(NoThunks k, NoThunks v) =>
Proxy (MonoidMap k v) -> String
$cnoThunks :: forall k v.
(NoThunks k, NoThunks v) =>
Context -> MonoidMap k v -> IO (Maybe ThunkInfo)
noThunks :: Context -> MonoidMap k v -> IO (Maybe ThunkInfo)
$cwNoThunks :: forall k v.
(NoThunks k, NoThunks v) =>
Context -> MonoidMap k v -> IO (Maybe ThunkInfo)
wNoThunks :: Context -> MonoidMap k v -> IO (Maybe ThunkInfo)
$cshowTypeOf :: forall k v.
(NoThunks k, NoThunks v) =>
Proxy (MonoidMap k v) -> String
showTypeOf :: Proxy (MonoidMap k v) -> String
NoThunks)
via Map k v
deriving ((forall a. Eq a => Eq (MonoidMap k a)) =>
(forall a b.
(a -> b -> Bool) -> MonoidMap k a -> MonoidMap k b -> Bool)
-> Eq1 (MonoidMap k)
forall a. Eq a => Eq (MonoidMap k a)
forall k a. (Eq k, Eq a) => Eq (MonoidMap k a)
forall k a b.
Eq k =>
(a -> b -> Bool) -> MonoidMap k a -> MonoidMap k b -> Bool
forall a b.
(a -> b -> Bool) -> MonoidMap k a -> MonoidMap k b -> Bool
forall (f :: * -> *).
(forall a. Eq a => Eq (f a)) =>
(forall a b. (a -> b -> Bool) -> f a -> f b -> Bool) -> Eq1 f
$cliftEq :: forall k a b.
Eq k =>
(a -> b -> Bool) -> MonoidMap k a -> MonoidMap k b -> Bool
liftEq :: forall a b.
(a -> b -> Bool) -> MonoidMap k a -> MonoidMap k b -> Bool
Eq1, (forall a. Show a => Show (MonoidMap k a)) =>
(forall a.
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> MonoidMap k a -> ShowS)
-> (forall a.
(Int -> a -> ShowS) -> ([a] -> ShowS) -> [MonoidMap k a] -> ShowS)
-> Show1 (MonoidMap k)
forall a. Show a => Show (MonoidMap k a)
forall k a. (Show k, Show a) => Show (MonoidMap k a)
forall k a.
Show k =>
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> MonoidMap k a -> ShowS
forall k a.
Show k =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> [MonoidMap k a] -> ShowS
forall a.
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> MonoidMap k a -> ShowS
forall a.
(Int -> a -> ShowS) -> ([a] -> ShowS) -> [MonoidMap k a] -> ShowS
forall (f :: * -> *).
(forall a. Show a => Show (f a)) =>
(forall a.
(Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS)
-> (forall a.
(Int -> a -> ShowS) -> ([a] -> ShowS) -> [f a] -> ShowS)
-> Show1 f
$cliftShowsPrec :: forall k a.
Show k =>
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> MonoidMap k a -> ShowS
liftShowsPrec :: forall a.
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> MonoidMap k a -> ShowS
$cliftShowList :: forall k a.
Show k =>
(Int -> a -> ShowS) -> ([a] -> ShowS) -> [MonoidMap k a] -> ShowS
liftShowList :: forall a.
(Int -> a -> ShowS) -> ([a] -> ShowS) -> [MonoidMap k a] -> ShowS
Show1, (forall m. Monoid m => MonoidMap k m -> m)
-> (forall m a. Monoid m => (a -> m) -> MonoidMap k a -> m)
-> (forall m a. Monoid m => (a -> m) -> MonoidMap k a -> m)
-> (forall a b. (a -> b -> b) -> b -> MonoidMap k a -> b)
-> (forall a b. (a -> b -> b) -> b -> MonoidMap k a -> b)
-> (forall b a. (b -> a -> b) -> b -> MonoidMap k a -> b)
-> (forall b a. (b -> a -> b) -> b -> MonoidMap k a -> b)
-> (forall a. (a -> a -> a) -> MonoidMap k a -> a)
-> (forall a. (a -> a -> a) -> MonoidMap k a -> a)
-> (forall a. MonoidMap k a -> [a])
-> (forall a. MonoidMap k a -> Bool)
-> (forall a. MonoidMap k a -> Int)
-> (forall a. Eq a => a -> MonoidMap k a -> Bool)
-> (forall a. Ord a => MonoidMap k a -> a)
-> (forall a. Ord a => MonoidMap k a -> a)
-> (forall a. Num a => MonoidMap k a -> a)
-> (forall a. Num a => MonoidMap k a -> a)
-> Foldable (MonoidMap k)
forall a. Eq a => a -> MonoidMap k a -> Bool
forall a. Num a => MonoidMap k a -> a
forall a. Ord a => MonoidMap k a -> a
forall m. Monoid m => MonoidMap k m -> m
forall a. MonoidMap k a -> Bool
forall a. MonoidMap k a -> Int
forall a. MonoidMap k a -> [a]
forall a. (a -> a -> a) -> MonoidMap k a -> a
forall k a. Eq a => a -> MonoidMap k a -> Bool
forall k a. Num a => MonoidMap k a -> a
forall k a. Ord a => MonoidMap k a -> a
forall m a. Monoid m => (a -> m) -> MonoidMap k a -> m
forall k m. Monoid m => MonoidMap k m -> m
forall k a. MonoidMap k a -> Bool
forall k a. MonoidMap k a -> Int
forall k a. MonoidMap k a -> [a]
forall b a. (b -> a -> b) -> b -> MonoidMap k a -> b
forall a b. (a -> b -> b) -> b -> MonoidMap k a -> b
forall k a. (a -> a -> a) -> MonoidMap k a -> a
forall k m a. Monoid m => (a -> m) -> MonoidMap k a -> m
forall k b a. (b -> a -> b) -> b -> MonoidMap k a -> b
forall k a b. (a -> b -> b) -> b -> MonoidMap k a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall k m. Monoid m => MonoidMap k m -> m
fold :: forall m. Monoid m => MonoidMap k m -> m
$cfoldMap :: forall k m a. Monoid m => (a -> m) -> MonoidMap k a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> MonoidMap k a -> m
$cfoldMap' :: forall k m a. Monoid m => (a -> m) -> MonoidMap k a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> MonoidMap k a -> m
$cfoldr :: forall k a b. (a -> b -> b) -> b -> MonoidMap k a -> b
foldr :: forall a b. (a -> b -> b) -> b -> MonoidMap k a -> b
$cfoldr' :: forall k a b. (a -> b -> b) -> b -> MonoidMap k a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> MonoidMap k a -> b
$cfoldl :: forall k b a. (b -> a -> b) -> b -> MonoidMap k a -> b
foldl :: forall b a. (b -> a -> b) -> b -> MonoidMap k a -> b
$cfoldl' :: forall k b a. (b -> a -> b) -> b -> MonoidMap k a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> MonoidMap k a -> b
$cfoldr1 :: forall k a. (a -> a -> a) -> MonoidMap k a -> a
foldr1 :: forall a. (a -> a -> a) -> MonoidMap k a -> a
$cfoldl1 :: forall k a. (a -> a -> a) -> MonoidMap k a -> a
foldl1 :: forall a. (a -> a -> a) -> MonoidMap k a -> a
$ctoList :: forall k a. MonoidMap k a -> [a]
toList :: forall a. MonoidMap k a -> [a]
$cnull :: forall k a. MonoidMap k a -> Bool
null :: forall a. MonoidMap k a -> Bool
$clength :: forall k a. MonoidMap k a -> Int
length :: forall a. MonoidMap k a -> Int
$celem :: forall k a. Eq a => a -> MonoidMap k a -> Bool
elem :: forall a. Eq a => a -> MonoidMap k a -> Bool
$cmaximum :: forall k a. Ord a => MonoidMap k a -> a
maximum :: forall a. Ord a => MonoidMap k a -> a
$cminimum :: forall k a. Ord a => MonoidMap k a -> a
minimum :: forall a. Ord a => MonoidMap k a -> a
$csum :: forall k a. Num a => MonoidMap k a -> a
sum :: forall a. Num a => MonoidMap k a -> a
$cproduct :: forall k a. Num a => MonoidMap k a -> a
product :: forall a. Num a => MonoidMap k a -> a
Foldable)
via Map k
deriving ((forall k. Eq k => Eq1 (MonoidMap k)) =>
(forall a b c d.
(a -> b -> Bool)
-> (c -> d -> Bool) -> MonoidMap a c -> MonoidMap b d -> Bool)
-> Eq2 MonoidMap
forall k. Eq k => Eq1 (MonoidMap k)
forall a b c d.
(a -> b -> Bool)
-> (c -> d -> Bool) -> MonoidMap a c -> MonoidMap b d -> Bool
forall (f :: * -> * -> *).
(forall a. Eq a => Eq1 (f a)) =>
(forall a b c d.
(a -> b -> Bool) -> (c -> d -> Bool) -> f a c -> f b d -> Bool)
-> Eq2 f
$cliftEq2 :: forall a b c d.
(a -> b -> Bool)
-> (c -> d -> Bool) -> MonoidMap a c -> MonoidMap b d -> Bool
liftEq2 :: forall a b c d.
(a -> b -> Bool)
-> (c -> d -> Bool) -> MonoidMap a c -> MonoidMap b d -> Bool
Eq2, (forall k. Show k => Show1 (MonoidMap k)) =>
(forall a b.
(Int -> a -> ShowS)
-> ([a] -> ShowS)
-> (Int -> b -> ShowS)
-> ([b] -> ShowS)
-> Int
-> MonoidMap a b
-> ShowS)
-> (forall a b.
(Int -> a -> ShowS)
-> ([a] -> ShowS)
-> (Int -> b -> ShowS)
-> ([b] -> ShowS)
-> [MonoidMap a b]
-> ShowS)
-> Show2 MonoidMap
forall k. Show k => Show1 (MonoidMap k)
forall a b.
(Int -> a -> ShowS)
-> ([a] -> ShowS)
-> (Int -> b -> ShowS)
-> ([b] -> ShowS)
-> Int
-> MonoidMap a b
-> ShowS
forall a b.
(Int -> a -> ShowS)
-> ([a] -> ShowS)
-> (Int -> b -> ShowS)
-> ([b] -> ShowS)
-> [MonoidMap a b]
-> ShowS
forall (f :: * -> * -> *).
(forall a. Show a => Show1 (f a)) =>
(forall a b.
(Int -> a -> ShowS)
-> ([a] -> ShowS)
-> (Int -> b -> ShowS)
-> ([b] -> ShowS)
-> Int
-> f a b
-> ShowS)
-> (forall a b.
(Int -> a -> ShowS)
-> ([a] -> ShowS)
-> (Int -> b -> ShowS)
-> ([b] -> ShowS)
-> [f a b]
-> ShowS)
-> Show2 f
$cliftShowsPrec2 :: forall a b.
(Int -> a -> ShowS)
-> ([a] -> ShowS)
-> (Int -> b -> ShowS)
-> ([b] -> ShowS)
-> Int
-> MonoidMap a b
-> ShowS
liftShowsPrec2 :: forall a b.
(Int -> a -> ShowS)
-> ([a] -> ShowS)
-> (Int -> b -> ShowS)
-> ([b] -> ShowS)
-> Int
-> MonoidMap a b
-> ShowS
$cliftShowList2 :: forall a b.
(Int -> a -> ShowS)
-> ([a] -> ShowS)
-> (Int -> b -> ShowS)
-> ([b] -> ShowS)
-> [MonoidMap a b]
-> ShowS
liftShowList2 :: forall a b.
(Int -> a -> ShowS)
-> ([a] -> ShowS)
-> (Int -> b -> ShowS)
-> ([b] -> ShowS)
-> [MonoidMap a b]
-> ShowS
Show2, (forall m. Monoid m => MonoidMap m m -> m)
-> (forall m a b.
Monoid m =>
(a -> m) -> (b -> m) -> MonoidMap a b -> m)
-> (forall a c b.
(a -> c -> c) -> (b -> c -> c) -> c -> MonoidMap a b -> c)
-> (forall c a b.
(c -> a -> c) -> (c -> b -> c) -> c -> MonoidMap a b -> c)
-> Bifoldable MonoidMap
forall m. Monoid m => MonoidMap m m -> m
forall m a b.
Monoid m =>
(a -> m) -> (b -> m) -> MonoidMap a b -> m
forall c a b.
(c -> a -> c) -> (c -> b -> c) -> c -> MonoidMap a b -> c
forall a c b.
(a -> c -> c) -> (b -> c -> c) -> c -> MonoidMap a b -> c
forall (p :: * -> * -> *).
(forall m. Monoid m => p m m -> m)
-> (forall m a b. Monoid m => (a -> m) -> (b -> m) -> p a b -> m)
-> (forall a c b.
(a -> c -> c) -> (b -> c -> c) -> c -> p a b -> c)
-> (forall c a b.
(c -> a -> c) -> (c -> b -> c) -> c -> p a b -> c)
-> Bifoldable p
$cbifold :: forall m. Monoid m => MonoidMap m m -> m
bifold :: forall m. Monoid m => MonoidMap m m -> m
$cbifoldMap :: forall m a b.
Monoid m =>
(a -> m) -> (b -> m) -> MonoidMap a b -> m
bifoldMap :: forall m a b.
Monoid m =>
(a -> m) -> (b -> m) -> MonoidMap a b -> m
$cbifoldr :: forall a c b.
(a -> c -> c) -> (b -> c -> c) -> c -> MonoidMap a b -> c
bifoldr :: forall a c b.
(a -> c -> c) -> (b -> c -> c) -> c -> MonoidMap a b -> c
$cbifoldl :: forall c a b.
(c -> a -> c) -> (c -> b -> c) -> c -> MonoidMap a b -> c
bifoldl :: forall c a b.
(c -> a -> c) -> (c -> b -> c) -> c -> MonoidMap a b -> c
Bifoldable)
via Map
newtype NonNull v = UnsafeNonNull {forall v. NonNull v -> v
getNonNull :: v}
maybeNonNull :: MonoidNull v => v -> Maybe (NonNull v)
maybeNonNull :: forall v. MonoidNull v => v -> Maybe (NonNull v)
maybeNonNull !v
v
| v -> Bool
forall m. MonoidNull m => m -> Bool
C.null v
v = Maybe (NonNull v)
forall a. Maybe a
Nothing
| Bool
otherwise = NonNull v -> Maybe (NonNull v)
forall a. a -> Maybe a
Just (v -> NonNull v
forall v. v -> NonNull v
UnsafeNonNull v
v)
{-# INLINE maybeNonNull #-}
applyNonNull :: (v -> a) -> (NonNull v -> a)
applyNonNull :: forall v a. (v -> a) -> NonNull v -> a
applyNonNull = (v -> a) -> NonNull v -> a
forall a b. Coercible a b => a -> b
coerce
{-# INLINE applyNonNull #-}
applyNonNull2 :: (v1 -> v2 -> a) -> (NonNull v1 -> NonNull v2 -> a)
applyNonNull2 :: forall v1 v2 a. (v1 -> v2 -> a) -> NonNull v1 -> NonNull v2 -> a
applyNonNull2 = (v1 -> v2 -> a) -> NonNull v1 -> NonNull v2 -> a
forall a b. Coercible a b => a -> b
coerce
{-# INLINE applyNonNull2 #-}
instance (Ord k, MonoidNull v) =>
IsList (MonoidMap k v)
where
type Item (MonoidMap k v) = (k, v)
fromList :: [Item (MonoidMap k v)] -> MonoidMap k v
fromList = [(k, v)] -> MonoidMap k v
[Item (MonoidMap k v)] -> MonoidMap k v
forall k v. (Ord k, MonoidNull v) => [(k, v)] -> MonoidMap k v
fromList
toList :: MonoidMap k v -> [Item (MonoidMap k v)]
toList = MonoidMap k v -> [(k, v)]
MonoidMap k v -> [Item (MonoidMap k v)]
forall k v. MonoidMap k v -> [(k, v)]
toList
instance (Ord k, Read k, MonoidNull v, Read v) =>
Read (MonoidMap k v)
where
readPrec :: ReadPrec (MonoidMap k v)
readPrec = Map k v -> MonoidMap k v
forall v k. MonoidNull v => Map k v -> MonoidMap k v
fromMap (Map k v -> MonoidMap k v)
-> ReadPrec (Map k v) -> ReadPrec (MonoidMap k v)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadPrec (Map k v)
forall a. Read a => ReadPrec a
readPrec
instance (Ord k, MonoidNull v) =>
Semigroup (MonoidMap k v)
where
<> :: MonoidMap k v -> MonoidMap k v -> MonoidMap k v
(<>) = MonoidMap k v -> MonoidMap k v -> MonoidMap k v
forall k v.
(Ord k, MonoidNull v) =>
MonoidMap k v -> MonoidMap k v -> MonoidMap k v
append
stimes :: forall b. Integral b => b -> MonoidMap k v -> MonoidMap k v
stimes b
0 = MonoidMap k v -> MonoidMap k v -> MonoidMap k v
forall a b. a -> b -> a
const MonoidMap k v
forall a. Monoid a => a
mempty
stimes b
1 = MonoidMap k v -> MonoidMap k v
forall a. a -> a
id
stimes b
n = (v -> v) -> MonoidMap k v -> MonoidMap k v
forall v2 v1 k.
MonoidNull v2 =>
(v1 -> v2) -> MonoidMap k v1 -> MonoidMap k v2
map (b -> v -> v
forall b. Integral b => b -> v -> v
forall a b. (Semigroup a, Integral b) => b -> a -> a
stimes b
n)
instance (Ord k, MonoidNull v, Commutative v) =>
Commutative (MonoidMap k v)
instance (Ord k, MonoidNull v, LeftReductive v) =>
LeftReductive (MonoidMap k v)
where
isPrefixOf :: MonoidMap k v -> MonoidMap k v -> Bool
isPrefixOf = MonoidMap k v -> MonoidMap k v -> Bool
forall k v.
(Ord k, Monoid v, LeftReductive v) =>
MonoidMap k v -> MonoidMap k v -> Bool
isPrefixOf
stripPrefix :: MonoidMap k v -> MonoidMap k v -> Maybe (MonoidMap k v)
stripPrefix = MonoidMap k v -> MonoidMap k v -> Maybe (MonoidMap k v)
forall k v.
(Ord k, MonoidNull v, LeftReductive v) =>
MonoidMap k v -> MonoidMap k v -> Maybe (MonoidMap k v)
stripPrefix
instance (Ord k, MonoidNull v, RightReductive v) =>
RightReductive (MonoidMap k v)
where
isSuffixOf :: MonoidMap k v -> MonoidMap k v -> Bool
isSuffixOf = MonoidMap k v -> MonoidMap k v -> Bool
forall k v.
(Ord k, Monoid v, RightReductive v) =>
MonoidMap k v -> MonoidMap k v -> Bool
isSuffixOf
stripSuffix :: MonoidMap k v -> MonoidMap k v -> Maybe (MonoidMap k v)
stripSuffix = MonoidMap k v -> MonoidMap k v -> Maybe (MonoidMap k v)
forall k v.
(Ord k, MonoidNull v, RightReductive v) =>
MonoidMap k v -> MonoidMap k v -> Maybe (MonoidMap k v)
stripSuffix
instance (Ord k, MonoidNull v, Reductive v) =>
Reductive (MonoidMap k v)
where
</> :: MonoidMap k v -> MonoidMap k v -> Maybe (MonoidMap k v)
(</>) = MonoidMap k v -> MonoidMap k v -> Maybe (MonoidMap k v)
forall k v.
(Ord k, MonoidNull v, Reductive v) =>
MonoidMap k v -> MonoidMap k v -> Maybe (MonoidMap k v)
minusMaybe
instance (Ord k, MonoidNull v, LeftCancellative v) =>
LeftCancellative (MonoidMap k v)
instance (Ord k, MonoidNull v, RightCancellative v) =>
RightCancellative (MonoidMap k v)
instance (Ord k, MonoidNull v, Cancellative v) =>
Cancellative (MonoidMap k v)
instance (Ord k, MonoidNull v) =>
Monoid (MonoidMap k v)
where
mempty :: MonoidMap k v
mempty = MonoidMap k v
forall k v. MonoidMap k v
empty
instance (Ord k, MonoidNull v) =>
MonoidNull (MonoidMap k v)
where
null :: MonoidMap k v -> Bool
null = MonoidMap k v -> Bool
forall k a. MonoidMap k a -> Bool
null
instance (Ord k, PositiveMonoid v) =>
PositiveMonoid (MonoidMap k v)
instance (Ord k, MonoidNull v, LeftGCDMonoid v) =>
LeftGCDMonoid (MonoidMap k v)
where
commonPrefix :: MonoidMap k v -> MonoidMap k v -> MonoidMap k v
commonPrefix = MonoidMap k v -> MonoidMap k v -> MonoidMap k v
forall k v.
(Ord k, MonoidNull v, LeftGCDMonoid v) =>
MonoidMap k v -> MonoidMap k v -> MonoidMap k v
commonPrefix
instance (Ord k, MonoidNull v, LeftDistributiveGCDMonoid v) =>
LeftDistributiveGCDMonoid (MonoidMap k v)
instance (Ord k, MonoidNull v, RightGCDMonoid v) =>
RightGCDMonoid (MonoidMap k v)
where
commonSuffix :: MonoidMap k v -> MonoidMap k v -> MonoidMap k v
commonSuffix = MonoidMap k v -> MonoidMap k v -> MonoidMap k v
forall k v.
(Ord k, MonoidNull v, RightGCDMonoid v) =>
MonoidMap k v -> MonoidMap k v -> MonoidMap k v
commonSuffix
instance (Ord k, MonoidNull v, RightDistributiveGCDMonoid v) =>
RightDistributiveGCDMonoid (MonoidMap k v)
instance (Ord k, MonoidNull v, OverlappingGCDMonoid v) =>
OverlappingGCDMonoid (MonoidMap k v)
where
overlap :: MonoidMap k v -> MonoidMap k v -> MonoidMap k v
overlap = MonoidMap k v -> MonoidMap k v -> MonoidMap k v
forall k v.
(Ord k, MonoidNull v, OverlappingGCDMonoid v) =>
MonoidMap k v -> MonoidMap k v -> MonoidMap k v
overlap
stripPrefixOverlap :: MonoidMap k v -> MonoidMap k v -> MonoidMap k v
stripPrefixOverlap = MonoidMap k v -> MonoidMap k v -> MonoidMap k v
forall k v.
(Ord k, MonoidNull v, OverlappingGCDMonoid v) =>
MonoidMap k v -> MonoidMap k v -> MonoidMap k v
stripPrefixOverlap
stripSuffixOverlap :: MonoidMap k v -> MonoidMap k v -> MonoidMap k v
stripSuffixOverlap = MonoidMap k v -> MonoidMap k v -> MonoidMap k v
forall k v.
(Ord k, MonoidNull v, OverlappingGCDMonoid v) =>
MonoidMap k v -> MonoidMap k v -> MonoidMap k v
stripSuffixOverlap
stripOverlap :: MonoidMap k v
-> MonoidMap k v -> (MonoidMap k v, MonoidMap k v, MonoidMap k v)
stripOverlap = MonoidMap k v
-> MonoidMap k v -> (MonoidMap k v, MonoidMap k v, MonoidMap k v)
forall k v.
(Ord k, MonoidNull v, OverlappingGCDMonoid v) =>
MonoidMap k v
-> MonoidMap k v -> (MonoidMap k v, MonoidMap k v, MonoidMap k v)
stripOverlap
instance (Ord k, MonoidNull v, GCDMonoid v) =>
GCDMonoid (MonoidMap k v)
where
gcd :: MonoidMap k v -> MonoidMap k v -> MonoidMap k v
gcd = MonoidMap k v -> MonoidMap k v -> MonoidMap k v
forall k v.
(Ord k, MonoidNull v, GCDMonoid v) =>
MonoidMap k v -> MonoidMap k v -> MonoidMap k v
intersection
instance (Ord k, MonoidNull v, DistributiveGCDMonoid v) =>
DistributiveGCDMonoid (MonoidMap k v)
instance (Ord k, MonoidNull v, LCMMonoid v) =>
LCMMonoid (MonoidMap k v)
where
lcm :: MonoidMap k v -> MonoidMap k v -> MonoidMap k v
lcm = MonoidMap k v -> MonoidMap k v -> MonoidMap k v
forall k v.
(Ord k, MonoidNull v, LCMMonoid v) =>
MonoidMap k v -> MonoidMap k v -> MonoidMap k v
union
instance (Ord k, MonoidNull v, DistributiveLCMMonoid v) =>
DistributiveLCMMonoid (MonoidMap k v)
instance (Ord k, MonoidNull v, Monus v) =>
Monus (MonoidMap k v)
where
<\> :: MonoidMap k v -> MonoidMap k v -> MonoidMap k v
(<\>) = MonoidMap k v -> MonoidMap k v -> MonoidMap k v
forall k v.
(Ord k, MonoidNull v, Monus v) =>
MonoidMap k v -> MonoidMap k v -> MonoidMap k v
monus
instance (Ord k, MonoidNull v, Group v) =>
Group (MonoidMap k v)
where
invert :: MonoidMap k v -> MonoidMap k v
invert = MonoidMap k v -> MonoidMap k v
forall v k.
(MonoidNull v, Group v) =>
MonoidMap k v -> MonoidMap k v
invert
~~ :: MonoidMap k v -> MonoidMap k v -> MonoidMap k v
(~~) = MonoidMap k v -> MonoidMap k v -> MonoidMap k v
forall k v.
(Ord k, MonoidNull v, Group v) =>
MonoidMap k v -> MonoidMap k v -> MonoidMap k v
minus
pow :: forall x. Integral x => MonoidMap k v -> x -> MonoidMap k v
pow = MonoidMap k v -> x -> MonoidMap k v
forall i v k.
(Integral i, MonoidNull v, Group v) =>
MonoidMap k v -> i -> MonoidMap k v
power
instance (Ord k, MonoidNull v, Abelian v) =>
Abelian (MonoidMap k v)
empty :: MonoidMap k v
empty :: forall k v. MonoidMap k v
empty = Map k (NonNull v) -> MonoidMap k v
forall k v. Map k (NonNull v) -> MonoidMap k v
MonoidMap Map k (NonNull v)
forall k a. Map k a
Map.empty
fromList :: (Ord k, MonoidNull v) => [(k, v)] -> MonoidMap k v
fromList :: forall k v. (Ord k, MonoidNull v) => [(k, v)] -> MonoidMap k v
fromList = (v -> v -> v) -> [(k, v)] -> MonoidMap k v
forall k v.
(Ord k, MonoidNull v) =>
(v -> v -> v) -> [(k, v)] -> MonoidMap k v
fromListWith v -> v -> v
forall a. Semigroup a => a -> a -> a
(<>)
fromListWith
:: (Ord k, MonoidNull v)
=> (v -> v -> v)
-> [(k, v)]
-> MonoidMap k v
fromListWith :: forall k v.
(Ord k, MonoidNull v) =>
(v -> v -> v) -> [(k, v)] -> MonoidMap k v
fromListWith v -> v -> v
f =
Map k v -> MonoidMap k v
forall v k. MonoidNull v => Map k v -> MonoidMap k v
fromMap (Map k v -> MonoidMap k v)
-> ([(k, v)] -> Map k v) -> [(k, v)] -> MonoidMap k v
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (v -> v -> v) -> [(k, v)] -> Map k v
forall k a. Ord k => (a -> a -> a) -> [(k, a)] -> Map k a
Map.fromListWith ((v -> v -> v) -> v -> v -> v
forall a b c. (a -> b -> c) -> b -> a -> c
flip v -> v -> v
f)
fromMap :: MonoidNull v => Map k v -> MonoidMap k v
fromMap :: forall v k. MonoidNull v => Map k v -> MonoidMap k v
fromMap = Map k (NonNull v) -> MonoidMap k v
forall k v. Map k (NonNull v) -> MonoidMap k v
MonoidMap (Map k (NonNull v) -> MonoidMap k v)
-> (Map k v -> Map k (NonNull v)) -> Map k v -> MonoidMap k v
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (v -> Maybe (NonNull v)) -> Map k v -> Map k (NonNull v)
forall a b k. (a -> Maybe b) -> Map k a -> Map k b
Map.mapMaybe v -> Maybe (NonNull v)
forall v. MonoidNull v => v -> Maybe (NonNull v)
maybeNonNull
singleton :: (Ord k, MonoidNull v) => k -> v -> MonoidMap k v
singleton :: forall k v. (Ord k, MonoidNull v) => k -> v -> MonoidMap k v
singleton k
k v
v = k -> v -> MonoidMap k v -> MonoidMap k v
forall k v.
(Ord k, MonoidNull v) =>
k -> v -> MonoidMap k v -> MonoidMap k v
set k
k v
v MonoidMap k v
forall a. Monoid a => a
mempty
toList :: MonoidMap k v -> [(k, v)]
toList :: forall k v. MonoidMap k v -> [(k, v)]
toList = Map k v -> [(k, v)]
forall k a. Map k a -> [(k, a)]
Map.toAscList (Map k v -> [(k, v)])
-> (MonoidMap k v -> Map k v) -> MonoidMap k v -> [(k, v)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MonoidMap k v -> Map k v
forall k v. MonoidMap k v -> Map k v
toMap
toMap :: forall k v. MonoidMap k v -> Map k v
toMap :: forall k v. MonoidMap k v -> Map k v
toMap = MonoidMap k v -> Map k v
forall a b. Coercible a b => a -> b
coerce
get :: (Ord k, Monoid v) => k -> MonoidMap k v -> v
get :: forall k v. (Ord k, Monoid v) => k -> MonoidMap k v -> v
get k
k MonoidMap k v
m = v -> Maybe v -> v
forall a. a -> Maybe a -> a
fromMaybe v
forall a. Monoid a => a
mempty (Maybe v -> v) -> Maybe v -> v
forall a b. (a -> b) -> a -> b
$ k -> Map k v -> Maybe v
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup k
k (Map k v -> Maybe v) -> Map k v -> Maybe v
forall a b. (a -> b) -> a -> b
$ MonoidMap k v -> Map k v
forall k v. MonoidMap k v -> Map k v
toMap MonoidMap k v
m
set :: (Ord k, MonoidNull v) => k -> v -> MonoidMap k v -> MonoidMap k v
set :: forall k v.
(Ord k, MonoidNull v) =>
k -> v -> MonoidMap k v -> MonoidMap k v
set k
k v
v (MonoidMap Map k (NonNull v)
m) = Map k (NonNull v) -> MonoidMap k v
forall k v. Map k (NonNull v) -> MonoidMap k v
MonoidMap (Map k (NonNull v) -> MonoidMap k v)
-> Map k (NonNull v) -> MonoidMap k v
forall a b. (a -> b) -> a -> b
$ case v -> Maybe (NonNull v)
forall v. MonoidNull v => v -> Maybe (NonNull v)
maybeNonNull v
v of
Just NonNull v
v0 -> k -> NonNull v -> Map k (NonNull v) -> Map k (NonNull v)
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert k
k NonNull v
v0 Map k (NonNull v)
m
Maybe (NonNull v)
Nothing -> k -> Map k (NonNull v) -> Map k (NonNull v)
forall k a. Ord k => k -> Map k a -> Map k a
Map.delete k
k Map k (NonNull v)
m
adjust
:: (Ord k, MonoidNull v)
=> (v -> v)
-> k
-> MonoidMap k v
-> MonoidMap k v
adjust :: forall k v.
(Ord k, MonoidNull v) =>
(v -> v) -> k -> MonoidMap k v -> MonoidMap k v
adjust v -> v
f k
k (MonoidMap Map k (NonNull v)
m) = Map k (NonNull v) -> MonoidMap k v
forall k v. Map k (NonNull v) -> MonoidMap k v
MonoidMap (Map k (NonNull v) -> MonoidMap k v)
-> Map k (NonNull v) -> MonoidMap k v
forall a b. (a -> b) -> a -> b
$
(Maybe (NonNull v) -> Maybe (NonNull v))
-> k -> Map k (NonNull v) -> Map k (NonNull v)
forall k a.
Ord k =>
(Maybe a -> Maybe a) -> k -> Map k a -> Map k a
Map.alter (v -> Maybe (NonNull v)
forall v. MonoidNull v => v -> Maybe (NonNull v)
maybeNonNull (v -> Maybe (NonNull v))
-> (Maybe (NonNull v) -> v)
-> Maybe (NonNull v)
-> Maybe (NonNull v)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. v -> (NonNull v -> v) -> Maybe (NonNull v) -> v
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (v -> v
f v
forall a. Monoid a => a
mempty) ((v -> v) -> NonNull v -> v
forall v a. (v -> a) -> NonNull v -> a
applyNonNull v -> v
f)) k
k Map k (NonNull v)
m
nullify :: Ord k => k -> MonoidMap k v -> MonoidMap k v
nullify :: forall k v. Ord k => k -> MonoidMap k v -> MonoidMap k v
nullify k
k (MonoidMap Map k (NonNull v)
m) = Map k (NonNull v) -> MonoidMap k v
forall k v. Map k (NonNull v) -> MonoidMap k v
MonoidMap (Map k (NonNull v) -> MonoidMap k v)
-> Map k (NonNull v) -> MonoidMap k v
forall a b. (a -> b) -> a -> b
$ k -> Map k (NonNull v) -> Map k (NonNull v)
forall k a. Ord k => k -> Map k a -> Map k a
Map.delete k
k Map k (NonNull v)
m
null :: MonoidMap k v -> Bool
null :: forall k a. MonoidMap k a -> Bool
null = Map k v -> Bool
forall k a. Map k a -> Bool
Map.null (Map k v -> Bool)
-> (MonoidMap k v -> Map k v) -> MonoidMap k v -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MonoidMap k v -> Map k v
forall k v. MonoidMap k v -> Map k v
toMap
nullKey :: Ord k => k -> MonoidMap k v -> Bool
nullKey :: forall k v. Ord k => k -> MonoidMap k v -> Bool
nullKey k
k = k -> Map k v -> Bool
forall k a. Ord k => k -> Map k a -> Bool
Map.notMember k
k (Map k v -> Bool)
-> (MonoidMap k v -> Map k v) -> MonoidMap k v -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MonoidMap k v -> Map k v
forall k v. MonoidMap k v -> Map k v
toMap
nonNull :: MonoidMap k v -> Bool
nonNull :: forall k a. MonoidMap k a -> Bool
nonNull = Bool -> Bool
not (Bool -> Bool) -> (MonoidMap k v -> Bool) -> MonoidMap k v -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MonoidMap k v -> Bool
forall k a. MonoidMap k a -> Bool
null
nonNullCount :: MonoidMap k v -> Int
nonNullCount :: forall k a. MonoidMap k a -> Int
nonNullCount = Map k v -> Int
forall k a. Map k a -> Int
Map.size (Map k v -> Int)
-> (MonoidMap k v -> Map k v) -> MonoidMap k v -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MonoidMap k v -> Map k v
forall k v. MonoidMap k v -> Map k v
toMap
nonNullKey :: Ord k => k -> MonoidMap k v -> Bool
nonNullKey :: forall k v. Ord k => k -> MonoidMap k v -> Bool
nonNullKey k
k = k -> Map k v -> Bool
forall k a. Ord k => k -> Map k a -> Bool
Map.member k
k (Map k v -> Bool)
-> (MonoidMap k v -> Map k v) -> MonoidMap k v -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MonoidMap k v -> Map k v
forall k v. MonoidMap k v -> Map k v
toMap
nonNullKeys :: MonoidMap k v -> Set k
nonNullKeys :: forall k v. MonoidMap k v -> Set k
nonNullKeys = Map k v -> Set k
forall k a. Map k a -> Set k
Map.keysSet (Map k v -> Set k)
-> (MonoidMap k v -> Map k v) -> MonoidMap k v -> Set k
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MonoidMap k v -> Map k v
forall k v. MonoidMap k v -> Map k v
toMap
take :: Int -> MonoidMap k v -> MonoidMap k v
take :: forall k v. Int -> MonoidMap k v -> MonoidMap k v
take Int
i (MonoidMap Map k (NonNull v)
m) = Map k (NonNull v) -> MonoidMap k v
forall k v. Map k (NonNull v) -> MonoidMap k v
MonoidMap (Int -> Map k (NonNull v) -> Map k (NonNull v)
forall k a. Int -> Map k a -> Map k a
Map.take Int
i Map k (NonNull v)
m)
drop :: Int -> MonoidMap k v -> MonoidMap k v
drop :: forall k v. Int -> MonoidMap k v -> MonoidMap k v
drop Int
i (MonoidMap Map k (NonNull v)
m) = Map k (NonNull v) -> MonoidMap k v
forall k v. Map k (NonNull v) -> MonoidMap k v
MonoidMap (Int -> Map k (NonNull v) -> Map k (NonNull v)
forall k a. Int -> Map k a -> Map k a
Map.drop Int
i Map k (NonNull v)
m)
splitAt :: Int -> MonoidMap k a -> (MonoidMap k a, MonoidMap k a)
splitAt :: forall k a. Int -> MonoidMap k a -> (MonoidMap k a, MonoidMap k a)
splitAt Int
i MonoidMap k a
m = (Int -> MonoidMap k a -> MonoidMap k a
forall k v. Int -> MonoidMap k v -> MonoidMap k v
take Int
i MonoidMap k a
m, Int -> MonoidMap k a -> MonoidMap k a
forall k v. Int -> MonoidMap k v -> MonoidMap k v
drop Int
i MonoidMap k a
m)
filter :: (v -> Bool) -> MonoidMap k v -> MonoidMap k v
filter :: forall v k. (v -> Bool) -> MonoidMap k v -> MonoidMap k v
filter v -> Bool
f (MonoidMap Map k (NonNull v)
m) = Map k (NonNull v) -> MonoidMap k v
forall k v. Map k (NonNull v) -> MonoidMap k v
MonoidMap (Map k (NonNull v) -> MonoidMap k v)
-> Map k (NonNull v) -> MonoidMap k v
forall a b. (a -> b) -> a -> b
$ (NonNull v -> Bool) -> Map k (NonNull v) -> Map k (NonNull v)
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter ((v -> Bool) -> NonNull v -> Bool
forall v a. (v -> a) -> NonNull v -> a
applyNonNull v -> Bool
f) Map k (NonNull v)
m
filterKeys :: (k -> Bool) -> MonoidMap k v -> MonoidMap k v
filterKeys :: forall k v. (k -> Bool) -> MonoidMap k v -> MonoidMap k v
filterKeys k -> Bool
f (MonoidMap Map k (NonNull v)
m) = Map k (NonNull v) -> MonoidMap k v
forall k v. Map k (NonNull v) -> MonoidMap k v
MonoidMap (Map k (NonNull v) -> MonoidMap k v)
-> Map k (NonNull v) -> MonoidMap k v
forall a b. (a -> b) -> a -> b
$ (k -> NonNull v -> Bool) -> Map k (NonNull v) -> Map k (NonNull v)
forall k a. (k -> a -> Bool) -> Map k a -> Map k a
Map.filterWithKey (\k
k NonNull v
_ -> k -> Bool
f k
k) Map k (NonNull v)
m
filterWithKey :: (k -> v -> Bool) -> MonoidMap k v -> MonoidMap k v
filterWithKey :: forall k v. (k -> v -> Bool) -> MonoidMap k v -> MonoidMap k v
filterWithKey k -> v -> Bool
f (MonoidMap Map k (NonNull v)
m) =
Map k (NonNull v) -> MonoidMap k v
forall k v. Map k (NonNull v) -> MonoidMap k v
MonoidMap (Map k (NonNull v) -> MonoidMap k v)
-> Map k (NonNull v) -> MonoidMap k v
forall a b. (a -> b) -> a -> b
$ (k -> NonNull v -> Bool) -> Map k (NonNull v) -> Map k (NonNull v)
forall k a. (k -> a -> Bool) -> Map k a -> Map k a
Map.filterWithKey ((v -> Bool) -> NonNull v -> Bool
forall v a. (v -> a) -> NonNull v -> a
applyNonNull ((v -> Bool) -> NonNull v -> Bool)
-> (k -> v -> Bool) -> k -> NonNull v -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. k -> v -> Bool
f) Map k (NonNull v)
m
partition :: (v -> Bool) -> MonoidMap k v -> (MonoidMap k v, MonoidMap k v)
partition :: forall v k.
(v -> Bool) -> MonoidMap k v -> (MonoidMap k v, MonoidMap k v)
partition v -> Bool
f (MonoidMap Map k (NonNull v)
m) =
(Map k (NonNull v) -> MonoidMap k v)
-> (Map k (NonNull v) -> MonoidMap k v)
-> (Map k (NonNull v), Map k (NonNull v))
-> (MonoidMap k v, MonoidMap k v)
forall a b c d. (a -> b) -> (c -> d) -> (a, c) -> (b, d)
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
B.bimap Map k (NonNull v) -> MonoidMap k v
forall k v. Map k (NonNull v) -> MonoidMap k v
MonoidMap Map k (NonNull v) -> MonoidMap k v
forall k v. Map k (NonNull v) -> MonoidMap k v
MonoidMap ((Map k (NonNull v), Map k (NonNull v))
-> (MonoidMap k v, MonoidMap k v))
-> (Map k (NonNull v), Map k (NonNull v))
-> (MonoidMap k v, MonoidMap k v)
forall a b. (a -> b) -> a -> b
$ (NonNull v -> Bool)
-> Map k (NonNull v) -> (Map k (NonNull v), Map k (NonNull v))
forall a k. (a -> Bool) -> Map k a -> (Map k a, Map k a)
Map.partition ((v -> Bool) -> NonNull v -> Bool
forall v a. (v -> a) -> NonNull v -> a
applyNonNull v -> Bool
f) Map k (NonNull v)
m
partitionKeys
:: (k -> Bool) -> MonoidMap k v -> (MonoidMap k v, MonoidMap k v)
partitionKeys :: forall k v.
(k -> Bool) -> MonoidMap k v -> (MonoidMap k v, MonoidMap k v)
partitionKeys k -> Bool
f (MonoidMap Map k (NonNull v)
m) =
(Map k (NonNull v) -> MonoidMap k v)
-> (Map k (NonNull v) -> MonoidMap k v)
-> (Map k (NonNull v), Map k (NonNull v))
-> (MonoidMap k v, MonoidMap k v)
forall a b c d. (a -> b) -> (c -> d) -> (a, c) -> (b, d)
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
B.bimap Map k (NonNull v) -> MonoidMap k v
forall k v. Map k (NonNull v) -> MonoidMap k v
MonoidMap Map k (NonNull v) -> MonoidMap k v
forall k v. Map k (NonNull v) -> MonoidMap k v
MonoidMap ((Map k (NonNull v), Map k (NonNull v))
-> (MonoidMap k v, MonoidMap k v))
-> (Map k (NonNull v), Map k (NonNull v))
-> (MonoidMap k v, MonoidMap k v)
forall a b. (a -> b) -> a -> b
$ (k -> NonNull v -> Bool)
-> Map k (NonNull v) -> (Map k (NonNull v), Map k (NonNull v))
forall k a. (k -> a -> Bool) -> Map k a -> (Map k a, Map k a)
Map.partitionWithKey (\k
k NonNull v
_ -> k -> Bool
f k
k) Map k (NonNull v)
m
partitionWithKey
:: (k -> v -> Bool) -> MonoidMap k v -> (MonoidMap k v, MonoidMap k v)
partitionWithKey :: forall k v.
(k -> v -> Bool) -> MonoidMap k v -> (MonoidMap k v, MonoidMap k v)
partitionWithKey k -> v -> Bool
f (MonoidMap Map k (NonNull v)
m) =
(Map k (NonNull v) -> MonoidMap k v)
-> (Map k (NonNull v) -> MonoidMap k v)
-> (Map k (NonNull v), Map k (NonNull v))
-> (MonoidMap k v, MonoidMap k v)
forall a b c d. (a -> b) -> (c -> d) -> (a, c) -> (b, d)
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
B.bimap Map k (NonNull v) -> MonoidMap k v
forall k v. Map k (NonNull v) -> MonoidMap k v
MonoidMap Map k (NonNull v) -> MonoidMap k v
forall k v. Map k (NonNull v) -> MonoidMap k v
MonoidMap ((Map k (NonNull v), Map k (NonNull v))
-> (MonoidMap k v, MonoidMap k v))
-> (Map k (NonNull v), Map k (NonNull v))
-> (MonoidMap k v, MonoidMap k v)
forall a b. (a -> b) -> a -> b
$ (k -> NonNull v -> Bool)
-> Map k (NonNull v) -> (Map k (NonNull v), Map k (NonNull v))
forall k a. (k -> a -> Bool) -> Map k a -> (Map k a, Map k a)
Map.partitionWithKey ((v -> Bool) -> NonNull v -> Bool
forall v a. (v -> a) -> NonNull v -> a
applyNonNull ((v -> Bool) -> NonNull v -> Bool)
-> (k -> v -> Bool) -> k -> NonNull v -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. k -> v -> Bool
f) Map k (NonNull v)
m
map
:: MonoidNull v2
=> (v1 -> v2)
-> MonoidMap k v1
-> MonoidMap k v2
map :: forall v2 v1 k.
MonoidNull v2 =>
(v1 -> v2) -> MonoidMap k v1 -> MonoidMap k v2
map v1 -> v2
f (MonoidMap Map k (NonNull v1)
m) =
Map k (NonNull v2) -> MonoidMap k v2
forall k v. Map k (NonNull v) -> MonoidMap k v
MonoidMap (Map k (NonNull v2) -> MonoidMap k v2)
-> Map k (NonNull v2) -> MonoidMap k v2
forall a b. (a -> b) -> a -> b
$ (NonNull v1 -> Maybe (NonNull v2))
-> Map k (NonNull v1) -> Map k (NonNull v2)
forall a b k. (a -> Maybe b) -> Map k a -> Map k b
Map.mapMaybe (v2 -> Maybe (NonNull v2)
forall v. MonoidNull v => v -> Maybe (NonNull v)
maybeNonNull (v2 -> Maybe (NonNull v2))
-> (NonNull v1 -> v2) -> NonNull v1 -> Maybe (NonNull v2)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (v1 -> v2) -> NonNull v1 -> v2
forall v a. (v -> a) -> NonNull v -> a
applyNonNull v1 -> v2
f) Map k (NonNull v1)
m
mapKeys
:: (Ord k2, MonoidNull v)
=> (k1 -> k2)
-> MonoidMap k1 v
-> MonoidMap k2 v
mapKeys :: forall k2 v k1.
(Ord k2, MonoidNull v) =>
(k1 -> k2) -> MonoidMap k1 v -> MonoidMap k2 v
mapKeys = (v -> v -> v) -> (k1 -> k2) -> MonoidMap k1 v -> MonoidMap k2 v
forall k2 v k1.
(Ord k2, MonoidNull v) =>
(v -> v -> v) -> (k1 -> k2) -> MonoidMap k1 v -> MonoidMap k2 v
mapKeysWith v -> v -> v
forall a. Semigroup a => a -> a -> a
(<>)
mapKeysWith
:: (Ord k2, MonoidNull v)
=> (v -> v -> v)
-> (k1 -> k2)
-> MonoidMap k1 v
-> MonoidMap k2 v
mapKeysWith :: forall k2 v k1.
(Ord k2, MonoidNull v) =>
(v -> v -> v) -> (k1 -> k2) -> MonoidMap k1 v -> MonoidMap k2 v
mapKeysWith v -> v -> v
combine k1 -> k2
fk = (v -> v -> v) -> [(k2, v)] -> MonoidMap k2 v
forall k v.
(Ord k, MonoidNull v) =>
(v -> v -> v) -> [(k, v)] -> MonoidMap k v
fromListWith v -> v -> v
combine ([(k2, v)] -> MonoidMap k2 v)
-> (MonoidMap k1 v -> [(k2, v)])
-> MonoidMap k1 v
-> MonoidMap k2 v
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((k1, v) -> (k2, v)) -> [(k1, v)] -> [(k2, v)]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((k1 -> k2) -> (k1, v) -> (k2, v)
forall a b c. (a -> b) -> (a, c) -> (b, c)
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
B.first k1 -> k2
fk) ([(k1, v)] -> [(k2, v)])
-> (MonoidMap k1 v -> [(k1, v)]) -> MonoidMap k1 v -> [(k2, v)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MonoidMap k1 v -> [(k1, v)]
forall k v. MonoidMap k v -> [(k, v)]
toList
foldl :: (r -> v -> r) -> r -> MonoidMap k v -> r
foldl :: forall r v k. (r -> v -> r) -> r -> MonoidMap k v -> r
foldl =
(((r -> v -> r) -> r -> Map k v -> r)
-> (r -> v -> r) -> r -> MonoidMap k v -> r
forall {r} {v} {k}.
((r -> v -> r) -> r -> Map k v -> r)
-> (r -> v -> r) -> r -> MonoidMap k v -> r
forall a b. Coercible a b => a -> b
coerce
:: ((r -> v -> r) -> r -> Map k v -> r)
-> ((r -> v -> r) -> r -> MonoidMap k v -> r)
)
(r -> v -> r) -> r -> Map k v -> r
forall a b k. (a -> b -> a) -> a -> Map k b -> a
Map.foldl
{-# INLINE foldl #-}
foldr :: (v -> r -> r) -> r -> MonoidMap k v -> r
foldr :: forall v r k. (v -> r -> r) -> r -> MonoidMap k v -> r
foldr =
(((v -> r -> r) -> r -> Map k v -> r)
-> (v -> r -> r) -> r -> MonoidMap k v -> r
forall {v} {r} {k}.
((v -> r -> r) -> r -> Map k v -> r)
-> (v -> r -> r) -> r -> MonoidMap k v -> r
forall a b. Coercible a b => a -> b
coerce
:: ((v -> r -> r) -> r -> Map k v -> r)
-> ((v -> r -> r) -> r -> MonoidMap k v -> r)
)
(v -> r -> r) -> r -> Map k v -> r
forall a b k. (a -> b -> b) -> b -> Map k a -> b
Map.foldr
{-# INLINE foldr #-}
foldlWithKey :: (r -> k -> v -> r) -> r -> MonoidMap k v -> r
foldlWithKey :: forall r k v. (r -> k -> v -> r) -> r -> MonoidMap k v -> r
foldlWithKey =
(((r -> k -> v -> r) -> r -> Map k v -> r)
-> (r -> k -> v -> r) -> r -> MonoidMap k v -> r
forall {r} {k} {v}.
((r -> k -> v -> r) -> r -> Map k v -> r)
-> (r -> k -> v -> r) -> r -> MonoidMap k v -> r
forall a b. Coercible a b => a -> b
coerce
:: ((r -> k -> v -> r) -> r -> Map k v -> r)
-> ((r -> k -> v -> r) -> r -> MonoidMap k v -> r)
)
(r -> k -> v -> r) -> r -> Map k v -> r
forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey
{-# INLINE foldlWithKey #-}
foldrWithKey :: (k -> v -> r -> r) -> r -> MonoidMap k v -> r
foldrWithKey :: forall k v r. (k -> v -> r -> r) -> r -> MonoidMap k v -> r
foldrWithKey =
(((k -> v -> r -> r) -> r -> Map k v -> r)
-> (k -> v -> r -> r) -> r -> MonoidMap k v -> r
forall {k} {v} {r}.
((k -> v -> r -> r) -> r -> Map k v -> r)
-> (k -> v -> r -> r) -> r -> MonoidMap k v -> r
forall a b. Coercible a b => a -> b
coerce
:: ((k -> v -> r -> r) -> r -> Map k v -> r)
-> ((k -> v -> r -> r) -> r -> MonoidMap k v -> r)
)
(k -> v -> r -> r) -> r -> Map k v -> r
forall k a b. (k -> a -> b -> b) -> b -> Map k a -> b
Map.foldrWithKey
{-# INLINE foldrWithKey #-}
foldMapWithKey :: Monoid r => (k -> v -> r) -> MonoidMap k v -> r
foldMapWithKey :: forall r k v. Monoid r => (k -> v -> r) -> MonoidMap k v -> r
foldMapWithKey =
(((k -> v -> r) -> Map k v -> r)
-> (k -> v -> r) -> MonoidMap k v -> r
forall {k} {v} {r}.
((k -> v -> r) -> Map k v -> r)
-> (k -> v -> r) -> MonoidMap k v -> r
forall a b. Coercible a b => a -> b
coerce
:: ((k -> v -> r) -> Map k v -> r)
-> ((k -> v -> r) -> MonoidMap k v -> r)
)
(k -> v -> r) -> Map k v -> r
forall m k a. Monoid m => (k -> a -> m) -> Map k a -> m
Map.foldMapWithKey
{-# INLINE foldMapWithKey #-}
foldl' :: (r -> v -> r) -> r -> MonoidMap k v -> r
foldl' :: forall r v k. (r -> v -> r) -> r -> MonoidMap k v -> r
foldl' =
(((r -> v -> r) -> r -> Map k v -> r)
-> (r -> v -> r) -> r -> MonoidMap k v -> r
forall {r} {v} {k}.
((r -> v -> r) -> r -> Map k v -> r)
-> (r -> v -> r) -> r -> MonoidMap k v -> r
forall a b. Coercible a b => a -> b
coerce
:: ((r -> v -> r) -> r -> Map k v -> r)
-> ((r -> v -> r) -> r -> MonoidMap k v -> r)
)
(r -> v -> r) -> r -> Map k v -> r
forall a b k. (a -> b -> a) -> a -> Map k b -> a
Map.foldl'
{-# INLINE foldl' #-}
foldr' :: (v -> r -> r) -> r -> MonoidMap k v -> r
foldr' :: forall v r k. (v -> r -> r) -> r -> MonoidMap k v -> r
foldr' =
(((v -> r -> r) -> r -> Map k v -> r)
-> (v -> r -> r) -> r -> MonoidMap k v -> r
forall {v} {r} {k}.
((v -> r -> r) -> r -> Map k v -> r)
-> (v -> r -> r) -> r -> MonoidMap k v -> r
forall a b. Coercible a b => a -> b
coerce
:: ((v -> r -> r) -> r -> Map k v -> r)
-> ((v -> r -> r) -> r -> MonoidMap k v -> r)
)
(v -> r -> r) -> r -> Map k v -> r
forall a b k. (a -> b -> b) -> b -> Map k a -> b
Map.foldr'
{-# INLINE foldr' #-}
foldlWithKey' :: (r -> k -> v -> r) -> r -> MonoidMap k v -> r
foldlWithKey' :: forall r k v. (r -> k -> v -> r) -> r -> MonoidMap k v -> r
foldlWithKey' =
(((r -> k -> v -> r) -> r -> Map k v -> r)
-> (r -> k -> v -> r) -> r -> MonoidMap k v -> r
forall {r} {k} {v}.
((r -> k -> v -> r) -> r -> Map k v -> r)
-> (r -> k -> v -> r) -> r -> MonoidMap k v -> r
forall a b. Coercible a b => a -> b
coerce
:: ((r -> k -> v -> r) -> r -> Map k v -> r)
-> ((r -> k -> v -> r) -> r -> MonoidMap k v -> r)
)
(r -> k -> v -> r) -> r -> Map k v -> r
forall a k b. (a -> k -> b -> a) -> a -> Map k b -> a
Map.foldlWithKey'
{-# INLINE foldlWithKey' #-}
foldrWithKey' :: (k -> v -> r -> r) -> r -> MonoidMap k v -> r
foldrWithKey' :: forall k v r. (k -> v -> r -> r) -> r -> MonoidMap k v -> r
foldrWithKey' =
(((k -> v -> r -> r) -> r -> Map k v -> r)
-> (k -> v -> r -> r) -> r -> MonoidMap k v -> r
forall {k} {v} {r}.
((k -> v -> r -> r) -> r -> Map k v -> r)
-> (k -> v -> r -> r) -> r -> MonoidMap k v -> r
forall a b. Coercible a b => a -> b
coerce
:: ((k -> v -> r -> r) -> r -> Map k v -> r)
-> ((k -> v -> r -> r) -> r -> MonoidMap k v -> r)
)
(k -> v -> r -> r) -> r -> Map k v -> r
forall k a b. (k -> a -> b -> b) -> b -> Map k a -> b
Map.foldrWithKey'
{-# INLINE foldrWithKey' #-}
isSubmapOf
:: (Ord k, Monoid v, Reductive v)
=> MonoidMap k v
-> MonoidMap k v
-> Bool
isSubmapOf :: forall k v.
(Ord k, Monoid v, Reductive v) =>
MonoidMap k v -> MonoidMap k v -> Bool
isSubmapOf = (v -> v -> Bool) -> MonoidMap k v -> MonoidMap k v -> Bool
forall k v1 v2.
(Ord k, Monoid v1, Monoid v2) =>
(v1 -> v2 -> Bool) -> MonoidMap k v1 -> MonoidMap k v2 -> Bool
isSubmapOfBy ((v -> v -> Bool) -> MonoidMap k v -> MonoidMap k v -> Bool)
-> (v -> v -> Bool) -> MonoidMap k v -> MonoidMap k v -> Bool
forall a b. (a -> b) -> a -> b
$ \v
v1 v
v2 -> Maybe v -> Bool
forall a. Maybe a -> Bool
isJust (v
v2 v -> v -> Maybe v
forall m. Reductive m => m -> m -> Maybe m
</> v
v1)
{-# INLINE isSubmapOf #-}
isSubmapOfBy
:: (Ord k, Monoid v1, Monoid v2)
=> (v1 -> v2 -> Bool)
-> MonoidMap k v1
-> MonoidMap k v2
-> Bool
isSubmapOfBy :: forall k v1 v2.
(Ord k, Monoid v1, Monoid v2) =>
(v1 -> v2 -> Bool) -> MonoidMap k v1 -> MonoidMap k v2 -> Bool
isSubmapOfBy v1 -> v2 -> Bool
leq MonoidMap k v1
m1 MonoidMap k v2
m2 =
(k -> Bool) -> Set k -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all
(\k
k -> k -> MonoidMap k v1 -> v1
forall k v. (Ord k, Monoid v) => k -> MonoidMap k v -> v
get k
k MonoidMap k v1
m1 v1 -> v2 -> Bool
`leq` k -> MonoidMap k v2 -> v2
forall k v. (Ord k, Monoid v) => k -> MonoidMap k v -> v
get k
k MonoidMap k v2
m2)
(MonoidMap k v1 -> Set k
forall k v. MonoidMap k v -> Set k
nonNullKeys MonoidMap k v1
m1)
{-# INLINE isSubmapOfBy #-}
disjoint
:: (Ord k, GCDMonoid v, MonoidNull v)
=> MonoidMap k v
-> MonoidMap k v
-> Bool
disjoint :: forall k v.
(Ord k, GCDMonoid v, MonoidNull v) =>
MonoidMap k v -> MonoidMap k v -> Bool
disjoint = (v -> v -> Bool) -> MonoidMap k v -> MonoidMap k v -> Bool
forall k v1 v2.
(Ord k, Monoid v1, Monoid v2) =>
(v1 -> v2 -> Bool) -> MonoidMap k v1 -> MonoidMap k v2 -> Bool
disjointBy (\v
v1 v
v2 -> v -> Bool
forall m. MonoidNull m => m -> Bool
C.null (v -> v -> v
forall m. GCDMonoid m => m -> m -> m
C.gcd v
v1 v
v2))
{-# INLINE disjoint #-}
disjointBy
:: (Ord k, Monoid v1, Monoid v2)
=> (v1 -> v2 -> Bool)
-> MonoidMap k v1
-> MonoidMap k v2
-> Bool
disjointBy :: forall k v1 v2.
(Ord k, Monoid v1, Monoid v2) =>
(v1 -> v2 -> Bool) -> MonoidMap k v1 -> MonoidMap k v2 -> Bool
disjointBy v1 -> v2 -> Bool
f MonoidMap k v1
m1 MonoidMap k v2
m2 =
(k -> Bool) -> Set k -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all
(\k
k -> v1 -> v2 -> Bool
f (k -> MonoidMap k v1 -> v1
forall k v. (Ord k, Monoid v) => k -> MonoidMap k v -> v
get k
k MonoidMap k v1
m1) (k -> MonoidMap k v2 -> v2
forall k v. (Ord k, Monoid v) => k -> MonoidMap k v -> v
get k
k MonoidMap k v2
m2))
(Set k -> Set k -> Set k
forall a. Ord a => Set a -> Set a -> Set a
Set.intersection (MonoidMap k v1 -> Set k
forall k v. MonoidMap k v -> Set k
nonNullKeys MonoidMap k v1
m1) (MonoidMap k v2 -> Set k
forall k v. MonoidMap k v -> Set k
nonNullKeys MonoidMap k v2
m2))
{-# INLINE disjointBy #-}
append
:: (Ord k, MonoidNull v)
=> MonoidMap k v
-> MonoidMap k v
-> MonoidMap k v
append :: forall k v.
(Ord k, MonoidNull v) =>
MonoidMap k v -> MonoidMap k v -> MonoidMap k v
append = MergeStrategy Identity k v v v
-> MonoidMap k v -> MonoidMap k v -> MonoidMap k v
forall k v1 v2 v3.
Ord k =>
MergeStrategy Identity k v1 v2 v3
-> MonoidMap k v1 -> MonoidMap k v2 -> MonoidMap k v3
merge MergeStrategy
{ withNonNullL :: WhenOneSideNull Identity k v v
withNonNullL =
WhenOneSideNull Identity k v v
forall (f :: * -> *) k v. Applicative f => WhenOneSideNull f k v v
keepNonNull
, withNonNullR :: WhenOneSideNull Identity k v v
withNonNullR =
WhenOneSideNull Identity k v v
forall (f :: * -> *) k v. Applicative f => WhenOneSideNull f k v v
keepNonNull
, withNonNullP :: WhenBothNonNull Identity k v v v
withNonNullP =
(v -> v -> v) -> WhenBothNonNull Identity k v v v
forall (f :: * -> *) v3 v1 v2 k.
(Applicative f, MonoidNull v3) =>
(v1 -> v2 -> v3) -> WhenBothNonNull f k v1 v2 v3
withBoth v -> v -> v
forall a. Semigroup a => a -> a -> a
(<>)
}
{-# INLINE append #-}
isPrefixOf
:: (Ord k, Monoid v, LeftReductive v)
=> MonoidMap k v
-> MonoidMap k v
-> Bool
isPrefixOf :: forall k v.
(Ord k, Monoid v, LeftReductive v) =>
MonoidMap k v -> MonoidMap k v -> Bool
isPrefixOf = (v -> v -> Bool) -> MonoidMap k v -> MonoidMap k v -> Bool
forall k v1 v2.
(Ord k, Monoid v1, Monoid v2) =>
(v1 -> v2 -> Bool) -> MonoidMap k v1 -> MonoidMap k v2 -> Bool
isSubmapOfBy v -> v -> Bool
forall m. LeftReductive m => m -> m -> Bool
C.isPrefixOf
{-# INLINE isPrefixOf #-}
isSuffixOf
:: (Ord k, Monoid v, RightReductive v)
=> MonoidMap k v
-> MonoidMap k v
-> Bool
isSuffixOf :: forall k v.
(Ord k, Monoid v, RightReductive v) =>
MonoidMap k v -> MonoidMap k v -> Bool
isSuffixOf = (v -> v -> Bool) -> MonoidMap k v -> MonoidMap k v -> Bool
forall k v1 v2.
(Ord k, Monoid v1, Monoid v2) =>
(v1 -> v2 -> Bool) -> MonoidMap k v1 -> MonoidMap k v2 -> Bool
isSubmapOfBy v -> v -> Bool
forall m. RightReductive m => m -> m -> Bool
C.isSuffixOf
{-# INLINE isSuffixOf #-}
stripPrefix
:: (Ord k, MonoidNull v, LeftReductive v)
=> MonoidMap k v
-> MonoidMap k v
-> Maybe (MonoidMap k v)
stripPrefix :: forall k v.
(Ord k, MonoidNull v, LeftReductive v) =>
MonoidMap k v -> MonoidMap k v -> Maybe (MonoidMap k v)
stripPrefix = MergeStrategy Maybe k v v v
-> MonoidMap k v -> MonoidMap k v -> Maybe (MonoidMap k v)
forall (f :: * -> *) k v1 v2 v3.
(Applicative f, Ord k) =>
MergeStrategy f k v1 v2 v3
-> MonoidMap k v1 -> MonoidMap k v2 -> f (MonoidMap k v3)
mergeA MergeStrategy
{ withNonNullL :: WhenOneSideNull Maybe k v v
withNonNullL =
(v -> Maybe v) -> WhenOneSideNull Maybe k v v
forall (f :: * -> *) v2 v1 k.
(Applicative f, MonoidNull v2) =>
(v1 -> f v2) -> WhenOneSideNull f k v1 v2
withNonNullA (\v
v -> v -> v -> Maybe v
forall m. LeftReductive m => m -> m -> Maybe m
C.stripPrefix v
v v
forall a. Monoid a => a
mempty)
, withNonNullR :: WhenOneSideNull Maybe k v v
withNonNullR =
WhenOneSideNull Maybe k v v
forall (f :: * -> *) k v. Applicative f => WhenOneSideNull f k v v
keepNonNull
, withNonNullP :: WhenBothNonNull Maybe k v v v
withNonNullP =
(v -> v -> Maybe v) -> WhenBothNonNull Maybe k v v v
forall (f :: * -> *) v3 v1 v2 k.
(Applicative f, MonoidNull v3) =>
(v1 -> v2 -> f v3) -> WhenBothNonNull f k v1 v2 v3
withBothA v -> v -> Maybe v
forall m. LeftReductive m => m -> m -> Maybe m
C.stripPrefix
}
{-# INLINE stripPrefix #-}
stripSuffix
:: (Ord k, MonoidNull v, RightReductive v)
=> MonoidMap k v
-> MonoidMap k v
-> Maybe (MonoidMap k v)
stripSuffix :: forall k v.
(Ord k, MonoidNull v, RightReductive v) =>
MonoidMap k v -> MonoidMap k v -> Maybe (MonoidMap k v)
stripSuffix = MergeStrategy Maybe k v v v
-> MonoidMap k v -> MonoidMap k v -> Maybe (MonoidMap k v)
forall (f :: * -> *) k v1 v2 v3.
(Applicative f, Ord k) =>
MergeStrategy f k v1 v2 v3
-> MonoidMap k v1 -> MonoidMap k v2 -> f (MonoidMap k v3)
mergeA MergeStrategy
{ withNonNullL :: WhenOneSideNull Maybe k v v
withNonNullL =
(v -> Maybe v) -> WhenOneSideNull Maybe k v v
forall (f :: * -> *) v2 v1 k.
(Applicative f, MonoidNull v2) =>
(v1 -> f v2) -> WhenOneSideNull f k v1 v2
withNonNullA (\v
v -> v -> v -> Maybe v
forall m. RightReductive m => m -> m -> Maybe m
C.stripSuffix v
v v
forall a. Monoid a => a
mempty)
, withNonNullR :: WhenOneSideNull Maybe k v v
withNonNullR =
WhenOneSideNull Maybe k v v
forall (f :: * -> *) k v. Applicative f => WhenOneSideNull f k v v
keepNonNull
, withNonNullP :: WhenBothNonNull Maybe k v v v
withNonNullP =
(v -> v -> Maybe v) -> WhenBothNonNull Maybe k v v v
forall (f :: * -> *) v3 v1 v2 k.
(Applicative f, MonoidNull v3) =>
(v1 -> v2 -> f v3) -> WhenBothNonNull f k v1 v2 v3
withBothA v -> v -> Maybe v
forall m. RightReductive m => m -> m -> Maybe m
C.stripSuffix
}
{-# INLINE stripSuffix #-}
commonPrefix
:: (Ord k, MonoidNull v, LeftGCDMonoid v)
=> MonoidMap k v
-> MonoidMap k v
-> MonoidMap k v
commonPrefix :: forall k v.
(Ord k, MonoidNull v, LeftGCDMonoid v) =>
MonoidMap k v -> MonoidMap k v -> MonoidMap k v
commonPrefix = MergeStrategy Identity k v v v
-> MonoidMap k v -> MonoidMap k v -> MonoidMap k v
forall k v1 v2 v3.
Ord k =>
MergeStrategy Identity k v1 v2 v3
-> MonoidMap k v1 -> MonoidMap k v2 -> MonoidMap k v3
merge MergeStrategy
{ withNonNullL :: WhenOneSideNull Identity k v v
withNonNullL =
WhenOneSideNull Identity k v v
forall (f :: * -> *) k v1 v2.
Applicative f =>
WhenOneSideNull f k v1 v2
keepNull
, withNonNullR :: WhenOneSideNull Identity k v v
withNonNullR =
WhenOneSideNull Identity k v v
forall (f :: * -> *) k v1 v2.
Applicative f =>
WhenOneSideNull f k v1 v2
keepNull
, withNonNullP :: WhenBothNonNull Identity k v v v
withNonNullP =
(v -> v -> v) -> WhenBothNonNull Identity k v v v
forall (f :: * -> *) v3 v1 v2 k.
(Applicative f, MonoidNull v3) =>
(v1 -> v2 -> v3) -> WhenBothNonNull f k v1 v2 v3
withBoth v -> v -> v
forall m. LeftGCDMonoid m => m -> m -> m
C.commonPrefix
}
{-# INLINE commonPrefix #-}
commonSuffix
:: (Ord k, MonoidNull v, RightGCDMonoid v)
=> MonoidMap k v
-> MonoidMap k v
-> MonoidMap k v
commonSuffix :: forall k v.
(Ord k, MonoidNull v, RightGCDMonoid v) =>
MonoidMap k v -> MonoidMap k v -> MonoidMap k v
commonSuffix = MergeStrategy Identity k v v v
-> MonoidMap k v -> MonoidMap k v -> MonoidMap k v
forall k v1 v2 v3.
Ord k =>
MergeStrategy Identity k v1 v2 v3
-> MonoidMap k v1 -> MonoidMap k v2 -> MonoidMap k v3
merge MergeStrategy
{ withNonNullL :: WhenOneSideNull Identity k v v
withNonNullL =
WhenOneSideNull Identity k v v
forall (f :: * -> *) k v1 v2.
Applicative f =>
WhenOneSideNull f k v1 v2
keepNull
, withNonNullR :: WhenOneSideNull Identity k v v
withNonNullR =
WhenOneSideNull Identity k v v
forall (f :: * -> *) k v1 v2.
Applicative f =>
WhenOneSideNull f k v1 v2
keepNull
, withNonNullP :: WhenBothNonNull Identity k v v v
withNonNullP =
(v -> v -> v) -> WhenBothNonNull Identity k v v v
forall (f :: * -> *) v3 v1 v2 k.
(Applicative f, MonoidNull v3) =>
(v1 -> v2 -> v3) -> WhenBothNonNull f k v1 v2 v3
withBoth v -> v -> v
forall m. RightGCDMonoid m => m -> m -> m
C.commonSuffix
}
{-# INLINE commonSuffix #-}
stripCommonPrefix
:: (Ord k, MonoidNull v, LeftGCDMonoid v)
=> MonoidMap k v
-> MonoidMap k v
-> (MonoidMap k v, MonoidMap k v, MonoidMap k v)
stripCommonPrefix :: forall k v.
(Ord k, MonoidNull v, LeftGCDMonoid v) =>
MonoidMap k v
-> MonoidMap k v -> (MonoidMap k v, MonoidMap k v, MonoidMap k v)
stripCommonPrefix = MonoidMap k v
-> MonoidMap k v -> (MonoidMap k v, MonoidMap k v, MonoidMap k v)
forall m. LeftGCDMonoid m => m -> m -> (m, m, m)
C.stripCommonPrefix
stripCommonSuffix
:: (Ord k, MonoidNull v, RightGCDMonoid v)
=> MonoidMap k v
-> MonoidMap k v
-> (MonoidMap k v, MonoidMap k v, MonoidMap k v)
stripCommonSuffix :: forall k v.
(Ord k, MonoidNull v, RightGCDMonoid v) =>
MonoidMap k v
-> MonoidMap k v -> (MonoidMap k v, MonoidMap k v, MonoidMap k v)
stripCommonSuffix = MonoidMap k v
-> MonoidMap k v -> (MonoidMap k v, MonoidMap k v, MonoidMap k v)
forall m. RightGCDMonoid m => m -> m -> (m, m, m)
C.stripCommonSuffix
overlap
:: (Ord k, MonoidNull v, OverlappingGCDMonoid v)
=> MonoidMap k v
-> MonoidMap k v
-> MonoidMap k v
overlap :: forall k v.
(Ord k, MonoidNull v, OverlappingGCDMonoid v) =>
MonoidMap k v -> MonoidMap k v -> MonoidMap k v
overlap = MergeStrategy Identity k v v v
-> MonoidMap k v -> MonoidMap k v -> MonoidMap k v
forall k v1 v2 v3.
Ord k =>
MergeStrategy Identity k v1 v2 v3
-> MonoidMap k v1 -> MonoidMap k v2 -> MonoidMap k v3
merge MergeStrategy
{ withNonNullL :: WhenOneSideNull Identity k v v
withNonNullL =
WhenOneSideNull Identity k v v
forall (f :: * -> *) k v1 v2.
Applicative f =>
WhenOneSideNull f k v1 v2
keepNull
, withNonNullR :: WhenOneSideNull Identity k v v
withNonNullR =
WhenOneSideNull Identity k v v
forall (f :: * -> *) k v1 v2.
Applicative f =>
WhenOneSideNull f k v1 v2
keepNull
, withNonNullP :: WhenBothNonNull Identity k v v v
withNonNullP =
(v -> v -> v) -> WhenBothNonNull Identity k v v v
forall (f :: * -> *) v3 v1 v2 k.
(Applicative f, MonoidNull v3) =>
(v1 -> v2 -> v3) -> WhenBothNonNull f k v1 v2 v3
withBoth v -> v -> v
forall m. OverlappingGCDMonoid m => m -> m -> m
C.overlap
}
{-# INLINE overlap #-}
stripPrefixOverlap
:: (Ord k, MonoidNull v, OverlappingGCDMonoid v)
=> MonoidMap k v
-> MonoidMap k v
-> MonoidMap k v
stripPrefixOverlap :: forall k v.
(Ord k, MonoidNull v, OverlappingGCDMonoid v) =>
MonoidMap k v -> MonoidMap k v -> MonoidMap k v
stripPrefixOverlap = MergeStrategy Identity k v v v
-> MonoidMap k v -> MonoidMap k v -> MonoidMap k v
forall k v1 v2 v3.
Ord k =>
MergeStrategy Identity k v1 v2 v3
-> MonoidMap k v1 -> MonoidMap k v2 -> MonoidMap k v3
merge MergeStrategy
{ withNonNullL :: WhenOneSideNull Identity k v v
withNonNullL =
WhenOneSideNull Identity k v v
forall (f :: * -> *) k v1 v2.
Applicative f =>
WhenOneSideNull f k v1 v2
keepNull
, withNonNullR :: WhenOneSideNull Identity k v v
withNonNullR =
WhenOneSideNull Identity k v v
forall (f :: * -> *) k v. Applicative f => WhenOneSideNull f k v v
keepNonNull
, withNonNullP :: WhenBothNonNull Identity k v v v
withNonNullP =
(v -> v -> v) -> WhenBothNonNull Identity k v v v
forall (f :: * -> *) v3 v1 v2 k.
(Applicative f, MonoidNull v3) =>
(v1 -> v2 -> v3) -> WhenBothNonNull f k v1 v2 v3
withBoth v -> v -> v
forall m. OverlappingGCDMonoid m => m -> m -> m
C.stripPrefixOverlap
}
{-# INLINE stripPrefixOverlap #-}
stripSuffixOverlap
:: (Ord k, MonoidNull v, OverlappingGCDMonoid v)
=> MonoidMap k v
-> MonoidMap k v
-> MonoidMap k v
stripSuffixOverlap :: forall k v.
(Ord k, MonoidNull v, OverlappingGCDMonoid v) =>
MonoidMap k v -> MonoidMap k v -> MonoidMap k v
stripSuffixOverlap = MergeStrategy Identity k v v v
-> MonoidMap k v -> MonoidMap k v -> MonoidMap k v
forall k v1 v2 v3.
Ord k =>
MergeStrategy Identity k v1 v2 v3
-> MonoidMap k v1 -> MonoidMap k v2 -> MonoidMap k v3
merge MergeStrategy
{ withNonNullL :: WhenOneSideNull Identity k v v
withNonNullL =
WhenOneSideNull Identity k v v
forall (f :: * -> *) k v1 v2.
Applicative f =>
WhenOneSideNull f k v1 v2
keepNull
, withNonNullR :: WhenOneSideNull Identity k v v
withNonNullR =
WhenOneSideNull Identity k v v
forall (f :: * -> *) k v. Applicative f => WhenOneSideNull f k v v
keepNonNull
, withNonNullP :: WhenBothNonNull Identity k v v v
withNonNullP =
(v -> v -> v) -> WhenBothNonNull Identity k v v v
forall (f :: * -> *) v3 v1 v2 k.
(Applicative f, MonoidNull v3) =>
(v1 -> v2 -> v3) -> WhenBothNonNull f k v1 v2 v3
withBoth v -> v -> v
forall m. OverlappingGCDMonoid m => m -> m -> m
C.stripSuffixOverlap
}
{-# INLINE stripSuffixOverlap #-}
stripOverlap
:: (Ord k, MonoidNull v, OverlappingGCDMonoid v)
=> MonoidMap k v
-> MonoidMap k v
-> (MonoidMap k v, MonoidMap k v, MonoidMap k v)
stripOverlap :: forall k v.
(Ord k, MonoidNull v, OverlappingGCDMonoid v) =>
MonoidMap k v
-> MonoidMap k v -> (MonoidMap k v, MonoidMap k v, MonoidMap k v)
stripOverlap MonoidMap k v
m1 MonoidMap k v
m2 =
( MonoidMap k v -> MonoidMap k v -> MonoidMap k v
forall k v.
(Ord k, MonoidNull v, OverlappingGCDMonoid v) =>
MonoidMap k v -> MonoidMap k v -> MonoidMap k v
stripSuffixOverlap MonoidMap k v
m2 MonoidMap k v
m1
, MonoidMap k v
m1 MonoidMap k v -> MonoidMap k v -> MonoidMap k v
forall k v.
(Ord k, MonoidNull v, OverlappingGCDMonoid v) =>
MonoidMap k v -> MonoidMap k v -> MonoidMap k v
`overlap` MonoidMap k v
m2
, MonoidMap k v -> MonoidMap k v -> MonoidMap k v
forall k v.
(Ord k, MonoidNull v, OverlappingGCDMonoid v) =>
MonoidMap k v -> MonoidMap k v -> MonoidMap k v
stripPrefixOverlap MonoidMap k v
m1 MonoidMap k v
m2
)
intersection
:: (Ord k, MonoidNull v, GCDMonoid v)
=> MonoidMap k v
-> MonoidMap k v
-> MonoidMap k v
intersection :: forall k v.
(Ord k, MonoidNull v, GCDMonoid v) =>
MonoidMap k v -> MonoidMap k v -> MonoidMap k v
intersection = MergeStrategy Identity k v v v
-> MonoidMap k v -> MonoidMap k v -> MonoidMap k v
forall k v1 v2 v3.
Ord k =>
MergeStrategy Identity k v1 v2 v3
-> MonoidMap k v1 -> MonoidMap k v2 -> MonoidMap k v3
merge MergeStrategy
{ withNonNullL :: WhenOneSideNull Identity k v v
withNonNullL =
WhenOneSideNull Identity k v v
forall (f :: * -> *) k v1 v2.
Applicative f =>
WhenOneSideNull f k v1 v2
keepNull
, withNonNullR :: WhenOneSideNull Identity k v v
withNonNullR =
WhenOneSideNull Identity k v v
forall (f :: * -> *) k v1 v2.
Applicative f =>
WhenOneSideNull f k v1 v2
keepNull
, withNonNullP :: WhenBothNonNull Identity k v v v
withNonNullP =
(v -> v -> v) -> WhenBothNonNull Identity k v v v
forall (f :: * -> *) v3 v1 v2 k.
(Applicative f, MonoidNull v3) =>
(v1 -> v2 -> v3) -> WhenBothNonNull f k v1 v2 v3
withBoth v -> v -> v
forall m. GCDMonoid m => m -> m -> m
C.gcd
}
{-# INLINE intersection #-}
union
:: (Ord k, MonoidNull v, LCMMonoid v)
=> MonoidMap k v
-> MonoidMap k v
-> MonoidMap k v
union :: forall k v.
(Ord k, MonoidNull v, LCMMonoid v) =>
MonoidMap k v -> MonoidMap k v -> MonoidMap k v
union = MergeStrategy Identity k v v v
-> MonoidMap k v -> MonoidMap k v -> MonoidMap k v
forall k v1 v2 v3.
Ord k =>
MergeStrategy Identity k v1 v2 v3
-> MonoidMap k v1 -> MonoidMap k v2 -> MonoidMap k v3
merge MergeStrategy
{ withNonNullL :: WhenOneSideNull Identity k v v
withNonNullL =
WhenOneSideNull Identity k v v
forall (f :: * -> *) k v. Applicative f => WhenOneSideNull f k v v
keepNonNull
, withNonNullR :: WhenOneSideNull Identity k v v
withNonNullR =
WhenOneSideNull Identity k v v
forall (f :: * -> *) k v. Applicative f => WhenOneSideNull f k v v
keepNonNull
, withNonNullP :: WhenBothNonNull Identity k v v v
withNonNullP =
(v -> v -> v) -> WhenBothNonNull Identity k v v v
forall (f :: * -> *) v3 v1 v2 k.
(Applicative f, MonoidNull v3) =>
(v1 -> v2 -> v3) -> WhenBothNonNull f k v1 v2 v3
withBoth v -> v -> v
forall m. LCMMonoid m => m -> m -> m
C.lcm
}
{-# INLINE union #-}
minus
:: (Ord k, MonoidNull v, Group v)
=> MonoidMap k v
-> MonoidMap k v
-> MonoidMap k v
minus :: forall k v.
(Ord k, MonoidNull v, Group v) =>
MonoidMap k v -> MonoidMap k v -> MonoidMap k v
minus = MergeStrategy Identity k v v v
-> MonoidMap k v -> MonoidMap k v -> MonoidMap k v
forall k v1 v2 v3.
Ord k =>
MergeStrategy Identity k v1 v2 v3
-> MonoidMap k v1 -> MonoidMap k v2 -> MonoidMap k v3
merge MergeStrategy
{ withNonNullL :: WhenOneSideNull Identity k v v
withNonNullL =
WhenOneSideNull Identity k v v
forall (f :: * -> *) k v. Applicative f => WhenOneSideNull f k v v
keepNonNull
, withNonNullR :: WhenOneSideNull Identity k v v
withNonNullR =
(v -> v) -> WhenOneSideNull Identity k v v
forall (f :: * -> *) v2 v1 k.
(Applicative f, MonoidNull v2) =>
(v1 -> v2) -> WhenOneSideNull f k v1 v2
withNonNull v -> v
forall m. Group m => m -> m
C.invert
, withNonNullP :: WhenBothNonNull Identity k v v v
withNonNullP =
(v -> v -> v) -> WhenBothNonNull Identity k v v v
forall (f :: * -> *) v3 v1 v2 k.
(Applicative f, MonoidNull v3) =>
(v1 -> v2 -> v3) -> WhenBothNonNull f k v1 v2 v3
withBoth v -> v -> v
forall m. Group m => m -> m -> m
(C.~~)
}
{-# INLINE minus #-}
minusMaybe
:: (Ord k, MonoidNull v, Reductive v)
=> MonoidMap k v
-> MonoidMap k v
-> Maybe (MonoidMap k v)
minusMaybe :: forall k v.
(Ord k, MonoidNull v, Reductive v) =>
MonoidMap k v -> MonoidMap k v -> Maybe (MonoidMap k v)
minusMaybe = MergeStrategy Maybe k v v v
-> MonoidMap k v -> MonoidMap k v -> Maybe (MonoidMap k v)
forall (f :: * -> *) k v1 v2 v3.
(Applicative f, Ord k) =>
MergeStrategy f k v1 v2 v3
-> MonoidMap k v1 -> MonoidMap k v2 -> f (MonoidMap k v3)
mergeA MergeStrategy
{ withNonNullL :: WhenOneSideNull Maybe k v v
withNonNullL =
WhenOneSideNull Maybe k v v
forall (f :: * -> *) k v. Applicative f => WhenOneSideNull f k v v
keepNonNull
, withNonNullR :: WhenOneSideNull Maybe k v v
withNonNullR =
(v -> Maybe v) -> WhenOneSideNull Maybe k v v
forall (f :: * -> *) v2 v1 k.
(Applicative f, MonoidNull v2) =>
(v1 -> f v2) -> WhenOneSideNull f k v1 v2
withNonNullA (\v
v -> v
forall a. Monoid a => a
mempty v -> v -> Maybe v
forall m. Reductive m => m -> m -> Maybe m
</> v
v)
, withNonNullP :: WhenBothNonNull Maybe k v v v
withNonNullP =
(v -> v -> Maybe v) -> WhenBothNonNull Maybe k v v v
forall (f :: * -> *) v3 v1 v2 k.
(Applicative f, MonoidNull v3) =>
(v1 -> v2 -> f v3) -> WhenBothNonNull f k v1 v2 v3
withBothA v -> v -> Maybe v
forall m. Reductive m => m -> m -> Maybe m
(</>)
}
{-# INLINE minusMaybe #-}
monus
:: (Ord k, MonoidNull v, Monus v)
=> MonoidMap k v
-> MonoidMap k v
-> MonoidMap k v
monus :: forall k v.
(Ord k, MonoidNull v, Monus v) =>
MonoidMap k v -> MonoidMap k v -> MonoidMap k v
monus = MergeStrategy Identity k v v v
-> MonoidMap k v -> MonoidMap k v -> MonoidMap k v
forall k v1 v2 v3.
Ord k =>
MergeStrategy Identity k v1 v2 v3
-> MonoidMap k v1 -> MonoidMap k v2 -> MonoidMap k v3
merge MergeStrategy
{ withNonNullL :: WhenOneSideNull Identity k v v
withNonNullL =
WhenOneSideNull Identity k v v
forall (f :: * -> *) k v. Applicative f => WhenOneSideNull f k v v
keepNonNull
, withNonNullR :: WhenOneSideNull Identity k v v
withNonNullR =
WhenOneSideNull Identity k v v
forall (f :: * -> *) k v1 v2.
Applicative f =>
WhenOneSideNull f k v1 v2
keepNull
, withNonNullP :: WhenBothNonNull Identity k v v v
withNonNullP =
(v -> v -> v) -> WhenBothNonNull Identity k v v v
forall (f :: * -> *) v3 v1 v2 k.
(Applicative f, MonoidNull v3) =>
(v1 -> v2 -> v3) -> WhenBothNonNull f k v1 v2 v3
withBoth v -> v -> v
forall m. Monus m => m -> m -> m
(<\>)
}
{-# INLINE monus #-}
invert
:: (MonoidNull v, Group v)
=> MonoidMap k v
-> MonoidMap k v
invert :: forall v k.
(MonoidNull v, Group v) =>
MonoidMap k v -> MonoidMap k v
invert = (v -> v) -> MonoidMap k v -> MonoidMap k v
forall v2 v1 k.
MonoidNull v2 =>
(v1 -> v2) -> MonoidMap k v1 -> MonoidMap k v2
map v -> v
forall m. Group m => m -> m
C.invert
{-# INLINE invert #-}
power
:: (Integral i, MonoidNull v, Group v)
=> MonoidMap k v
-> i
-> MonoidMap k v
power :: forall i v k.
(Integral i, MonoidNull v, Group v) =>
MonoidMap k v -> i -> MonoidMap k v
power MonoidMap k v
m i
i = (v -> v) -> MonoidMap k v -> MonoidMap k v
forall v2 v1 k.
MonoidNull v2 =>
(v1 -> v2) -> MonoidMap k v1 -> MonoidMap k v2
map (v -> i -> v
forall x. Integral x => v -> x -> v
forall m x. (Group m, Integral x) => m -> x -> m
`C.pow` i
i) MonoidMap k v
m
{-# INLINE power #-}
intersectionWith
:: (Ord k, MonoidNull v3)
=> (v1 -> v2 -> v3)
-> MonoidMap k v1
-> MonoidMap k v2
-> MonoidMap k v3
intersectionWith :: forall k v3 v1 v2.
(Ord k, MonoidNull v3) =>
(v1 -> v2 -> v3)
-> MonoidMap k v1 -> MonoidMap k v2 -> MonoidMap k v3
intersectionWith v1 -> v2 -> v3
f = MergeStrategy Identity k v1 v2 v3
-> MonoidMap k v1 -> MonoidMap k v2 -> MonoidMap k v3
forall k v1 v2 v3.
Ord k =>
MergeStrategy Identity k v1 v2 v3
-> MonoidMap k v1 -> MonoidMap k v2 -> MonoidMap k v3
merge MergeStrategy
{ withNonNullL :: WhenOneSideNull Identity k v1 v3
withNonNullL =
WhenOneSideNull Identity k v1 v3
forall (f :: * -> *) k v1 v2.
Applicative f =>
WhenOneSideNull f k v1 v2
keepNull
, withNonNullR :: WhenOneSideNull Identity k v2 v3
withNonNullR =
WhenOneSideNull Identity k v2 v3
forall (f :: * -> *) k v1 v2.
Applicative f =>
WhenOneSideNull f k v1 v2
keepNull
, withNonNullP :: WhenBothNonNull Identity k v1 v2 v3
withNonNullP =
(v1 -> v2 -> v3) -> WhenBothNonNull Identity k v1 v2 v3
forall (f :: * -> *) v3 v1 v2 k.
(Applicative f, MonoidNull v3) =>
(v1 -> v2 -> v3) -> WhenBothNonNull f k v1 v2 v3
withBoth v1 -> v2 -> v3
f
}
{-# INLINE intersectionWith #-}
intersectionWithA
:: (Applicative f, Ord k, MonoidNull v3)
=> (v1 -> v2 -> f v3)
-> MonoidMap k v1
-> MonoidMap k v2
-> f (MonoidMap k v3)
intersectionWithA :: forall (f :: * -> *) k v3 v1 v2.
(Applicative f, Ord k, MonoidNull v3) =>
(v1 -> v2 -> f v3)
-> MonoidMap k v1 -> MonoidMap k v2 -> f (MonoidMap k v3)
intersectionWithA v1 -> v2 -> f v3
f = MergeStrategy f k v1 v2 v3
-> MonoidMap k v1 -> MonoidMap k v2 -> f (MonoidMap k v3)
forall (f :: * -> *) k v1 v2 v3.
(Applicative f, Ord k) =>
MergeStrategy f k v1 v2 v3
-> MonoidMap k v1 -> MonoidMap k v2 -> f (MonoidMap k v3)
mergeA MergeStrategy
{ withNonNullL :: WhenOneSideNull f k v1 v3
withNonNullL =
WhenOneSideNull f k v1 v3
forall (f :: * -> *) k v1 v2.
Applicative f =>
WhenOneSideNull f k v1 v2
keepNull
, withNonNullR :: WhenOneSideNull f k v2 v3
withNonNullR =
WhenOneSideNull f k v2 v3
forall (f :: * -> *) k v1 v2.
Applicative f =>
WhenOneSideNull f k v1 v2
keepNull
, withNonNullP :: WhenBothNonNull f k v1 v2 v3
withNonNullP =
(v1 -> v2 -> f v3) -> WhenBothNonNull f k v1 v2 v3
forall (f :: * -> *) v3 v1 v2 k.
(Applicative f, MonoidNull v3) =>
(v1 -> v2 -> f v3) -> WhenBothNonNull f k v1 v2 v3
withBothA v1 -> v2 -> f v3
f
}
{-# INLINE intersectionWithA #-}
unionWith
:: (Ord k, Monoid v1, Monoid v2, MonoidNull v3)
=> (v1 -> v2 -> v3)
-> MonoidMap k v1
-> MonoidMap k v2
-> MonoidMap k v3
unionWith :: forall k v1 v2 v3.
(Ord k, Monoid v1, Monoid v2, MonoidNull v3) =>
(v1 -> v2 -> v3)
-> MonoidMap k v1 -> MonoidMap k v2 -> MonoidMap k v3
unionWith v1 -> v2 -> v3
f = MergeStrategy Identity k v1 v2 v3
-> MonoidMap k v1 -> MonoidMap k v2 -> MonoidMap k v3
forall k v1 v2 v3.
Ord k =>
MergeStrategy Identity k v1 v2 v3
-> MonoidMap k v1 -> MonoidMap k v2 -> MonoidMap k v3
merge MergeStrategy
{ withNonNullL :: WhenOneSideNull Identity k v1 v3
withNonNullL =
(v1 -> v3) -> WhenOneSideNull Identity k v1 v3
forall (f :: * -> *) v2 v1 k.
(Applicative f, MonoidNull v2) =>
(v1 -> v2) -> WhenOneSideNull f k v1 v2
withNonNull (\v1
v -> v1 -> v2 -> v3
f v1
v v2
forall a. Monoid a => a
mempty)
, withNonNullR :: WhenOneSideNull Identity k v2 v3
withNonNullR =
(v2 -> v3) -> WhenOneSideNull Identity k v2 v3
forall (f :: * -> *) v2 v1 k.
(Applicative f, MonoidNull v2) =>
(v1 -> v2) -> WhenOneSideNull f k v1 v2
withNonNull (\v2
v -> v1 -> v2 -> v3
f v1
forall a. Monoid a => a
mempty v2
v)
, withNonNullP :: WhenBothNonNull Identity k v1 v2 v3
withNonNullP =
(v1 -> v2 -> v3) -> WhenBothNonNull Identity k v1 v2 v3
forall (f :: * -> *) v3 v1 v2 k.
(Applicative f, MonoidNull v3) =>
(v1 -> v2 -> v3) -> WhenBothNonNull f k v1 v2 v3
withBoth v1 -> v2 -> v3
f
}
{-# INLINE unionWith #-}
unionWithA
:: (Applicative f, Ord k, Monoid v1, Monoid v2, MonoidNull v3)
=> (v1 -> v2 -> f v3)
-> MonoidMap k v1
-> MonoidMap k v2
-> f (MonoidMap k v3)
unionWithA :: forall (f :: * -> *) k v1 v2 v3.
(Applicative f, Ord k, Monoid v1, Monoid v2, MonoidNull v3) =>
(v1 -> v2 -> f v3)
-> MonoidMap k v1 -> MonoidMap k v2 -> f (MonoidMap k v3)
unionWithA v1 -> v2 -> f v3
f = MergeStrategy f k v1 v2 v3
-> MonoidMap k v1 -> MonoidMap k v2 -> f (MonoidMap k v3)
forall (f :: * -> *) k v1 v2 v3.
(Applicative f, Ord k) =>
MergeStrategy f k v1 v2 v3
-> MonoidMap k v1 -> MonoidMap k v2 -> f (MonoidMap k v3)
mergeA MergeStrategy
{ withNonNullL :: WhenOneSideNull f k v1 v3
withNonNullL =
(v1 -> f v3) -> WhenOneSideNull f k v1 v3
forall (f :: * -> *) v2 v1 k.
(Applicative f, MonoidNull v2) =>
(v1 -> f v2) -> WhenOneSideNull f k v1 v2
withNonNullA (\v1
v -> v1 -> v2 -> f v3
f v1
v v2
forall a. Monoid a => a
mempty)
, withNonNullR :: WhenOneSideNull f k v2 v3
withNonNullR =
(v2 -> f v3) -> WhenOneSideNull f k v2 v3
forall (f :: * -> *) v2 v1 k.
(Applicative f, MonoidNull v2) =>
(v1 -> f v2) -> WhenOneSideNull f k v1 v2
withNonNullA (\v2
v -> v1 -> v2 -> f v3
f v1
forall a. Monoid a => a
mempty v2
v)
, withNonNullP :: WhenBothNonNull f k v1 v2 v3
withNonNullP =
(v1 -> v2 -> f v3) -> WhenBothNonNull f k v1 v2 v3
forall (f :: * -> *) v3 v1 v2 k.
(Applicative f, MonoidNull v3) =>
(v1 -> v2 -> f v3) -> WhenBothNonNull f k v1 v2 v3
withBothA v1 -> v2 -> f v3
f
}
{-# INLINE unionWithA #-}
type WhenOneSideNull f k vx vr
= Map.WhenMissing f k (NonNull vx) (NonNull vr)
type WhenBothNonNull f k v1 v2 vr
= Map.WhenMatched f k (NonNull v1) (NonNull v2) (NonNull vr)
data MergeStrategy f k v1 v2 v3 = MergeStrategy
{ forall (f :: * -> *) k v1 v2 v3.
MergeStrategy f k v1 v2 v3 -> WhenOneSideNull f k v1 v3
withNonNullL :: !(WhenOneSideNull f k v1 v3)
, forall (f :: * -> *) k v1 v2 v3.
MergeStrategy f k v1 v2 v3 -> WhenOneSideNull f k v2 v3
withNonNullR :: !(WhenOneSideNull f k v2 v3)
, forall (f :: * -> *) k v1 v2 v3.
MergeStrategy f k v1 v2 v3 -> WhenBothNonNull f k v1 v2 v3
withNonNullP :: !(WhenBothNonNull f k v1 v2 v3)
}
merge
:: Ord k
=> MergeStrategy Identity k v1 v2 v3
-> MonoidMap k v1
-> MonoidMap k v2
-> MonoidMap k v3
merge :: forall k v1 v2 v3.
Ord k =>
MergeStrategy Identity k v1 v2 v3
-> MonoidMap k v1 -> MonoidMap k v2 -> MonoidMap k v3
merge (MergeStrategy WhenOneSideNull Identity k v1 v3
nnl WhenOneSideNull Identity k v2 v3
nnr WhenBothNonNull Identity k v1 v2 v3
nnp) (MonoidMap Map k (NonNull v1)
m1) (MonoidMap Map k (NonNull v2)
m2) =
Map k (NonNull v3) -> MonoidMap k v3
forall k v. Map k (NonNull v) -> MonoidMap k v
MonoidMap (Map k (NonNull v3) -> MonoidMap k v3)
-> Map k (NonNull v3) -> MonoidMap k v3
forall a b. (a -> b) -> a -> b
$ WhenOneSideNull Identity k v1 v3
-> WhenOneSideNull Identity k v2 v3
-> WhenBothNonNull Identity k v1 v2 v3
-> Map k (NonNull v1)
-> Map k (NonNull v2)
-> Map k (NonNull v3)
forall k a c b.
Ord k =>
SimpleWhenMissing k a c
-> SimpleWhenMissing k b c
-> SimpleWhenMatched k a b c
-> Map k a
-> Map k b
-> Map k c
Map.merge WhenOneSideNull Identity k v1 v3
nnl WhenOneSideNull Identity k v2 v3
nnr WhenBothNonNull Identity k v1 v2 v3
nnp Map k (NonNull v1)
m1 Map k (NonNull v2)
m2
{-# INLINE merge #-}
mergeA
:: (Applicative f, Ord k)
=> MergeStrategy f k v1 v2 v3
-> MonoidMap k v1
-> MonoidMap k v2
-> f (MonoidMap k v3)
mergeA :: forall (f :: * -> *) k v1 v2 v3.
(Applicative f, Ord k) =>
MergeStrategy f k v1 v2 v3
-> MonoidMap k v1 -> MonoidMap k v2 -> f (MonoidMap k v3)
mergeA (MergeStrategy WhenOneSideNull f k v1 v3
nnl WhenOneSideNull f k v2 v3
nnr WhenBothNonNull f k v1 v2 v3
nnp) (MonoidMap Map k (NonNull v1)
m1) (MonoidMap Map k (NonNull v2)
m2) =
Map k (NonNull v3) -> MonoidMap k v3
forall k v. Map k (NonNull v) -> MonoidMap k v
MonoidMap (Map k (NonNull v3) -> MonoidMap k v3)
-> f (Map k (NonNull v3)) -> f (MonoidMap k v3)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> WhenOneSideNull f k v1 v3
-> WhenOneSideNull f k v2 v3
-> WhenBothNonNull f k v1 v2 v3
-> Map k (NonNull v1)
-> Map k (NonNull v2)
-> f (Map k (NonNull v3))
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)
Map.mergeA WhenOneSideNull f k v1 v3
nnl WhenOneSideNull f k v2 v3
nnr WhenBothNonNull f k v1 v2 v3
nnp Map k (NonNull v1)
m1 Map k (NonNull v2)
m2
{-# INLINE mergeA #-}
keepNull
:: Applicative f
=> WhenOneSideNull f k v1 v2
keepNull :: forall (f :: * -> *) k v1 v2.
Applicative f =>
WhenOneSideNull f k v1 v2
keepNull = WhenMissing f k (NonNull v1) (NonNull v2)
forall (f :: * -> *) k x y. Applicative f => WhenMissing f k x y
Map.dropMissing
{-# INLINE keepNull #-}
keepNonNull
:: Applicative f
=> WhenOneSideNull f k v v
keepNonNull :: forall (f :: * -> *) k v. Applicative f => WhenOneSideNull f k v v
keepNonNull = WhenMissing f k (NonNull v) (NonNull v)
forall (f :: * -> *) k x. Applicative f => WhenMissing f k x x
Map.preserveMissing
{-# INLINE keepNonNull #-}
withNonNull
:: (Applicative f, MonoidNull v2)
=> (v1 -> v2)
-> WhenOneSideNull f k v1 v2
withNonNull :: forall (f :: * -> *) v2 v1 k.
(Applicative f, MonoidNull v2) =>
(v1 -> v2) -> WhenOneSideNull f k v1 v2
withNonNull v1 -> v2
f
= (k -> NonNull v1 -> Maybe (NonNull v2))
-> WhenMissing f k (NonNull v1) (NonNull v2)
forall (f :: * -> *) k x y.
Applicative f =>
(k -> x -> Maybe y) -> WhenMissing f k x y
Map.mapMaybeMissing
((k -> NonNull v1 -> Maybe (NonNull v2))
-> WhenMissing f k (NonNull v1) (NonNull v2))
-> (k -> NonNull v1 -> Maybe (NonNull v2))
-> WhenMissing f k (NonNull v1) (NonNull v2)
forall a b. (a -> b) -> a -> b
$ \k
_k NonNull v1
v -> v2 -> Maybe (NonNull v2)
forall v. MonoidNull v => v -> Maybe (NonNull v)
maybeNonNull (v2 -> Maybe (NonNull v2)) -> v2 -> Maybe (NonNull v2)
forall a b. (a -> b) -> a -> b
$ (v1 -> v2) -> NonNull v1 -> v2
forall v a. (v -> a) -> NonNull v -> a
applyNonNull v1 -> v2
f NonNull v1
v
{-# INLINE withNonNull #-}
withNonNullA
:: (Applicative f, MonoidNull v2)
=> (v1 -> f v2)
-> WhenOneSideNull f k v1 v2
withNonNullA :: forall (f :: * -> *) v2 v1 k.
(Applicative f, MonoidNull v2) =>
(v1 -> f v2) -> WhenOneSideNull f k v1 v2
withNonNullA v1 -> f v2
f
= (k -> NonNull v1 -> f (Maybe (NonNull v2)))
-> WhenMissing f k (NonNull v1) (NonNull v2)
forall (f :: * -> *) k x y.
Applicative f =>
(k -> x -> f (Maybe y)) -> WhenMissing f k x y
Map.traverseMaybeMissing
((k -> NonNull v1 -> f (Maybe (NonNull v2)))
-> WhenMissing f k (NonNull v1) (NonNull v2))
-> (k -> NonNull v1 -> f (Maybe (NonNull v2)))
-> WhenMissing f k (NonNull v1) (NonNull v2)
forall a b. (a -> b) -> a -> b
$ \k
_k NonNull v1
v -> v2 -> Maybe (NonNull v2)
forall v. MonoidNull v => v -> Maybe (NonNull v)
maybeNonNull (v2 -> Maybe (NonNull v2)) -> f v2 -> f (Maybe (NonNull v2))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (v1 -> f v2) -> NonNull v1 -> f v2
forall v a. (v -> a) -> NonNull v -> a
applyNonNull v1 -> f v2
f NonNull v1
v
{-# INLINE withNonNullA #-}
withBoth
:: (Applicative f, MonoidNull v3)
=> (v1 -> v2 -> v3)
-> WhenBothNonNull f k v1 v2 v3
withBoth :: forall (f :: * -> *) v3 v1 v2 k.
(Applicative f, MonoidNull v3) =>
(v1 -> v2 -> v3) -> WhenBothNonNull f k v1 v2 v3
withBoth v1 -> v2 -> v3
f
= (k -> NonNull v1 -> NonNull v2 -> Maybe (NonNull v3))
-> WhenMatched f k (NonNull v1) (NonNull v2) (NonNull v3)
forall (f :: * -> *) k x y z.
Applicative f =>
(k -> x -> y -> Maybe z) -> WhenMatched f k x y z
Map.zipWithMaybeMatched
((k -> NonNull v1 -> NonNull v2 -> Maybe (NonNull v3))
-> WhenMatched f k (NonNull v1) (NonNull v2) (NonNull v3))
-> (k -> NonNull v1 -> NonNull v2 -> Maybe (NonNull v3))
-> WhenMatched f k (NonNull v1) (NonNull v2) (NonNull v3)
forall a b. (a -> b) -> a -> b
$ \k
_k NonNull v1
v1 NonNull v2
v2 -> v3 -> Maybe (NonNull v3)
forall v. MonoidNull v => v -> Maybe (NonNull v)
maybeNonNull (v3 -> Maybe (NonNull v3)) -> v3 -> Maybe (NonNull v3)
forall a b. (a -> b) -> a -> b
$ (v1 -> v2 -> v3) -> NonNull v1 -> NonNull v2 -> v3
forall v1 v2 a. (v1 -> v2 -> a) -> NonNull v1 -> NonNull v2 -> a
applyNonNull2 v1 -> v2 -> v3
f NonNull v1
v1 NonNull v2
v2
{-# INLINE withBoth #-}
withBothA
:: (Applicative f, MonoidNull v3)
=> (v1 -> v2 -> f v3)
-> WhenBothNonNull f k v1 v2 v3
withBothA :: forall (f :: * -> *) v3 v1 v2 k.
(Applicative f, MonoidNull v3) =>
(v1 -> v2 -> f v3) -> WhenBothNonNull f k v1 v2 v3
withBothA v1 -> v2 -> f v3
f
= (k -> NonNull v1 -> NonNull v2 -> f (Maybe (NonNull v3)))
-> WhenMatched f k (NonNull v1) (NonNull v2) (NonNull v3)
forall (f :: * -> *) k x y z.
Applicative f =>
(k -> x -> y -> f (Maybe z)) -> WhenMatched f k x y z
Map.zipWithMaybeAMatched
((k -> NonNull v1 -> NonNull v2 -> f (Maybe (NonNull v3)))
-> WhenMatched f k (NonNull v1) (NonNull v2) (NonNull v3))
-> (k -> NonNull v1 -> NonNull v2 -> f (Maybe (NonNull v3)))
-> WhenMatched f k (NonNull v1) (NonNull v2) (NonNull v3)
forall a b. (a -> b) -> a -> b
$ \k
_k NonNull v1
v1 NonNull v2
v2 -> v3 -> Maybe (NonNull v3)
forall v. MonoidNull v => v -> Maybe (NonNull v)
maybeNonNull (v3 -> Maybe (NonNull v3)) -> f v3 -> f (Maybe (NonNull v3))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (v1 -> v2 -> f v3) -> NonNull v1 -> NonNull v2 -> f v3
forall v1 v2 a. (v1 -> v2 -> a) -> NonNull v1 -> NonNull v2 -> a
applyNonNull2 v1 -> v2 -> f v3
f NonNull v1
v1 NonNull v2
v2
{-# INLINE withBothA #-}