on master help sign in
Expose mut array stream APIs via MutArray.Stream
3899b86Harendra Kumar
core/src/Streamly/Internal/Data/MutArray/Stream.hs+14−16
@@ -8,19 +8,30 @@
8--
8--
9-- Combinators to efficiently manipulate streams of mutable arrays.
9-- Combinators to efficiently manipulate streams of mutable arrays.
10--
10--
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+--
11module Streamly.Internal.Data.MutArray.Stream
14module Streamly.Internal.Data.MutArray.Stream
12 (
15 (
13 -- * Generation
16 -- * Generation
14− chunksOf
17+ MArray.chunksOf
18+ , MArray.pinnedChunksOf
19+ , MArray.writeChunks -- chunksWrite?
20+ , MArray.splitOn -- chunksSplitOn
15
21
16 -- * Compaction
22 -- * Compaction
17 , packArraysChunksOf
23 , packArraysChunksOf
18 , SpliceState (..)
24 , SpliceState (..)
19 , lpackArraysChunksOf
25 , lpackArraysChunksOf
20− , compact
26+ , compact -- chunksCompact
21 , compactLE
27 , compactLE
22 , compactEQ
28 , compactEQ
23 , compactGE
29 , compactGE
30+
31+ -- * Elimination
32+ , MArray.flattenArrays -- chunksConcat
33+ , MArray.flattenArraysRev -- chunksConcatRev
34+ , MArray.fromArrayStreamK -- chunksCoalesce
24 )
35 )
25where
36where
26
37
@@ -38,24 +49,11 @@ import Streamly.Internal.Data.Parser (ParseError)
38import Streamly.Internal.Data.Stream.Type (Stream)
49import Streamly.Internal.Data.Stream.Type (Stream)
39import Streamly.Internal.Data.Tuple.Strict (Tuple'(..))
50import Streamly.Internal.Data.Tuple.Strict (Tuple'(..))
40
51
41−import qualified Streamly.Internal.Data.MutArray.Type as MArray
52+import qualified Streamly.Internal.Data.MutArray as MArray
42import qualified Streamly.Internal.Data.Fold.Type as FL
53import qualified Streamly.Internal.Data.Fold.Type as FL
43import qualified Streamly.Internal.Data.Parser as ParserD
54import qualified Streamly.Internal.Data.Parser as ParserD
44import qualified Streamly.Internal.Data.Stream as D
55import qualified Streamly.Internal.Data.Stream as D
45
56
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−
59-------------------------------------------------------------------------------
57-------------------------------------------------------------------------------
60-- Compact
58-- Compact
61-------------------------------------------------------------------------------
59-------------------------------------------------------------------------------
core/src/Streamly/Internal/Data/MutArray/Type.hs+6−4
@@ -1348,10 +1348,12 @@ chunksOfAs ps n (D.Stream step state) =
1348
1348
1349 step' _ GroupFinish = return D.Stop
1349 step' _ GroupFinish = return D.Stop
1350
1350
1351−-- | @chunksOf n stream@ groups the input stream into a stream of
1351+-- | @chunksOf n stream@ groups the elements in the input stream into arrays of
1352−-- arrays of size n.
1352+-- @n@ elements each.
1353--
1353--
1354+-- Same as the following but may be more efficient:
1355+--
1354−-- @chunksOf n = StreamD.foldMany (MutArray.writeN n)@
1356+-- >>> chunksOf n = Stream.foldMany (MutArray.writeN n)
1355--
1357--
1356-- /Pre-release/
1358-- /Pre-release/
1357{-# INLINE_NORMAL chunksOf #-}
1359{-# INLINE_NORMAL chunksOf #-}
@@ -1884,7 +1886,7 @@ pinnedWriteNAligned :: forall m a. (MonadIO m, Unbox a)
1884pinnedWriteNAligned align = writeNWith (pinnedNewAligned align)
1886pinnedWriteNAligned align = writeNWith (pinnedNewAligned align)
1885
1887
1886-- XXX Buffer to a list instead?
1888-- XXX Buffer to a list instead?
1887−--
1889+
1888-- | Buffer a stream into a stream of arrays.
1890-- | Buffer a stream into a stream of arrays.
1889--
1891--
1890-- >>> writeChunks n = Fold.many (MutArray.writeN n) Fold.toStreamK
1892-- >>> writeChunks n = Fold.many (MutArray.writeN n) Fold.toStreamK