Unlike
groupBy this combinator performs a rolling comparison of
two successive elements in the input stream. Assuming the input stream
is
[a,b,c,...] and the comparison function is
cmp,
the parser first assigns the element
a to the first group,
then if
a `cmp` b is
True b is also assigned
to the same group. If
b `cmp` c is
True then
c is also assigned to the same group and so on. When the
comparison fails the parser is terminated. Each group is folded using
the
Fold f and the result of the fold is the result of
the parser.
- Stops - when the comparison fails.
- Fails - never.
>>> :{
runGroupsByRolling eq =
Stream.fold Fold.toList
. Stream.parseMany (Parser.groupByRolling eq Fold.toList)
. Stream.fromList
:}
>>> runGroupsByRolling (<) []
[]
>>> runGroupsByRolling (<) [1]
[Right [1]]
>>> runGroupsByRolling (<) [3, 5, 4, 1, 2, 0]
[Right [3,5],Right [4],Right [1,2],Right [0]]
Pre-release