packages feed

foldl 1.4.13 → 1.4.14

raw patch · 4 files changed

+33/−6 lines, 4 filesdep ~primitivedep ~semigroupoidsPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: primitive, semigroupoids

API changes (from Hackage documentation)

+ Control.Foldl.NonEmpty: nonEmpty :: Fold1 a (NonEmpty a)
+ Control.Foldl.NonEmpty: toFold :: Fold1 a b -> Fold a (Maybe b)
- Control.Foldl.NonEmpty: fold1 :: Fold1 a b -> NonEmpty a -> b
+ Control.Foldl.NonEmpty: fold1 :: Foldable1 f => Fold1 a b -> f a -> b

Files

CHANGELOG.md view
@@ -1,3 +1,9 @@+1.4.14++- Add [`Control.Foldl.NonEmpty.nonEmpty`](https://github.com/Gabriella439/foldl/pull/186)+- Add [`Control.Foldl.NonEmpty.toFold`](https://github.com/Gabriella439/foldl/pull/191)+ - [Generalize `fold1` to work with `Foldable1`](https://github.com/Gabriella439/foldl/pull/185)+ 1.4.13  * New "Control.Foldl.NonEmpty" module for folding non-empty containers
foldl.cabal view
@@ -1,5 +1,5 @@ Name: foldl-Version: 1.4.13+Version: 1.4.14 Cabal-Version: >=1.10 Build-Type: Simple License: BSD3@@ -35,7 +35,7 @@         unordered-containers        < 0.3 ,         hashable                    < 1.5 ,         contravariant               < 1.6 ,-        profunctors                 < 5.7 ,+        profunctors  >= 3.2      && < 5.7 ,         semigroupoids >= 1.0     && < 5.4 ,         comonad      >= 4.0      && < 6     if impl(ghc < 8.0)
src/Control/Foldl.hs view
@@ -1236,8 +1236,6 @@  {-| @(prefilterM f folder)@ returns a new 'FoldM' where the folder's input is used   only when the input satisfies a monadic predicate f.--> foldM (prefilterM p folder) list = foldM folder (filter p list) -} prefilterM :: (Monad m) => (a -> m Bool) -> FoldM m a r -> FoldM m a r prefilterM f (FoldM step begin done) = FoldM step' begin done
src/Control/Foldl/NonEmpty.hs view
@@ -13,8 +13,10 @@  import Control.Applicative (liftA2) import Control.Foldl (Fold(..))+import Control.Foldl.Internal (Either'(..)) import Data.List.NonEmpty (NonEmpty(..)) import Data.Profunctor (Profunctor(..))+import Data.Semigroup.Foldable (Foldable1(..)) import Prelude hiding (head, last, minimum, maximum)  import qualified Control.Foldl as Foldl@@ -143,14 +145,35 @@     {-# INLINE logBase #-}  -- | Apply a strict left `Fold1` to a `NonEmpty` list-fold1 :: Fold1 a b -> NonEmpty a -> b-fold1 (Fold1 k) (a :| as) = Foldl.fold (k a) as+fold1 :: Foldable1 f => Fold1 a b -> f a -> b+fold1 (Fold1 k) as1 = Foldl.fold (k a) as+  where+    a :| as = toNonEmpty as1 {-# INLINABLE fold1 #-}  -- | Promote any `Fold` to an equivalent `Fold1` fromFold :: Fold a b -> Fold1 a b fromFold (Fold step begin done) = Fold1 (\a -> Fold step (step begin a) done) {-# INLINABLE fromFold #-}++-- | Promote any `Fold1` to an equivalent `Fold`+toFold :: Fold1 a b -> Fold a (Maybe b)+toFold (Fold1 k0) = Fold step begin done+  where+    begin = Left' k0++    step (Left' k) a = Right' (k a)+    step (Right' (Fold step' begin' done')) a =+        Right' (Fold step' (step' begin' a) done')++    done (Right' (Fold _ begin' done')) = Just (done' begin')+    done (Left' _) = Nothing+{-# INLINABLE toFold #-}++-- | Fold all values within a non-empty container into a `NonEmpty` list+nonEmpty :: Fold1 a (NonEmpty a)+nonEmpty = Fold1 (\a -> fmap (a :|) Foldl.list)+{-# INLINEABLE nonEmpty #-}  -- | Fold all values within a non-empty container using (`<>`) sconcat :: Semigroup a => Fold1 a a