packages feed

foldl 1.3.5 → 1.3.7

raw patch · 4 files changed

+35/−2 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Control.Foldl: groupBy :: Ord g => (a -> g) -> Fold a r -> Fold a (Map g r)

Files

CHANGELOG.md view
@@ -1,3 +1,11 @@+1.3.7++* Add `groupBy`++1.3.6++* Documentation improvements+ 1.3.5  * Add `Choice` instance for `Fold`
README.md view
@@ -1,4 +1,4 @@-# `foldl` v1.3.5+# `foldl` v1.3.7  Use this `foldl` library when you want to compute multiple folds over a collection in one pass over the data without space leaks.
foldl.cabal view
@@ -1,5 +1,5 @@ Name: foldl-Version: 1.3.5+Version: 1.3.7 Cabal-Version: >=1.8.0.2 Build-Type: Simple License: BSD3
src/Control/Foldl.hs view
@@ -35,6 +35,7 @@     executables that use this library to further improve performance. -} +{-# LANGUAGE BangPatterns              #-} {-# LANGUAGE CPP                       #-} {-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE FlexibleContexts          #-}@@ -130,6 +131,7 @@     , foldOverM     , folded     , filtered+    , groupBy      -- * Re-exports     -- $reexports@@ -146,6 +148,8 @@ import Data.Foldable (Foldable) import Data.Functor.Identity (Identity, runIdentity) import Data.Functor.Contravariant (Contravariant(..))+import Data.Map.Strict (Map, alter)+import Data.Maybe (fromMaybe) import Data.Monoid hiding ((<>)) import Data.Semigroup (Semigroup(..)) import Data.Profunctor@@ -1134,6 +1138,14 @@    This can also be done with 'handles' (@handles (filtered f)@) but @prefilter@   does not need you to depend on a lens library.++> fold (prefilter p folder) list = fold folder (filter p list)++>>> fold (prefilter (>5) Control.Foldl.sum) [1..10]+40++>>> fold Control.Foldl.sum (filter (>5) [1..10])+40 -} prefilter :: (a -> Bool) -> Fold a r -> Fold a r prefilter f (Fold step begin done) = Fold step' begin done@@ -1143,6 +1155,8 @@  {-| @(prefilterM f folder)@ returns a new 'Fold' 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@@ -1304,6 +1318,17 @@     | p x = k x     | otherwise = mempty {-# INLINABLE filtered #-}++{-| Perform a 'Fold' while grouping the data according to a specified group+projection function. Returns the folded result grouped as a map keyed by the+group.++-}+groupBy :: Ord g => (a -> g) -> Fold a r -> Fold a (Map g r)+groupBy grouper (Fold f i e) = Fold f' mempty (fmap e)+  where+    f' !m !a = alter (\o -> Just (f (fromMaybe i o) a)) (grouper a) m+{-# INLINABLE groupBy #-}  {- $reexports     @Control.Monad.Primitive@ re-exports the 'PrimMonad' type class