Skip to content

Commit

Permalink
Deprecate chunksOf from Data.Stream module
Browse files Browse the repository at this point in the history
  • Loading branch information
adithyaov committed Dec 19, 2024
1 parent 4e7b848 commit 8d913e3
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 18 deletions.
4 changes: 2 additions & 2 deletions benchmark/Streamly/Benchmark/Data/Array/Stream.hs
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ main = do
then return (undefined, undefined)
else
do
small <- Stream.toList $ Stream.chunksOf 100 $ sourceUnfoldrM value 0
big <- Stream.toList $ Stream.chunksOf value $ sourceUnfoldrM value 0
small <- Stream.toList $ Array.chunksOf 100 $ sourceUnfoldrM value 0
big <- Stream.toList $ Array.chunksOf value $ sourceUnfoldrM value 0
return (small, big)

allBenchmarks env arrays value =
Expand Down
2 changes: 1 addition & 1 deletion benchmark/Streamly/Benchmark/Data/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ main = do

where

alloc value = Stream.fold Fold.toList $ Stream.chunksOf 100 $ sourceUnfoldrM value 0
alloc value = Stream.fold Fold.toList $ Array.chunksOf 100 $ sourceUnfoldrM value 0

allBenchmarks env arrays value =
[ bgroup (o_1_space_prefix moduleName) (o_1_space_serial value)
Expand Down
3 changes: 2 additions & 1 deletion benchmark/Streamly/Benchmark/Data/ParserK.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Control.Monad.IO.Class (MonadIO)
import Data.Foldable (asum)
#ifdef BENCH_CHUNKED
import Streamly.Data.Array (Array, Unbox)
import qualified Streamly.Internal.Data.Array as Array (chunksOf)
#endif
#ifdef BENCH_CHUNKED_GENERIC
import Streamly.Data.Array.Generic (Array)
Expand Down Expand Up @@ -116,7 +117,7 @@ benchIOSink value name f =
>>= f
. StreamK.fromStream
#ifdef BENCH_CHUNKED
. Stream.chunksOf 4000
. Array.chunksOf 4000
#endif
#ifdef BENCH_CHUNKED_GENERIC
. GenArr.chunksOf 4000
Expand Down
9 changes: 4 additions & 5 deletions benchmark/Streamly/Benchmark/FileSystem/Handle/Read.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import GHC.Magic (inline)
import GHC.Magic (noinline)
import System.IO (Handle)

import qualified Streamly.Data.Stream as Stream
import qualified Streamly.Data.Fold as Fold
import qualified Streamly.FileSystem.Handle as FH
import qualified Streamly.Internal.Data.Array as A
Expand Down Expand Up @@ -249,7 +248,7 @@ inspect $ 'groupsOf `hasNoType` ''IUF.ConcatState -- FH.read/UF.many
{-# INLINE chunksOf #-}
chunksOf :: Int -> Handle -> IO Int
chunksOf n inh =
S.fold Fold.length $ Stream.chunksOf n (S.unfold FH.reader inh)
S.fold Fold.length $ A.chunksOf n (S.unfold FH.reader inh)

o_1_space_reduce_read_grouped :: BenchEnv -> [Benchmark]
o_1_space_reduce_read_grouped env =
Expand Down Expand Up @@ -288,11 +287,11 @@ o_1_space_reduce_read_grouped env =
groupsOf 1000 inh

-- chunksOf may use a different impl than groupsOf
, mkBenchSmall "S.chunksOf 1" env $ \inh _ ->
, mkBenchSmall "A.chunksOf 1" env $ \inh _ ->
chunksOf 1 inh
, mkBench "S.chunksOf 10" env $ \inh _ ->
, mkBench "A.chunksOf 10" env $ \inh _ ->
chunksOf 10 inh
, mkBench "S.chunksOf 1000" env $ \inh _ ->
, mkBench "A.chunksOf 1000" env $ \inh _ ->
chunksOf 1000 inh
]
]
Expand Down
15 changes: 10 additions & 5 deletions core/src/Streamly/Data/Stream.hs
Original file line number Diff line number Diff line change
Expand Up @@ -665,11 +665,6 @@ module Streamly.Data.Stream
, runReaderT
, runStateT

