FoldWhile¶
Folds a function over a list while a predicate holds, returning the first accumulator value for which the predicate fails (or the final value if it never fails).
The initial value is tested first, so a value that already fails is returned without any folding:
The three-argument form takes the initial value from the head of the list:
An m argument supplies the last m results to the test:
A trailing n continues folding n extra times past the failing value
(or steps back with a negative value):