deep-map 0.3.0 → 0.3.1
raw patch · 3 files changed
+45/−40 lines, 3 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- 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: filterWithKeys :: (Deep (k ': ks) -> v -> Bool) -> DeepMap (k ': ks) v -> DeepMap (k ': ks) v
+ Data.Map.Deep: instance Witherable.Filterable (Data.Map.Deep.DeepMap ks)
+ Data.Map.Deep: instance Witherable.FilterableWithIndex (Data.Map.Deep.Deep ks) (Data.Map.Deep.DeepMap ks)
+ Data.Map.Deep: instance Witherable.Witherable (Data.Map.Deep.DeepMap ks)
+ Data.Map.Deep: instance Witherable.WitherableWithIndex (Data.Map.Deep.Deep ks) (Data.Map.Deep.DeepMap ks)
+ Data.Map.Deep: partitionWithKeys :: (Deep (k ': ks) -> v -> Bool) -> DeepMap (k ': ks) v -> (DeepMap (k ': ks) v, DeepMap (k ': ks) v)
- Data.Map.Deep: mapMaybeWithKeys :: (Deep (k ': ks) -> v -> Maybe w) -> DeepMap (k ': ks) v -> DeepMap (k ': ks) w
+ Data.Map.Deep: mapMaybeWithKeys :: (Deep (k ': ks) -> a -> Maybe b) -> DeepMap (k ': ks) a -> DeepMap (k ': ks) b
Files
- CHANGELOG.md +7/−1
- deep-map.cabal +1/−1
- src/Data/Map/Deep.hs +37/−38
CHANGELOG.md view
@@ -1,9 +1,15 @@ # Revision history for deep-map -## 0.3+## 0.3.1 +* fix recursive definition of `mapMaybe`+* add `filterWithKeys` and `partitionWithKeys`++## 0.3.0+ * rename constructors and patterns * add support for `witherable` classes+* add `mapMaybeWithKeys` and `mapEitherWithKeys` ## 0.2.0.1
deep-map.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: deep-map-version: 0.3.0+version: 0.3.1 category: Data, Statistics synopsis: Deeply-nested, multiple key type maps. description:
src/Data/Map/Deep.hs view
@@ -339,13 +339,14 @@ , toDescList -- * Filter- , Data.Map.Deep.filter+ , filter , filter1 , filter2 , filter3 , filter4 , filter5 , filterWithKey+ , filterWithKeys , filterWithKey1 , filterWithKey2 , filterWithKey3@@ -368,6 +369,7 @@ , partition4 , partition5 , partitionWithKey+ , partitionWithKeys , partitionWithKey1 , partitionWithKey2 , partitionWithKey3@@ -463,10 +465,10 @@ import Data.Traversable.WithIndex import GHC.Generics import Witherable- ( Filterable- , FilterableWithIndex- , Witherable- , WitherableWithIndex+ ( Filterable (mapMaybe)+ , FilterableWithIndex (imapMaybe)+ , Witherable (wither)+ , WitherableWithIndex (iwither) ) import Witherable qualified import Prelude hiding@@ -529,19 +531,14 @@ 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+instance Filterable (DeepMap ks) where+ mapMaybe f = \case+ Core v -> maybe (error "DeepMap: mapMaybe shrink on Core") Core $ f v+ Wrap m -> Wrap $ fmap (Witherable.mapMaybe f) m+instance Witherable (DeepMap ks) where+ wither f = \case+ Core v -> maybe (error "DeepMap: withered Core") Core <$> f v+ Wrap m -> Wrap <$> traverse (Witherable.wither f) m -- | For use with indexed maps, folds, and traversals. type Deep :: [Type] -> Type@@ -606,19 +603,15 @@ 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 FilterableWithIndex (Deep ks) (DeepMap ks) where+ imapMaybe f = \case+ Core v -> maybe (error "DeepMap: imapMaybe shrink on Core") Core $ f D0 v+ Wrap m -> Wrap $ Map.mapMaybeWithKey (\k ds -> itraverse (f . D1 k) ds) m -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+instance WitherableWithIndex (Deep ks) (DeepMap ks) where+ iwither f = \case+ Core v -> maybe (error "DeepMap: iwithered Core") Core <$> f D0 v+ Wrap m -> Wrap <$> itraverse (Witherable.iwither . (f .) . D1) m deriving instance (Typeable v) => Typeable (DeepMap '[] v) @@ -3122,29 +3115,32 @@ -- | /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) $ Data.Map.Deep.filter (any p) m+filter2 p m = mapShallow (filter1 p) $ 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) $ Data.Map.Deep.filter (any p) m+filter3 p m = mapShallow (filter2 p) $ 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) $ Data.Map.Deep.filter (any p) m+filter4 p m = mapShallow (filter3 p) $ 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) $ Data.Map.Deep.filter (any p) m+filter5 p m = mapShallow (filter4 p) $ 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 (Wrap m) = Wrap $ Map.filterWithKey p m +filterWithKeys :: (Deep (k ': ks) -> v -> Bool) -> DeepMap (k ': ks) v -> DeepMap (k ': ks) v+filterWithKeys = Witherable.ifilter+ -- | /O(n)/. Filter all key/value pairs that satisfy the predicate. filterWithKey1 :: (k -> v -> Bool) -> DeepMap '[k] v -> DeepMap '[k] v filterWithKey1 p =@@ -3324,6 +3320,12 @@ (DeepMap (k ': ks) v, DeepMap (k ': ks) v) partitionWithKey p (Wrap m) = Wrap *** Wrap $ Map.partitionWithKey p m +partitionWithKeys ::+ (Deep (k ': ks) -> v -> Bool) ->+ DeepMap (k ': ks) v ->+ (DeepMap (k ': ks) v, DeepMap (k ': ks) v)+partitionWithKeys p = Witherable.ifilter p &&& Witherable.ifilter ((not .) . p)+ -- | /O(n)/. Partition the map according to a predicate (satisfied, failed). partitionWithKey1 :: (k -> v -> Bool) -> DeepMap '[k] v -> (DeepMap '[k] v, DeepMap '[k] v)@@ -3379,10 +3381,7 @@ mapMaybe :: (v -> Maybe w) -> DeepMap (k ': ks) v -> DeepMap (k ': ks) w 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 :: (Deep (k ': ks) -> a -> Maybe b) -> DeepMap (k ': ks) a -> DeepMap (k ': ks) b 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.