many package:streamly-core

Collect zero or more applications of a fold. many first second applies the first fold repeatedly on the input stream and accumulates it's results using the second fold.
>>> two = Fold.take 2 Fold.toList

>>> twos = Fold.many two Fold.toList

>>> Stream.fold twos $ Stream.fromList [1..10]
[[1,2],[3,4],[5,6],[7,8],[9,10]]
Stops when second fold stops. See also: concatMap, foldMany
Collect zero or more parses. Apply the supplied parser repeatedly on the input stream and push the parse results to a downstream fold. Stops: when the downstream fold stops or the parser fails. Fails: never, produces zero or more results.
>>> many = Parser.countBetween 0 maxBound
Compare with many.
Apply the first unfold to each output element of the second unfold and flatten the output in a single stream.
>>> many u = Unfold.many2 (Unfold.lmap snd u)
manyTill chunking test f tries the parser test on the input, if test fails it backtracks and tries chunking, after chunking succeeds test is tried again and so on. The parser stops when test succeeds. The output of test is discarded and the output of chunking is accumulated by the supplied fold. The parser fails if chunking fails. Stops when the fold f stops.
Like many, but the "first" fold emits an output at the end even if no input is received. Internal See also: concatMap, foldMany
Like many but uses a Parser instead of a Fold to collect the results. Parsing stops or fails if the collecting parser stops or fails. Unimplemented
manyThen f collect recover repeats the parser collect on the input and collects the output in the supplied fold. If the the parser collect fails, parser recover is run until it stops and then we start repeating the parser collect again. The parser fails if the recovery parser fails. For example, this can be used to find a key frame in a video stream after an error. Unimplemented
Like manyTill but uses a Parser to collect the results instead of a Fold. Parsing stops or fails if the collecting parser stops or fails. We can implemnent parsers like the following using manyTillP:
countBetweenTill m n f p = manyTillP (takeBetween m n f) p
Unimplemented
unfoldManyInterleave for documentation and notes. This is almost identical to unfoldManyInterleave in StreamD module. The many combinator is in fact manyAppend to be more explicit in naming. Internal
Apply a Fold repeatedly on a stream and emit the results in the output stream. Definition:
>>> foldMany f = Stream.parseMany (Parser.fromFold f)
Example, empty stream:
>>> f = Fold.take 2 Fold.sum

>>> fmany = Stream.fold Fold.toList . Stream.foldMany f

>>> fmany $ Stream.fromList []
[]
Example, last fold empty:
>>> fmany $ Stream.fromList [1..4]
[3,7]
Example, last fold non-empty:
>>> fmany $ Stream.fromList [1..5]
[3,7,5]
Note that using a closed fold e.g. Fold.take 0, would result in an infinite stream on a non-empty input stream.
Apply a Parser repeatedly on a stream and emit the parsed values in the output stream. Example:
>>> s = Stream.fromList [1..10]

>>> parser = Parser.takeBetween 0 2 Fold.sum

>>> Stream.fold Fold.toList $ Stream.parseMany parser s
[Right 3,Right 7,Right 11,Right 15,Right 19]
This is the streaming equivalent of the many parse combinator. Known Issues: When the parser fails there is no way to get the remaining stream.
unfoldMany unfold stream uses unfold to map the input stream elements to streams and then flattens the generated streams into a single output stream. Like concatMap but uses an Unfold for stream generation. Unlike concatMap this can fuse the Unfold code with the inner loop and therefore provide many times better performance.
Apply an ChunkFold repeatedly on an array stream and emit the fold outputs in the output stream. See "Streamly.Data.Stream.foldMany" for more details. Pre-release
Like many but uses a Refold for collecting.
Like many but uses a Refold for splitting. Internal
Scan the input of a Fold to change it in a stateful manner using another Fold. The scan restarts with a fresh state if the fold terminates. Pre-release
Unfold and flatten the input stream of a fold.
Stream.fold (unfoldMany u f) = Stream.fold f . Stream.unfoldMany u
Pre-release
See documentation of many. Pre-release
Like splitMany, but inner fold emits an output at the end even if no input is received. Internal
Apply a parser repeatedly on a buffered source producer to generate a producer of parsed values. Pre-release