HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulestreamly-core-0.2.2Haskell2010

Streamly.Internal.Data.Array.Stream

Deprecated. Please use Streamly.Internal.Data.Array instead.

Combinators to efficiently manipulate streams of immutable arrays.

We can either push these in the MutArray module with a "chunks" prefix or keep this as a separate module and release it.

  • 25 values

Creation

3 declarations
valuechunksOf :: (MonadIO m, Unbox a) => Int -> Stream m a -> Stream m (Array a)
#

chunksOf n stream groups the elements in the input stream into arrays of n elements each.

Same as the following but may be more efficient:

Example1 expression
chunksOf n = Stream.foldMany (Array.writeN n)

Pre-release

Flattening to elements

8 declarations
valueconcat :: (Monad m, Unbox a) => Stream m (Array a) -> Stream m a
#

Convert a stream of arrays into a stream of their elements.

Example1 expression
concat = Stream.unfoldMany Array.reader
valueconcatRev :: (Monad m, Unbox a) => Stream m (Array a) -> Stream m a
#

Convert a stream of arrays into a stream of their elements reversing the contents of each array before flattening.

Example1 expression
concatRev = Stream.unfoldMany Array.readerRev
valueinterpose :: (Monad m, Unbox a) => a -> Stream m (Array a) -> Stream m a
#

Insert the given element between arrays and flatten.

Example1 expression
interpose x = Stream.interpose x Array.reader
valueinterposeSuffix
  1. :: (Monad m, Unbox a)
  2. => a
  3. -> Stream m (Array a)
  4. -> Stream m a
#

Insert the given element after each array and flatten. This is similar to unlines.

Example1 expression
interposeSuffix x = Stream.interposeSuffix x Array.reader

Elimination

0 declarations

Element Folds

valuefoldBreak
  1. :: (MonadIO m, Unbox a)
  2. => Fold m a b
  3. -> StreamK m (Array a)
  4. -> m (b, StreamK m (Array a))
#

Fold an array stream using the supplied Fold. Returns the fold result and the unconsumed stream.

foldBreak f = runArrayFoldBreak (ChunkFold.fromFold f)

Instead of using this we can adapt the fold to ParserK and use parseBreakChunks instead. ParserK allows composing using Monad as well.

foldBreak f s =
      fmap (first (fromRight undefined))
    $ K.parseBreakChunks (ParserK.adaptC (PR.fromFold f)) s

We can compare perf and remove this one or define it in terms of that.

Internal

valueparseBreak
  1. :: (MonadIO m, Unbox a)
  2. => Parser a m b
  3. -> StreamK m (Array a)
  4. -> m (Either ParseError b, StreamK m (Array a))
#

Parse an array stream using the supplied Parser. Returns the parse result and the unconsumed stream. Throws ParseError if the parse fails.

> parseBreak p = K.parseBreakChunks (ParserK.adaptC p)

This is redundant and we can just use parseBreakChunks, as ParserK can be composed using Monad. The only advantage of this is that we do not need to adapt.

We can compare perf and remove this one or define it in terms of that.

Internal

Array Folds

valuerunArrayParserDBreak
  1. :: (MonadIO m, Unbox a)
  2. => Parser (Array a) m b
  3. -> Stream m (Array a)
  4. -> m (Either ParseError b, Stream m (Array a))
#

Note that this is not the same as using a Parser (Array a) m b with the regular "Streamly.Internal.Data.IsStream.parse" function. The regular parse would consume the input arrays as single unit. This parser parses in the way as described in the ChunkFold module. The input arrays are treated as n element units and can be consumed partially. The remaining elements are inserted in the source stream as an array.

valuetoArray :: (MonadIO m, Unbox a) => Stream m (Array a) -> m (Array a)
#

Given a stream of arrays, splice them all together to generate a single array. The stream must be finite.

Compaction

2 declarations

Splitting

2 declarations