streamly
streamly copied to clipboard
Nested termination in folds and parsers
Fold.many and Parse.many are functions with no termination. The default termination reapplies the parsing/folding combinator.
Parse.many itself can have a natural nesting termination by terminating on parser failure
Folds on the other hand don't have a failure and have to represent nesting termination in an elegant way, One simple solution is to pass in the nested terminating condition, For example,
manyEndBy :: (a -> Bool) -> Fold m a b -> Fold m b c -> Fold m a c
Note that terminating folds don't have backtracking and manyWhile is only possible with 1 element backtracking.
We need to think about 1 element backtracking in folds and if it's worth adding it.
Perhaps the manyTill parser is the right solution for this?