>>> 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
>>> many = Parser.countBetween 0 maxBoundCompare with many.
>>> many u = Unfold.many2 (Unfold.lmap snd u)
>>> 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.
>>> 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.
Stream.fold (unfoldMany u f) = Stream.fold f . Stream.unfoldMany uPre-release