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.
Deprecated: Please use unfoldEach instead.
manyTill p test f tries the parser test on the input, if test fails it backtracks and tries p, after p succeeds test is tried again and so on. The parser stops when test succeeds. The output of test is discarded and the output of p is accumulated by the supplied fold. The parser fails if p 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
Deprecated: Use carry with unfoldEach instead.
Deprecated: Please use unfoldEachInterleave instead.
Apply a terminating Fold repeatedly on a stream and emit the results in the output stream. If the last fold is empty, it's result is not emitted. This means if the input stream is empty the result is also an empty stream. See foldManyPost for an alternate behavior which always results in a non-empty stream even if the input stream is empty. Definition:
>>> foldMany f = Stream.parseMany (Parser.fromFold f)
Example, empty stream, omits the empty fold value:
>>> f = Fold.take 2 Fold.toList

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

>>> fmany $ Stream.fromList []
[]
Example, omits the last empty fold value:
>>> fmany $ Stream.fromList [1..4]
[[1,2],[3,4]]
Example, last fold non-empty:
>>> fmany $ Stream.fromList [1..5]
[[1,2],[3,4],[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. Usage:
>>> s = Stream.fromList [1..10]

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

>>> Stream.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.
Deprecated: Please use unfoldEach instead.
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
Deprecated: Please use scanlMany instead.
Scan the input of a Fold to change it in a stateful manner using a Scanl. The scan restarts with a fresh state if it 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
Scan the input of a Scanl to change it in a stateful manner using another Scanl. The scan restarts with a fresh state if it terminates. Pre-release