deep-map 0.2.0.1 → 0.3.0
raw patch · 4 files changed
+379/−307 lines, 4 filesdep +witherabledep ~containersPVP ok
version bump matches the API change (PVP)
Dependencies added: witherable
Dependency ranges changed: containers
API changes (from Hackage documentation)
- Data.Map.Deep: [Bare] :: v -> DeepMap '[] v
- Data.Map.Deep: [Nest] :: Ord k => Map k (DeepMap ks v) -> DeepMap (k ': ks) v
- Data.Map.Deep: onBare2 :: (v -> w -> x) -> DeepMap '[] v -> DeepMap '[] w -> DeepMap '[] x
- Data.Map.Deep: onNest2 :: (Map k (DeepMap ks v) -> Map k (DeepMap ls w) -> Map k (DeepMap ms x)) -> DeepMap (k ': ks) v -> DeepMap (k ': ls) w -> DeepMap (k ': ms) x
+ Data.Map.Deep: [Core] :: v -> DeepMap '[] v
+ Data.Map.Deep: [Wrap] :: Ord k => Map k (DeepMap ks v) -> DeepMap (k ': ks) v
+ Data.Map.Deep: assocsDeep :: DeepMap ks v -> [(Deep ks, v)]
+ Data.Map.Deep: elemsDeep :: DeepMap ks v -> [v]
+ Data.Map.Deep: instance (GHC.Show.Show k, GHC.Show.Show (Data.Map.Deep.Deep ks)) => GHC.Show.Show (Data.Map.Deep.Deep (k : ks))
+ Data.Map.Deep: instance Witherable.Filterable (Data.Map.Deep.DeepMap '[])
+ Data.Map.Deep: instance Witherable.Filterable (Data.Map.Deep.DeepMap (k : ks))
+ Data.Map.Deep: instance Witherable.FilterableWithIndex (Data.Map.Deep.Deep '[]) (Data.Map.Deep.DeepMap '[])
+ Data.Map.Deep: instance Witherable.FilterableWithIndex (Data.Map.Deep.Deep (k : ks)) (Data.Map.Deep.DeepMap (k : ks))
+ Data.Map.Deep: instance Witherable.Witherable (Data.Map.Deep.DeepMap '[])
+ Data.Map.Deep: instance Witherable.Witherable (Data.Map.Deep.DeepMap ks) => Witherable.Witherable (Data.Map.Deep.DeepMap (k : ks))
+ Data.Map.Deep: instance Witherable.WitherableWithIndex (Data.Map.Deep.Deep '[]) (Data.Map.Deep.DeepMap '[])
+ Data.Map.Deep: instance Witherable.WitherableWithIndex (Data.Map.Deep.Deep ks) (Data.Map.Deep.DeepMap ks) => Witherable.WitherableWithIndex (Data.Map.Deep.Deep (k : ks)) (Data.Map.Deep.DeepMap (k : ks))
+ Data.Map.Deep: keysDeep :: DeepMap ks v -> [Deep ks]
+ Data.Map.Deep: mapEitherWithKeys :: (Deep (k ': ks) -> v -> Either w x) -> DeepMap (k ': ks) v -> (DeepMap (k ': ks) w, DeepMap (k ': ks) x)
+ Data.Map.Deep: mapMaybeWithKeys :: (Deep (k ': ks) -> v -> Maybe w) -> DeepMap (k ': ks) v -> DeepMap (k ': ks) w
+ Data.Map.Deep: onCore2 :: (v -> w -> x) -> DeepMap '[] v -> DeepMap '[] w -> DeepMap '[] x
+ Data.Map.Deep: onWrap2 :: (Map k (DeepMap ks v) -> Map k (DeepMap ls w) -> Map k (DeepMap ms x)) -> DeepMap (k ': ks) v -> DeepMap (k ': ls) w -> DeepMap (k ': ms) x
- Data.Map.Deep: pattern Deep1 :: () => k -> Deep ks -> Deep (k ': ks)
+ Data.Map.Deep: pattern D1 :: () => k -> Deep ks -> Deep (k ': ks)
- Data.Map.Deep: pattern Deep5 :: (Ord k0, Ord k1, Ord k2, Ord k3, Ord k4) => k0 -> k1 -> k2 -> k3 -> k4 -> Deep ks -> Deep (k0 ': (k1 ': (k2 ': (k3 ': (k4 ': ks)))))
+ Data.Map.Deep: pattern D5 :: (Ord k0, Ord k1, Ord k2, Ord k3, Ord k4) => k0 -> k1 -> k2 -> k3 -> k4 -> Deep ks -> Deep (k0 ': (k1 ': (k2 ': (k3 ': (k4 ': ks)))))
- Data.Map.Deep: toMap :: DeepMap (k ': '[]) v -> Map k v
+ Data.Map.Deep: toMap :: DeepMap '[k] v -> Map k v
Files
- CHANGELOG.md +5/−0
- README.md +2/−2
- deep-map.cabal +3/−2
- src/Data/Map/Deep.hs +369/−303
CHANGELOG.md view
@@ -1,5 +1,10 @@ # Revision history for deep-map +## 0.3++* rename constructors and patterns+* add support for `witherable` classes+ ## 0.2.0.1 * Update copyright and re-trigger Hackage build with newer ghc
README.md view
@@ -9,8 +9,8 @@ ```hs type DeepMap :: [Type] -> Type -> Type data DeepMap ks v where- Bare :: v -> DeepMap '[] v- Nest :: Map k (DeepMap ks v) -> DeepMap (k ': ks) v+ Core :: v -> DeepMap '[] v+ Wrap :: Map k (DeepMap ks v) -> DeepMap (k ': ks) v ``` For a given `(k ': ks) :: [Type]`, the type `DeepMap (k ': ks) v` is isomorphic to lists of the form `[(k, k0, .., kn, v)]` where `ks = '[k0, ..., kn]`, but with better performance.
deep-map.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: deep-map-version: 0.2.0.1+version: 0.3.0 category: Data, Statistics synopsis: Deeply-nested, multiple key type maps. description:@@ -41,7 +41,8 @@ hs-source-dirs: src build-depends: , base >=4.11 && <5- , containers >=0.5.11 && <0.7+ , containers >=0.5.11 && <0.8 , indexed-traversable ^>=0.1.2+ , witherable >=0.5 exposed-modules: Data.Map.Deep
src/Data/Map/Deep.hs view
@@ -12,8 +12,8 @@ module Data.Map.Deep ( -- * Map type DeepMap (..)- , onBare2- , onNest2+ , onCore2+ , onWrap2 -- * Construction , empty@@ -322,10 +322,13 @@ -- * Conversion , elems , elems1+ , elemsDeep , keys+ , keysSet+ , keysDeep , assocs , assocs1- , keysSet+ , assocsDeep , invertKeys -- ** Lists@@ -336,7 +339,7 @@ , toDescList -- * Filter- , filter+ , Data.Map.Deep.filter , filter1 , filter2 , filter3@@ -373,7 +376,8 @@ , takeWhileAntitone , dropWhileAntitone , spanAntitone- , mapMaybe+ , Data.Map.Deep.mapMaybe+ , mapMaybeWithKeys , mapShallowMaybe , mapShallowMaybeWithKey , mapMaybeWithKey1@@ -382,6 +386,7 @@ , mapMaybeWithKey4 , mapMaybeWithKey5 , mapEither+ , mapEitherWithKeys , mapShallowEither , mapShallowEitherWithKey , mapEitherWithKey1@@ -429,11 +434,11 @@ -- * Deep , Deep- , pattern Deep1- , pattern Deep2- , pattern Deep3- , pattern Deep4- , pattern Deep5+ , pattern D1+ , pattern D2+ , pattern D3+ , pattern D4+ , pattern D5 ) where @@ -443,6 +448,7 @@ import Data.Either (isLeft) import Data.Foldable (Foldable (fold, foldl', foldr', toList)) import Data.Foldable.WithIndex+import Data.Function ((&)) import Data.Functor ((<&>)) import Data.Functor.Compose (Compose (..)) import Data.Functor.Const (Const (..))@@ -456,6 +462,13 @@ import Data.Set qualified as Set import Data.Traversable.WithIndex import GHC.Generics+import Witherable+ ( Filterable+ , FilterableWithIndex+ , Witherable+ , WitherableWithIndex+ )+import Witherable qualified import Prelude hiding ( drop , filter@@ -467,48 +480,48 @@ ) data DeepMap (ks :: [Type]) (v :: Type) :: Type where- Bare :: {getBare :: v} -> DeepMap '[] v- Nest :: (Ord k) => {getNest :: Map k (DeepMap ks v)} -> DeepMap (k ': ks) v+ Core :: {getCore :: v} -> DeepMap '[] v+ Wrap :: (Ord k) => {getWrap :: Map k (DeepMap ks v)} -> DeepMap (k ': ks) v instance (Eq v) => Eq (DeepMap '[] v) where (==) :: (Eq v) => DeepMap '[] v -> DeepMap '[] v -> Bool- Bare v1 == Bare v2 = v1 == v2+ Core v1 == Core v2 = v1 == v2 instance (Eq k, Eq (DeepMap ks v)) => Eq (DeepMap (k ': ks) v) where (==) :: (Eq k, Eq (DeepMap ks v)) => (DeepMap (k : ks) v -> DeepMap (k : ks) v -> Bool)- Nest v1 == Nest v2 = v1 == v2+ Wrap v1 == Wrap v2 = v1 == v2 instance (Ord v) => Ord (DeepMap '[] v) where (<=) :: (Ord v) => DeepMap '[] v -> DeepMap '[] v -> Bool- Bare v1 <= Bare v2 = v1 <= v2+ Core v1 <= Core v2 = v1 <= v2 instance (Ord k, Ord (DeepMap ks v)) => Ord (DeepMap (k ': ks) v) where (<=) :: (Ord k, Ord (DeepMap ks v)) => DeepMap (k : ks) v -> DeepMap (k : ks) v -> Bool- Nest v1 <= Nest v2 = v1 <= v2+ Wrap v1 <= Wrap v2 = v1 <= v2 instance (Show v) => Show (DeepMap '[] v) where- show (Bare v) = "Bare " <> show v+ show (Core v) = "Core " <> show v instance (Show k, Show (DeepMap ks v)) => Show (DeepMap (k ': ks) v) where- show (Nest v) = "Nest {" <> show v <> "}"+ show (Wrap v) = "Wrap {" <> show v <> "}" instance (Semigroup v) => Semigroup (DeepMap '[] v) where- (<>) = onBare2 (<>)+ (<>) = onCore2 (<>) instance (Ord k, Semigroup (DeepMap ks v)) => Semigroup (DeepMap (k ': ks) v) where- (<>) = onNest2 $ Map.unionWith (<>)+ (<>) = onWrap2 $ Map.unionWith (<>) instance (Monoid v) => Monoid (DeepMap '[] v) where- mempty = Bare mempty+ mempty = Core mempty instance (Ord k, Semigroup (DeepMap ks v)) => Monoid (DeepMap (k ': ks) v) where- mempty = Nest mempty+ mempty = Wrap mempty deriving instance Functor (DeepMap ks) @@ -516,11 +529,25 @@ deriving instance Traversable (DeepMap ks) +instance Filterable (DeepMap '[]) where+ mapMaybe f (Core v) = maybe (error "DeepMap: mapMaybe shrink on Core") Core $ f v+instance Witherable (DeepMap '[]) where+ wither f (Core v) = maybe (error "DeepMap: withered Core") Core <$> f v++instance Filterable (DeepMap (k ': ks)) where+ mapMaybe = Data.Map.Deep.mapMaybe++instance+ (Witherable (DeepMap ks)) =>+ Witherable (DeepMap (k ': ks))+ where+ wither f (Wrap m) = Wrap <$> traverse (Witherable.wither f) m+ -- | For use with indexed maps, folds, and traversals. type Deep :: [Type] -> Type data Deep ks where- Deep0 :: Deep '[]- Deep1 :: (Ord k) => k -> Deep ks -> Deep (k ': ks)+ D0 :: Deep '[]+ D1 :: (Ord k) => k -> Deep ks -> Deep (k ': ks) deriving instance Eq (Deep '[]) @@ -532,28 +559,30 @@ deriving instance (Ord k, Ord (Deep ks)) => Ord (Deep (k ': ks)) -pattern Deep2 ::+deriving instance (Show k, Show (Deep ks)) => Show (Deep (k ': ks))++pattern D2 :: (Ord k0, Ord k1) => (k0 -> k1 -> Deep ks -> Deep (k0 ': k1 ': ks))-pattern Deep2 k0 k1 ks = Deep1 k0 (Deep1 k1 ks)+pattern D2 k0 k1 ks = D1 k0 (D1 k1 ks) -{-# COMPLETE Deep2 #-}+{-# COMPLETE D2 #-} -pattern Deep3 ::+pattern D3 :: (Ord k0, Ord k1, Ord k2) => (k0 -> k1 -> k2 -> Deep ks -> Deep (k0 ': k1 ': k2 ': ks))-pattern Deep3 k0 k1 k2 ks = Deep1 k0 (Deep2 k1 k2 ks)+pattern D3 k0 k1 k2 ks = D1 k0 (D2 k1 k2 ks) -{-# COMPLETE Deep3 #-}+{-# COMPLETE D3 #-} -pattern Deep4 ::+pattern D4 :: (Ord k0, Ord k1, Ord k2, Ord k3) => (k0 -> k1 -> k2 -> k3 -> Deep ks -> Deep (k0 ': k1 ': k2 ': k3 ': ks))-pattern Deep4 k0 k1 k2 k3 ks = Deep1 k0 (Deep3 k1 k2 k3 ks)+pattern D4 k0 k1 k2 k3 ks = D1 k0 (D3 k1 k2 k3 ks) -{-# COMPLETE Deep4 #-}+{-# COMPLETE D4 #-} -pattern Deep5 ::+pattern D5 :: (Ord k0, Ord k1, Ord k2, Ord k3, Ord k4) => k0 -> k1 ->@@ -561,9 +590,9 @@ k3 -> k4 -> (Deep ks -> Deep (k0 ': k1 ': k2 ': k3 ': k4 ': ks))-pattern Deep5 k0 k1 k2 k3 k4 ks = Deep1 k0 (Deep4 k1 k2 k3 k4 ks)+pattern D5 k0 k1 k2 k3 k4 ks = D1 k0 (D4 k1 k2 k3 k4 ks) -{-# COMPLETE Deep5 #-}+{-# COMPLETE D5 #-} instance FunctorWithIndex (Deep ks) (DeepMap ks) @@ -574,33 +603,47 @@ (Applicative f) => ((Deep ks -> a -> f b) -> DeepMap ks a -> f (DeepMap ks b)) itraverse f = \case- Bare v -> Bare <$> f Deep0 v- Nest m -> Nest <$> itraverse (itraverse . (f .) . Deep1) m+ Core v -> Core <$> f D0 v+ Wrap m -> Wrap <$> itraverse (itraverse . (f .) . D1) m +instance Witherable.FilterableWithIndex (Deep (k ': ks)) (DeepMap (k ': ks))++instance Witherable.FilterableWithIndex (Deep '[]) (DeepMap '[]) where+ imapMaybe f (Core v) = maybe (error "DeepMap: imapMaybe shrink on Core") Core $ f D0 v++instance Witherable.WitherableWithIndex (Deep '[]) (DeepMap '[]) where+ iwither f (Core v) = maybe (error "DeepMap: iwithered Core") Core <$> f D0 v++instance+ (Witherable.WitherableWithIndex (Deep ks) (DeepMap ks)) =>+ Witherable.WitherableWithIndex (Deep (k ': ks)) (DeepMap (k ': ks))+ where+ iwither f (Wrap m) = Wrap <$> itraverse (Witherable.iwither . (f .) . D1) m+ deriving instance (Typeable v) => Typeable (DeepMap '[] v) deriving instance (Typeable k, Typeable (DeepMap ks v)) => Typeable (DeepMap (k ': ks) v) tyDeepMap :: DataType-tyDeepMap = mkDataType "Data.Map.Monoidal.Deep.DeepMap" [conBare, conNest]+tyDeepMap = mkDataType "Data.Map.Monoidal.Deep.DeepMap" [conCore, conWrap] -conBare, conNest :: Constr-conBare = mkConstr tyDeepMap "Bare" [] Data.Data.Prefix-conNest = mkConstr tyDeepMap "Nest" [] Data.Data.Prefix+conCore, conWrap :: Constr+conCore = mkConstr tyDeepMap "Core" [] Data.Data.Prefix+conWrap = mkConstr tyDeepMap "Wrap" [] Data.Data.Prefix instance (Data v) => Data (DeepMap '[] v) where dataTypeOf :: (Data v) => DeepMap '[] v -> DataType dataTypeOf _ = tyDeepMap toConstr :: (Data v) => DeepMap '[] v -> Constr- toConstr (Bare _) = conBare+ toConstr (Core _) = conCore gunfold :: (Data v) => (forall b r. (Data b) => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (DeepMap '[] v)- gunfold k z _ = k (z Bare)+ gunfold k z _ = k (z Core) instance ( Ord k@@ -628,7 +671,7 @@ , Data (DeepMap ks v) ) => (DeepMap (k : ks) v -> Constr)- toConstr (Nest _) = conNest+ toConstr (Wrap _) = conWrap gunfold :: ( Ord k , Data k@@ -640,14 +683,14 @@ (forall r. r -> c r) -> Constr -> c (DeepMap (k : ks) v)- gunfold k z _ = k (z Nest)+ gunfold k z _ = k (z Wrap) instance (Generic v) => Generic (DeepMap '[] v) where type Rep (DeepMap '[] v) = Const v from :: (Generic v) => DeepMap '[] v -> Const v x- from (Bare v) = Const v+ from (Core v) = Const v to :: (Generic v) => Const v x -> DeepMap '[] v- to (Const v) = Bare v+ to (Const v) = Core v instance (Ord k, Generic k, Generic (DeepMap ks v)) =>@@ -661,93 +704,105 @@ to :: (Ord k, Generic k, Generic (DeepMap ks v)) => (Rep (DeepMap (k : ks) v) x -> DeepMap (k : ks) v)- to (Compose kvs) = Nest . Map.fromList $ (\(Const k :*: dm') -> (k, to dm')) <$> kvs+ to (Compose kvs) = Wrap . Map.fromList $ kvs <&> \(Const k :*: dm') -> (k, to dm') -- | Apply a two-argument function through a shallow 'DeepMap', akin to 'liftA2'.-onBare2 :: (v -> w -> x) -> DeepMap '[] v -> DeepMap '[] w -> DeepMap '[] x-onBare2 f (Bare v) (Bare w) = Bare $ f v w+onCore2 :: (v -> w -> x) -> DeepMap '[] v -> DeepMap '[] w -> DeepMap '[] x+onCore2 f (Core v) (Core w) = Core $ f v w -- | Apply a two-argument function through a shallow 'DeepMap', akin to 'liftA2'.-onBare2F ::+onCore2F :: (Functor f) => (v -> w -> f x) -> DeepMap '[] v -> DeepMap '[] w -> f (DeepMap '[] x)-onBare2F f (Bare v) (Bare w) = Bare <$> f v w+onCore2F f (Core v) (Core w) = Core <$> f v w -- | Apply a two-argument 'Map' function through a deep 'DeepMap', akin to 'liftA2'.-onNest2 ::+onWrap2 :: (Map k (DeepMap ks v) -> Map k (DeepMap ls w) -> Map k (DeepMap ms x)) -> DeepMap (k ': ks) v -> DeepMap (k ': ls) w -> DeepMap (k ': ms) x-onNest2 f (Nest v) (Nest w) = Nest $ f v w+onWrap2 f (Wrap v) (Wrap w) = Wrap $ f v w -- | Half of the isomorphism of a depth-1 'DeepMap' to a 'Data.Map.Strict.Map'. See also 'fromMap'.-toMap :: DeepMap (k ': '[]) v -> Map k v-toMap (Nest m) = getBare <$> m+toMap :: DeepMap '[k] v -> Map k v+toMap (Wrap m) = getCore <$> m -- | Half of the isomorphism of a depth-1 'DeepMap' to a 'Data.Map.Strict.Map'. See also 'toMap'. fromMap :: (Ord k) => Map k v -> DeepMap '[k] v-fromMap m = Nest (Bare <$> m)+fromMap m = Wrap (Core <$> m) -- | A singleton 'DeepMap'. Use with '(@|)' to create deep nestings: -- -- >>> "Outer" @> 0 @| [5]--- Nest {fromList [("Outer",Nest {fromList [(0,Bare [5])]})]}+-- Wrap {fromList [("Outer",Wrap {fromList [(0,Core [5])]})]} infixr 6 @> (@>) :: (Ord k) => k -> DeepMap ks v -> DeepMap (k ': ks) v-k @> a = Nest $ Map.singleton k a+k @> a = Wrap $ Map.singleton k a {-# INLINE (@>) #-} -- | Infix synonym for 'singleton'. Use with '(@>)' to create deep nestings: -- -- >>> "Outer" @> 0 @| [5]--- Nest {fromList [("Outer",Nest {fromList [(0,Bare [5])]})]}+-- Wrap {fromList [("Outer",Wrap {fromList [(0,Core [5])]})]} infixr 6 @| (@|) :: (Ord k) => k -> v -> DeepMap '[k] v-k @| a = Nest . Map.singleton k $ Bare a+k @| a = Wrap $ Map.singleton k (Core a) {-# INLINE (@|) #-} deep :: Deep ks -> v -> DeepMap ks v deep js v = case js of- Deep0 -> Bare v- Deep1 k ks -> k @> deep ks v+ D0 -> Core v+ D1 k ks -> k @> deep ks v -- | /O(1)/. The empty, arbitrary positive-depth 'DeepMap'. empty :: (Ord k) => DeepMap (k ': ks) v-empty = Nest Map.empty+empty = Wrap Map.empty -- | /O(1)/. A depth-1 'DeepMap' with a single key/value pair. singleton :: (Ord k) => k -> v -> DeepMap '[k] v-singleton k v = Nest . Map.singleton k $ Bare v+singleton k v = Wrap $ Map.singleton k (Core v) -- | /O(n)/. Return all submaps of the map in ascending order of its keys. Subject to list fusion. elems :: DeepMap (k ': ks) v -> [DeepMap ks v]-elems (Nest m) = Map.elems m+elems (Wrap m) = Map.elems m +-- | /O(n)/. Return all values of the 'DeepMap' at distinct key chains.+elemsDeep :: DeepMap ks v -> [v]+elemsDeep = fmap snd . assocsDeep+ -- | /O(n)/. Return all values of the singly-nested map in ascending order of its keys. Subject to list fusion. elems1 :: DeepMap '[k] v -> [v]-elems1 m = getBare <$> elems m+elems1 m = getCore <$> elems m -- | /O(n)/. Return all keys of the map in ascending order. Subject to list fusion. keys :: DeepMap (k ': ks) v -> [k]-keys (Nest m) = Map.keys m+keys (Wrap m) = Map.keys m +-- | /O(n)/. Return all distinct key chains of the 'DeepMap'.+keysDeep :: DeepMap ks v -> [Deep ks]+keysDeep = fmap fst . assocsDeep+ -- | /O(n)/. Return all pairs of the map in ascending key order. Subject to list fusion. assocs :: DeepMap (k ': ks) v -> [(k, DeepMap ks v)]-assocs (Nest m) = Map.assocs m+assocs (Wrap m) = Map.assocs m +-- | /O(n)/. Return all keychain-value pairs of the 'DeepMap'.+assocsDeep :: DeepMap ks v -> [(Deep ks, v)]+assocsDeep = ifoldMap ((pure .) . (,))+ -- | /O(n)/. Return all pairs of the singly-nested map in ascending key order. Subject to list fusion. assocs1 :: DeepMap '[k] v -> [(k, v)]-assocs1 dm = fmap getBare <$> assocs dm+assocs1 dm = fmap getCore <$> assocs dm -- | /O(n)/. The set of all keys of the map. keysSet :: DeepMap (k ': ks) v -> Set k-keysSet (Nest m) = Map.keysSet m+keysSet (Wrap m) = Map.keysSet m -- | /O(n log n)/. Build a deeper 'DeepMap' from a list of key/'DeepMap' pairs. -- If the list contains more than one value for the same key,@@ -755,7 +810,7 @@ fromList :: (Ord k, Semigroup (DeepMap ks v)) => ([(k, DeepMap ks v)] -> DeepMap (k ': ks) v)-fromList kvs = Nest $ Map.fromListWith (flip (<>)) kvs+fromList kvs = Wrap $ Map.fromListWith (flip (<>)) kvs fromListDeep :: (Monoid (DeepMap ks v)) =>@@ -809,12 +864,12 @@ (DeepMap ks v -> DeepMap ks v -> DeepMap ks v) -> [(k, DeepMap ks v)] -> DeepMap (k ': ks) v-fromListWith f kvs = Nest $ Map.fromListWith f kvs+fromListWith f kvs = Wrap $ Map.fromListWith f kvs -- | /O(n log n)/. Build a depth-1 'DeepMap' from a list of key/value pairs -- using the provided combining function. fromListWith1 :: (Ord k) => (v -> v -> v) -> [(k, v)] -> DeepMap '[k] v-fromListWith1 f kvs = Nest $ Bare <$> Map.fromListWith f kvs+fromListWith1 f kvs = Wrap $ Core <$> Map.fromListWith f kvs -- | /O(n log n)/. Build a deeper 'DeepMap' from a list of key/'DeepMap' pairs with a combining function. fromListWithKey ::@@ -822,11 +877,11 @@ (k -> DeepMap ks v -> DeepMap ks v -> DeepMap ks v) -> [(k, DeepMap ks v)] -> DeepMap (k ': ks) v-fromListWithKey f kvs = Nest $ Map.fromListWithKey f kvs+fromListWithKey f kvs = Wrap $ Map.fromListWithKey f kvs -- | /O(n log n)/. Build a depth-1 'DeepMap' from a list of key/value pairs with a combining function. fromListWithKey1 :: (Ord k) => (k -> v -> v -> v) -> [(k, v)] -> DeepMap '[k] v-fromListWithKey1 f kvs = Nest $ Bare <$> Map.fromListWithKey f kvs+fromListWithKey1 f kvs = Wrap $ Core <$> Map.fromListWithKey f kvs -- | /O(n log n)/. Build a depth-2 'DeepMap' from a list of keys and values with a combining function. fromListWithKey2 ::@@ -835,9 +890,8 @@ [(k0, k1, v)] -> DeepMap '[k0, k1] v fromListWithKey2 f kvs =- fromListWithKey (unionWithKey1 . f)- $ (\(k0, k1, v) -> (k0, k1 @| v))- <$> kvs+ fromListWithKey (unionWithKey1 . f) $+ kvs <&> \(k0, k1, v) -> (k0, k1 @| v) -- | /O(n log n)/. Build a depth-3 'DeepMap' from a list of keys and values with a combining function. fromListWithKey3 ::@@ -846,9 +900,8 @@ [(k0, k1, k2, v)] -> DeepMap '[k0, k1, k2] v fromListWithKey3 f kvs =- fromListWithKey (unionWithKey2 . f)- $ (\(k0, k1, k2, v) -> (k0, k1 @> k2 @| v))- <$> kvs+ fromListWithKey (unionWithKey2 . f) $+ kvs <&> \(k0, k1, k2, v) -> (k0, k1 @> k2 @| v) -- | /O(n log n)/. Build a depth-3 'DeepMap' from a list of keys and values with a combining function. fromListWithKey4 ::@@ -857,9 +910,8 @@ [(k0, k1, k2, k3, v)] -> DeepMap '[k0, k1, k2, k3] v fromListWithKey4 f kvs =- fromListWithKey (unionWithKey3 . f)- $ (\(k0, k1, k2, k3, v) -> (k0, k1 @> k2 @> k3 @| v))- <$> kvs+ fromListWithKey (unionWithKey3 . f) $+ kvs <&> \(k0, k1, k2, k3, v) -> (k0, k1 @> k2 @> k3 @| v) -- | /O(n log n)/. Build a depth-3 'DeepMap' from a list of keys and values with a combining function. fromListWithKey5 ::@@ -868,9 +920,8 @@ [(k0, k1, k2, k3, k4, v)] -> DeepMap '[k0, k1, k2, k3, k4] v fromListWithKey5 f kvs =- fromListWithKey (unionWithKey4 . f)- $ (\(k0, k1, k2, k3, k4, v) -> (k0, k1 @> k2 @> k3 @> k4 @| v))- <$> kvs+ fromListWithKey (unionWithKey4 . f) $+ kvs <&> \(k0, k1, k2, k3, k4, v) -> (k0, k1 @> k2 @> k3 @> k4 @| v) -- | /O(log n)/. Insert a key/'DeepMap' pair into the 'DeepMap'. If the key is already -- present in the map, the associated value is combined with the new value as @old '<>' new@.@@ -882,7 +933,7 @@ DeepMap ks v -> DeepMap (k ': ks) v -> DeepMap (k ': ks) v-insert k dm (Nest m) = Nest $ Map.insertWith (flip (<>)) k dm m+insert k dm (Wrap m) = Wrap $ Map.insertWith (flip (<>)) k dm m insertDeep :: (Ord k, Semigroup (DeepMap ks v)) =>@@ -890,7 +941,7 @@ v -> DeepMap (k ': ks) v -> DeepMap (k ': ks) v-insertDeep (Deep1 k0 ks) = insert k0 . deep ks+insertDeep (D1 k0 ks) = insert k0 . deep ks -- | /O(log n)/. Insert a new key and value into a depth-1 'DeepMap'. If the key is already -- present in the map, the associated value is combined with the new value as @old '<>' new@.@@ -961,7 +1012,7 @@ -- present in the map, the associated value is replaced by the new value. overwrite :: (Ord k) => k -> DeepMap ks v -> DeepMap (k ': ks) v -> DeepMap (k ': ks) v-overwrite k v (Nest m) = Nest $ Map.insert k v m+overwrite k v (Wrap m) = Wrap $ Map.insert k v m overwriteDeep :: (Ord k, Semigroup (DeepMap ks v)) =>@@ -969,18 +1020,18 @@ v -> DeepMap (k ': ks) v -> DeepMap (k ': ks) v-overwriteDeep (Deep1 k0 ks) = overwrite k0 . deep ks+overwriteDeep (D1 k0 ks) = overwrite k0 . deep ks -- | /O(log n)/. Insert a new key/value pair into a depth-1 'DeepMap'. If the key is already -- present in the map, the associated value is replaced by the new value. overwrite1 :: (Ord k) => k -> v -> DeepMap '[k] v -> DeepMap '[k] v-overwrite1 k v = overwrite k (Bare v)+overwrite1 k v = overwrite k (Core v) -- | /O(log n)/. Insert a new key-chain/value pair into a depth-2 'DeepMap'. If the key is already -- present in the map, the associated value is replaced by the new value. overwrite2 :: (Ord k0, Ord k1) => k0 -> k1 -> v -> DeepMap '[k0, k1] v -> DeepMap '[k0, k1] v-overwrite2 k0 k1 v m = overwrite k0 (overwrite k1 (Bare v) . fromMaybe empty $ m @? k0) m+overwrite2 k0 k1 v m = overwrite k0 (overwrite k1 (Core v) . fromMaybe empty $ m @? k0) m -- | /O(log n)/. Insert a new key-chain/value pair into a depth-3 'DeepMap'. If the key is already -- present in the map, the associated value is replaced by the new value.@@ -1029,7 +1080,7 @@ DeepMap ks v -> DeepMap (k ': ks) v -> (Maybe (DeepMap ks v), DeepMap (k ': ks) v)-overwriteLookup k v (Nest m) = Nest <$> Map.insertLookupWithKey (const const) k v m+overwriteLookup k v (Wrap m) = Wrap <$> Map.insertLookupWithKey (const const) k v m overwriteLookupDeep :: (Ord k, Semigroup (DeepMap ks v)) =>@@ -1037,7 +1088,7 @@ v -> DeepMap (k ': ks) v -> (Maybe (DeepMap ks v), DeepMap (k ': ks) v)-overwriteLookupDeep (Deep1 k0 ks) = overwriteLookup k0 . deep ks+overwriteLookupDeep (D1 k0 ks) = overwriteLookup k0 . deep ks -- | /O(log n)/. Combines replacement and retrieval at depth 1. overwriteLookup1 ::@@ -1102,7 +1153,7 @@ DeepMap ks v -> DeepMap (k ': ks) v -> DeepMap (k ': ks) v-insertWith f k v (Nest m) = Nest $ Map.insertWith f k v m+insertWith f k v (Wrap m) = Wrap $ Map.insertWith f k v m -- | /O(log n)/. Insert with a function, combining new value and old value -- using the supplied function.@@ -1111,7 +1162,7 @@ -- or overwrite with @old ~~ new@ if there was already a value @old@ at @k@. insertWith1 :: (Ord k) => (v -> v -> v) -> k -> v -> DeepMap '[k] v -> DeepMap '[k] v-insertWith1 f k v = insertWith (onBare2 f) k (Bare v)+insertWith1 f k v = insertWith (onCore2 f) k (Core v) -- | /O(log n)/. Insert with a function, combining new value and old value -- using the supplied function.@@ -1188,13 +1239,13 @@ DeepMap ks v -> DeepMap (k ': ks) v -> DeepMap (k ': ks) v-insertWithKey f k v (Nest m) = Nest $ Map.insertWithKey f k v m+insertWithKey f k v (Wrap m) = Wrap $ Map.insertWithKey f k v m -- | /O(log n)/. Insert with a function, combining new value and old value -- using the supplied function with access to the given keys. insertWithKey1 :: (Ord k) => (k -> v -> v -> v) -> k -> v -> DeepMap '[k] v -> DeepMap '[k] v-insertWithKey1 f k v = insertWithKey (onBare2 . f) k (Bare v)+insertWithKey1 f k v = insertWithKey (onCore2 . f) k (Core v) -- | /O(log n)/. Insert with a function, combining new value and old value -- using the supplied function with access to the given keys.@@ -1268,7 +1319,7 @@ DeepMap ks v -> DeepMap (k ': ks) v -> (Maybe (DeepMap ks v), DeepMap (k ': ks) v)-insertLookupWithKey f k v (Nest m) = Nest <$> Map.insertLookupWithKey f k v m+insertLookupWithKey f k v (Wrap m) = Wrap <$> Map.insertLookupWithKey f k v m -- | /O(log n)/. Combines insertion and retrieval. insertLookupWithKey1 ::@@ -1332,7 +1383,7 @@ -- | /O(log n)/. Delete a key and its value from the map, or do nothing if the key is missing. delete :: (Ord k) => k -> DeepMap (k ': ks) v -> DeepMap (k ': ks) v-delete k (Nest m) = Nest $ Map.delete k m+delete k (Wrap m) = Wrap $ Map.delete k m deleteDeep :: (Monoid v) =>@@ -1340,8 +1391,8 @@ DeepMap ks v -> DeepMap ks v deleteDeep = \cases- Deep0 _ -> mempty- (Deep1 k ks) m -> case m @? k of+ D0 _ -> mempty+ (D1 k ks) m -> case m @? k of Nothing -> m Just dm -> overwrite k (deleteDeep ks dm) m @@ -1403,12 +1454,12 @@ k -> DeepMap (k ': ks) v -> DeepMap (k ': ks) v-adjust f k (Nest m) = Nest $ Map.adjust f k m+adjust f k (Wrap m) = Wrap $ Map.adjust f k m adjustDeep :: (v -> v) -> Deep ks -> DeepMap ks v -> DeepMap ks v adjustDeep f = \cases- Deep0 (Bare v) -> Bare (f v)- (Deep1 k ks) (Nest m) -> Nest $ Map.adjust (adjustDeep f ks) k m+ D0 (Core v) -> Core (f v)+ (D1 k ks) (Wrap m) -> Wrap $ Map.adjust (adjustDeep f ks) k m -- | /O(log n)/. Change a value at a specific key with the result of the provided function, -- or do nothing if the key is missing.@@ -1481,7 +1532,7 @@ k -> DeepMap (k ': ks) v -> DeepMap (k ': ks) v-adjustWithKey f k (Nest m) = Nest $ Map.adjustWithKey f k m+adjustWithKey f k (Wrap m) = Wrap $ Map.adjustWithKey f k m -- | /O(log n)/. Change a value at a specific key with access to the key itself, -- or do nothing if the key is missing.@@ -1555,7 +1606,7 @@ k -> DeepMap (k ': ks) v -> DeepMap (k ': ks) v-update f k (Nest m) = Nest $ Map.update f k m+update f k (Wrap m) = Wrap $ Map.update f k m updateDeep :: (Monoid v) =>@@ -1564,8 +1615,8 @@ DeepMap ks v -> DeepMap ks v updateDeep f = \cases- Deep0 (Bare v) -> maybe mempty Bare (f v)- (Deep1 k ks) (Nest m) -> Nest $ Map.adjust (updateDeep f ks) k m+ D0 (Core v) -> maybe mempty Core (f v)+ (D1 k ks) (Wrap m) -> Wrap $ Map.adjust (updateDeep f ks) k m -- | /O(log n)/. Change a 'DeepMap' at a specific key. If the function evaluates to 'Nothing', -- the key and submap are removed. If the key is missing, do nothing.@@ -1639,7 +1690,7 @@ k -> DeepMap (k ': ks) v -> DeepMap (k ': ks) v-updateWithKey f k (Nest m) = Nest $ Map.updateWithKey f k m+updateWithKey f k (Wrap m) = Wrap $ Map.updateWithKey f k m -- | /O(log n)/. Change a value at a specific key with access to the key itself. -- If the function evaluates to 'Nothing', the key and value are removed.@@ -1719,7 +1770,7 @@ k -> DeepMap (k ': ks) v -> (Maybe (DeepMap ks v), DeepMap (k ': ks) v)-updateLookupWithKey f k (Nest m) = Nest <$> Map.updateLookupWithKey f k m+updateLookupWithKey f k (Wrap m) = Wrap <$> Map.updateLookupWithKey f k m -- | /O(log n)/. Combines change and retrieval. updateLookupWithKey1 ::@@ -1783,7 +1834,7 @@ k -> DeepMap (k ': ks) v -> DeepMap (k ': ks) v-alter f k (Nest m) = Nest $ Map.alter f k m+alter f k (Wrap m) = Wrap $ Map.alter f k m alterDeep :: (Monoid v) =>@@ -1792,13 +1843,13 @@ DeepMap ks v -> DeepMap ks v alterDeep f = \cases- Deep0 (Bare v) -> maybe mempty Bare (f (Just v))- (Deep1 k ks) (Nest m) -> Nest $ Map.adjust (alterDeep f ks) k m+ D0 (Core v) -> maybe mempty Core (f (Just v))+ (D1 k ks) (Wrap m) -> Wrap $ Map.adjust (alterDeep f ks) k m -- | /O(log n)/. Can be used to 'insert', 'overwrite', 'delete', or 'update' a value. alter1 :: (Ord k) => (Maybe v -> Maybe v) -> k -> DeepMap '[k] v -> DeepMap '[k] v-alter1 f = alter (fmap Bare . f . fmap getBare)+alter1 f = alter (fmap Core . f . fmap getCore) -- | /O(log n)/. Can be used to 'insert', 'overwrite', 'delete', or 'update' a value. alter2 ::@@ -1860,7 +1911,7 @@ k -> DeepMap (k ': ks) v -> f (DeepMap (k ': ks) v)-alterF f k (Nest m) = Nest <$> Map.alterF f k m+alterF f k (Wrap m) = Wrap <$> Map.alterF f k m alterFDeep :: (Monoid v, Applicative f) =>@@ -1869,8 +1920,8 @@ DeepMap ks v -> f (DeepMap ks v) alterFDeep f = \cases- Deep0 (Bare v) -> maybe mempty Bare <$> f (Just v)- (Deep1 k ks) (Nest m) -> Nest <$> Map.alterF (traverse (alterFDeep f ks)) k m+ D0 (Core v) -> maybe mempty Core <$> f (Just v)+ (D1 k ks) (Wrap m) -> Wrap <$> Map.alterF (traverse (alterFDeep f ks)) k m alterF1 :: (Functor f, Ord k) =>@@ -1878,7 +1929,7 @@ k -> DeepMap '[k] v -> f (DeepMap '[k] v)-alterF1 f = alterF (fmap (fmap Bare) . f . fmap getBare)+alterF1 f = alterF (fmap (fmap Core) . f . fmap getCore) alterF2 :: (Functor f, Ord k0, Ord k1) =>@@ -1936,16 +1987,16 @@ -- | /O(log n)/. Lookup the value at a key. lookup :: (Ord k) => k -> DeepMap (k ': ks) v -> Maybe (DeepMap ks v)-lookup k (Nest m) = Map.lookup k m+lookup k (Wrap m) = Map.lookup k m lookupDeep :: Deep ks -> DeepMap ks v -> Maybe v lookupDeep = \cases- Deep0 (Bare v) -> pure v- (Deep1 k ks) m -> lookupDeep ks =<< m @? k+ D0 (Core v) -> pure v+ (D1 k ks) m -> lookupDeep ks =<< m @? k -- | /O(log n)/. Lookup the value at a key. lookup1 :: (Ord k) => k -> DeepMap '[k] v -> Maybe v-lookup1 k (Nest m) = getBare <$> Map.lookup k m+lookup1 k (Wrap m) = getCore <$> Map.lookup k m -- | /O(log n)/. A flipped, infix variant of 'lookup'. (@?) :: (Ord k) => DeepMap (k ': ks) v -> k -> Maybe (DeepMap ks v)@@ -2022,35 +2073,35 @@ -- | /O(log n)/. Is the key a member of the map? See also 'notMember'. member :: (Ord k) => k -> DeepMap (k ': ks) v -> Bool-member k (Nest m) = Map.member k m+member k (Wrap m) = Map.member k m -- | /O(log n)/. Is the key missing from the map? See also 'member'. notMember :: (Ord k) => k -> DeepMap (k ': ks) v -> Bool-notMember k (Nest m) = Map.notMember k m+notMember k (Wrap m) = Map.notMember k m -- | Find the next smallest key to the given one, and return its key/value pair. lookupLT :: (Ord k) => k -> DeepMap (k ': ks) v -> Maybe (k, DeepMap ks v)-lookupLT k (Nest m) = Map.lookupLT k m+lookupLT k (Wrap m) = Map.lookupLT k m -- | Find the next largest key to the given one, and return its key/value pair. lookupGT :: (Ord k) => k -> DeepMap (k ': ks) v -> Maybe (k, DeepMap ks v)-lookupGT k (Nest m) = Map.lookupGT k m+lookupGT k (Wrap m) = Map.lookupGT k m -- | Find the largest key up to the given one, and return its key/value pair. lookupLE :: (Ord k) => k -> DeepMap (k ': ks) v -> Maybe (k, DeepMap ks v)-lookupLE k (Nest m) = Map.lookupLE k m+lookupLE k (Wrap m) = Map.lookupLE k m -- | Find the smallest key down to the given one, and return its key/value pair. lookupGE :: (Ord k) => k -> DeepMap (k ': ks) v -> Maybe (k, DeepMap ks v)-lookupGE k (Nest m) = Map.lookupGE k m+lookupGE k (Wrap m) = Map.lookupGE k m -- | /O(1)/. Is the 'DeepMap' empty? null :: DeepMap (k ': ks) v -> Bool-null (Nest m) = Map.null m+null (Wrap m) = Map.null m -- | /O(1)/. The number of outermost keys in the 'DeepMap'. size :: DeepMap (k ': ks) v -> Int-size (Nest m) = Map.size m+size (Wrap m) = Map.size m -- | /O(m log(n \/ m + 1)), m <= n/. Join two 'DeepMap's together using '(<>)' to combine -- the values of duplicate keys.@@ -2070,12 +2121,12 @@ DeepMap (k ': ks) v -> DeepMap (k ': ks) v -> DeepMap (k ': ks) v-unionWith f = onNest2 (Map.unionWith f)+unionWith f = onWrap2 (Map.unionWith f) -- | /O(m log(n \/ m + 1)), m <= n/. Join two 'DeepMap's with a combining function. unionWith1 :: (Ord k) => (v -> v -> v) -> DeepMap '[k] v -> DeepMap '[k] v -> DeepMap '[k] v-unionWith1 f = onNest2 (Map.unionWith (onBare2 f))+unionWith1 f = onWrap2 (Map.unionWith (onCore2 f)) -- | /O(m log(n \/ m + 1)), m <= n/. Join two 'DeepMap's with a combining function. unionWith2 ::@@ -2120,7 +2171,7 @@ DeepMap (k ': ks) v -> DeepMap (k ': ks) v -> DeepMap (k ': ks) v-unionWithKey f = onNest2 (Map.unionWithKey f)+unionWithKey f = onWrap2 (Map.unionWithKey f) -- | /O(m log(n \/ m + 1)), m <= n/. Join two 'DeepMap's with a combining function with access to the keys. unionWithKey1 ::@@ -2129,7 +2180,7 @@ DeepMap '[k] v -> DeepMap '[k] v -> DeepMap '[k] v-unionWithKey1 f = onNest2 (Map.unionWithKey $ onBare2 . f)+unionWithKey1 f = onWrap2 (Map.unionWithKey $ onCore2 . f) -- | /O(m log(n \/ m + 1)), m <= n/. Join two 'DeepMap's with a combining function with access to the keys. unionWithKey2 ::@@ -2191,7 +2242,7 @@ -- keeping the values of the left-hand map. difference :: (Ord k) => DeepMap (k ': ks) v -> DeepMap (k ': ls) w -> DeepMap (k ': ks) v-difference = onNest2 Map.difference+difference = onWrap2 Map.difference -- | Infix synonym for 'difference'. (\\) ::@@ -2205,7 +2256,7 @@ DeepMap (k ': ks) v -> DeepMap (k ': ls) w -> DeepMap (k ': ks) v-differenceWith f = onNest2 (Map.differenceWith f)+differenceWith f = onWrap2 (Map.differenceWith f) -- | /O(n + m)/. Difference with a combining function. Deletes keys if the value is 'Nothing'. differenceWith1 ::@@ -2214,7 +2265,7 @@ DeepMap '[k] v -> DeepMap '[k] w -> DeepMap '[k] v-differenceWith1 f = onNest2 (Map.differenceWith $ onBare2F f)+differenceWith1 f = onWrap2 (Map.differenceWith $ onCore2F f) -- | /O(n + m)/. Difference with a combining function. Deletes keys if the value is 'Nothing'. differenceWithKey ::@@ -2223,7 +2274,7 @@ DeepMap (k ': ks) v -> DeepMap (k ': ls) w -> DeepMap (k ': ks) v-differenceWithKey f = onNest2 (Map.differenceWithKey f)+differenceWithKey f = onWrap2 (Map.differenceWithKey f) -- | /O(n + m)/. Difference with a combining function. Deletes keys if the value is 'Nothing'. differenceWithKey1 ::@@ -2232,13 +2283,13 @@ DeepMap '[k] v -> DeepMap '[k] w -> DeepMap '[k] v-differenceWithKey1 f = onNest2 (Map.differenceWithKey $ onBare2F . f)+differenceWithKey1 f = onWrap2 (Map.differenceWithKey $ onCore2F . f) -- | /O(m log(n \/ m + 1)), m <= n/. The set-intersection of the keys in a map, -- keeping the values of the left-hand map. intersection :: (Ord k) => DeepMap (k ': ks) v -> DeepMap (k ': ls) w -> DeepMap (k ': ks) v-intersection = onNest2 Map.intersection+intersection = onWrap2 Map.intersection -- | /O(m log(n \/ m + 1)), m <= n/. Intersection with a combining function. intersectionWith ::@@ -2247,12 +2298,12 @@ DeepMap (k ': ks) v -> DeepMap (k ': ls) w -> DeepMap (k ': ms) x-intersectionWith f = onNest2 (Map.intersectionWith f)+intersectionWith f = onWrap2 (Map.intersectionWith f) -- | /O(m log(n \/ m + 1)), m <= n/. Intersection with a combining function. intersectionWith1 :: (Ord k) => (v -> w -> x) -> DeepMap '[k] v -> DeepMap '[k] w -> DeepMap '[k] x-intersectionWith1 f = onNest2 (Map.intersectionWith $ onBare2 f)+intersectionWith1 f = onWrap2 (Map.intersectionWith $ onCore2 f) -- | /O(m log(n \/ m + 1)), m <= n/. Intersection with a combining function. intersectionWithKey ::@@ -2261,7 +2312,7 @@ DeepMap (k ': ks) v -> DeepMap (k ': ls) w -> DeepMap (k ': ms) x-intersectionWithKey f = onNest2 (Map.intersectionWithKey f)+intersectionWithKey f = onWrap2 (Map.intersectionWithKey f) -- | /O(m log(n \/ m + 1)), m <= n/. Intersection with a combining function. intersectionWithKey1 ::@@ -2270,7 +2321,7 @@ DeepMap '[k] v -> DeepMap '[k] w -> DeepMap '[k] x-intersectionWithKey1 f = onNest2 (Map.intersectionWithKey $ onBare2 . f)+intersectionWithKey1 f = onWrap2 (Map.intersectionWithKey $ onCore2 . f) -- | /O(m log(n \/ m + 1)), m <= n/. Intersection with a combining function. intersectionWithKey2 ::@@ -2311,18 +2362,18 @@ -- | /O(n)/. Strictly more general than 'fmap' in that it may change the types of the inner keys. mapShallow :: (DeepMap ks v -> DeepMap ls w) -> DeepMap (k ': ks) v -> DeepMap (k ': ls) w-mapShallow f (Nest m) = Nest $ fmap f m+mapShallow f (Wrap m) = Wrap $ fmap f m -- | /O(n)/. Like 'mapShallow' but the function has access to the outer keys. mapShallowWithKey :: (k -> DeepMap ks v -> DeepMap ls w) -> DeepMap (k ': ks) v -> DeepMap (k ': ls) w-mapShallowWithKey f (Nest m) = Nest $ Map.mapWithKey f m+mapShallowWithKey f (Wrap m) = Wrap $ Map.mapWithKey f m -- | /O(n)/. Like 'fmap' but the function has access to the outer keys. mapWithKey1 :: (k -> v -> w) -> DeepMap '[k] v -> DeepMap '[k] w-mapWithKey1 f (Nest m) = Nest $ Map.mapWithKey (fmap . f) m+mapWithKey1 f (Wrap m) = Wrap $ Map.mapWithKey (fmap . f) m -- | /O(n)/. Like 'fmap' but the function has access to the outer keys. mapWithKey2 ::@@ -2354,7 +2405,7 @@ (DeepMap ks v -> f (DeepMap ls w)) -> DeepMap (k ': ks) v -> f (DeepMap (k ': ls) w)-traverseShallow f (Nest m) = Nest <$> traverse f m+traverseShallow f (Wrap m) = Wrap <$> traverse f m -- | /O(n)/. Like 'traverseShallow' but the function has access to the keys. traverseShallowWithKey ::@@ -2362,12 +2413,12 @@ (k -> DeepMap ks v -> f (DeepMap ls w)) -> DeepMap (k ': ks) v -> f (DeepMap (k ': ls) w)-traverseShallowWithKey f (Nest m) = Nest <$> Map.traverseWithKey f m+traverseShallowWithKey f (Wrap m) = Wrap <$> Map.traverseWithKey f m -- | /O(n)/. Like 'traverse' but the function has access to the keys. traverseWithKey1 :: (Applicative f) => (k -> v -> f w) -> DeepMap '[k] v -> f (DeepMap '[k] w)-traverseWithKey1 f (Nest m) = Nest <$> Map.traverseWithKey (traverse . f) m+traverseWithKey1 f (Wrap m) = Wrap <$> Map.traverseWithKey (traverse . f) m -- | /O(n)/. Like 'traverse' but the function has access to the keys. traverseWithKey2 ::@@ -2407,7 +2458,7 @@ (k -> DeepMap ks v -> f (Maybe (DeepMap ls w))) -> DeepMap (k ': ks) v -> f (DeepMap (k ': ls) w)-traverseMaybeWithKey f (Nest m) = Nest <$> Map.traverseMaybeWithKey f m+traverseMaybeWithKey f (Wrap m) = Wrap <$> Map.traverseMaybeWithKey f m -- | /O(n)/. Traverse keys/values and collect the 'Just' results. traverseMaybeWithKey1 ::@@ -2415,7 +2466,7 @@ (k -> v -> f (Maybe w)) -> DeepMap '[k] v -> f (DeepMap '[k] w)-traverseMaybeWithKey1 f (Nest m) = Nest <$> Map.traverseMaybeWithKey (\k (Bare v) -> fmap Bare <$> f k v) m+traverseMaybeWithKey1 f (Wrap m) = Wrap <$> Map.traverseMaybeWithKey (\k (Core v) -> fmap Core <$> f k v) m -- | /O(n)/. Traverse keys/values and collect the 'Just' results. traverseMaybeWithKey2 ::@@ -2455,12 +2506,12 @@ acc -> DeepMap (k ': ks) v -> (acc, DeepMap (k ': ls) w)-mapAccum f acc (Nest m) = Nest <$> Map.mapAccum f acc m+mapAccum f acc (Wrap m) = Wrap <$> Map.mapAccum f acc m -- | /O(n)/. Thread an accumulating argument through the 'DeepMap' in ascending order of keys. mapAccum1 :: (acc -> v -> (acc, w)) -> acc -> DeepMap '[k] v -> (acc, DeepMap '[k] w)-mapAccum1 f = mapAccum (\a (Bare v) -> Bare <$> f a v)+mapAccum1 f = mapAccum (\a (Core v) -> Core <$> f a v) -- | /O(n)/. Thread an accumulating argument through the 'DeepMap' in descending order of keys. mapAccumR ::@@ -2468,12 +2519,12 @@ acc -> DeepMap (k ': ks) v -> (acc, DeepMap (k ': ls) w)-mapAccumR f acc (Nest m) = Nest <$> Map.mapAccum f acc m+mapAccumR f acc (Wrap m) = Wrap <$> Map.mapAccum f acc m -- | /O(n)/. Thread an accumulating argument through the 'DeepMap' in descending order of keys. mapAccumR1 :: (acc -> v -> (acc, w)) -> acc -> DeepMap '[k] v -> (acc, DeepMap '[k] w)-mapAccumR1 f = mapAccumR (\a (Bare v) -> Bare <$> f a v)+mapAccumR1 f = mapAccumR (\a (Core v) -> Core <$> f a v) -- | /O(n)/. Like 'mapAccum' but the function has access to the keys. mapAccumWithKey ::@@ -2481,12 +2532,12 @@ acc -> DeepMap (k ': ks) v -> (acc, DeepMap (k ': ls) w)-mapAccumWithKey f acc (Nest m) = Nest <$> Map.mapAccumWithKey f acc m+mapAccumWithKey f acc (Wrap m) = Wrap <$> Map.mapAccumWithKey f acc m -- | /O(n)/. Like 'mapAccum' but the function has access to the keys. mapAccumWithKey1 :: (acc -> k -> v -> (acc, w)) -> acc -> DeepMap '[k] v -> (acc, DeepMap '[k] w)-mapAccumWithKey1 f = mapAccumWithKey (\k a (Bare v) -> Bare <$> f k a v)+mapAccumWithKey1 f = mapAccumWithKey (\k a (Core v) -> Core <$> f k a v) -- | /O(n)/. Like 'mapAccum' but the function has access to the keys. mapAccumWithKey2 ::@@ -2526,12 +2577,12 @@ acc -> DeepMap (k ': ks) v -> (acc, DeepMap (k ': ls) w)-mapAccumRWithKey f acc (Nest m) = Nest <$> Map.mapAccumRWithKey f acc m+mapAccumRWithKey f acc (Wrap m) = Wrap <$> Map.mapAccumRWithKey f acc m -- | /O(n)/. Like 'mapAccumR' but the function has access to the keys. mapAccumRWithKey1 :: (acc -> k -> v -> (acc, w)) -> acc -> DeepMap '[k] v -> (acc, DeepMap '[k] w)-mapAccumRWithKey1 f = mapAccumRWithKey (\k a (Bare v) -> Bare <$> f k a v)+mapAccumRWithKey1 f = mapAccumRWithKey (\k a (Core v) -> Core <$> f k a v) -- | /O(n)/. Like 'mapAccumR' but the function has access to the keys. mapAccumRWithKey2 ::@@ -2575,14 +2626,14 @@ (j -> k) -> DeepMap (j ': ks) v -> DeepMap (k ': ks) v-mapKeys f (Nest m) = Nest $ Map.mapKeysWith (<>) f m+mapKeys f (Wrap m) = Wrap $ Map.mapKeysWith (<>) f m mapKeysDeep :: (Monoid (DeepMap ks v)) => ((Deep js -> Deep ks) -> DeepMap js v -> DeepMap ks v) mapKeysDeep jk = \case- Bare v -> deep (jk Deep0) v- Nest (m :: Map j (DeepMap js0 v)) -> ifoldMap (mapKeysDeep . (jk .) . Deep1) m+ Core v -> deep (jk D0) v+ Wrap (m :: Map j (DeepMap js0 v)) -> ifoldMap (mapKeysDeep . (jk .) . D1) m -- | /O(n log n)/. Map a function over the keys of a 'DeepMap'. mapKeys1 :: (Ord k, Semigroup v) => (j -> k) -> DeepMap '[j] v -> DeepMap '[k] v@@ -2637,12 +2688,12 @@ (j -> k) -> DeepMap (j ': ks) v -> DeepMap (k ': ks) v-mapKeysWith (~~) f (Nest m) = Nest $ Map.mapKeysWith (~~) f m+mapKeysWith (~~) f (Wrap m) = Wrap $ Map.mapKeysWith (~~) f m -- | /O(n log n)/. Map a function over the keys of a 'DeepMap' with a value-combining function. mapKeysWith1 :: (Ord k) => (v -> v -> v) -> (j -> k) -> DeepMap '[j] v -> DeepMap '[k] v-mapKeysWith1 (~~) = mapKeysWith (onBare2 (~~))+mapKeysWith1 (~~) = mapKeysWith (onCore2 (~~)) -- | /O(n log n)/. Map a function over the keys of a 'DeepMap' with a value-combining function. mapKeysWith2 ::@@ -2697,7 +2748,7 @@ (j -> f k) -> DeepMap (j ': ks) v -> f (DeepMap (k ': ks) v)-traverseKeys f (Nest m) = Nest <$> traverseKeysMap f m+traverseKeys f (Wrap m) = Wrap <$> traverseKeysMap f m where traverseKeysMap :: (Applicative f, Ord k) => (j -> f k) -> Map j a -> f (Map k a)@@ -2710,8 +2761,8 @@ DeepMap js v -> f (DeepMap ks v) traverseKeysDeep f = \case- Bare v -> f Deep0 <&> (`deep` v)- Nest m -> fold <$> itraverse (traverseKeysDeep . (f .) . Deep1) m+ Core v -> f D0 <&> (`deep` v)+ Wrap m -> fold <$> itraverse (traverseKeysDeep . (f .) . D1) m -- | /O(n log n)/. Map an applicative function over the outer keys of the map -- and collect the results using the specified combining function.@@ -2721,7 +2772,7 @@ (j -> f k) -> DeepMap (j ': ks) v -> f (DeepMap (k ': ks) v)-traverseKeysWith (~~) f (Nest m) = Nest <$> traverseKeysWithMap (~~) f m+traverseKeysWith (~~) f (Wrap m) = Wrap <$> traverseKeysWithMap (~~) f m where traverseKeysWithMap :: (Applicative f, Ord k) => (a -> a -> a) -> (j -> f k) -> Map j a -> f (Map k a)@@ -2803,7 +2854,7 @@ (j -> m k) -> DeepMap '[j] v -> m (DeepMap '[k] v)-mapKeysMWith1 (~~) = mapKeysMWith (onBare2 (~~))+mapKeysMWith1 (~~) = mapKeysMWith (onCore2 (~~)) -- | /O(n log n)/. Map a monadic function over the keys of a 'DeepMap' with a value-combining function. mapKeysMWith2 ::@@ -2859,15 +2910,15 @@ =<< traverseShallow (mapKeysMWith4 (~~) f1 f2 f3 f4) m foldShallow :: (Monoid (DeepMap ks v)) => DeepMap (k ': ks) v -> DeepMap ks v-foldShallow (Nest m) = fold m+foldShallow (Wrap m) = fold m -- | /O(n)/. Fold the keys and submaps in the 'DeepMap' using the given right-associative binary operator. foldrWithKey :: (k -> DeepMap ks v -> b -> b) -> b -> DeepMap (k ': ks) v -> b-foldrWithKey f z (Nest m) = Map.foldrWithKey f z m+foldrWithKey f z (Wrap m) = Map.foldrWithKey f z m -- | /O(n)/. Fold the keys and values using the given right-associative binary operator. foldrWithKey1 :: (k -> v -> b -> b) -> b -> DeepMap '[k] v -> b-foldrWithKey1 f = foldrWithKey (\k (Bare v) -> f k v)+foldrWithKey1 f = foldrWithKey (\k (Core v) -> f k v) -- | /O(n)/. Fold the keys and values using the given right-associative binary operator. foldrWithKey2 :: (k0 -> k1 -> v -> b -> b) -> b -> DeepMap '[k0, k1] v -> b@@ -2893,11 +2944,11 @@ -- | /O(n)/. Fold the keys and submaps in the 'DeepMap' using the given left-associative binary operator. foldlWithKey :: (b -> k -> DeepMap ks v -> b) -> b -> DeepMap (k ': ks) v -> b-foldlWithKey f z (Nest m) = Map.foldlWithKey f z m+foldlWithKey f z (Wrap m) = Map.foldlWithKey f z m -- | /O(n)/. Fold the keys and values in the 'DeepMap' using the given left-associative binary operator. foldlWithKey1 :: (b -> k -> v -> b) -> b -> DeepMap '[k] v -> b-foldlWithKey1 f = foldlWithKey (\b k (Bare v) -> f b k v)+foldlWithKey1 f = foldlWithKey (\b k (Core v) -> f b k v) -- | /O(n)/. Fold the keys and values in the 'DeepMap' using the given left-associative binary operator. foldlWithKey2 :: (b -> k0 -> k1 -> v -> b) -> b -> DeepMap '[k0, k1] v -> b@@ -2923,11 +2974,11 @@ -- | /O(n)/. Strictly fold the keys and submaps in the 'DeepMap' using the given right-associative binary operator. foldrWithKey' :: (k -> DeepMap ks v -> b -> b) -> b -> DeepMap (k ': ks) v -> b-foldrWithKey' f z (Nest m) = Map.foldrWithKey' f z m+foldrWithKey' f z (Wrap m) = Map.foldrWithKey' f z m -- | /O(n)/. Strictly fold the keys and values using the given right-associative binary operator. foldrWithKey1' :: (k -> v -> b -> b) -> b -> DeepMap '[k] v -> b-foldrWithKey1' f = foldrWithKey' (\k (Bare v) -> f k v)+foldrWithKey1' f = foldrWithKey' (\k (Core v) -> f k v) -- | /O(n)/. Strictly fold the keys and values using the given right-associative binary operator. foldrWithKey2' :: (k0 -> k1 -> v -> b -> b) -> b -> DeepMap '[k0, k1] v -> b@@ -2953,11 +3004,11 @@ -- | /O(n)/. Strictly fold the keys and submaps in the 'DeepMap' using the given left-associative binary operator. foldlWithKey' :: (b -> k -> DeepMap ks v -> b) -> b -> DeepMap (k ': ks) v -> b-foldlWithKey' f z (Nest m) = Map.foldlWithKey' f z m+foldlWithKey' f z (Wrap m) = Map.foldlWithKey' f z m -- | /O(n)/. Strictly fold the keys and values in the 'DeepMap' using the given left-associative binary operator. foldlWithKey1' :: (b -> k -> v -> b) -> b -> DeepMap '[k] v -> b-foldlWithKey1' f = foldlWithKey' (\b k (Bare v) -> f b k v)+foldlWithKey1' f = foldlWithKey' (\b k (Core v) -> f b k v) -- | /O(n)/. Strictly fold the keys and values in the 'DeepMap' using the given left-associative binary operator. foldlWithKey2' :: (b -> k0 -> k1 -> v -> b) -> b -> DeepMap '[k0, k1] v -> b@@ -2984,11 +3035,11 @@ -- | /O(n)/. Fold the keys and submaps using the given monoid. foldMapWithKey :: (Monoid m) => (k -> DeepMap ks v -> m) -> DeepMap (k ': ks) v -> m-foldMapWithKey f (Nest m) = Map.foldMapWithKey f m+foldMapWithKey f (Wrap m) = Map.foldMapWithKey f m -- | /O(n)/. Fold the keys and values in the map using the given monoid. foldMapWithKey1 :: (Monoid m) => (k -> v -> m) -> DeepMap '[k] v -> m-foldMapWithKey1 f = foldMapWithKey (\k (Bare v) -> f k v)+foldMapWithKey1 f = foldMapWithKey (\k (Core v) -> f k v) -- | /O(n)/. Fold the keys and values in the map using the given monoid. foldMapWithKey2 ::@@ -3019,11 +3070,11 @@ -- | /O(n)/. Fold the keys and submaps using the given monoid. foldMapWithKey' :: (Monoid m) => (k -> DeepMap ks v -> m) -> DeepMap (k ': ks) v -> m-foldMapWithKey' f (Nest m) = Map.foldlWithKey' (\acc k v -> acc <> f k v) mempty m+foldMapWithKey' f (Wrap m) = Map.foldlWithKey' (\acc k v -> acc <> f k v) mempty m -- | /O(n)/. Fold the keys and values in the map using the given monoid. foldMapWithKey1' :: (Monoid m) => (k -> v -> m) -> DeepMap '[k] v -> m-foldMapWithKey1' f = foldMapWithKey' (\k (Bare v) -> f k v)+foldMapWithKey1' f = foldMapWithKey' (\k (Core v) -> f k v) -- | /O(n)/. Fold the keys and values in the map using the given monoid. foldMapWithKey2' ::@@ -3054,97 +3105,94 @@ -- | /O(n)/. Convert the map to a list of key/submap pairs where the keys are in ascending order. -- Subject to list fusion. toAscList :: DeepMap (k ': ks) v -> [(k, DeepMap ks v)]-toAscList (Nest m) = Map.toAscList m+toAscList (Wrap m) = Map.toAscList m -- | /O(n)/. Convert the map to a list of key/submap pairs where the keys are in descending order. -- Subject to list fusion. toDescList :: DeepMap (k ': ks) v -> [(k, DeepMap ks v)]-toDescList (Nest m) = Map.toDescList m+toDescList (Wrap m) = Map.toDescList m -- | /O(n)/. Filter all submaps that satisfy the predicate. filter :: (DeepMap ks v -> Bool) -> DeepMap (k ': ks) v -> DeepMap (k ': ks) v-filter p (Nest m) = Nest $ Map.filter p m+filter p (Wrap m) = Wrap $ Map.filter p m -- | /O(n)/. Filter all values that satisfy the predicate. filter1 :: (v -> Bool) -> DeepMap '[k] v -> DeepMap '[k] v-filter1 p (Nest m) = Nest $ Map.filter (p . getBare) m+filter1 p (Wrap m) = Wrap $ Map.filter (p . getCore) m -- | /O(n)/. Filter all values that satisfy the predicate. filter2 :: (v -> Bool) -> DeepMap '[k0, k1] v -> DeepMap '[k0, k1] v-filter2 p m = mapShallow (filter1 p) $ filter (any p) m+filter2 p m = mapShallow (filter1 p) $ Data.Map.Deep.filter (any p) m -- | /O(n)/. Filter all values that satisfy the predicate. filter3 :: (v -> Bool) -> DeepMap '[k0, k1, k2] v -> DeepMap '[k0, k1, k2] v-filter3 p m = mapShallow (filter2 p) $ filter (any p) m+filter3 p m = mapShallow (filter2 p) $ Data.Map.Deep.filter (any p) m -- | /O(n)/. Filter all values that satisfy the predicate. filter4 :: (v -> Bool) -> DeepMap '[k0, k1, k2, k3] v -> DeepMap '[k0, k1, k2, k3] v-filter4 p m = mapShallow (filter3 p) $ filter (any p) m+filter4 p m = mapShallow (filter3 p) $ Data.Map.Deep.filter (any p) m -- | /O(n)/. Filter all values that satisfy the predicate. filter5 :: (v -> Bool) -> DeepMap '[k0, k1, k2, k3, k4] v -> DeepMap '[k0, k1, k2, k3, k4] v-filter5 p m = mapShallow (filter4 p) $ filter (any p) m+filter5 p m = mapShallow (filter4 p) $ Data.Map.Deep.filter (any p) m -- | /O(n)/. Filter all key/submap pairs that satisfy the predicate. filterWithKey :: (k -> DeepMap ks v -> Bool) -> DeepMap (k ': ks) v -> DeepMap (k ': ks) v-filterWithKey p (Nest m) = Nest $ Map.filterWithKey p m+filterWithKey p (Wrap m) = Wrap $ Map.filterWithKey p m -- | /O(n)/. Filter all key/value pairs that satisfy the predicate. filterWithKey1 :: (k -> v -> Bool) -> DeepMap '[k] v -> DeepMap '[k] v-filterWithKey1 p m =+filterWithKey1 p = runIdentity- $ traverseMaybeWithKey1 (\k0 -> Identity . (bool (const Nothing) Just =<< p k0)) m+ . traverseMaybeWithKey1+ \k0 -> Identity . (bool (const Nothing) Just =<< p k0) -- | /O(n)/. Filter all key-chain/value pairs that satisfy the predicate. filterWithKey2 :: (k0 -> k1 -> v -> Bool) -> DeepMap '[k0, k1] v -> DeepMap '[k0, k1] v-filterWithKey2 p m =+filterWithKey2 p = runIdentity- $ traverseMaybeWithKey2- (\k0 k1 -> Identity . (bool (const Nothing) Just =<< p k0 k1))- m+ . traverseMaybeWithKey2+ \k0 k1 -> Identity . (bool (const Nothing) Just =<< p k0 k1) -- | /O(n)/. Filter all key-chain/value pairs that satisfy the predicate. filterWithKey3 :: (k0 -> k1 -> k2 -> v -> Bool) -> DeepMap '[k0, k1, k2] v -> DeepMap '[k0, k1, k2] v-filterWithKey3 p m =+filterWithKey3 p = runIdentity- $ traverseMaybeWithKey3- (\k0 k1 k2 -> Identity . (bool (const Nothing) Just =<< p k0 k1 k2))- m+ . traverseMaybeWithKey3+ \k0 k1 k2 -> Identity . (bool (const Nothing) Just =<< p k0 k1 k2) -- | /O(n)/. Filter all key-chain/value pairs that satisfy the predicate. filterWithKey4 :: (k0 -> k1 -> k2 -> k3 -> v -> Bool) -> DeepMap '[k0, k1, k2, k3] v -> DeepMap '[k0, k1, k2, k3] v-filterWithKey4 p m =+filterWithKey4 p = runIdentity- $ traverseMaybeWithKey4- (\k0 k1 k2 k3 -> Identity . (bool (const Nothing) Just =<< p k0 k1 k2 k3))- m+ . traverseMaybeWithKey4+ \k0 k1 k2 k3 -> Identity . (bool (const Nothing) Just =<< p k0 k1 k2 k3) -- | /O(n)/. Filter all key-chain/value pairs that satisfy the predicate. filterWithKey5 :: (k0 -> k1 -> k2 -> k3 -> k4 -> v -> Bool) -> DeepMap '[k0, k1, k2, k3, k4] v -> DeepMap '[k0, k1, k2, k3, k4] v-filterWithKey5 p m =+filterWithKey5 p = runIdentity- $ traverseMaybeWithKey5- (\k0 k1 k2 k3 k4 -> Identity . (bool (const Nothing) Just =<< p k0 k1 k2 k3 k4))- m+ . traverseMaybeWithKey5+ \k0 k1 k2 k3 k4 -> Identity . (bool (const Nothing) Just =<< p k0 k1 k2 k3 k4) -- | /O(m log(n \/ m + 1)), m <= n/. Restrict a 'Map' to only the keys in a given 'Set'. restrictKeys :: (Ord k) => DeepMap (k ': ks) v -> Set k -> DeepMap (k ': ks) v-restrictKeys (Nest m) s = Nest $ Map.restrictKeys m s+restrictKeys (Wrap m) s = Wrap $ Map.restrictKeys m s -- | /O(m log(n \/ m + 1)), m <= n/. Restrict a 'Map' to only the keys in a given 'Set'. restrictKeys2 ::@@ -3153,8 +3201,8 @@ Set (k0, k1) -> DeepMap (k0 ': k1 ': ks) v restrictKeys2 m s =- mapShallow (\dm -> restrictKeys dm (Set.map snd s))- $ restrictKeys m (Set.map fst s)+ mapShallow (\dm -> restrictKeys dm (Set.map snd s)) $+ restrictKeys m (Set.map fst s) -- | /O(m log(n \/ m + 1)), m <= n/. Restrict a 'Map' to only the keys in a given 'Set'. restrictKeys3 ::@@ -3163,8 +3211,8 @@ Set (k0, k1, k2) -> DeepMap (k0 ': k1 ': k2 ': ks) v restrictKeys3 m s =- mapShallow (\dm -> restrictKeys2 dm (Set.map (\(_, b, c) -> (b, c)) s))- $ restrictKeys m (Set.map (\(a, _, _) -> a) s)+ mapShallow (\dm -> restrictKeys2 dm (Set.map (\(_, b, c) -> (b, c)) s)) $+ restrictKeys m (Set.map (\(a, _, _) -> a) s) -- | /O(m log(n \/ m + 1)), m <= n/. Restrict a 'Map' to only the keys in a given 'Set'. restrictKeys4 ::@@ -3173,8 +3221,8 @@ Set (k0, k1, k2, k3) -> DeepMap (k0 ': k1 ': k2 ': k3 ': ks) v restrictKeys4 m s =- mapShallow (\dm -> restrictKeys3 dm (Set.map (\(_, b, c, d) -> (b, c, d)) s))- $ restrictKeys m (Set.map (\(a, _, _, _) -> a) s)+ mapShallow (\dm -> restrictKeys3 dm (Set.map (\(_, b, c, d) -> (b, c, d)) s)) $+ restrictKeys m (Set.map (\(a, _, _, _) -> a) s) -- | /O(m log(n \/ m + 1)), m <= n/. Restrict a 'Map' to only the keys in a given 'Set'. restrictKeys5 ::@@ -3189,7 +3237,7 @@ -- | /O(m log(n \/ m + 1)), m <= n/. Remove all the keys in a 'Set' from a 'Map'. withoutKeys :: (Ord k) => DeepMap (k ': ks) v -> Set k -> DeepMap (k ': ks) v-withoutKeys (Nest m) s = Nest $ Map.withoutKeys m s+withoutKeys (Wrap m) s = Wrap $ Map.withoutKeys m s -- | /O(m log(n \/ m + 1)), m <= n/. Remove all the keys in a 'Set' from a 'Map'. withoutKeys2 ::@@ -3198,8 +3246,8 @@ Set (k0, k1) -> DeepMap (k0 ': k1 ': ks) v withoutKeys2 m s =- mapShallow (\dm -> withoutKeys dm (Set.map snd s))- $ withoutKeys m (Set.map fst s)+ mapShallow (\dm -> withoutKeys dm (Set.map snd s)) $+ withoutKeys m (Set.map fst s) -- | /O(m log(n \/ m + 1)), m <= n/. Remove all the keys in a 'Set' from a 'Map'. withoutKeys3 ::@@ -3208,8 +3256,8 @@ Set (k0, k1, k2) -> DeepMap (k0 ': k1 ': k2 ': ks) v withoutKeys3 m s =- mapShallow (\dm -> withoutKeys2 dm (Set.map (\(_, b, c) -> (b, c)) s))- $ withoutKeys m (Set.map (\(a, _, _) -> a) s)+ mapShallow (\dm -> withoutKeys2 dm (Set.map (\(_, b, c) -> (b, c)) s)) $+ withoutKeys m (Set.map (\(a, _, _) -> a) s) -- | /O(m log(n \/ m + 1)), m <= n/. Remove all the keys in a 'Set' from a 'Map'. withoutKeys4 ::@@ -3218,8 +3266,8 @@ Set (k0, k1, k2, k3) -> DeepMap (k0 ': k1 ': k2 ': k3 ': ks) v withoutKeys4 m s =- mapShallow (\dm -> withoutKeys3 dm (Set.map (\(_, b, c, d) -> (b, c, d)) s))- $ withoutKeys m (Set.map (\(a, _, _, _) -> a) s)+ mapShallow (\dm -> withoutKeys3 dm (Set.map (\(_, b, c, d) -> (b, c, d)) s)) $+ withoutKeys m (Set.map (\(a, _, _, _) -> a) s) -- | /O(m log(n \/ m + 1)), m <= n/. Remove all the keys in a 'Set' from a 'Map'. withoutKeys5 ::@@ -3237,11 +3285,11 @@ (DeepMap ks v -> Bool) -> DeepMap (k ': ks) v -> (DeepMap (k ': ks) v, DeepMap (k ': ks) v)-partition p (Nest m) = Nest *** Nest $ Map.partition p m+partition p (Wrap m) = Wrap *** Wrap $ Map.partition p m -- | /O(n)/. Partition the map according to a predicate (satisfied, failed). partition1 :: (v -> Bool) -> DeepMap '[k] v -> (DeepMap '[k] v, DeepMap '[k] v)-partition1 p = partition (p . getBare)+partition1 p = partition (p . getCore) -- | /O(n)/. Partition the map according to a predicate (satisfied, failed). partition2 ::@@ -3274,12 +3322,12 @@ (k -> DeepMap ks v -> Bool) -> DeepMap (k ': ks) v -> (DeepMap (k ': ks) v, DeepMap (k ': ks) v)-partitionWithKey p (Nest m) = Nest *** Nest $ Map.partitionWithKey p m+partitionWithKey p (Wrap m) = Wrap *** Wrap $ Map.partitionWithKey p m -- | /O(n)/. Partition the map according to a predicate (satisfied, failed). partitionWithKey1 :: (k -> v -> Bool) -> DeepMap '[k] v -> (DeepMap '[k] v, DeepMap '[k] v)-partitionWithKey1 p = partitionWithKey (\k -> p k . getBare)+partitionWithKey1 p = partitionWithKey (\k -> p k . getCore) -- | /O(n)/. Partition the map according to a predicate (satisfied, failed). partitionWithKey2 ::@@ -3312,11 +3360,11 @@ -- | /O(n)/. Take while a predicate on the keys holds. See the note at 'spanAntitone'. takeWhileAntitone :: (k -> Bool) -> DeepMap (k ': ks) v -> DeepMap (k ': ks) v-takeWhileAntitone p (Nest m) = Nest $ Map.takeWhileAntitone p m+takeWhileAntitone p (Wrap m) = Wrap $ Map.takeWhileAntitone p m -- | /O(n)/. Drop while a predicate on the keys holds. See the note at 'spanAntitone'. dropWhileAntitone :: (k -> Bool) -> DeepMap (k ': ks) v -> DeepMap (k ': ks) v-dropWhileAntitone p (Nest m) = Nest $ Map.dropWhileAntitone p m+dropWhileAntitone p (Wrap m) = Wrap $ Map.dropWhileAntitone p m -- | /O(n)/. Take while a predicate on the keys holds. --@@ -3325,67 +3373,73 @@ -- (where the predicate is seen to hold before the first key and to fail after the last key). spanAntitone :: (k -> Bool) -> DeepMap (k ': ks) v -> (DeepMap (k ': ks) v, DeepMap (k ': ks) v)-spanAntitone p (Nest m) = Nest *** Nest $ Map.spanAntitone p m+spanAntitone p (Wrap m) = Wrap *** Wrap $ Map.spanAntitone p m -- | /O(n)/. Map values and collect the 'Just' results. mapMaybe :: (v -> Maybe w) -> DeepMap (k ': ks) v -> DeepMap (k ': ks) w-mapMaybe f (Nest m) = Nest $ Map.mapMaybe (traverse f) m+mapMaybe f (Wrap m) = Wrap $ Map.mapMaybe (traverse f) m +mapMaybeWithKeys ::+ (Deep (k ': ks) -> v -> Maybe w) ->+ DeepMap (k ': ks) v ->+ DeepMap (k ': ks) w+mapMaybeWithKeys = Witherable.imapMaybe+ -- | /O(n)/. Map values and collect the 'Just' results. Strictly more general than 'mapMaybe' in that the types of the inner keys can change. mapShallowMaybe :: (DeepMap ks v -> Maybe (DeepMap ls w)) -> DeepMap (k ': ks) v -> DeepMap (k ': ls) w-mapShallowMaybe f (Nest m) = Nest $ Map.mapMaybe f m+mapShallowMaybe f (Wrap m) = Wrap $ Map.mapMaybe f m -- | /O(n)/. Map values and collect the 'Just' results. mapShallowMaybeWithKey :: (k -> DeepMap ks v -> Maybe (DeepMap ls w)) -> DeepMap (k ': ks) v -> DeepMap (k ': ls) w-mapShallowMaybeWithKey f (Nest m) = Nest $ Map.mapMaybeWithKey f m+mapShallowMaybeWithKey f (Wrap m) = Wrap $ Map.mapMaybeWithKey f m -- | /O(n)/. Map values and collect the 'Just' results. mapMaybeWithKey1 :: (k -> v -> Maybe w) -> DeepMap '[k] v -> DeepMap '[k] w-mapMaybeWithKey1 f = mapShallowMaybeWithKey (\k -> fmap Bare . f k . getBare)+mapMaybeWithKey1 f = mapShallowMaybeWithKey (\k -> fmap Core . f k . getCore) -- | /O(n)/. Map values and collect the 'Just' results. mapMaybeWithKey2 :: (k0 -> k1 -> v -> Maybe w) -> DeepMap '[k0, k1] v -> DeepMap '[k0, k1] w-mapMaybeWithKey2 f m =+mapMaybeWithKey2 f = let g k0 k1 v = Identity $ f k0 k1 v in runIdentity- $ traverseMaybeWithKey (fmap (fmap Just) . traverseMaybeWithKey1 . g) m+ . traverseMaybeWithKey (fmap (fmap Just) . traverseMaybeWithKey1 . g) -- | /O(n)/. Map values and collect the 'Just' results. mapMaybeWithKey3 :: (k0 -> k1 -> k2 -> v -> Maybe w) -> DeepMap '[k0, k1, k2] v -> DeepMap '[k0, k1, k2] w-mapMaybeWithKey3 f m =+mapMaybeWithKey3 f = let g k0 k1 k2 v = Identity $ f k0 k1 k2 v in runIdentity- $ traverseMaybeWithKey (fmap (fmap Just) . traverseMaybeWithKey2 . g) m+ . traverseMaybeWithKey (fmap (fmap Just) . traverseMaybeWithKey2 . g) -- | /O(n)/. Map values and collect the 'Just' results. mapMaybeWithKey4 :: (k0 -> k1 -> k2 -> k3 -> v -> Maybe w) -> DeepMap '[k0, k1, k2, k3] v -> DeepMap '[k0, k1, k2, k3] w-mapMaybeWithKey4 f m =+mapMaybeWithKey4 f = let g k0 k1 k2 k3 v = Identity $ f k0 k1 k2 k3 v in runIdentity- $ traverseMaybeWithKey (fmap (fmap Just) . traverseMaybeWithKey3 . g) m+ . traverseMaybeWithKey (fmap (fmap Just) . traverseMaybeWithKey3 . g) -- | /O(n)/. Map values and collect the 'Just' results. mapMaybeWithKey5 :: (k0 -> k1 -> k2 -> k3 -> k4 -> v -> Maybe w) -> DeepMap '[k0, k1, k2, k3, k4] v -> DeepMap '[k0, k1, k2, k3, k4] w-mapMaybeWithKey5 f m =+mapMaybeWithKey5 f = let g k0 k1 k2 k3 k4 v = Identity $ f k0 k1 k2 k3 k4 v in runIdentity- $ traverseMaybeWithKey (fmap (fmap Just) . traverseMaybeWithKey4 . g) m+ . traverseMaybeWithKey (fmap (fmap Just) . traverseMaybeWithKey4 . g) -- | /O(n)/. Map values and collect the 'Left' and 'Right' results separately. mapEither ::@@ -3393,84 +3447,96 @@ DeepMap (k ': ks) v -> (DeepMap (k ': ks) w, DeepMap (k ': ks) x) mapEither f m =- ( mapMaybe ((Just ||| const Nothing) . f) m- , mapMaybe ((const Nothing ||| Just) . f) m+ ( Data.Map.Deep.mapMaybe ((Just ||| const Nothing) . f) m+ , Data.Map.Deep.mapMaybe ((const Nothing ||| Just) . f) m ) +mapEitherWithKeys ::+ (Deep (k ': ks) -> v -> Either w x) ->+ DeepMap (k ': ks) v ->+ (DeepMap (k ': ks) w, DeepMap (k ': ks) x)+mapEitherWithKeys f m =+ ( Witherable.imapMaybe (((Just ||| const Nothing) .) . f) m+ , Witherable.imapMaybe (((const Nothing ||| Just) .) . f) m+ )+ -- | /O(n)/. Map values and collect the 'Left' and 'Right' results separately. mapShallowEither :: (DeepMap ks v -> Either (DeepMap ls w) (DeepMap ms x)) -> DeepMap (k ': ks) v -> (DeepMap (k ': ls) w, DeepMap (k ': ms) x)-mapShallowEither f (Nest m) = Nest *** Nest $ Map.mapEither f m+mapShallowEither f (Wrap m) = Wrap *** Wrap $ Map.mapEither f m -- | /O(n)/. Map values and collect the 'Left' and 'Right' results separately. mapShallowEitherWithKey :: (k -> DeepMap ks v -> Either (DeepMap ls w) (DeepMap ms x)) -> DeepMap (k ': ks) v -> (DeepMap (k ': ls) w, DeepMap (k ': ms) x)-mapShallowEitherWithKey f (Nest m) = Nest *** Nest $ Map.mapEitherWithKey f m+mapShallowEitherWithKey f (Wrap m) = Wrap *** Wrap $ Map.mapEitherWithKey f m -- | /O(n)/. Map values and collect the 'Left' and 'Right' results separately. mapEitherWithKey1 :: (k -> v -> Either w x) -> DeepMap '[k] v -> (DeepMap '[k] w, DeepMap '[k] x)-mapEitherWithKey1 f (Nest m) =- Nest *** Nest $ Map.mapEitherWithKey (\k -> (Bare +++ Bare) . f k . getBare) m+mapEitherWithKey1 f (Wrap m) =+ Wrap *** Wrap $ Map.mapEitherWithKey (\k -> (Core +++ Core) . f k . getCore) m -- | /O(n)/. Map values and collect the 'Left' and 'Right' results separately. mapEitherWithKey2 :: (k0 -> k1 -> v -> Either w x) -> DeepMap '[k0, k1] v -> (DeepMap '[k0, k1] w, DeepMap '[k0, k1] x)-mapEitherWithKey2 f m =- (mapMaybe (Just ||| const Nothing) *** mapMaybe (const Nothing ||| Just))+mapEitherWithKey2 f =+ ( Data.Map.Deep.mapMaybe (Just ||| const Nothing)+ *** Data.Map.Deep.mapMaybe (const Nothing ||| Just)+ ) . partition2 isLeft- $ mapShallowWithKey (\k0 -> mapShallowWithKey $ fmap . f k0) m+ . mapShallowWithKey (\k0 -> mapShallowWithKey $ fmap . f k0) -- | /O(n)/. Map values and collect the 'Left' and 'Right' results separately. mapEitherWithKey3 :: (k0 -> k1 -> k2 -> v -> Either w x) -> DeepMap '[k0, k1, k2] v -> (DeepMap '[k0, k1, k2] w, DeepMap '[k0, k1, k2] x)-mapEitherWithKey3 f m =- (mapMaybe (Just ||| const Nothing) *** mapMaybe (const Nothing ||| Just))+mapEitherWithKey3 f =+ ( Data.Map.Deep.mapMaybe (Just ||| const Nothing)+ *** Data.Map.Deep.mapMaybe (const Nothing ||| Just)+ ) . partition3 isLeft- $ mapShallowWithKey- ( \k0 -> mapShallowWithKey $ \k1 ->- mapShallowWithKey $ fmap . f k0 k1- )- m+ . mapShallowWithKey \k0 -> mapShallowWithKey $ \k1 ->+ mapShallowWithKey $ fmap . f k0 k1 -- | /O(n)/. Map values and collect the 'Left' and 'Right' results separately. mapEitherWithKey4 :: (k0 -> k1 -> k2 -> k3 -> v -> Either w x) -> DeepMap '[k0, k1, k2, k3] v -> (DeepMap '[k0, k1, k2, k3] w, DeepMap '[k0, k1, k2, k3] x)-mapEitherWithKey4 f m =- (mapMaybe (Just ||| const Nothing) *** mapMaybe (const Nothing ||| Just))+mapEitherWithKey4 f =+ ( Data.Map.Deep.mapMaybe (Just ||| const Nothing)+ *** Data.Map.Deep.mapMaybe (const Nothing ||| Just)+ ) . partition4 isLeft- $ mapShallowWithKey+ . mapShallowWithKey ( \k0 -> mapShallowWithKey $ \k1 -> mapShallowWithKey $ \k2 -> mapShallowWithKey $ fmap . f k0 k1 k2 )- m -- | /O(n)/. Map values and collect the 'Left' and 'Right' results separately. mapEitherWithKey5 :: (k0 -> k1 -> k2 -> k3 -> k4 -> v -> Either w x) -> DeepMap '[k0, k1, k2, k3, k4] v -> (DeepMap '[k0, k1, k2, k3, k4] w, DeepMap '[k0, k1, k2, k3, k4] x)-mapEitherWithKey5 f m =- (mapMaybe (Just ||| const Nothing) *** mapMaybe (const Nothing ||| Just))+mapEitherWithKey5 f =+ ( Data.Map.Deep.mapMaybe (Just ||| const Nothing)+ *** Data.Map.Deep.mapMaybe (const Nothing ||| Just)+ ) . partition5 isLeft- $ mapShallowWithKey+ . mapShallowWithKey ( \k0 -> mapShallowWithKey $ \k1 -> mapShallowWithKey $ \k2 -> mapShallowWithKey $ \k3 -> mapShallowWithKey $ fmap . f k0 k1 k2 k3 )- m -- | /O(log n)/. Partition the map by comparing keys ((smaller, larger) than given). split ::@@ -3478,7 +3544,7 @@ k -> DeepMap (k ': ks) v -> (DeepMap (k ': ks) v, DeepMap (k ': ks) v)-split k (Nest m) = Nest *** Nest $ Map.split k m+split k (Wrap m) = Wrap *** Wrap $ Map.split k m -- | /O(log n)/. Like 'split' but the middle coordinate 'lookup's the value at the key. splitLookup ::@@ -3486,17 +3552,17 @@ k -> DeepMap (k ': ks) v -> (DeepMap (k ': ks) v, Maybe (DeepMap ks v), DeepMap (k ': ks) v)-splitLookup k (Nest m) = (\(n, y, p) -> (Nest n, y, Nest p)) $ Map.splitLookup k m+splitLookup k (Wrap m) = Map.splitLookup k m & \(n, y, p) -> (Wrap n, y, Wrap p) -- | /O(1)/. Decompose a map into pieces based on the structure of the underlying tree. splitRoot :: DeepMap (k ': ks) v -> [DeepMap (k ': ks) v]-splitRoot (Nest m) = Nest <$> Map.splitRoot m+splitRoot (Wrap m) = Wrap <$> Map.splitRoot m -- | /O(m log(n \/ m + 1)), m <= n/. Returns 'True' if all the keys in the left map -- exist in the right, __and__ their values all agree. isSubmapOf :: (Ord k, Eq (DeepMap ks v)) => DeepMap (k ': ks) v -> DeepMap (k ': ks) v -> Bool-isSubmapOf (Nest m) (Nest n) = Map.isSubmapOf m n+isSubmapOf (Wrap m) (Wrap n) = Map.isSubmapOf m n -- | /O(m log(n \/ m + 1)), m <= n/. Returns 'True' if all the keys in the left map -- exist in the right, __and__ the function returns 'True' when applied to respective values.@@ -3506,13 +3572,13 @@ DeepMap (k ': ks) v -> DeepMap (k ': ks) v -> Bool-isSubmapOfBy f (Nest m) (Nest n) = Map.isSubmapOfBy f m n+isSubmapOfBy f (Wrap m) (Wrap n) = Map.isSubmapOfBy f m n -- | /O(m log(n \/ m + 1)), m <= n/. Returns 'True' if all the keys in the left map -- exist in the right, __and__ their values all agree, __and__ the maps are not equal. isProperSubmapOf :: (Ord k, Eq (DeepMap ks v)) => DeepMap (k ': ks) v -> DeepMap (k ': ks) v -> Bool-isProperSubmapOf (Nest m) (Nest n) = Map.isProperSubmapOf m n+isProperSubmapOf (Wrap m) (Wrap n) = Map.isProperSubmapOf m n -- | /O(m log(n \/ m + 1)), m <= n/. Returns 'True' if all the keys in the left map -- exist in the right, __and__ the function returns 'True' when applied to respective values,@@ -3523,24 +3589,24 @@ DeepMap (k ': ks) v -> DeepMap (k ': ks) v -> Bool-isProperSubmapOfBy f (Nest m) (Nest n) = Map.isProperSubmapOfBy f m n+isProperSubmapOfBy f (Wrap m) (Wrap n) = Map.isProperSubmapOfBy f m n -- | /O(log n)/. Lookup the /index/ of a key, which is its zero-based index -- in the ordered sequence of keys. -- -- > 'lookupIndex' k m == 'Data.List.findIndex' k ('keys' m) lookupIndex :: (Ord k) => k -> DeepMap (k ': ks) v -> Maybe Int-lookupIndex k (Nest m) = Map.lookupIndex k m+lookupIndex k (Wrap m) = Map.lookupIndex k m -- | /O(log n)/. Lookup the /index/ of a key, which is its zero-based index -- in the ordered sequence of keys. Calls 'error' when the key is not in the map. findIndex :: (Ord k) => k -> DeepMap (k ': ks) v -> Int-findIndex i (Nest m) = Map.findIndex i m+findIndex i (Wrap m) = Map.findIndex i m -- | /O(log n)/. Retrieve an element by its /index/. Calls 'error' if @i@ is outside -- the range @0 <= i < 'size' m@. elemAt :: (Ord k) => Int -> DeepMap (k ': ks) v -> (k, DeepMap ks v)-elemAt i (Nest m) = Map.elemAt i m+elemAt i (Wrap m) = Map.elemAt i m -- | /O(log n)/. Update the element by its /index/. Calls 'error' if @i@ is outside -- the range @0 <= i < 'size' m@.@@ -3550,7 +3616,7 @@ Int -> DeepMap (k ': ks) v -> DeepMap (k ': ks) v-updateAt f i (Nest m) = Nest $ Map.updateAt f i m+updateAt f i (Wrap m) = Wrap $ Map.updateAt f i m -- | /O(log n)/. Delete the element by its /index/. Calls 'error' if @i@ is outside -- the range @0 <= i < 'size' m@.@@ -3560,106 +3626,106 @@ Int -> DeepMap (k ': ks) v -> DeepMap (k ': ks) v-deleteAt f i (Nest m) = Nest $ Map.updateAt f i m+deleteAt f i (Wrap m) = Wrap $ Map.updateAt f i m -- | Take the smallest @n@ keys. take :: Int -> DeepMap (k ': ks) v -> DeepMap (k ': ks) v-take n (Nest m) = Nest $ Map.take n m+take n (Wrap m) = Wrap $ Map.take n m -- | Drop the smallest @n@ keys. drop :: Int -> DeepMap (k ': ks) v -> DeepMap (k ': ks) v-drop n (Nest m) = Nest $ Map.take n m+drop n (Wrap m) = Wrap $ Map.take n m -- | /O(n)/. Split a map at a particular index. splitAt :: Int -> DeepMap (k ': ks) v -> (DeepMap (k ': ks) v, DeepMap (k ': ks) v)-splitAt i (Nest m) = Nest *** Nest $ Map.splitAt i m+splitAt i (Wrap m) = Wrap *** Wrap $ Map.splitAt i m -- | /O(log n)/. The minimal key of the map, or 'Nothing' if the map is empty. lookupMin :: DeepMap (k ': ks) v -> Maybe (k, DeepMap ks v)-lookupMin (Nest m) = Map.lookupMin m+lookupMin (Wrap m) = Map.lookupMin m -- | /O(log n)/. The maximal key of the map, or 'Nothing' if the map is empty. lookupMax :: DeepMap (k ': ks) v -> Maybe (k, DeepMap ks v)-lookupMax (Nest m) = Map.lookupMax m+lookupMax (Wrap m) = Map.lookupMax m -- | /O(log n)/. The minimal key of the map, or 'error' if the map is empty. findMin :: DeepMap (k ': ks) v -> (k, DeepMap ks v)-findMin (Nest m) = Map.findMin m+findMin (Wrap m) = Map.findMin m -- | /O(log n)/. The maximal key of the map, or 'error' if the map is empty. findMax :: DeepMap (k ': ks) v -> (k, DeepMap ks v)-findMax (Nest m) = Map.findMax m+findMax (Wrap m) = Map.findMax m -- | /O(log n)/. Delete the minimal key. deleteMin :: DeepMap (k ': ks) v -> DeepMap (k ': ks) v-deleteMin (Nest m) = Nest $ Map.deleteMin m+deleteMin (Wrap m) = Wrap $ Map.deleteMin m -- | /O(log n)/. Delete the maximal key. deleteMax :: DeepMap (k ': ks) v -> DeepMap (k ': ks) v-deleteMax (Nest m) = Nest $ Map.deleteMax m+deleteMax (Wrap m) = Wrap $ Map.deleteMax m -- | /O(log n)/. Delete and return the minimal key of the map, or 'error' if the map is empty. deleteFindMin :: DeepMap (k ': ks) v -> ((k, DeepMap ks v), DeepMap (k ': ks) v)-deleteFindMin (Nest m) = Nest <$> Map.deleteFindMin m+deleteFindMin (Wrap m) = Wrap <$> Map.deleteFindMin m -- | /O(log n)/. Delete and return the maximal key of the map, or 'error' if the map is empty. deleteFindMax :: DeepMap (k ': ks) v -> ((k, DeepMap ks v), DeepMap (k ': ks) v)-deleteFindMax (Nest m) = Nest <$> Map.deleteFindMax m+deleteFindMax (Wrap m) = Wrap <$> Map.deleteFindMax m -- | /O(log n)/. Update the value at the minimal key. updateMin :: (DeepMap ks v -> Maybe (DeepMap ks v)) -> DeepMap (k ': ks) v -> DeepMap (k ': ks) v-updateMin f (Nest m) = Nest $ Map.updateMin f m+updateMin f (Wrap m) = Wrap $ Map.updateMin f m -- | /O(log n)/. Update the value at the maximal key. updateMax :: (DeepMap ks v -> Maybe (DeepMap ks v)) -> DeepMap (k ': ks) v -> DeepMap (k ': ks) v-updateMax f (Nest m) = Nest $ Map.updateMax f m+updateMax f (Wrap m) = Wrap $ Map.updateMax f m -- | /O(log n)/. Update the value at the minimal key. updateMinWithKey :: (k -> DeepMap ks v -> Maybe (DeepMap ks v)) -> DeepMap (k ': ks) v -> DeepMap (k ': ks) v-updateMinWithKey f (Nest m) = Nest $ Map.updateMinWithKey f m+updateMinWithKey f (Wrap m) = Wrap $ Map.updateMinWithKey f m -- | /O(log n)/. Update the value at the maximal key. updateMaxWithKey :: (k -> DeepMap ks v -> Maybe (DeepMap ks v)) -> DeepMap (k ': ks) v -> DeepMap (k ': ks) v-updateMaxWithKey f (Nest m) = Nest $ Map.updateMaxWithKey f m+updateMaxWithKey f (Wrap m) = Wrap $ Map.updateMaxWithKey f m -- | /O(log n)/. Retrieve the value associated with the minimal key of the map, -- and the map stripped of that element, or 'Nothing' if passed an empty map. minView :: DeepMap (k ': ks) v -> Maybe (DeepMap ks v, DeepMap (k ': ks) v)-minView (Nest m) = fmap Nest <$> Map.minView m+minView (Wrap m) = fmap Wrap <$> Map.minView m -- | /O(log n)/. Retrieve the value associated with the maximal key of the map, -- and the map stripped of that element, or 'Nothing' if passed an empty map. maxView :: DeepMap (k ': ks) v -> Maybe (DeepMap ks v, DeepMap (k ': ks) v)-maxView (Nest m) = fmap Nest <$> Map.maxView m+maxView (Wrap m) = fmap Wrap <$> Map.maxView m -- | /O(log n)/. Retrieve the minimal key/value pair of the map, -- and the map stripped of that element, or 'Nothing' if passed an empty map. minViewWithKey :: DeepMap (k ': ks) v -> Maybe ((k, DeepMap ks v), DeepMap (k ': ks) v)-minViewWithKey (Nest m) = fmap Nest <$> Map.minViewWithKey m+minViewWithKey (Wrap m) = fmap Wrap <$> Map.minViewWithKey m -- | /O(log n)/. Retrieve the maximal key/value pair of the map, -- and the map stripped of that element, or 'Nothing' if passed an empty map. maxViewWithKey :: DeepMap (k ': ks) v -> Maybe ((k, DeepMap ks v), DeepMap (k ': ks) v)-maxViewWithKey (Nest m) = fmap Nest <$> Map.maxViewWithKey m+maxViewWithKey (Wrap m) = fmap Wrap <$> Map.maxViewWithKey m -- | "Transpose" a 'DeepMap', by swapping the outer two "dimensions". invertKeys :: (Ord j, Ord k, Semigroup (DeepMap ks v)) => DeepMap (j ': k ': ks) v -> DeepMap (k ': j ': ks) v-invertKeys = mapKeysDeep \(Deep2 j k d0) -> Deep2 k j d0+invertKeys = mapKeysDeep \(D2 j k d0) -> D2 k j d0