-- XXX Arrays could be different types, therefore, this should be in
-- specific array module. Or maybe we should abstract over array types.
-- * Stream of Arrays
, Array.chunksOf

-- * Deprecated
, scan
, scanMaybe
Expand All @@ -679,6 +674,7 @@ module Streamly.Data.Stream
, unfoldMany
, intercalate
, intercalateSuffix
, chunksOf
)
where

Expand All @@ -688,6 +684,15 @@ import Prelude
mapM, scanl, sequence, reverse, iterate, foldr1, repeat, replicate,
concatMap)

import Streamly.Internal.Data.Unbox (Unbox(..))
import Control.Monad.IO.Class (MonadIO(..))

import qualified Streamly.Internal.Data.Array.Type as Array

#include "DocTestDataStream.hs"

{-# DEPRECATED chunksOf "Please use chunksOf from the Array module instead." #-}
{-# INLINE chunksOf #-}
chunksOf :: forall m a. (MonadIO m, Unbox a)
=> Int -> Stream m a -> Stream m (Array.Array a)
chunksOf = Array.chunksOf
2 changes: 1 addition & 1 deletion core/src/Streamly/Internal/Data/Fold/Chunked.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
-- >> import qualified Streamly.Data.StreamK as StreamK
--
-- >> f = ChunkFold.fromFold (Fold.take 7 Fold.toList)
-- >> s = Stream.chunksOf 5 $ Stream.fromList "hello world"
-- >> s = Array.chunksOf 5 $ Stream.fromList "hello world"
-- >> ArrayStream.runArrayFold f (StreamK.fromStream s)
-- Right "hello w"
--
Expand Down
2 changes: 1 addition & 1 deletion core/src/Streamly/Internal/FileSystem/Handle.hs
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ writeChunksWithBufferOf = writeChunksWith
-- do not want buffering to occur at GHC level as well. Same thing applies to
-- writes as well.

-- XXX Maybe we should have a Fold.chunksOf like we have Stream.chunksOf
-- XXX Maybe we should have a Fold.chunksOf like we have Array.chunksOf

-- | @writeWith reqSize handle@ writes the input stream to @handle@.
-- Bytes in the input stream are collected into a buffer until we have a chunk
Expand Down
2 changes: 1 addition & 1 deletion test/Streamly/Test/Data/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ parseUnfold = do
<*> chooseInt (1, len)
<*> chooseInt (1, len)) $ \(ls, clen, tlen) ->
monadicIO $ do
arrays <- S.toList $ S.chunksOf clen (S.fromList ls)
arrays <- S.toList $ A.chunksOf clen (S.fromList ls)
let src = Producer.source (Just (Producer.OuterLoop arrays))
let parser = P.fromFold (FL.take tlen FL.toList)
let readSrc =
Expand Down
3 changes: 2 additions & 1 deletion test/Streamly/Test/Unicode/Stream.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Test.QuickCheck.Monadic (run, monadicIO, assert, PropertyM)
import Streamly.Data.Stream (Stream)

import qualified Streamly.Data.Array as A
import qualified Streamly.Internal.Data.Array as Array
import qualified Streamly.Data.Stream as Stream
import qualified Streamly.Internal.Data.Array.Stream as AS
import qualified Streamly.Internal.Data.Stream as Stream
Expand Down Expand Up @@ -106,7 +107,7 @@ propDecodeEncodeIdArrays :: Property
propDecodeEncodeIdArrays =
forAll genUnicode $ \list ->
monadicIO $ do
let wrds = Stream.chunksOf 8 $ SS.encodeUtf8' $ Stream.fromList list
let wrds = Array.chunksOf 8 $ SS.encodeUtf8' $ Stream.fromList list
chrs <- Stream.toList $ IUS.decodeUtf8Chunks wrds
assertEq chrs list

Expand Down

0 comments on commit 8d913e3

Please sign in to comment.