on master help sign in
Rename chunksOf to groupsOf
a43577bRanjeet Kumar Ranjan
benchmark/Streamly/Benchmark/FileSystem/Handle/Read.hs+20−20
@@ -215,7 +215,7 @@ o_1_space_reduce_toBytes env =
215
215
216chunksOfSum :: Int -> Handle -> IO Int
216chunksOfSum :: Int -> Handle -> IO Int
217chunksOfSum n inh =
217chunksOfSum n inh =
218− S.fold Fold.length $ IP.chunksOf n FL.sum (S.unfold FH.reader inh)
218+ S.fold Fold.length $ IP.groupsOf n FL.sum (S.unfold FH.reader inh)
219
219
220foldManyPostChunksOfSum :: Int -> Handle -> IO Int
220foldManyPostChunksOfSum :: Int -> Handle -> IO Int
221foldManyPostChunksOfSum n inh =
221foldManyPostChunksOfSum n inh =
@@ -231,20 +231,20 @@ foldManyChunksOfSum n inh =
231-- Even though allocations remain the same in both cases inlining improves time
231-- Even though allocations remain the same in both cases inlining improves time
232-- by 4x.
232-- by 4x.
233-- | Slice in chunks of size n and get the count of chunks.
233-- | Slice in chunks of size n and get the count of chunks.
234−{-# INLINE chunksOf #-}
234+{-# INLINE groupsOf #-}
235−chunksOf :: Int -> Handle -> IO Int
235+groupsOf :: Int -> Handle -> IO Int
236−chunksOf n inh =
236+groupsOf n inh =
237 -- writeNUnsafe gives 2.5x boost here over writeN.
237 -- writeNUnsafe gives 2.5x boost here over writeN.
238 S.fold Fold.length
238 S.fold Fold.length
239− $ IP.chunksOf n (AT.writeNUnsafe n) (S.unfold FH.reader inh)
239+ $ IP.groupsOf n (AT.writeNUnsafe n) (S.unfold FH.reader inh)
240
240
241#ifdef INSPECTION
241#ifdef INSPECTION
242−inspect $ hasNoTypeClasses 'chunksOf
242+inspect $ hasNoTypeClasses 'groupsOf
243−inspect $ 'chunksOf `hasNoType` ''Step
243+inspect $ 'groupsOf `hasNoType` ''Step
244−inspect $ 'chunksOf `hasNoType` ''FoldMany
244+inspect $ 'groupsOf `hasNoType` ''FoldMany
245−inspect $ 'chunksOf `hasNoType` ''AT.ArrayUnsafe -- AT.writeNUnsafe
245+inspect $ 'groupsOf `hasNoType` ''AT.ArrayUnsafe -- AT.writeNUnsafe
246 -- FH.read/A.read
246 -- FH.read/A.read
247−inspect $ 'chunksOf `hasNoType` ''IUF.ConcatState -- FH.read/UF.many
247+inspect $ 'groupsOf `hasNoType` ''IUF.ConcatState -- FH.read/UF.many
248#endif
248#endif
249
249
250{-# INLINE arraysOf #-}
250{-# INLINE arraysOf #-}
@@ -255,10 +255,10 @@ arraysOf n inh =
255o_1_space_reduce_read_grouped :: BenchEnv -> [Benchmark]
255o_1_space_reduce_read_grouped :: BenchEnv -> [Benchmark]
256o_1_space_reduce_read_grouped env =
256o_1_space_reduce_read_grouped env =
257 [ bgroup "reduce/read/chunks"
257 [ bgroup "reduce/read/chunks"
258− [ mkBench ("S.chunksOf " ++ show (bigSize env) ++ " FL.sum") env $
258+ [ mkBench ("S.groupsOf " ++ show (bigSize env) ++ " FL.sum") env $
259 \inh _ ->
259 \inh _ ->
260 chunksOfSum (bigSize env) inh
260 chunksOfSum (bigSize env) inh
261− , mkBench "S.chunksOf 1 FL.sum" env $ \inh _ ->
261+ , mkBench "S.groupsOf 1 FL.sum" env $ \inh _ ->
262 chunksOfSum 1 inh
262 chunksOfSum 1 inh
263
263
264 -- XXX investigate why we need inline/noinline in these cases (GHC)
264 -- XXX investigate why we need inline/noinline in these cases (GHC)
@@ -281,14 +281,14 @@ o_1_space_reduce_read_grouped env =
281 $ \inh _ -> inline foldManyChunksOfSum 1 inh
281 $ \inh _ -> inline foldManyChunksOfSum 1 inh
282
282
283 -- folding chunks to arrays
283 -- folding chunks to arrays
284− , mkBenchSmall "S.chunksOf 1" env $ \inh _ ->
284+ , mkBenchSmall "S.groupsOf 1" env $ \inh _ ->
285− chunksOf 1 inh
285+ groupsOf 1 inh
286− , mkBench "S.chunksOf 10" env $ \inh _ ->
286+ , mkBench "S.groupsOf 10" env $ \inh _ ->
287− chunksOf 10 inh
287+ groupsOf 10 inh
288− , mkBench "S.chunksOf 1000" env $ \inh _ ->
288+ , mkBench "S.groupsOf 1000" env $ \inh _ ->
289− chunksOf 1000 inh
289+ groupsOf 1000 inh
290−
290+
291− -- arraysOf may use a different impl than chunksOf
291+ -- arraysOf may use a different impl than groupsOf
292 , mkBenchSmall "S.arraysOf 1" env $ \inh _ ->
292 , mkBenchSmall "S.arraysOf 1" env $ \inh _ ->
293 arraysOf 1 inh
293 arraysOf 1 inh
294 , mkBench "S.arraysOf 10" env $ \inh _ ->
294 , mkBench "S.arraysOf 10" env $ \inh _ ->
core/src/Streamly/Data/Fold.hs+11−1
@@ -325,7 +325,7 @@ module Streamly.Data.Fold
325
325
326 -- ** Splitting
326 -- ** Splitting
327 , many
327 , many
328− , chunksOf
328+ , groupsOf
329 -- , intervalsOf
329 -- , intervalsOf
330
330
331 -- ** Nesting
331 -- ** Nesting
@@ -335,6 +335,7 @@ module Streamly.Data.Fold
335 , morphInner
335 , morphInner
336
336
337 -- * Deprecated
337 -- * Deprecated
338+ , chunksOf
338 , foldr
339 , foldr
339 , drainBy
340 , drainBy
340 , last
341 , last
@@ -362,3 +363,12 @@ import Streamly.Internal.Data.Fold.Container
362-- >>> import Data.Function ((&))
363-- >>> import Data.Function ((&))
363-- >>> import qualified Streamly.Data.Fold as Fold
364-- >>> import qualified Streamly.Data.Fold as Fold
364-- >>> import qualified Streamly.Data.Stream as Stream
365-- >>> import qualified Streamly.Data.Stream as Stream
366+
367+--------------------------------------------------------------------------------
368+-- Deprecated
369+--------------------------------------------------------------------------------
370+
371+{-# DEPRECATED chunksOf "Please use 'groupsOf' instead" #-}
372+{-# INLINE chunksOf #-}
373+chunksOf :: Monad m => Int -> Fold m a b -> Fold m b c -> Fold m a c
374+chunksOf = groupsOf
core/src/Streamly/Internal/Data/Fold.hs+2−2
@@ -283,7 +283,7 @@ module Streamly.Internal.Data.Fold
283 -- ** Splitting
283 -- ** Splitting
284 , many
284 , many
285 , manyPost
285 , manyPost
286− , chunksOf
286+ , groupsOf
287 , chunksBetween
287 , chunksBetween
288 , refoldMany
288 , refoldMany
289 , refoldMany1
289 , refoldMany1
@@ -461,7 +461,7 @@ breakStreamK strm fl = fmap f $ K.foldBreak fl (Stream.toStreamK strm)
461--
461--
462-- >>> :{
462-- >>> :{
463-- let f :: Fold IO Int (Stream Identity (Array Int))
463-- let f :: Fold IO Int (Stream Identity (Array Int))
464−-- f = Fold.chunksOf 2 (Array.writeN 3) Fold.toStream
464+-- f = Fold.groupsOf 2 (Array.writeN 3) Fold.toStream
465-- in pure f
465-- in pure f
466-- >>= Fold.addOne 1
466-- >>= Fold.addOne 1
467-- >>= Fold.addStream (Stream.enumerateFromTo 2 4)
467-- >>= Fold.addStream (Stream.enumerateFromTo 2 4)
core/src/Streamly/Internal/Data/Fold/Type.hs+8−8
@@ -382,7 +382,7 @@ module Streamly.Internal.Data.Fold.Type
382 , ManyState
382 , ManyState
383 , many
383 , many
384 , manyPost
384 , manyPost
385− , chunksOf
385+ , groupsOf
386 , refoldMany
386 , refoldMany
387 , refoldMany1
387 , refoldMany1
388
388
@@ -1334,7 +1334,7 @@ catEithers = lmap (either id id)
1334-- Parsing
1334-- Parsing
1335------------------------------------------------------------------------------
1335------------------------------------------------------------------------------
1336
1336
1337−-- Required to fuse "take" with "many" in "chunksOf", for ghc-9.x
1337+-- Required to fuse "take" with "many" in "groupsOf", for ghc-9.x
1338{-# ANN type Tuple'Fused Fuse #-}
1338{-# ANN type Tuple'Fused Fuse #-}
1339data Tuple'Fused a b = Tuple'Fused !a !b deriving Show
1339data Tuple'Fused a b = Tuple'Fused !a !b deriving Show
1340
1340
@@ -1712,25 +1712,25 @@ manyPost (Fold sstep sinitial sextract) (Fold cstep cinitial cextract) =
1712 Partial s -> cextract s
1712 Partial s -> cextract s
1713 Done b -> return b
1713 Done b -> return b
1714
1714
1715−-- | @chunksOf n split collect@ repeatedly applies the @split@ fold to chunks
1715+-- | @groupsOf n split collect@ repeatedly applies the @split@ fold to chunks
1716-- of @n@ items in the input stream and supplies the result to the @collect@
1716-- of @n@ items in the input stream and supplies the result to the @collect@
1717-- fold.
1717-- fold.
1718--
1718--
1719-- Definition:
1719-- Definition:
1720--
1720--
1721−-- >>> chunksOf n split = Fold.many (Fold.take n split)
1721+-- >>> groupsOf n split = Fold.many (Fold.take n split)
1722--
1722--
1723-- Example:
1723-- Example:
1724--
1724--
1725−-- >>> twos = Fold.chunksOf 2 Fold.toList Fold.toList
1725+-- >>> twos = Fold.groupsOf 2 Fold.toList Fold.toList
1726-- >>> Stream.fold twos $ Stream.fromList [1..10]
1726-- >>> Stream.fold twos $ Stream.fromList [1..10]
1727-- [[1,2],[3,4],[5,6],[7,8],[9,10]]
1727-- [[1,2],[3,4],[5,6],[7,8],[9,10]]
1728--
1728--
1729-- Stops when @collect@ stops.
1729-- Stops when @collect@ stops.
1730--
1730--
1731−{-# INLINE chunksOf #-}
1731+{-# INLINE groupsOf #-}
1732−chunksOf :: Monad m => Int -> Fold m a b -> Fold m b c -> Fold m a c
1732+groupsOf :: Monad m => Int -> Fold m a b -> Fold m b c -> Fold m a c
1733−chunksOf n split = many (take n split)
1733+groupsOf n split = many (take n split)
1734
1734
1735------------------------------------------------------------------------------
1735------------------------------------------------------------------------------
1736-- Refold and Fold Combinators
1736-- Refold and Fold Combinators
core/src/Streamly/Internal/Data/Stream/Chunked.hs+2−2
@@ -111,7 +111,7 @@ import qualified Streamly.Internal.Data.Stream.StreamK as K
111-- | @arraysOf n stream@ groups the elements in the input stream into arrays of
111-- | @arraysOf n stream@ groups the elements in the input stream into arrays of
112-- @n@ elements each.
112-- @n@ elements each.
113--
113--
114−-- > arraysOf n = Stream.chunksOf n (Array.writeN n)
114+-- > arraysOf n = Stream.groupsOf n (Array.writeN n)
115--
115--
116-- /Pre-release/
116-- /Pre-release/
117{-# INLINE arraysOf #-}
117{-# INLINE arraysOf #-}
@@ -541,7 +541,7 @@ toArraysInRange low high (Fold step initial extract) =
541{-# INLINE _toArraysOf #-}
541{-# INLINE _toArraysOf #-}
542_toArraysOf :: (MonadIO m, Unbox a)
542_toArraysOf :: (MonadIO m, Unbox a)
543 => Int -> Fold m a (Stream Identity (Array a))
543 => Int -> Fold m a (Stream Identity (Array a))
544−_toArraysOf n = FL.chunksOf n (A.writeNF n) FL.toStream
544+_toArraysOf n = FL.groupsOf n (A.writeNF n) FL.toStream
545-}
545-}
546
546
547-------------------------------------------------------------------------------
547-------------------------------------------------------------------------------
core/src/Streamly/Internal/Data/Stream/StreamD/Nesting.hs+1−1
@@ -138,7 +138,7 @@ module Streamly.Internal.Data.Stream.StreamD.Nesting
138
138
139 -- ** Grouping
139 -- ** Grouping
140 -- | Group segments of a stream and fold. Special case of parsing.
140 -- | Group segments of a stream and fold. Special case of parsing.
141− , chunksOf
141+ , groupsOf
142 , groupsBy
142 , groupsBy
143 , groupsRollingBy
143 , groupsRollingBy
144
144
core/src/Streamly/Internal/Data/Stream/StreamD/Type.hs+4−4
@@ -120,7 +120,7 @@ module Streamly.Internal.Data.Stream.StreamD.Type
120 , FoldManyPost (..)
120 , FoldManyPost (..)
121 , foldMany
121 , foldMany
122 , foldManyPost
122 , foldManyPost
123− , chunksOf
123+ , groupsOf
124 , refoldMany
124 , refoldMany
125
125
126 -- * Fold Iterate
126 -- * Fold Iterate
@@ -1860,9 +1860,9 @@ foldMany (Fold fstep initial extract) (Stream step state) =
1860 step' _ (FoldManyYield b next) = return $ Yield b next
1860 step' _ (FoldManyYield b next) = return $ Yield b next
1861 step' _ FoldManyDone = return Stop
1861 step' _ FoldManyDone = return Stop
1862
1862
1863−{-# INLINE chunksOf #-}
1863+{-# INLINE groupsOf #-}
1864−chunksOf :: Monad m => Int -> Fold m a b -> Stream m a -> Stream m b
1864+groupsOf :: Monad m => Int -> Fold m a b -> Stream m a -> Stream m b
1865−chunksOf n f = foldMany (FL.take n f)
1865+groupsOf n f = foldMany (FL.take n f)
1866
1866
1867-- Keep the argument order consistent with refoldIterateM.
1867-- Keep the argument order consistent with refoldIterateM.
1868
1868
core/src/Streamly/Internal/FileSystem/Dir.hs+1−1
@@ -448,7 +448,7 @@ writeChunksWithBufferOf n h = lpackArraysChunksOf n (writeChunks h)
448-- @since 0.7.0
448-- @since 0.7.0
449{-# INLINE writeWithBufferOf #-}
449{-# INLINE writeWithBufferOf #-}
450writeWithBufferOf :: MonadIO m => Int -> Handle -> Fold m Word8 ()
450writeWithBufferOf :: MonadIO m => Int -> Handle -> Fold m Word8 ()
451−writeWithBufferOf n h = FL.chunksOf n (writeNUnsafe n) (writeChunks h)
451+writeWithBufferOf n h = FL.groupsOf n (writeNUnsafe n) (writeChunks h)
452
452
453-- > write = 'writeWithBufferOf' A.defaultChunkSize
453-- > write = 'writeWithBufferOf' A.defaultChunkSize
454--
454--
core/src/Streamly/Internal/FileSystem/File.hs+2−2
@@ -103,7 +103,7 @@ import Prelude hiding (read)
103import qualified Control.Monad.Catch as MC
103import qualified Control.Monad.Catch as MC
104import qualified System.IO as SIO
104import qualified System.IO as SIO
105
105
106−import Streamly.Data.Fold (chunksOf, drain)
106+import Streamly.Data.Fold (groupsOf, drain)
107import Streamly.Internal.Data.Array.Type (Array(..), writeNUnsafe)
107import Streamly.Internal.Data.Array.Type (Array(..), writeNUnsafe)
108import Streamly.Internal.Data.Fold.Type (Fold(..))
108import Streamly.Internal.Data.Fold.Type (Fold(..))
109import Streamly.Data.Stream (Stream)
109import Streamly.Data.Stream (Stream)
@@ -464,7 +464,7 @@ writeChunks path = Fold step initial extract
464writeWith :: (MonadIO m, MonadCatch m)
464writeWith :: (MonadIO m, MonadCatch m)
465 => Int -> FilePath -> Fold m Word8 ()
465 => Int -> FilePath -> Fold m Word8 ()
466writeWith n path =
466writeWith n path =
467− chunksOf n (writeNUnsafe n) (writeChunks path)
467+ groupsOf n (writeNUnsafe n) (writeChunks path)
468
468
469{-# DEPRECATED writeWithBufferOf "Please use 'writeWith' instead" #-}
469{-# DEPRECATED writeWithBufferOf "Please use 'writeWith' instead" #-}
470{-# INLINE writeWithBufferOf #-}
470{-# INLINE writeWithBufferOf #-}
core/src/Streamly/Internal/FileSystem/Handle.hs+2−2
@@ -500,11 +500,11 @@ writeChunksWithBufferOf = writeChunksWith
500-- Bytes in the input stream are collected into a buffer until we have a chunk
500-- Bytes in the input stream are collected into a buffer until we have a chunk
501-- of @reqSize@ and then written to the IO device.
501-- of @reqSize@ and then written to the IO device.
502--
502--
503−-- >>> writeWith n h = Fold.chunksOf n (Array.writeNUnsafe n) (Handle.writeChunks h)
503+-- >>> writeWith n h = Fold.groupsOf n (Array.writeNUnsafe n) (Handle.writeChunks h)
504--
504--
505{-# INLINE writeWith #-}
505{-# INLINE writeWith #-}
506writeWith :: MonadIO m => Int -> Handle -> Fold m Word8 ()
506writeWith :: MonadIO m => Int -> Handle -> Fold m Word8 ()
507−writeWith n h = FL.chunksOf n (writeNUnsafe n) (writeChunks h)
507+writeWith n h = FL.groupsOf n (writeNUnsafe n) (writeChunks h)
508
508
509-- | Same as 'writeWith'
509-- | Same as 'writeWith'
510--
510--
docs/User/ProjectRelated/Changelog.md+1
@@ -49,6 +49,7 @@ higher level operations with additional dependencies.
49 * `serialWith` renamed to `splitWith`.
49 * `serialWith` renamed to `splitWith`.
50 * `variance`, and `stdDev` deprecated. Please use the
50 * `variance`, and `stdDev` deprecated. Please use the
51 `streamly-statistics` package instead.
51 `streamly-statistics` package instead.
52+ * `chunksOf` is renamed to `groupsOf`.
52* In `Streamly.Network.Socket`:
53* In `Streamly.Network.Socket`:
53 * `readWithBufferOf` renamed to `readWith`
54 * `readWithBufferOf` renamed to `readWith`
54 * `readChunksWithBufferOf` renamed to `readChunksWith`
55 * `readChunksWithBufferOf` renamed to `readChunksWith`
src/Streamly/Internal/Data/Stream/IsStream/Reduce.hs+2−2
@@ -193,7 +193,7 @@ import qualified Streamly.Internal.Data.Parser.ParserD as PRD (Parser(..))
193import qualified Streamly.Internal.Data.Stream.IsStream.Type as IsStream
193import qualified Streamly.Internal.Data.Stream.IsStream.Type as IsStream
194import qualified Streamly.Internal.Data.Stream.StreamD as D
194import qualified Streamly.Internal.Data.Stream.StreamD as D
195 ( foldMany
195 ( foldMany
196− , chunksOf
196+ , groupsOf
197 , refoldMany
197 , refoldMany
198 , foldIterateM
198 , foldIterateM
199 , refoldIterateM
199 , refoldIterateM
@@ -983,7 +983,7 @@ splitOnSuffixSeqAny _subseq _f _m = undefined
983chunksOf
983chunksOf
984 :: (IsStream t, Monad m)
984 :: (IsStream t, Monad m)
985 => Int -> Fold m a b -> t m a -> t m b
985 => Int -> Fold m a b -> t m a -> t m b
986−chunksOf n f = fromStreamD . D.chunksOf n f . toStreamD
986+chunksOf n f = fromStreamD . D.groupsOf n f . toStreamD
987
987
988-- | @arraysOf n stream@ groups the elements in the input stream into arrays of
988-- | @arraysOf n stream@ groups the elements in the input stream into arrays of
989-- @n@ elements each.
989-- @n@ elements each.
src/Streamly/Internal/Network/Inet/TCP.hs+1−1
@@ -399,7 +399,7 @@ writeWithBufferOf
399 -> PortNumber
399 -> PortNumber
400 -> Fold m Word8 ()
400 -> Fold m Word8 ()
401writeWithBufferOf n addr port =
401writeWithBufferOf n addr port =
402− FL.chunksOf n (writeNUnsafe n) (writeChunks addr port)
402+ FL.groupsOf n (writeNUnsafe n) (writeChunks addr port)
403
403
404-- | Write a stream to the supplied IPv4 host address and port number.
404-- | Write a stream to the supplied IPv4 host address and port number.
405--
405--
src/Streamly/Internal/Network/Socket.hs+1−1
@@ -502,7 +502,7 @@ putBytesWith n h m = putChunks h $ A.arraysOf n m
502--
502--
503{-# INLINE writeWith #-}
503{-# INLINE writeWith #-}
504writeWith :: MonadIO m => Int -> Socket -> Fold m Word8 ()
504writeWith :: MonadIO m => Int -> Socket -> Fold m Word8 ()
505−writeWith n h = FL.chunksOf n (A.writeNUnsafe n) (writeChunks h)
505+writeWith n h = FL.groupsOf n (A.writeNUnsafe n) (writeChunks h)
506
506
507-- | Same as 'writeWith'
507-- | Same as 'writeWith'
508--
508--