lens-witherable 0.1.0.2 → 0.1.1.0
raw patch · 3 files changed
+24/−8 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Witherable.Lens: filterOfA :: Applicative f => ((a -> Withering f a) -> s -> f s) -> (a -> f Bool) -> s -> f s
Files
- CHANGELOG.md +4/−0
- lens-witherable.cabal +1/−1
- src/Witherable/Lens.hs +19/−7
CHANGELOG.md view
@@ -1,5 +1,9 @@ # Revision history for lens-witherable +## 0.1.1.0 -- 2024-03-10++* Add filterOfA, some doc cleanups.+ ## 0.1.0.2 -- 2022-11-16 * Discovered cabal mixins. No longer using CPP, but now requiring GHC 8.2 or newer
lens-witherable.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: lens-witherable-version: 0.1.0.2+version: 0.1.1.0 synopsis: lens-compatible tools for working with witherable copyright: Copyright (C) 2021-2022 Carl Howells license: MIT
src/Witherable/Lens.hs view
@@ -60,10 +60,9 @@ -- | Remove elements from the current 'Withering' context if they -- don't match the predicate. This is similar in concept to @filtered@--- from lens. The major that instead of merely removing non-matching--- targets from the traversal, it removes those targets (and their--- parents up to the next 'withered' combinator) from the data--- structure entirely.+-- from lens but instead of merely removing non-matching+-- targets from the traversal, it removes those targets and their+-- parents up to the next 'withered' combinator. guarded :: Applicative f => (a -> Bool) -> (a -> Withering f b)@@ -78,15 +77,28 @@ filterOf :: ((a -> Withering Identity a) -> s -> Identity s) -> (a -> Bool) -> s -> s-filterOf w p = runIdentity . w (guarding p)+filterOf w p = runIdentity . w toWithering where- guarding p a+ toWithering a | p a = pure a | otherwise = empty infix 2 `filterOf` +-- | Remove elements matched by a specific 'Withering' context if they+-- don't match a predicate returning a result in an arbitrary+-- Applicative context.+filterOfA+ :: Applicative f+ => ((a -> Withering f a) -> s -> f s)+ -> (a -> f Bool) -> s -> f s+filterOfA w p = w toWitheringA+ where+ toWitheringA a = Withering $ (\x -> if x then Just a else Nothing) <$> p a+infix 2 `filterOfA`+ -- | Transform and filter elements matched by a specific 'Withering'--- context, a la 'Data.Maybe.mapMaybe'.+-- context, a la 'Data.Maybe.mapMaybe'. See 'witherOf' for a more+-- flexible version that works within arbitrary 'Applicative' effects. mapMaybeOf :: ((a -> Withering Identity b) -> s -> Identity t) -> (a -> Maybe b) -> s -> t