on master help sign in
Rename Consumer to Refold
06e5512Harendra Kumar
benchmark/Streamly/Benchmark/Prelude/Serial/NestedFold.hs+12−12
@@ -20,7 +20,7 @@ import Control.Monad.IO.Class (MonadIO(..))
20import Data.Monoid (Sum(..))
20import Data.Monoid (Sum(..))
21import GHC.Generics (Generic)
21import GHC.Generics (Generic)
22
22
23−import qualified Streamly.Internal.Data.Consumer.Type as Consumer
23+import qualified Streamly.Internal.Data.Refold.Type as Refold
24import qualified Streamly.Internal.Data.Fold as FL
24import qualified Streamly.Internal.Data.Fold as FL
25import qualified Streamly.Internal.Data.Stream.IsStream as Internal
25import qualified Streamly.Internal.Data.Stream.IsStream as Internal
26import qualified Streamly.Prelude as S
26import qualified Streamly.Prelude as S
@@ -141,12 +141,12 @@ foldMany =
141 . Internal.foldMany (FL.take 2 FL.mconcat)
141 . Internal.foldMany (FL.take 2 FL.mconcat)
142 . S.map Sum
142 . S.map Sum
143
143
144−{-# INLINE consumeMany #-}
144+{-# INLINE refoldMany #-}
145−consumeMany :: Monad m => SerialT m Int -> m ()
145+refoldMany :: Monad m => SerialT m Int -> m ()
146−consumeMany =
146+refoldMany =
147 S.drain
147 S.drain
148 . S.map getSum
148 . S.map getSum
149− . Internal.consumeMany (Consumer.take 2 Consumer.sconcat) (return mempty)
149+ . Internal.refoldMany (Refold.take 2 Refold.sconcat) (return mempty)
150 . S.map Sum
150 . S.map Sum
151
151
152{-# INLINE foldIterateM #-}
152{-# INLINE foldIterateM #-}
@@ -158,13 +158,13 @@ foldIterateM =
158 (return . FL.take 2 . FL.sconcat) (return (Sum 0))
158 (return . FL.take 2 . FL.sconcat) (return (Sum 0))
159 . S.map Sum
159 . S.map Sum
160
160
161−{-# INLINE consumeIterateM #-}
161+{-# INLINE refoldIterateM #-}
162−consumeIterateM :: Monad m => SerialT m Int -> m ()
162+refoldIterateM :: Monad m => SerialT m Int -> m ()
163−consumeIterateM =
163+refoldIterateM =
164 S.drain
164 S.drain
165 . S.map getSum
165 . S.map getSum
166− . Internal.consumeIterateM
166+ . Internal.refoldIterateM
167− (Consumer.take 2 Consumer.sconcat) (return (Sum 0))
167+ (Refold.take 2 Refold.sconcat) (return (Sum 0))
168 . S.map Sum
168 . S.map Sum
169
169
170o_1_space_grouping :: Int -> [Benchmark]
170o_1_space_grouping :: Int -> [Benchmark]
@@ -177,9 +177,9 @@ o_1_space_grouping value =
177 , benchIOSink value "groupsByRollingLT" groupsByRollingLT
177 , benchIOSink value "groupsByRollingLT" groupsByRollingLT
178 , benchIOSink value "groupsByRollingEq" groupsByRollingEq
178 , benchIOSink value "groupsByRollingEq" groupsByRollingEq
179 , benchIOSink value "foldMany" foldMany
179 , benchIOSink value "foldMany" foldMany
180− , benchIOSink value "consumeMany" consumeMany
180+ , benchIOSink value "refoldMany" refoldMany
181 , benchIOSink value "foldIterateM" foldIterateM
181 , benchIOSink value "foldIterateM" foldIterateM
182− , benchIOSink value "consumeIterateM" consumeIterateM
182+ , benchIOSink value "refoldIterateM" refoldIterateM
183 ]
183 ]
184 ]
184 ]
185
185
src/Streamly/Internal/Data/Fold/Type.hs+23−24
@@ -209,7 +209,7 @@ module Streamly.Internal.Data.Fold.Type
209 -- * Folds
209 -- * Folds
210 , fromPure
210 , fromPure
211 , fromEffect
211 , fromEffect
212− , fromConsumer
212+ , fromRefold
213 , drain
213 , drain
214 , toList
214 , toList
215 , toStreamK
215 , toStreamK
@@ -250,9 +250,9 @@ module Streamly.Internal.Data.Fold.Type
250 , many
250 , many
251 , manyPost
251 , manyPost
252 , chunksOf
252 , chunksOf
253− , consumeMany
253+ , refoldMany
254− , consumeMany1
254+ , refoldMany1
255− , appendConsumer
255+ , refold
256
256
257 -- ** Nesting
257 -- ** Nesting
258 , concatMap
258 , concatMap
@@ -272,7 +272,7 @@ import Fusion.Plugin.Types (Fuse(..))
272import Streamly.Internal.Data.Fold.Step (Step(..), mapMStep, chainStepM)
272import Streamly.Internal.Data.Fold.Step (Step(..), mapMStep, chainStepM)
273import Streamly.Internal.Data.Maybe.Strict (Maybe'(..), toMaybe)
273import Streamly.Internal.Data.Maybe.Strict (Maybe'(..), toMaybe)
274import Streamly.Internal.Data.Tuple.Strict (Tuple'(..))
274import Streamly.Internal.Data.Tuple.Strict (Tuple'(..))
275−import Streamly.Internal.Data.Consumer.Type (Consumer(..))
275+import Streamly.Internal.Data.Refold.Type (Refold(..))
276
276
277import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
277import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
278
278
@@ -505,7 +505,7 @@ mkFoldM_ :: Monad m => (b -> a -> m (Step b b)) -> m (Step b b) -> Fold m a b
505mkFoldM_ step initial = mkFoldM step initial return
505mkFoldM_ step initial = mkFoldM step initial return
506
506
507------------------------------------------------------------------------------
507------------------------------------------------------------------------------
508−-- Consumer
508+-- Refold
509------------------------------------------------------------------------------
509------------------------------------------------------------------------------
510
510
511-- This is similar to how we run an Unfold to generate a Stream. A Fold is like
511-- This is similar to how we run an Unfold to generate a Stream. A Fold is like
@@ -514,8 +514,8 @@ mkFoldM_ step initial = mkFoldM step initial return
514-- | Make a fold from a consumer.
514-- | Make a fold from a consumer.
515--
515--
516-- /Internal/
516-- /Internal/
517−fromConsumer :: Consumer m c a b -> c -> Fold m a b
517+fromRefold :: Refold m c a b -> c -> Fold m a b
518−fromConsumer (Consumer step inject extract) c =
518+fromRefold (Refold step inject extract) c =
519 Fold step (inject c) extract
519 Fold step (inject c) extract
520
520
521------------------------------------------------------------------------------
521------------------------------------------------------------------------------
@@ -1305,15 +1305,15 @@ chunksOf :: Monad m => Int -> Fold m a b -> Fold m b c -> Fold m a c
1305chunksOf n split = many (take n split)
1305chunksOf n split = many (take n split)
1306
1306
1307------------------------------------------------------------------------------
1307------------------------------------------------------------------------------
1308−-- Consumer and Fold Combinators
1308+-- Refold and Fold Combinators
1309------------------------------------------------------------------------------
1309------------------------------------------------------------------------------
1310
1310
1311−-- | Like 'many' but uses a 'Consumer' for collecting.
1311+-- | Like 'many' but uses a 'Refold' for collecting.
1312--
1312--
1313−{-# INLINE consumeMany #-}
1313+{-# INLINE refoldMany #-}
1314−consumeMany :: Monad m => Fold m a b -> Consumer m x b c -> Consumer m x a c
1314+refoldMany :: Monad m => Fold m a b -> Refold m x b c -> Refold m x a c
1315−consumeMany (Fold sstep sinitial sextract) (Consumer cstep cinject cextract) =
1315+refoldMany (Fold sstep sinitial sextract) (Refold cstep cinject cextract) =
1316− Consumer step inject extract
1316+ Refold step inject extract
1317
1317
1318 where
1318 where
1319
1319
@@ -1359,13 +1359,13 @@ consumeMany (Fold sstep sinitial sextract) (Consumer cstep cinject cextract) =
1359{-# ANN type ConsumeManyState Fuse #-}
1359{-# ANN type ConsumeManyState Fuse #-}
1360data ConsumeManyState x cs ss = ConsumeMany x cs (Either ss ss)
1360data ConsumeManyState x cs ss = ConsumeMany x cs (Either ss ss)
1361
1361
1362−-- | Like 'many' but uses a 'Consumer' for splitting.
1362+-- | Like 'many' but uses a 'Refold' for splitting.
1363--
1363--
1364-- /Internal/
1364-- /Internal/
1365−{-# INLINE consumeMany1 #-}
1365+{-# INLINE refoldMany1 #-}
1366−consumeMany1 :: Monad m => Consumer m x a b -> Fold m b c -> Consumer m x a c
1366+refoldMany1 :: Monad m => Refold m x a b -> Fold m b c -> Refold m x a c
1367−consumeMany1 (Consumer sstep sinject sextract) (Fold cstep cinitial cextract) =
1367+refoldMany1 (Refold sstep sinject sextract) (Fold cstep cinitial cextract) =
1368− Consumer step inject extract
1368+ Refold step inject extract
1369
1369
1370 where
1370 where
1371
1371
@@ -1408,10 +1408,9 @@ consumeMany1 (Consumer sstep sinject sextract) (Fold cstep cinitial cextract) =
1408 Partial s -> cextract s
1408 Partial s -> cextract s
1409 Done b -> return b
1409 Done b -> return b
1410
1410
1411−-- | Extend a fold by appending a Consumer.
1411+-- | Extract the output of a fold and refold is using a 'Refold'.
1412--
1412--
1413-- /Internal/
1413-- /Internal/
1414−{-# INLINE appendConsumer #-}
1414+{-# INLINE refold #-}
1415−appendConsumer :: Monad m => Fold m a b -> Consumer m b a b -> Fold m a b
1415+refold :: Monad m => Fold m a b -> Refold m b a b -> Fold m a b
1416−appendConsumer f (Consumer step inject extract) =
1417− Fold step (finish f >>= inject) extract
1416+refold f (Refold step inject extract) = Fold step (finish f >>= inject) extract
src/Streamly/Internal/Data/Consumer/Type.hs → src/Streamly/Internal/Data/Refold/Type.hsrenamed+34−34
@@ -1,5 +1,5 @@
1-- |
1-- |
2−-- Module : Streamly.Internal.Data.Consumer.Type
2+-- Module : Streamly.Internal.Data.Refold.Type
3-- Copyright : (c) 2019 Composewell Technologies
3-- Copyright : (c) 2019 Composewell Technologies
4-- License : BSD-3-Clause
4-- License : BSD-3-Clause
5-- Maintainer : streamly@composewell.com
5-- Maintainer : streamly@composewell.com
@@ -7,29 +7,29 @@
7-- Portability : GHC
7-- Portability : GHC
8--
8--
9-- The 'Fold' type embeds a default initial value, therefore, it is like a
9-- The 'Fold' type embeds a default initial value, therefore, it is like a
10−-- 'Monoid' whereas the 'Consumer' type has to be supplied with an initial
10+-- 'Monoid' whereas the 'Refold' type has to be supplied with an initial
11-- value, therefore, it is more like a 'Semigroup' operation.
11-- value, therefore, it is more like a 'Semigroup' operation.
12--
12--
13−-- Consumers can be appended to each other or to a fold to build the fold
13+-- Refolds can be appended to each other or to a fold to build the fold
14-- incrementally. This is useful in incremental builder like use cases.
14-- incrementally. This is useful in incremental builder like use cases.
15--
15--
16-- See the file splitting example in the @streamly-examples@ repository for an
16-- See the file splitting example in the @streamly-examples@ repository for an
17−-- application of the 'Consumer' type. The 'Fold' type does not perform as well
17+-- application of the 'Refold' type. The 'Fold' type does not perform as well
18-- in this situation.
18-- in this situation.
19--
19--
20−-- 'Consumer' type is to 'Fold' as 'Unfold' type is to 'Stream'. Like 'Unfold'
20+-- 'Refold' type is to 'Fold' as 'Unfold' type is to 'Stream'. 'Unfold'
21−-- provides better optimizaiton than stream in nested operations similarly
21+-- provides better optimizaiton than stream in nested operations, similarly,
22−-- 'Consumer' provides better optimization than 'Fold'.
22+-- 'Refold' provides better optimization than 'Fold'.
23--
23--
24−module Streamly.Internal.Data.Consumer.Type
24+module Streamly.Internal.Data.Refold.Type
25 (
25 (
26 -- * Types
26 -- * Types
27− Consumer (..)
27+ Refold (..)
28
28
29 -- * Constructors
29 -- * Constructors
30 , foldl'
30 , foldl'
31
31
32− -- * Consumers
32+ -- * Refolds
33 -- ** Accumulators
33 -- ** Accumulators
34 , sconcat
34 , sconcat
35 , drainBy
35 , drainBy
@@ -54,11 +54,11 @@ import Prelude hiding (take, iterate)
54
54
55-- $setup
55-- $setup
56-- >>> :m
56-- >>> :m
57−-- >>> import qualified Streamly.Internal.Data.Consumer.Type as Consumer
57+-- >>> import qualified Streamly.Internal.Data.Refold.Type as Refold
58-- >>> import qualified Streamly.Internal.Data.Fold.Type as Fold
58-- >>> import qualified Streamly.Internal.Data.Fold.Type as Fold
59-- >>> import qualified Streamly.Internal.Data.Stream.IsStream as Stream
59-- >>> import qualified Streamly.Internal.Data.Stream.IsStream as Stream
60
60
61−-- All folds in the Fold module should be implemented using Consumers.
61+-- All folds in the Fold module should be implemented using Refolds.
62--
62--
63-- | Like 'Fold' except that the initial state of the accmulator can be
63-- | Like 'Fold' except that the initial state of the accmulator can be
64-- generated using a dynamically supplied input. This affords better stream
64-- generated using a dynamically supplied input. This affords better stream
@@ -66,9 +66,9 @@ import Prelude hiding (take, iterate)
66-- is determined based on a dynamic value.
66-- is determined based on a dynamic value.
67--
67--
68-- /Internal/
68-- /Internal/
69−data Consumer m c a b =
69+data Refold m c a b =
70 -- | @Fold @ @ step @ @ inject @ @ extract@
70 -- | @Fold @ @ step @ @ inject @ @ extract@
71− forall s. Consumer (s -> a -> m (Step s b)) (c -> m (Step s b)) (s -> m b)
71+ forall s. Refold (s -> a -> m (Step s b)) (c -> m (Step s b)) (s -> m b)
72
72
73------------------------------------------------------------------------------
73------------------------------------------------------------------------------
74-- Left fold constructors
74-- Left fold constructors
@@ -84,9 +84,9 @@ data Consumer m c a b =
84-- /Internal/
84-- /Internal/
85--
85--
86{-# INLINE foldl' #-}
86{-# INLINE foldl' #-}
87−foldl' :: Monad m => (b -> a -> b) -> Consumer m b a b
87+foldl' :: Monad m => (b -> a -> b) -> Refold m b a b
88foldl' step =
88foldl' step =
89− Consumer
89+ Refold
90 (\s a -> return $ Partial $ step s a)
90 (\s a -> return $ Partial $ step s a)
91 (return . Partial)
91 (return . Partial)
92 return
92 return
@@ -99,8 +99,8 @@ foldl' step =
99--
99--
100-- /Internal/
100-- /Internal/
101{-# INLINE lmapM #-}
101{-# INLINE lmapM #-}
102−lmapM :: Monad m => (a -> m b) -> Consumer m c b r -> Consumer m c a r
102+lmapM :: Monad m => (a -> m b) -> Refold m c b r -> Refold m c a r
103−lmapM f (Consumer step inject extract) = Consumer step1 inject extract
103+lmapM f (Refold step inject extract) = Refold step1 inject extract
104
104
105 where
105 where
106
106
@@ -114,8 +114,8 @@ lmapM f (Consumer step inject extract) = Consumer step1 inject extract
114--
114--
115-- /Internal/
115-- /Internal/
116{-# INLINE rmapM #-}
116{-# INLINE rmapM #-}
117−rmapM :: Monad m => (b -> m c) -> Consumer m x a b -> Consumer m x a c
117+rmapM :: Monad m => (b -> m c) -> Refold m x a b -> Refold m x a c
118−rmapM f (Consumer step inject extract) = Consumer step1 inject1 (extract >=> f)
118+rmapM f (Refold step inject extract) = Refold step1 inject1 (extract >=> f)
119
119
120 where
120 where
121
121
@@ -123,15 +123,15 @@ rmapM f (Consumer step inject extract) = Consumer step1 inject1 (extract >=> f)
123 step1 s a = step s a >>= mapMStep f
123 step1 s a = step s a >>= mapMStep f
124
124
125------------------------------------------------------------------------------
125------------------------------------------------------------------------------
126−-- Consumers
126+-- Refolds
127------------------------------------------------------------------------------
127------------------------------------------------------------------------------
128
128
129-- |
129-- |
130--
130--
131-- /Internal/
131-- /Internal/
132{-# INLINE drainBy #-}
132{-# INLINE drainBy #-}
133−drainBy :: Monad m => (c -> a -> m b) -> Consumer m c a ()
133+drainBy :: Monad m => (c -> a -> m b) -> Refold m c a ()
134−drainBy f = Consumer step inject extract
134+drainBy f = Refold step inject extract
135
135
136 where
136 where
137
137
@@ -148,14 +148,14 @@ drainBy f = Consumer step inject extract
148-- | Append the elements of an input stream to a provided starting value.
148-- | Append the elements of an input stream to a provided starting value.
149--
149--
150-- >>> stream = Stream.map Data.Monoid.Sum $ Stream.enumerateFromTo 1 10
150-- >>> stream = Stream.map Data.Monoid.Sum $ Stream.enumerateFromTo 1 10
151−-- >>> Stream.fold (Fold.fromConsumer Consumer.sconcat 10) stream
151+-- >>> Stream.fold (Fold.fromRefold Refold.sconcat 10) stream
152-- Sum {getSum = 65}
152-- Sum {getSum = 65}
153--
153--
154−-- >>> sconcat = Consumer.foldl' (<>)
154+-- >>> sconcat = Refold.foldl' (<>)
155--
155--
156-- /Internal/
156-- /Internal/
157{-# INLINE sconcat #-}
157{-# INLINE sconcat #-}
158−sconcat :: (Monad m, Semigroup a) => Consumer m a a a
158+sconcat :: (Monad m, Semigroup a) => Refold m a a a
159sconcat = foldl' (<>)
159sconcat = foldl' (<>)
160
160
161------------------------------------------------------------------------------
161------------------------------------------------------------------------------
@@ -166,9 +166,9 @@ sconcat = foldl' (<>)
166--
166--
167-- /Internal/
167-- /Internal/
168{-# INLINE append #-}
168{-# INLINE append #-}
169−append :: Monad m => Consumer m x a b -> Consumer m b a b -> Consumer m x a b
169+append :: Monad m => Refold m x a b -> Refold m b a b -> Refold m x a b
170−append (Consumer step1 inject1 extract1) (Consumer step2 inject2 extract2) =
170+append (Refold step1 inject1 extract1) (Refold step2 inject2 extract2) =
171− Consumer step inject extract
171+ Refold step inject extract
172
172
173 where
173 where
174
174
@@ -198,9 +198,9 @@ append (Consumer step1 inject1 extract1) (Consumer step2 inject2 extract2) =
198-- the output of the previous run to the next.
198-- the output of the previous run to the next.
199--
199--
200-- /Internal/
200-- /Internal/
201−iterate :: Monad m => Consumer m b a b -> Consumer m b a b
201+iterate :: Monad m => Refold m b a b -> Refold m b a b
202−iterate (Consumer step1 inject1 extract1) =
202+iterate (Refold step1 inject1 extract1) =
203− Consumer step inject extract1
203+ Refold step inject extract1
204
204
205 where
205 where
206
206
@@ -226,8 +226,8 @@ data Tuple'Fused a b = Tuple'Fused !a !b deriving Show
226--
226--
227-- /Internal/
227-- /Internal/
228{-# INLINE take #-}
228{-# INLINE take #-}
229−take :: Monad m => Int -> Consumer m x a b -> Consumer m x a b
229+take :: Monad m => Int -> Refold m x a b -> Refold m x a b
230−take n (Consumer fstep finject fextract) = Consumer step inject extract
230+take n (Refold fstep finject fextract) = Refold step inject extract
231
231
232 where
232 where
233
233
src/Streamly/Internal/Data/Stream/IsStream/Reduce.hs+13−13
@@ -29,10 +29,10 @@ module Streamly.Internal.Data.Stream.IsStream.Reduce
29 -- | Apply folds on a stream.
29 -- | Apply folds on a stream.
30 , foldMany
30 , foldMany
31 , foldManyPost
31 , foldManyPost
32− , consumeMany
32+ , refoldMany
33 , foldSequence
33 , foldSequence
34 , foldIterateM
34 , foldIterateM
35− , consumeIterateM
35+ , refoldIterateM
36
36
37 -- ** Chunking
37 -- ** Chunking
38 -- | Element unaware grouping.
38 -- | Element unaware grouping.
@@ -155,7 +155,7 @@ import Data.Maybe (isNothing)
155import Foreign.Storable (Storable)
155import Foreign.Storable (Storable)
156import Streamly.Internal.Control.Concurrent (MonadAsync)
156import Streamly.Internal.Control.Concurrent (MonadAsync)
157import Streamly.Internal.Data.Fold.Type (Fold (..))
157import Streamly.Internal.Data.Fold.Type (Fold (..))
158−import Streamly.Internal.Data.Consumer.Type (Consumer (..))
158+import Streamly.Internal.Data.Refold.Type (Refold (..))
159import Streamly.Internal.Data.Parser (Parser (..))
159import Streamly.Internal.Data.Parser (Parser (..))
160import Streamly.Internal.Data.Array.Foreign.Type (Array)
160import Streamly.Internal.Data.Array.Foreign.Type (Array)
161import Streamly.Internal.Data.Stream.IsStream.Common
161import Streamly.Internal.Data.Stream.IsStream.Common
@@ -295,13 +295,13 @@ foldMany
295 -> t m b
295 -> t m b
296foldMany f m = fromStreamD $ D.foldMany f (toStreamD m)
296foldMany f m = fromStreamD $ D.foldMany f (toStreamD m)
297
297
298−-- | Like 'foldMany' but using the 'Consumer' type instead of 'Fold'.
298+-- | Like 'foldMany' but using the 'Refold' type instead of 'Fold'.
299--
299--
300-- /Pre-release/
300-- /Pre-release/
301−{-# INLINE consumeMany #-}
301+{-# INLINE refoldMany #-}
302−consumeMany :: (IsStream t, Monad m) =>
302+refoldMany :: (IsStream t, Monad m) =>
303− Consumer m c a b -> m c -> t m a -> t m b
303+ Refold m c a b -> m c -> t m a -> t m b
304−consumeMany f action = fromStreamD . D.consumeMany f action . toStreamD
304+refoldMany f action = fromStreamD . D.refoldMany f action . toStreamD
305
305
306-- | Apply a stream of folds to an input stream and emit the results in the
306-- | Apply a stream of folds to an input stream and emit the results in the
307-- output stream.
307-- output stream.
@@ -339,14 +339,14 @@ foldIterateM ::
339 (IsStream t, Monad m) => (b -> m (Fold m a b)) -> m b -> t m a -> t m b
339 (IsStream t, Monad m) => (b -> m (Fold m a b)) -> m b -> t m a -> t m b
340foldIterateM f i m = fromStreamD $ D.foldIterateM f i (toStreamD m)
340foldIterateM f i m = fromStreamD $ D.foldIterateM f i (toStreamD m)
341
341
342−-- | Like 'foldIterateM' but using the 'Consumer' type instead. This could be
342+-- | Like 'foldIterateM' but using the 'Refold' type instead. This could be
343-- much more efficient due to stream fusion.
343-- much more efficient due to stream fusion.
344--
344--
345-- /Internal/
345-- /Internal/
346−{-# INLINE consumeIterateM #-}
346+{-# INLINE refoldIterateM #-}
347−consumeIterateM :: (IsStream t, Monad m) =>
347+refoldIterateM :: (IsStream t, Monad m) =>
348− Consumer m b a b -> m b -> t m a -> t m b
348+ Refold m b a b -> m b -> t m a -> t m b
349−consumeIterateM c i m = fromStreamD $ D.consumeIterateM c i (toStreamD m)
349+refoldIterateM c i m = fromStreamD $ D.refoldIterateM c i (toStreamD m)
350
350
351------------------------------------------------------------------------------
351------------------------------------------------------------------------------
352-- Parsing
352-- Parsing
src/Streamly/Internal/Data/Stream/StreamD/Nesting.hs+8−8
@@ -112,9 +112,9 @@ module Streamly.Internal.Data.Stream.StreamD.Nesting
112 -- ** Folding
112 -- ** Folding
113 -- | Apply folds on a stream.
113 -- | Apply folds on a stream.
114 , foldMany
114 , foldMany
115− , consumeMany
115+ , refoldMany
116 , foldIterateM
116 , foldIterateM
117− , consumeIterateM
117+ , refoldIterateM
118
118
119 -- ** Parsing
119 -- ** Parsing
120 -- | Parsing is opposite to flattening. 'parseMany' is dual to concatMap or
120 -- | Parsing is opposite to flattening. 'parseMany' is dual to concatMap or
@@ -159,7 +159,7 @@ import Fusion.Plugin.Types (Fuse(..))
159import GHC.Types (SPEC(..))
159import GHC.Types (SPEC(..))
160
160
161import Streamly.Internal.Data.Array.Foreign.Type (Array(..))
161import Streamly.Internal.Data.Array.Foreign.Type (Array(..))
162−import Streamly.Internal.Data.Consumer.Type (Consumer(..))
162+import Streamly.Internal.Data.Refold.Type (Refold(..))
163import Streamly.Internal.Data.Fold.Type (Fold(..))
163import Streamly.Internal.Data.Fold.Type (Fold(..))
164import Streamly.Internal.Data.Parser (ParseError(..))
164import Streamly.Internal.Data.Parser (ParseError(..))
165import Streamly.Internal.Data.SVar.Type (adaptState)
165import Streamly.Internal.Data.SVar.Type (adaptState)
@@ -1032,14 +1032,14 @@ data CIterState s f fs b
1032 | CIterYield b (CIterState s f fs b)
1032 | CIterYield b (CIterState s f fs b)
1033 | CIterStop
1033 | CIterStop
1034
1034
1035−-- | Like 'foldIterateM' but using the 'Consumer' type instead. This could be
1035+-- | Like 'foldIterateM' but using the 'Refold' type instead. This could be
1036-- much more efficient due to stream fusion.
1036-- much more efficient due to stream fusion.
1037--
1037--
1038-- /Internal/
1038-- /Internal/
1039−{-# INLINE_NORMAL consumeIterateM #-}
1039+{-# INLINE_NORMAL refoldIterateM #-}
1040−consumeIterateM ::
1040+refoldIterateM ::
1041− Monad m => Consumer m b a b -> m b -> Stream m a -> Stream m b
1041+ Monad m => Refold m b a b -> m b -> Stream m a -> Stream m b
1042−consumeIterateM (Consumer fstep finject fextract) initial (Stream step state) =
1042+refoldIterateM (Refold fstep finject fextract) initial (Stream step state) =
1043 Stream stepOuter (CIterInit state initial)
1043 Stream stepOuter (CIterInit state initial)
1044
1044
1045 where
1045 where
src/Streamly/Internal/Data/Stream/StreamD/Type.hs+6−6
@@ -84,7 +84,7 @@ module Streamly.Internal.Data.Stream.StreamD.Type
84 , FoldManyPost (..)
84 , FoldManyPost (..)
85 , foldMany
85 , foldMany
86 , foldManyPost
86 , foldManyPost
87− , consumeMany
87+ , refoldMany
88 , chunksOf
88 , chunksOf
89 )
89 )
90where
90where
@@ -100,7 +100,7 @@ import GHC.Types (SPEC(..))
100import Prelude hiding (map, mapM, foldr, take, concatMap, takeWhile)
100import Prelude hiding (map, mapM, foldr, take, concatMap, takeWhile)
101
101
102import Streamly.Internal.Data.Fold.Type (Fold(..))
102import Streamly.Internal.Data.Fold.Type (Fold(..))
103−import Streamly.Internal.Data.Consumer.Type (Consumer(..))
103+import Streamly.Internal.Data.Refold.Type (Refold(..))
104import Streamly.Internal.Data.Stream.StreamD.Step (Step (..))
104import Streamly.Internal.Data.Stream.StreamD.Step (Step (..))
105import Streamly.Internal.Data.SVar.Type (State, adaptState, defState)
105import Streamly.Internal.Data.SVar.Type (State, adaptState, defState)
106import Streamly.Internal.Data.Unfold.Type (Unfold(..))
106import Streamly.Internal.Data.Unfold.Type (Unfold(..))
@@ -949,12 +949,12 @@ chunksOf n f = foldMany (FL.take n f)
949
949
950-- Keep the argument order consistent with consumeIterateM
950-- Keep the argument order consistent with consumeIterateM
951--
951--
952−-- | Like 'foldMany' but for the 'Consumer' type.
952+-- | Like 'foldMany' but for the 'Refold' type.
953--
953--
954-- /Internal/
954-- /Internal/
955−{-# INLINE_NORMAL consumeMany #-}
955+{-# INLINE_NORMAL refoldMany #-}
956−consumeMany :: Monad m => Consumer m x a b -> m x -> Stream m a -> Stream m b
956+refoldMany :: Monad m => Refold m x a b -> m x -> Stream m a -> Stream m b
957−consumeMany (Consumer fstep inject extract) action (Stream step state) =
957+refoldMany (Refold fstep inject extract) action (Stream step state) =
958 Stream step' (FoldManyStart state)
958 Stream step' (FoldManyStart state)
959
959
960 where
960 where
src/Streamly/Internal/FileSystem/Handle.hs+10−10
@@ -111,7 +111,7 @@ import Prelude hiding (read)
111
111
112import Streamly.Internal.BaseCompat
112import Streamly.Internal.BaseCompat
113import Streamly.Internal.Data.Fold (Fold)
113import Streamly.Internal.Data.Fold (Fold)
114−import Streamly.Internal.Data.Consumer.Type (Consumer(..))
114+import Streamly.Internal.Data.Refold.Type (Refold(..))
115import Streamly.Internal.Data.Unfold.Type (Unfold(..))
115import Streamly.Internal.Data.Unfold.Type (Unfold(..))
116import Streamly.Internal.Data.Array.Foreign.Type
116import Streamly.Internal.Data.Array.Foreign.Type
117 (Array(..), writeNUnsafe, unsafeFreezeWithShrink)
117 (Array(..), writeNUnsafe, unsafeFreezeWithShrink)
@@ -125,7 +125,7 @@ import Streamly.Internal.System.IO (defaultChunkSize)
125
125
126import qualified Streamly.Internal.Data.Array.Foreign as A
126import qualified Streamly.Internal.Data.Array.Foreign as A
127import qualified Streamly.Internal.Data.Array.Stream.Foreign as AS
127import qualified Streamly.Internal.Data.Array.Stream.Foreign as AS
128−import qualified Streamly.Internal.Data.Consumer.Type as Consumer
128+import qualified Streamly.Internal.Data.Refold.Type as Refold
129import qualified Streamly.Internal.Data.Fold as FL
129import qualified Streamly.Internal.Data.Fold as FL
130import qualified Streamly.Internal.Data.Fold.Type as FL
130import qualified Streamly.Internal.Data.Fold.Type as FL
131import qualified Streamly.Internal.Data.Stream.IsStream as S
131import qualified Streamly.Internal.Data.Stream.IsStream as S
@@ -457,12 +457,12 @@ putBytes = putBytesWithBufferOf defaultChunkSize
457writeChunks :: (MonadIO m, Storable a) => Handle -> Fold m (Array a) ()
457writeChunks :: (MonadIO m, Storable a) => Handle -> Fold m (Array a) ()
458writeChunks h = FL.drainBy (putChunk h)
458writeChunks h = FL.drainBy (putChunk h)
459
459
460−-- | Like writeChunks but uses the experimental 'Consumer' API.
460+-- | Like writeChunks but uses the experimental 'Refold' API.
461--
461--
462-- /Internal/
462-- /Internal/
463{-# INLINE consumeChunks #-}
463{-# INLINE consumeChunks #-}
464−consumeChunks :: (MonadIO m, Storable a) => Consumer m Handle (Array a) ()
464+consumeChunks :: (MonadIO m, Storable a) => Refold m Handle (Array a) ()
465−consumeChunks = Consumer.drainBy putChunk
465+consumeChunks = Refold.drainBy putChunk
466
466
467-- XXX lpackArraysChunksOf should be written idiomatically
467-- XXX lpackArraysChunksOf should be written idiomatically
468--
468--
@@ -499,13 +499,13 @@ writeChunksWithBufferOf n h = lpackArraysChunksOf n (writeChunks h)
499writeWithBufferOf :: MonadIO m => Int -> Handle -> Fold m Word8 ()
499writeWithBufferOf :: MonadIO m => Int -> Handle -> Fold m Word8 ()
500writeWithBufferOf n h = FL.chunksOf n (writeNUnsafe n) (writeChunks h)
500writeWithBufferOf n h = FL.chunksOf n (writeNUnsafe n) (writeChunks h)
501
501
502−-- | Like 'writeWithBufferOf' but uses the experimental 'Consumer' API.
502+-- | Like 'writeWithBufferOf' but uses the experimental 'Refold' API.
503--
503--
504-- /Internal/
504-- /Internal/
505{-# INLINE consumerWithBufferOf #-}
505{-# INLINE consumerWithBufferOf #-}
506−consumerWithBufferOf :: MonadIO m => Int -> Consumer m Handle Word8 ()
506+consumerWithBufferOf :: MonadIO m => Int -> Refold m Handle Word8 ()
507consumerWithBufferOf n =
507consumerWithBufferOf n =
508− FL.consumeMany (FL.take n $ writeNUnsafe n) consumeChunks
508+ FL.refoldMany (FL.take n $ writeNUnsafe n) consumeChunks
509
509
510-- | Write a byte stream to a file handle. Accumulates the input in chunks of
510-- | Write a byte stream to a file handle. Accumulates the input in chunks of
511-- up to 'Streamly.Internal.Data.Array.Foreign.Type.defaultChunkSize' before writing
511-- up to 'Streamly.Internal.Data.Array.Foreign.Type.defaultChunkSize' before writing
@@ -518,11 +518,11 @@ consumerWithBufferOf n =
518write :: MonadIO m => Handle -> Fold m Word8 ()
518write :: MonadIO m => Handle -> Fold m Word8 ()
519write = writeWithBufferOf defaultChunkSize
519write = writeWithBufferOf defaultChunkSize
520
520
521−-- | Like 'write' but uses the experimental 'Consumer' API.
521+-- | Like 'write' but uses the experimental 'Refold' API.
522--
522--
523-- /Internal/
523-- /Internal/
524{-# INLINE consumer #-}
524{-# INLINE consumer #-}
525−consumer :: MonadIO m => Consumer m Handle Word8 ()
525+consumer :: MonadIO m => Refold m Handle Word8 ()
526consumer = consumerWithBufferOf defaultChunkSize
526consumer = consumerWithBufferOf defaultChunkSize
527
527
528{-
528{-
streamly.cabal+1−1
@@ -386,7 +386,7 @@ library
386 , Streamly.Internal.Data.SVar
386 , Streamly.Internal.Data.SVar
387 , Streamly.Internal.Data.Stream.StreamK.Type
387 , Streamly.Internal.Data.Stream.StreamK.Type
388 , Streamly.Internal.Data.Fold.Step
388 , Streamly.Internal.Data.Fold.Step
389− , Streamly.Internal.Data.Consumer.Type
389+ , Streamly.Internal.Data.Refold.Type
390 , Streamly.Internal.Data.Fold.Type
390 , Streamly.Internal.Data.Fold.Type
391 , Streamly.Internal.Data.Stream.StreamD.Step
391 , Streamly.Internal.Data.Stream.StreamD.Step
392 , Streamly.Internal.Data.Stream.StreamD.Type
392 , Streamly.Internal.Data.Stream.StreamD.Type