control-block 0.0.1 → 0.0.2
raw patch · 3 files changed
+63/−9 lines, 3 filesdep ~witherablePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: witherable
API changes (from Hackage documentation)
+ Control.Block: (<*>) :: Applicative f => f (a -> b) -> f a -> f b
+ Control.Block: foldL :: Foldable t => (y -> x -> y) -> y -> t x -> y
+ Control.Block: foldL1 :: Foldable1 t => (x -> x -> x) -> t x -> x
+ Control.Block: foldLM :: (Foldable t, Monad m) => (y -> x -> m y) -> y -> t x -> m y
+ Control.Block: foldR :: Foldable t => (x -> y -> y) -> y -> t x -> y
+ Control.Block: foldR1 :: Foldable1 t => (x -> x -> x) -> t x -> x
+ Control.Block: foldRM :: (Foldable t, Monad m) => (x -> y -> m y) -> y -> t x -> m y
+ Control.Block: reduceLM :: (Foldable t, Monad m) => y -> t x -> (y -> x -> m y) -> m y
+ Control.Block: reduceRM :: (Foldable t, Monad m) => y -> t x -> (x -> y -> m y) -> m y
Files
- CHANGELOG.md +6/−0
- control-block.cabal +2/−2
- lib/Control/Block.hs +55/−7
CHANGELOG.md view
@@ -1,5 +1,11 @@ # Revision history for `control-block` +## 0.0.2++Includes support for `witherable-0.5` and adds new consistently-+named versions of `foldl` and `foldr` for the matching `reduce`,+as well as monadic `fold` and `reduce` leftwards and rightwards.+ ## 0.0.1 Higher-order functions with their function arguments at the end,
control-block.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: control-block-version: 0.0.1+version: 0.0.2 license: BSD-2-Clause license-file: LICENSE author: Melanie Phoenix@@ -28,6 +28,6 @@ build-depends: , base >=4.14 && <5 , indexed-traversable >=0.1.3 && <0.2- , witherable >=0.4.2 && <0.5+ , witherable >=0.4.2 && <0.6 exposed-modules: Control.Block
lib/Control/Block.hs view
@@ -11,6 +11,7 @@ , ichange -- * Applicative+ , (<*>) , (<**>) , apply , through@@ -36,10 +37,18 @@ , ireduceA -- ** Without monoids+ , foldL , reduceL+ , foldL1 , reduceL1+ , foldR , reduceR+ , foldR1 , reduceR1+ , foldLM+ , reduceLM+ , foldRM+ , reduceRM -- * Traversable , traverse@@ -83,6 +92,7 @@ import Data.Foldable qualified as Fold import Data.Foldable.WithIndex import Data.Foldable1 (Foldable1, foldMap1, foldl1', toNonEmpty)+import Data.Foldable1 qualified as Fold1 import Data.Function import Data.Functor import Data.Functor.WithIndex@@ -111,7 +121,7 @@ through :: (Applicative f) => f x -> f (x -> y) -> f y through = (<**>) --- | 'foldMap' through an 'Applicative' functor.+-- | 'Fold.foldMap' through an 'Applicative' functor. foldMapA :: (Foldable t, Applicative f, Monoid m) => (x -> f m) -> t x -> f m foldMapA f = Fold.foldl' (\ !fm x -> liftA2 (<>) fm (f x)) (pure mempty) @@ -132,7 +142,7 @@ reduce1 :: (Foldable1 t, Semigroup s) => t x -> (x -> s) -> s reduce1 = flip foldMap1 --- | Flipped version of 'foldMap'.+-- | Flipped version of 'Fold.foldMap'. reduce :: (Foldable t, Monoid m) => t x -> (x -> m) -> m reduce = flip Fold.foldMap @@ -140,22 +150,60 @@ ireduce :: (FoldableWithIndex i t, Monoid m) => t x -> (i -> x -> m) -> m ireduce = flip ifoldMap --- | A version of 'foldl'' taking the accumulator first, then the @Foldable@.+-- | Consistent name of 'Fold.foldl''.+foldL :: (Foldable t) => (y -> x -> y) -> y -> t x -> y+foldL = Fold.foldl'++-- | A version of 'Fold.foldl'' taking the accumulator first, then the @Foldable@. reduceL :: (Foldable t) => y -> t x -> (y -> x -> y) -> y reduceL = flip . flip Fold.foldl' --- | A version of 'foldl1'' taking the accumulator first, then the @Foldable1@.+-- | Consistent name of 'Fold1.foldl1''.+foldL1 :: (Foldable1 t) => (x -> x -> x) -> t x -> x+foldL1 = Fold1.foldl1'++-- | A version of 'Fold1.foldl1'' taking the accumulator first, then the @Foldable1@. reduceL1 :: (Foldable1 t) => t x -> (x -> x -> x) -> x reduceL1 = flip foldl1' --- | A version of 'foldr' taking the accumulator first, then the @Foldable@.+-- | Consistent name of 'foldM'.+foldLM :: (Foldable t, Monad m) => (y -> x -> m y) -> y -> t x -> m y+foldLM f z0 xs = Fold.foldr c pure xs z0+ where+ {-# INLINE c #-}+ c x k z = f z x >>= k++-- | A version of 'foldM' taking the accumulator first, then the @Foldable@,+reduceLM :: (Foldable t, Monad m) => y -> t x -> (y -> x -> m y) -> m y+reduceLM z0 xs f = foldLM f z0 xs++-- | Consistent name of 'Fold.foldr'.+foldR :: (Foldable t) => (x -> y -> y) -> y -> t x -> y+foldR = Fold.foldr++-- | A version of 'Fold.foldr' taking the accumulator first, then the @Foldable@. reduceR :: (Foldable t) => y -> t x -> (x -> y -> y) -> y reduceR = flip . flip Fold.foldr --- | A version of 'foldr1' taking the accumulator first, then the @Foldable@.+-- | Consistent name of 'Fold1.foldr1'.+foldR1 :: (Foldable1 t) => (x -> x -> x) -> t x -> x+foldR1 = Fold1.foldr1++-- | A version of 'Fold.foldr1' taking the accumulator first, then the @Foldable@. reduceR1 :: (Foldable1 t) => t x -> (x -> x -> x) -> x reduceR1 = flip Fold.foldr1 +-- | Consistent name of 'Fold.foldrM'.+foldRM :: (Foldable t, Monad m) => (x -> y -> m y) -> y -> t x -> m y+foldRM f z0 xs = Fold.foldl c pure xs z0+ where+ {-# INLINE c #-}+ c k x z = f x z >>= k++-- | A version of 'foldRM' taking the accumulator first, then the @Foldable@.+reduceRM :: (Foldable t, Monad m) => y -> t x -> (x -> y -> m y) -> m y+reduceRM z0 xs f = foldRM f z0 xs+ -- | Flipped version of 'foldMapA'. reduceA :: (Foldable t, Applicative f, Monoid m) => t x -> (x -> f m) -> f m reduceA = flip foldMapA@@ -197,7 +245,7 @@ isift :: (FilterableWithIndex i t) => t x -> (i -> x -> Bool) -> t x isift = flip ifilter --- | Flipped version of 'mapMaybe'.+-- | Flipped version of 'Witherable.mapMaybe'. changeMaybe :: (Filterable t) => t x -> (x -> Maybe y) -> t y changeMaybe = flip Witherable.mapMaybe