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.