on master help sign in
Expose splitOn and chunksSplitOn
commitfec7c6b2fcdf3381237de282c0d29164ecdfbfde authorRanjeet Kumar Ranjan <ranjeetr@composewell.com> dateMon 20 Mar 2023, 14:26 (4 years ago) parentd45b17c
1 file changed+20
core/src/Streamly/Data/Stream.hs+20
core/src/Streamly/Data/Stream.hs+20
@@ -436,6 +436,10 @@ module Streamly.Data.Stream
436436 , parseMany
437437 , Array.chunksOf
438438
439+ -- * Splitting
440+ , splitOn
441+ , chunksSplitOn
442+
439443 -- * Buffered Operations
440444 -- | Operations that require buffering of the stream.
441445 -- Reverse is essentially a left fold followed by an unfold.
@@ -493,7 +497,12 @@ module Streamly.Data.Stream
493497 )
494498where
495499
500+import Control.Monad.IO.Class (MonadIO)
501+import Data.Word (Word8)
502+import Streamly.Data.Array (Array)
503+
496504import qualified Streamly.Internal.Data.Array.Type as Array
505+import qualified Streamly.Internal.Data.Stream.Chunked as ArrayStream
497506import Streamly.Internal.Data.Stream.StreamD
498507import Prelude
499508 hiding (filter, drop, dropWhile, take, takeWhile, zipWith, foldr,
@@ -607,3 +616,14 @@ import Prelude
607616--
608617-- 'Stream' and 'StreamK' types can be interconverted. See
609618-- "Streamly.Data.StreamK" module for conversion operations.
619+
620+-- | Split a stream of arrays on a given separator byte, dropping the separator
621+-- and coalescing all the arrays between two separators into a single array.
622+--
623+{-# INLINE chunksSplitOn #-}
624+chunksSplitOn
625+ :: (MonadIO m)
626+ => Word8
627+ -> Stream m (Array Word8)
628+ -> Stream m (Array Word8)
629+chunksSplitOn = ArrayStream.splitOn