foldl 1.3.2 → 1.3.3
raw patch · 4 files changed
+32/−2 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Control.Foldl: vectorM :: (PrimMonad m, Vector v a) => FoldM m a (v a)
Files
- CHANGELOG.md +4/−0
- README.md +1/−1
- foldl.cabal +1/−1
- src/Control/Foldl.hs +26/−0
CHANGELOG.md view
@@ -1,3 +1,7 @@+1.3.3++* Add back the old `vector` as `vectorM`+ 1.3.2 * Compatibility with `Semigroup` becoming a super-class of `Monoid`
README.md view
@@ -1,4 +1,4 @@-# `foldl` v1.3.2+# `foldl` v1.3.3 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.2+Version: 1.3.3 Cabal-Version: >=1.8.0.2 Build-Type: Simple License: BSD3
src/Control/Foldl.hs view
@@ -104,6 +104,7 @@ , map , hashMap , vector+ , vectorM -- * Utilities -- $utilities@@ -917,6 +918,31 @@ done = VectorBuilder.Vector.build {-# INLINABLE vector #-}++maxChunkSize :: Int+maxChunkSize = 8 * 1024 * 1024++{-| Fold all values into a vector++ This is more efficient than `vector` but is impure+-}+vectorM :: (PrimMonad m, Vector v a) => FoldM m a (v a)+vectorM = FoldM step begin done+ where+ begin = do+ mv <- M.unsafeNew 10+ return (Pair mv 0)+ step (Pair mv idx) a = do+ let len = M.length mv+ mv' <- if idx >= len+ then M.unsafeGrow mv (min len maxChunkSize)+ else return mv+ M.unsafeWrite mv' idx a+ return (Pair mv' (idx + 1))+ done (Pair mv idx) = do+ v <- V.freeze mv+ return (V.unsafeTake idx v)+{-# INLINABLE vectorM #-} {- $utilities 'purely' and 'impurely' allow you to write folds compatible with the @foldl@