summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabrielGonzalez <>2017-05-30 17:56:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2017-05-30 17:56:00 (GMT)
commitb24533225828b9246617b100f62877d9668c05e0 (patch)
tree579b836344dca98cf2b95015c89cace937aa52c4
parentceb9f3cdc6c0a54bf3b0092d0614931cade45574 (diff)
version 1.3.01.3.0
-rw-r--r--CHANGELOG.md4
-rw-r--r--README.md2
-rw-r--r--foldl.cabal5
-rw-r--r--src/Control/Foldl.hs27
4 files changed, 17 insertions, 21 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ee4e55e..9671413 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+1.3.0
+
+* BREAKING CHANGE: Change `vector` to be a pure `Fold` (which is faster, too!)
+
1.2.5
* Add support for folding new containers: `hashSet`, `map`, and `hashMap`
diff --git a/README.md b/README.md
index 316fd9a..9f7fbe8 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# `foldl` v1.2.5
+# `foldl` v1.3.0
Use this `foldl` library when you want to compute multiple folds over a
collection in one pass over the data without space leaks.
diff --git a/foldl.cabal b/foldl.cabal
index 1b08dab..630f84b 100644
--- a/foldl.cabal
+++ b/foldl.cabal
@@ -1,5 +1,5 @@
Name: foldl
-Version: 1.2.5
+Version: 1.3.0
Cabal-Version: >=1.8.0.2
Build-Type: Simple
License: BSD3
@@ -37,7 +37,8 @@ Library
hashable < 1.3 ,
contravariant < 1.5 ,
profunctors < 5.3 ,
- comonad >= 4.0 && < 6
+ comonad >= 4.0 && < 6 ,
+ vector-builder < 0.4
Exposed-Modules:
Control.Foldl,
Control.Foldl.ByteString,
diff --git a/src/Control/Foldl.hs b/src/Control/Foldl.hs
index 872b39c..1e9c3cd 100644
--- a/src/Control/Foldl.hs
+++ b/src/Control/Foldl.hs
@@ -178,6 +178,8 @@ 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
+import qualified VectorBuilder.Builder
+import qualified VectorBuilder.Vector
{-| Efficient representation of a left fold that preserves the fold's step
function, initial accumulator, and extraction function
@@ -896,26 +898,15 @@ hashMap = Fold step begin done
done = id
{-# INLINABLE hashMap #-}
-maxChunkSize :: Int
-maxChunkSize = 8 * 1024 * 1024
-
-- | Fold all values into a vector
-vector :: (PrimMonad m, Vector v a) => FoldM m a (v a)
-vector = FoldM step begin done
+vector :: Vector v a => Fold a (v a)
+vector = Fold 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)
+ begin = VectorBuilder.Builder.empty
+
+ step x a = x <> VectorBuilder.Builder.singleton a
+
+ done = VectorBuilder.Vector.build
{-# INLINABLE vector #-}
{- $utilities