foldl 1.2.4 → 1.2.5
raw patch · 5 files changed
+91/−3 lines, 5 filesdep +hashabledep +unordered-containersdep ~containersPVP ok
version bump matches the API change (PVP)
Dependencies added: hashable, unordered-containers
Dependency ranges changed: containers
API changes (from Hackage documentation)
+ Control.Foldl: hashMap :: (Eq a, Hashable a) => Fold (a, b) (HashMap a b)
+ Control.Foldl: hashSet :: (Eq a, Hashable a) => Fold a (HashSet a)
+ Control.Foldl: map :: Ord a => Fold (a, b) (Map a b)
+ Control.Foldl: postscan :: Traversable t => Fold a b -> t a -> t b
+ Control.Foldl: prescan :: Traversable t => Fold a b -> t a -> t b
Files
- CHANGELOG.md +14/−0
- README.md +1/−1
- bench/benchmarks.hs +1/−1
- foldl.cabal +3/−1
- src/Control/Foldl.hs +72/−0
CHANGELOG.md view
@@ -1,3 +1,17 @@+1.2.5++* Add support for folding new containers: `hashSet`, `map`, and `hashMap`+* Add `prescan`/`postscan` which generalize `scan` to `Traversable` types++1.2.4++* Add `lazy` folds for `Text` and `ByteString`+* Documentation fixes and improvements++1.2.3++* Add `lookup`+ 1.2.2 * Add numerically stable `mean`, `variance`, and `std` folds
README.md view
@@ -1,4 +1,4 @@-# `foldl` v1.2.4+# `foldl` v1.2.5 Use this `foldl` library when you want to compute multiple folds over a collection in one pass over the data without space leaks.
bench/benchmarks.hs view
@@ -1,6 +1,6 @@ module Main (main) where -import Control.Foldl+import Control.Foldl hiding (map) import Criterion.Main import qualified Data.List import Prelude hiding (length, sum)
foldl.cabal view
@@ -1,5 +1,5 @@ Name: foldl-Version: 1.2.4+Version: 1.2.5 Cabal-Version: >=1.8.0.2 Build-Type: Simple License: BSD3@@ -33,6 +33,8 @@ transformers >= 0.2.0.0 && < 0.6 , vector >= 0.7 && < 0.13, containers < 0.6 ,+ unordered-containers < 0.3 ,+ hashable < 1.3 , contravariant < 1.5 , profunctors < 5.3 , comonad >= 4.0 && < 6
src/Control/Foldl.hs view
@@ -35,6 +35,7 @@ executables that use this library to further improve performance. -} +{-# LANGUAGE CPP #-} {-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE RankNTypes #-}@@ -49,6 +50,11 @@ , fold , foldM , scan+#if MIN_VERSION_base(4,8,0)+ , prescan+ , postscan+#else+#endif -- * Folds , Control.Foldl.mconcat@@ -94,6 +100,9 @@ , nub , eqNub , set+ , hashSet+ , map+ , hashMap , vector -- * Utilities@@ -139,6 +148,7 @@ import Data.Sequence ((|>)) import Data.Vector.Generic (Vector, Mutable) import Data.Vector.Generic.Mutable (MVector)+import Data.Hashable (Hashable) import System.Random.MWC (GenIO, createSystemRandom, uniformR) import Prelude hiding ( head@@ -156,12 +166,16 @@ , elem , notElem , lookup+ , map ) import qualified Data.Foldable as F import qualified Data.List as List import qualified Data.Sequence as Seq import qualified Data.Set as Set+import qualified Data.Map.Strict as Map+import qualified Data.HashMap.Strict as HashMap+import qualified Data.HashSet as HashSet import qualified Data.Vector.Generic as V import qualified Data.Vector.Generic.Mutable as M @@ -461,6 +475,37 @@ cons a k x = done x:(k $! step x a) {-# INLINE scan #-} +#if MIN_VERSION_base(4,8,0)+{-| Convert a `Fold` into a prescan for any `Traversable` type++ \"Prescan\" means that the last element of the scan is not included+-}+prescan :: Traversable t => Fold a b -> t a -> t b+prescan (Fold step begin done) as = bs+ where+ step' x a = (x', b)+ where+ x' = step x a+ b = done x+ (_, bs) = List.mapAccumL step' begin as+{-# INLINE prescan #-}++{-| Convert a `Fold` into a postscan for any `Traversable` type++ \"Postscan\" means that the first element of the scan is not included+-}+postscan :: Traversable t => Fold a b -> t a -> t b+postscan (Fold step begin done) as = bs+ where+ step' x a = (x', b)+ where+ x' = step x a+ b = done x'+ (_, bs) = List.mapAccumL step' begin as+{-# INLINE postscan #-}+#else+#endif+ -- | Fold all values within a container using 'mappend' and 'mempty' mconcat :: Monoid a => Fold a a mconcat = Fold mappend mempty id@@ -823,6 +868,33 @@ set :: Ord a => Fold a (Set.Set a) set = Fold (flip Set.insert) Set.empty id {-# INLINABLE set #-}++-- | Fold values into a hash-set+hashSet :: (Eq a, Hashable a) => Fold a (HashSet.HashSet a)+hashSet = Fold (flip HashSet.insert) HashSet.empty id+{-# INLINABLE hashSet #-}++{-|+Fold pairs into a map.+-}+map :: Ord a => Fold (a, b) (Map.Map a b)+map = Fold step begin done+ where+ begin = mempty+ step m (k, v) = Map.insert k v m+ done = id+{-# INLINABLE map #-}++{-|+Fold pairs into a hash-map.+-}+hashMap :: (Eq a, Hashable a) => Fold (a, b) (HashMap.HashMap a b)+hashMap = Fold step begin done+ where+ begin = mempty+ step m (k, v) = HashMap.insert k v m+ done = id+{-# INLINABLE hashMap #-} maxChunkSize :: Int maxChunkSize = 8 * 1024 * 1024