on master help sign in
Expose mut array stream APIs via MutArray.Stream
commit3899b8640e9be8a749b0b28c9d381234ca6e60ed authorHarendra Kumar <harendra@composewell.com> dateFri 24 Nov 2023, 06:47 (3 years ago) parentdfa2079
2 files changed+20−20
core/src/Streamly/Internal/Data/MutArray/Stream.hs+14−16 core/src/Streamly/Internal/Data/MutArray/Type.hs+6−4
core/src/Streamly/Internal/Data/MutArray/Stream.hs+14−16
@@ -8,19 +8,30 @@
88--
99-- Combinators to efficiently manipulate streams of mutable arrays.
1010--
11+-- We can either push these in the MutArray module with a "chunks" prefix or
12+-- keep this as a separate module and release it.
13+--
1114module Streamly.Internal.Data.MutArray.Stream
1215 (
1316 -- * Generation
14− chunksOf
17+ MArray.chunksOf
18+ , MArray.pinnedChunksOf
19+ , MArray.writeChunks -- chunksWrite?
20+ , MArray.splitOn -- chunksSplitOn
1521
1622 -- * Compaction
1723 , packArraysChunksOf
1824 , SpliceState (..)
1925 , lpackArraysChunksOf
20− , compact
26+ , compact -- chunksCompact
2127 , compactLE
2228 , compactEQ
2329 , compactGE
30+
31+ -- * Elimination
32+ , MArray.flattenArrays -- chunksConcat
33+ , MArray.flattenArraysRev -- chunksConcatRev
34+ , MArray.fromArrayStreamK -- chunksCoalesce
2435 )
2536where
2637
@@ -38,24 +49,11 @@ import Streamly.Internal.Data.Parser (ParseError)
3849import Streamly.Internal.Data.Stream.Type (Stream)
3950import Streamly.Internal.Data.Tuple.Strict (Tuple'(..))
4051
41−import qualified Streamly.Internal.Data.MutArray.Type as MArray
52+import qualified Streamly.Internal.Data.MutArray as MArray
4253import qualified Streamly.Internal.Data.Fold.Type as FL
4354import qualified Streamly.Internal.Data.Parser as ParserD
4455import qualified Streamly.Internal.Data.Stream as D
4556
46−-- | @chunksOf n stream@ groups the elements in the input stream into arrays of
47−-- @n@ elements each.
48−--
49−-- Same as the following but may be more efficient:
50−--
51−-- > chunksOf n = Stream.foldMany (MArray.writeN n)
52−--
53−-- /Pre-release/
54−{-# INLINE chunksOf #-}
55−chunksOf :: (MonadIO m, Unbox a)
56− => Int -> Stream m a -> Stream m (MutArray a)
57−chunksOf = MArray.chunksOf
58−
5957-------------------------------------------------------------------------------
6058-- Compact
6159-------------------------------------------------------------------------------
core/src/Streamly/Internal/Data/MutArray/Type.hs+6−4
@@ -1348,10 +1348,12 @@ chunksOfAs ps n (D.Stream step state) =
13481348
13491349 step' _ GroupFinish = return D.Stop
13501350
1351−-- | @chunksOf n stream@ groups the input stream into a stream of
1352−-- arrays of size n.
1351+-- | @chunksOf n stream@ groups the elements in the input stream into arrays of
1352+-- @n@ elements each.
13531353--
1354−-- @chunksOf n = StreamD.foldMany (MutArray.writeN n)@
1354+-- Same as the following but may be more efficient:
1355+--
1356+-- >>> chunksOf n = Stream.foldMany (MutArray.writeN n)
13551357--
13561358-- /Pre-release/
13571359{-# INLINE_NORMAL chunksOf #-}
@@ -1884,7 +1886,7 @@ pinnedWriteNAligned :: forall m a. (MonadIO m, Unbox a)
18841886pinnedWriteNAligned align = writeNWith (pinnedNewAligned align)
18851887
18861888-- XXX Buffer to a list instead?
1887−--
1889+
18881890-- | Buffer a stream into a stream of arrays.
18891891--
18901892-- >>> writeChunks n = Fold.many (MutArray.writeN n) Fold.toStreamK