on master help sign in
Rename Consumer to Refold

Consumer is a very generic name. One cannot intuitively distinguish between Consumer and Fold. "Refold" gives a better idea that its a slightly modified version of Fold with a starting value. Also, it fits better as a dual to Unfold.

commit06e55120cee3c7183a8622275495e84f1d834036 authorHarendra Kumar <harendra@composewell.com> dateSun 17 Oct 2021, 20:18 (5 years ago) parent7029f6f
8 files changed+107−108
benchmark/Streamly/Benchmark/Prelude/Serial/NestedFold.hs+12−12 src/Streamly/Internal/Data/Fold/Type.hs+23−24 src/Streamly/Internal/Data/Consumer/Type.hs → src/Streamly/Internal/Data/Refold/Type.hs+34−34 src/Streamly/Internal/Data/Stream/IsStream/Reduce.hs+13−13 src/Streamly/Internal/Data/Stream/StreamD/Nesting.hs+8−8 src/Streamly/Internal/Data/Stream/StreamD/Type.hs+6−6 src/Streamly/Internal/FileSystem/Handle.hs+10−10 streamly.cabal+1−1
benchmark/Streamly/Benchmark/Prelude/Serial/NestedFold.hs+12−12
@@ -20,7 +20,7 @@ import Control.Monad.IO.Class (MonadIO(..))
2020import Data.Monoid (Sum(..))
2121import GHC.Generics (Generic)
2222
23−import qualified Streamly.Internal.Data.Consumer.Type as Consumer
23+import qualified Streamly.Internal.Data.Refold.Type as Refold
2424import qualified Streamly.Internal.Data.Fold as FL
2525import qualified Streamly.Internal.Data.Stream.IsStream as Internal
2626import qualified Streamly.Prelude as S
@@ -141,12 +141,12 @@ foldMany =
141141 . Internal.foldMany (FL.take 2 FL.mconcat)
142142 . S.map Sum
143143
144−{-# INLINE consumeMany #-}
145−consumeMany :: Monad m => SerialT m Int -> m ()
146−consumeMany =
144+{-# INLINE refoldMany #-}
145+refoldMany :: Monad m => SerialT m Int -> m ()
146+refoldMany =
147147 S.drain
148148 . S.map getSum
149− . Internal.consumeMany (Consumer.take 2 Consumer.sconcat) (return mempty)
149+ . Internal.refoldMany (Refold.take 2 Refold.sconcat) (return mempty)
150150 . S.map Sum
151151
152152{-# INLINE foldIterateM #-}
@@ -158,13 +158,13 @@ foldIterateM =
158158 (return . FL.take 2 . FL.sconcat) (return (Sum 0))
159159 . S.map Sum
160160
161−{-# INLINE consumeIterateM #-}
162−consumeIterateM :: Monad m => SerialT m Int -> m ()
163−consumeIterateM =
161+{-# INLINE refoldIterateM #-}
162+refoldIterateM :: Monad m => SerialT m Int -> m ()
163+refoldIterateM =
164164 S.drain
165165 . S.map getSum
166− . Internal.consumeIterateM
167− (Consumer.take 2 Consumer.sconcat) (return (Sum 0))
166+ . Internal.refoldIterateM
167+ (Refold.take 2 Refold.sconcat) (return (Sum 0))
168168 . S.map Sum
169169
170170o_1_space_grouping :: Int -> [Benchmark]
@@ -177,9 +177,9 @@ o_1_space_grouping value =
177177 , benchIOSink value "groupsByRollingLT" groupsByRollingLT
178178 , benchIOSink value "groupsByRollingEq" groupsByRollingEq
179179 , benchIOSink value "foldMany" foldMany
180− , benchIOSink value "consumeMany" consumeMany
180+ , benchIOSink value "refoldMany" refoldMany
181181 , benchIOSink value "foldIterateM" foldIterateM
182− , benchIOSink value "consumeIterateM" consumeIterateM
182+ , benchIOSink value "refoldIterateM" refoldIterateM
183183 ]
184184 ]
185185
src/Streamly/Internal/Data/Fold/Type.hs+23−24
@@ -209,7 +209,7 @@ module Streamly.Internal.Data.Fold.Type
209209 -- * Folds
210210 , fromPure
211211 , fromEffect
212− , fromConsumer
212+ , fromRefold
213213 , drain
214214 , toList
215215 , toStreamK
@@ -250,9 +250,9 @@ module Streamly.Internal.Data.Fold.Type
250250 , many
251251 , manyPost
252252 , chunksOf
253− , consumeMany
254− , consumeMany1
255− , appendConsumer
253+ , refoldMany
254+ , refoldMany1
255+ , refold
256256
257257 -- ** Nesting
258258 , concatMap
@@ -272,7 +272,7 @@ import Fusion.Plugin.Types (Fuse(..))
272272import Streamly.Internal.Data.Fold.Step (Step(..), mapMStep, chainStepM)
273273import Streamly.Internal.Data.Maybe.Strict (Maybe'(..), toMaybe)
274274import Streamly.Internal.Data.Tuple.Strict (Tuple'(..))
275−import Streamly.Internal.Data.Consumer.Type (Consumer(..))
275+import Streamly.Internal.Data.Refold.Type (Refold(..))
276276
277277import qualified Streamly.Internal.Data.Stream.StreamK.Type as K
278278
@@ -505,7 +505,7 @@ mkFoldM_ :: Monad m => (b -> a -> m (Step b b)) -> m (Step b b) -> Fold m a b
505505mkFoldM_ step initial = mkFoldM step initial return
506506
507507------------------------------------------------------------------------------
508−-- Consumer
508+-- Refold
509509------------------------------------------------------------------------------
510510
511511-- 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
514514-- | Make a fold from a consumer.
515515--
516516-- /Internal/
517−fromConsumer :: Consumer m c a b -> c -> Fold m a b
518−fromConsumer (Consumer step inject extract) c =
517+fromRefold :: Refold m c a b -> c -> Fold m a b
518+fromRefold (Refold step inject extract) c =
519519 Fold step (inject c) extract
520520
521521------------------------------------------------------------------------------
@@ -1305,15 +1305,15 @@ chunksOf :: Monad m => Int -> Fold m a b -> Fold m b c -> Fold m a c
13051305chunksOf n split = many (take n split)
13061306
13071307------------------------------------------------------------------------------
1308−-- Consumer and Fold Combinators
1308+-- Refold and Fold Combinators
13091309------------------------------------------------------------------------------
13101310
1311−-- | Like 'many' but uses a 'Consumer' for collecting.
1311+-- | Like 'many' but uses a 'Refold' for collecting.
13121312--
1313−{-# INLINE consumeMany #-}
1314−consumeMany :: Monad m => Fold m a b -> Consumer m x b c -> Consumer m x a c
1315−consumeMany (Fold sstep sinitial sextract) (Consumer cstep cinject cextract) =
1316− Consumer step inject extract
1313+{-# INLINE refoldMany #-}
1314+refoldMany :: Monad m => Fold m a b -> Refold m x b c -> Refold m x a c
1315+refoldMany (Fold sstep sinitial sextract) (Refold cstep cinject cextract) =
1316+ Refold step inject extract
13171317
13181318 where
13191319
@@ -1359,13 +1359,13 @@ consumeMany (Fold sstep sinitial sextract) (Consumer cstep cinject cextract) =
13591359{-# ANN type ConsumeManyState Fuse #-}
13601360data ConsumeManyState x cs ss = ConsumeMany x cs (Either ss ss)
13611361
1362−-- | Like 'many' but uses a 'Consumer' for splitting.
1362+-- | Like 'many' but uses a 'Refold' for splitting.
13631363--
13641364-- /Internal/
1365−{-# INLINE consumeMany1 #-}
1366−consumeMany1 :: Monad m => Consumer m x a b -> Fold m b c -> Consumer m x a c
1367−consumeMany1 (Consumer sstep sinject sextract) (Fold cstep cinitial cextract) =
1368− Consumer step inject extract
1365+{-# INLINE refoldMany1 #-}
1366+refoldMany1 :: Monad m => Refold m x a b -> Fold m b c -> Refold m x a c
1367+refoldMany1 (Refold sstep sinject sextract) (Fold cstep cinitial cextract) =
1368+ Refold step inject extract
13691369
13701370 where
13711371
@@ -1408,10 +1408,9 @@ consumeMany1 (Consumer sstep sinject sextract) (Fold cstep cinitial cextract) =
14081408 Partial s -> cextract s
14091409 Done b -> return b
14101410
1411−-- | Extend a fold by appending a Consumer.
1411+-- | Extract the output of a fold and refold is using a 'Refold'.
14121412--
14131413-- /Internal/
1414−{-# INLINE appendConsumer #-}
1415−appendConsumer :: Monad m => Fold m a b -> Consumer m b a b -> Fold m a b
1416−appendConsumer f (Consumer step inject extract) =
1417− Fold step (finish f >>= inject) extract
1414+{-# INLINE refold #-}
1415+refold :: Monad m => Fold m a b -> Refold m b a b -> Fold m a b
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 @@
11-- |
2−-- Module : Streamly.Internal.Data.Consumer.Type
2+-- Module : Streamly.Internal.Data.Refold.Type
33-- Copyright : (c) 2019 Composewell Technologies
44-- License : BSD-3-Clause
55-- Maintainer : streamly@composewell.com
@@ -7,29 +7,29 @@
77-- Portability : GHC
88--
99-- 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
1111-- value, therefore, it is more like a 'Semigroup' operation.
1212--
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
1414-- incrementally. This is useful in incremental builder like use cases.
1515--
1616-- 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
1818-- in this situation.
1919--
20−-- 'Consumer' type is to 'Fold' as 'Unfold' type is to 'Stream'. Like 'Unfold'
21−-- provides better optimizaiton than stream in nested operations similarly
22−-- 'Consumer' provides better optimization than 'Fold'.
20+-- 'Refold' type is to 'Fold' as 'Unfold' type is to 'Stream'. 'Unfold'
21+-- provides better optimizaiton than stream in nested operations, similarly,
22+-- 'Refold' provides better optimization than 'Fold'.
2323--
24−module Streamly.Internal.Data.Consumer.Type
24+module Streamly.Internal.Data.Refold.Type
2525 (
2626 -- * Types
27− Consumer (..)
27+ Refold (..)
2828
2929 -- * Constructors
3030 , foldl'
3131
32− -- * Consumers
32+ -- * Refolds
3333 -- ** Accumulators
3434 , sconcat
3535 , drainBy
@@ -54,11 +54,11 @@ import Prelude hiding (take, iterate)
5454
5555-- $setup
5656-- >>> :m
57−-- >>> import qualified Streamly.Internal.Data.Consumer.Type as Consumer
57+-- >>> import qualified Streamly.Internal.Data.Refold.Type as Refold
5858-- >>> import qualified Streamly.Internal.Data.Fold.Type as Fold
5959-- >>> import qualified Streamly.Internal.Data.Stream.IsStream as Stream
6060
61−-- All folds in the Fold module should be implemented using Consumers.
61+-- All folds in the Fold module should be implemented using Refolds.
6262--
6363-- | Like 'Fold' except that the initial state of the accmulator can be
6464-- generated using a dynamically supplied input. This affords better stream
@@ -66,9 +66,9 @@ import Prelude hiding (take, iterate)
6666-- is determined based on a dynamic value.
6767--
6868-- /Internal/
69−data Consumer m c a b =
69+data Refold m c a b =
7070 -- | @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)
7272
7373------------------------------------------------------------------------------
7474-- Left fold constructors
@@ -84,9 +84,9 @@ data Consumer m c a b =
8484-- /Internal/
8585--
8686{-# 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
8888foldl' step =
89− Consumer
89+ Refold
9090 (\s a -> return $ Partial $ step s a)
9191 (return . Partial)
9292 return
@@ -99,8 +99,8 @@ foldl' step =
9999--
100100-- /Internal/
101101{-# INLINE lmapM #-}
102−lmapM :: Monad m => (a -> m b) -> Consumer m c b r -> Consumer m c a r
103−lmapM f (Consumer step inject extract) = Consumer step1 inject extract
102+lmapM :: Monad m => (a -> m b) -> Refold m c b r -> Refold m c a r
103+lmapM f (Refold step inject extract) = Refold step1 inject extract
104104
105105 where
106106
@@ -114,8 +114,8 @@ lmapM f (Consumer step inject extract) = Consumer step1 inject extract
114114--
115115-- /Internal/
116116{-# INLINE rmapM #-}
117−rmapM :: Monad m => (b -> m c) -> Consumer m x a b -> Consumer m x a c
118−rmapM f (Consumer step inject extract) = Consumer step1 inject1 (extract >=> f)
117+rmapM :: Monad m => (b -> m c) -> Refold m x a b -> Refold m x a c
118+rmapM f (Refold step inject extract) = Refold step1 inject1 (extract >=> f)
119119
120120 where
121121
@@ -123,15 +123,15 @@ rmapM f (Consumer step inject extract) = Consumer step1 inject1 (extract >=> f)
123123 step1 s a = step s a >>= mapMStep f
124124
125125------------------------------------------------------------------------------
126−-- Consumers
126+-- Refolds
127127------------------------------------------------------------------------------
128128
129129-- |
130130--
131131-- /Internal/
132132{-# INLINE drainBy #-}
133−drainBy :: Monad m => (c -> a -> m b) -> Consumer m c a ()
134−drainBy f = Consumer step inject extract
133+drainBy :: Monad m => (c -> a -> m b) -> Refold m c a ()
134+drainBy f = Refold step inject extract
135135
136136 where
137137
@@ -148,14 +148,14 @@ drainBy f = Consumer step inject extract
148148-- | Append the elements of an input stream to a provided starting value.
149149--
150150-- >>> 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
152152-- Sum {getSum = 65}
153153--
154−-- >>> sconcat = Consumer.foldl' (<>)
154+-- >>> sconcat = Refold.foldl' (<>)
155155--
156156-- /Internal/
157157{-# INLINE sconcat #-}
158−sconcat :: (Monad m, Semigroup a) => Consumer m a a a
158+sconcat :: (Monad m, Semigroup a) => Refold m a a a
159159sconcat = foldl' (<>)
160160
161161------------------------------------------------------------------------------
@@ -166,9 +166,9 @@ sconcat = foldl' (<>)
166166--
167167-- /Internal/
168168{-# INLINE append #-}
169−append :: Monad m => Consumer m x a b -> Consumer m b a b -> Consumer m x a b
170−append (Consumer step1 inject1 extract1) (Consumer step2 inject2 extract2) =
171− Consumer step inject extract
169+append :: Monad m => Refold m x a b -> Refold m b a b -> Refold m x a b
170+append (Refold step1 inject1 extract1) (Refold step2 inject2 extract2) =
171+ Refold step inject extract
172172
173173 where
174174
@@ -198,9 +198,9 @@ append (Consumer step1 inject1 extract1) (Consumer step2 inject2 extract2) =
198198-- the output of the previous run to the next.
199199--
200200-- /Internal/
201−iterate :: Monad m => Consumer m b a b -> Consumer m b a b
202−iterate (Consumer step1 inject1 extract1) =
203− Consumer step inject extract1
201+iterate :: Monad m => Refold m b a b -> Refold m b a b
202+iterate (Refold step1 inject1 extract1) =
203+ Refold step inject extract1
204204
205205 where
206206
@@ -226,8 +226,8 @@ data Tuple'Fused a b = Tuple'Fused !a !b deriving Show
226226--
227227-- /Internal/
228228{-# INLINE take #-}
229−take :: Monad m => Int -> Consumer m x a b -> Consumer m x a b
230−take n (Consumer fstep finject fextract) = Consumer step inject extract
229+take :: Monad m => Int -> Refold m x a b -> Refold m x a b
230+take n (Refold fstep finject fextract) = Refold step inject extract
231231
232232 where
233233
src/Streamly/Internal/Data/Stream/IsStream/Reduce.hs+13−13
@@ -29,10 +29,10 @@ module Streamly.Internal.Data.Stream.IsStream.Reduce
2929 -- | Apply folds on a stream.
3030 , foldMany
3131 , foldManyPost
32− , consumeMany
32+ , refoldMany
3333 , foldSequence
3434 , foldIterateM
35− , consumeIterateM
35+ , refoldIterateM
3636
3737 -- ** Chunking
3838 -- | Element unaware grouping.
@@ -155,7 +155,7 @@ import Data.Maybe (isNothing)
155155import Foreign.Storable (Storable)
156156import Streamly.Internal.Control.Concurrent (MonadAsync)
157157import Streamly.Internal.Data.Fold.Type (Fold (..))
158−import Streamly.Internal.Data.Consumer.Type (Consumer (..))
158+import Streamly.Internal.Data.Refold.Type (Refold (..))
159159import Streamly.Internal.Data.Parser (Parser (..))
160160import Streamly.Internal.Data.Array.Foreign.Type (Array)
161161import Streamly.Internal.Data.Stream.IsStream.Common
@@ -295,13 +295,13 @@ foldMany
295295 -> t m b
296296foldMany f m = fromStreamD $ D.foldMany f (toStreamD m)
297297
298−-- | Like 'foldMany' but using the 'Consumer' type instead of 'Fold'.
298+-- | Like 'foldMany' but using the 'Refold' type instead of 'Fold'.
299299--
300300-- /Pre-release/
301−{-# INLINE consumeMany #-}
302−consumeMany :: (IsStream t, Monad m) =>
303− Consumer m c a b -> m c -> t m a -> t m b
304−consumeMany f action = fromStreamD . D.consumeMany f action . toStreamD
301+{-# INLINE refoldMany #-}
302+refoldMany :: (IsStream t, Monad m) =>
303+ Refold m c a b -> m c -> t m a -> t m b
304+refoldMany f action = fromStreamD . D.refoldMany f action . toStreamD
305305
306306-- | Apply a stream of folds to an input stream and emit the results in the
307307-- output stream.
@@ -339,14 +339,14 @@ foldIterateM ::
339339 (IsStream t, Monad m) => (b -> m (Fold m a b)) -> m b -> t m a -> t m b
340340foldIterateM f i m = fromStreamD $ D.foldIterateM f i (toStreamD m)
341341
342−-- | Like 'foldIterateM' but using the 'Consumer' type instead. This could be
342+-- | Like 'foldIterateM' but using the 'Refold' type instead. This could be
343343-- much more efficient due to stream fusion.
344344--
345345-- /Internal/
346−{-# INLINE consumeIterateM #-}
347−consumeIterateM :: (IsStream t, Monad m) =>
348− Consumer m b a b -> m b -> t m a -> t m b
349−consumeIterateM c i m = fromStreamD $ D.consumeIterateM c i (toStreamD m)
346+{-# INLINE refoldIterateM #-}
347+refoldIterateM :: (IsStream t, Monad m) =>
348+ Refold m b a b -> m b -> t m a -> t m b
349+refoldIterateM c i m = fromStreamD $ D.refoldIterateM c i (toStreamD m)
350350
351351------------------------------------------------------------------------------
352352-- Parsing
src/Streamly/Internal/Data/Stream/StreamD/Nesting.hs+8−8
@@ -112,9 +112,9 @@ module Streamly.Internal.Data.Stream.StreamD.Nesting
112112 -- ** Folding
113113 -- | Apply folds on a stream.
114114 , foldMany
115− , consumeMany
115+ , refoldMany
116116 , foldIterateM
117− , consumeIterateM
117+ , refoldIterateM
118118
119119 -- ** Parsing
120120 -- | Parsing is opposite to flattening. 'parseMany' is dual to concatMap or
@@ -159,7 +159,7 @@ import Fusion.Plugin.Types (Fuse(..))
159159import GHC.Types (SPEC(..))
160160
161161import Streamly.Internal.Data.Array.Foreign.Type (Array(..))
162−import Streamly.Internal.Data.Consumer.Type (Consumer(..))
162+import Streamly.Internal.Data.Refold.Type (Refold(..))
163163import Streamly.Internal.Data.Fold.Type (Fold(..))
164164import Streamly.Internal.Data.Parser (ParseError(..))
165165import Streamly.Internal.Data.SVar.Type (adaptState)
@@ -1032,14 +1032,14 @@ data CIterState s f fs b
10321032 | CIterYield b (CIterState s f fs b)
10331033 | CIterStop
10341034
1035−-- | Like 'foldIterateM' but using the 'Consumer' type instead. This could be
1035+-- | Like 'foldIterateM' but using the 'Refold' type instead. This could be
10361036-- much more efficient due to stream fusion.
10371037--
10381038-- /Internal/
1039−{-# INLINE_NORMAL consumeIterateM #-}
1040−consumeIterateM ::
1041− Monad m => Consumer m b a b -> m b -> Stream m a -> Stream m b
1042−consumeIterateM (Consumer fstep finject fextract) initial (Stream step state) =
1039+{-# INLINE_NORMAL refoldIterateM #-}
1040+refoldIterateM ::
1041+ Monad m => Refold m b a b -> m b -> Stream m a -> Stream m b
1042+refoldIterateM (Refold fstep finject fextract) initial (Stream step state) =
10431043 Stream stepOuter (CIterInit state initial)
10441044
10451045 where
src/Streamly/Internal/Data/Stream/StreamD/Type.hs+6−6
@@ -84,7 +84,7 @@ module Streamly.Internal.Data.Stream.StreamD.Type
8484 , FoldManyPost (..)
8585 , foldMany
8686 , foldManyPost
87− , consumeMany
87+ , refoldMany
8888 , chunksOf
8989 )
9090where
@@ -100,7 +100,7 @@ import GHC.Types (SPEC(..))
100100import Prelude hiding (map, mapM, foldr, take, concatMap, takeWhile)
101101
102102import Streamly.Internal.Data.Fold.Type (Fold(..))
103−import Streamly.Internal.Data.Consumer.Type (Consumer(..))
103+import Streamly.Internal.Data.Refold.Type (Refold(..))
104104import Streamly.Internal.Data.Stream.StreamD.Step (Step (..))
105105import Streamly.Internal.Data.SVar.Type (State, adaptState, defState)
106106import Streamly.Internal.Data.Unfold.Type (Unfold(..))
@@ -949,12 +949,12 @@ chunksOf n f = foldMany (FL.take n f)
949949
950950-- Keep the argument order consistent with consumeIterateM
951951--
952−-- | Like 'foldMany' but for the 'Consumer' type.
952+-- | Like 'foldMany' but for the 'Refold' type.
953953--
954954-- /Internal/
955−{-# INLINE_NORMAL consumeMany #-}
956−consumeMany :: Monad m => Consumer m x a b -> m x -> Stream m a -> Stream m b
957−consumeMany (Consumer fstep inject extract) action (Stream step state) =
955+{-# INLINE_NORMAL refoldMany #-}
956+refoldMany :: Monad m => Refold m x a b -> m x -> Stream m a -> Stream m b
957+refoldMany (Refold fstep inject extract) action (Stream step state) =
958958 Stream step' (FoldManyStart state)
959959
960960 where
src/Streamly/Internal/FileSystem/Handle.hs+10−10
@@ -111,7 +111,7 @@ import Prelude hiding (read)
111111
112112import Streamly.Internal.BaseCompat
113113import Streamly.Internal.Data.Fold (Fold)
114−import Streamly.Internal.Data.Consumer.Type (Consumer(..))
114+import Streamly.Internal.Data.Refold.Type (Refold(..))
115115import Streamly.Internal.Data.Unfold.Type (Unfold(..))
116116import Streamly.Internal.Data.Array.Foreign.Type
117117 (Array(..), writeNUnsafe, unsafeFreezeWithShrink)
@@ -125,7 +125,7 @@ import Streamly.Internal.System.IO (defaultChunkSize)
125125
126126import qualified Streamly.Internal.Data.Array.Foreign as A
127127import 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
129129import qualified Streamly.Internal.Data.Fold as FL
130130import qualified Streamly.Internal.Data.Fold.Type as FL
131131import qualified Streamly.Internal.Data.Stream.IsStream as S
@@ -457,12 +457,12 @@ putBytes = putBytesWithBufferOf defaultChunkSize
457457writeChunks :: (MonadIO m, Storable a) => Handle -> Fold m (Array a) ()
458458writeChunks h = FL.drainBy (putChunk h)
459459
460−-- | Like writeChunks but uses the experimental 'Consumer' API.
460+-- | Like writeChunks but uses the experimental 'Refold' API.
461461--
462462-- /Internal/
463463{-# INLINE consumeChunks #-}
464−consumeChunks :: (MonadIO m, Storable a) => Consumer m Handle (Array a) ()
465−consumeChunks = Consumer.drainBy putChunk
464+consumeChunks :: (MonadIO m, Storable a) => Refold m Handle (Array a) ()
465+consumeChunks = Refold.drainBy putChunk
466466
467467-- XXX lpackArraysChunksOf should be written idiomatically
468468--
@@ -499,13 +499,13 @@ writeChunksWithBufferOf n h = lpackArraysChunksOf n (writeChunks h)
499499writeWithBufferOf :: MonadIO m => Int -> Handle -> Fold m Word8 ()
500500writeWithBufferOf n h = FL.chunksOf n (writeNUnsafe n) (writeChunks h)
501501
502−-- | Like 'writeWithBufferOf' but uses the experimental 'Consumer' API.
502+-- | Like 'writeWithBufferOf' but uses the experimental 'Refold' API.
503503--
504504-- /Internal/
505505{-# INLINE consumerWithBufferOf #-}
506−consumerWithBufferOf :: MonadIO m => Int -> Consumer m Handle Word8 ()
506+consumerWithBufferOf :: MonadIO m => Int -> Refold m Handle Word8 ()
507507consumerWithBufferOf n =
508− FL.consumeMany (FL.take n $ writeNUnsafe n) consumeChunks
508+ FL.refoldMany (FL.take n $ writeNUnsafe n) consumeChunks
509509
510510-- | Write a byte stream to a file handle. Accumulates the input in chunks of
511511-- up to 'Streamly.Internal.Data.Array.Foreign.Type.defaultChunkSize' before writing
@@ -518,11 +518,11 @@ consumerWithBufferOf n =
518518write :: MonadIO m => Handle -> Fold m Word8 ()
519519write = writeWithBufferOf defaultChunkSize
520520
521−-- | Like 'write' but uses the experimental 'Consumer' API.
521+-- | Like 'write' but uses the experimental 'Refold' API.
522522--
523523-- /Internal/
524524{-# INLINE consumer #-}
525−consumer :: MonadIO m => Consumer m Handle Word8 ()
525+consumer :: MonadIO m => Refold m Handle Word8 ()
526526consumer = consumerWithBufferOf defaultChunkSize
527527
528528{-
streamly.cabal+1−1
@@ -386,7 +386,7 @@ library
386386 , Streamly.Internal.Data.SVar
387387 , Streamly.Internal.Data.Stream.StreamK.Type
388388 , Streamly.Internal.Data.Fold.Step
389− , Streamly.Internal.Data.Consumer.Type
389+ , Streamly.Internal.Data.Refold.Type
390390 , Streamly.Internal.Data.Fold.Type
391391 , Streamly.Internal.Data.Stream.StreamD.Step
392392 , Streamly.Internal.Data.Stream.StreamD.Type