on master help sign in
Expose splitOn and chunksSplitOn
fec7c6bRanjeet Kumar Ranjan
core/src/Streamly/Data/Stream.hs+20
@@ -436,6 +436,10 @@ module Streamly.Data.Stream
436 , parseMany
436 , parseMany
437 , Array.chunksOf
437 , Array.chunksOf
438
438
439+ -- * Splitting
440+ , splitOn
441+ , chunksSplitOn
442+
439 -- * Buffered Operations
443 -- * Buffered Operations
440 -- | Operations that require buffering of the stream.
444 -- | Operations that require buffering of the stream.
441 -- Reverse is essentially a left fold followed by an unfold.
445 -- Reverse is essentially a left fold followed by an unfold.
@@ -493,7 +497,12 @@ module Streamly.Data.Stream
493 )
497 )
494where
498where
495
499
500+import Control.Monad.IO.Class (MonadIO)
501+import Data.Word (Word8)
502+import Streamly.Data.Array (Array)
503+
496import qualified Streamly.Internal.Data.Array.Type as Array
504import qualified Streamly.Internal.Data.Array.Type as Array
505+import qualified Streamly.Internal.Data.Stream.Chunked as ArrayStream
497import Streamly.Internal.Data.Stream.StreamD
506import Streamly.Internal.Data.Stream.StreamD
498import Prelude
507import Prelude
499 hiding (filter, drop, dropWhile, take, takeWhile, zipWith, foldr,
508 hiding (filter, drop, dropWhile, take, takeWhile, zipWith, foldr,
@@ -607,3 +616,14 @@ import Prelude
607--
616--
608-- 'Stream' and 'StreamK' types can be interconverted. See
617-- 'Stream' and 'StreamK' types can be interconverted. See
609-- "Streamly.Data.StreamK" module for conversion operations.
618-- "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