Enum

reduce_while/3

reduce_while(enumerable, acc, fun)

Reduces enumerable until it’s exhausted or fun returns {:halt, term}.

The return value for fun is expected to be

If fun returns {:halt, acc} the reduction is halted and the function returns acc.

Otherwise, if enumerable is exhausted, the function returns the accumulator of the last {:cont, acc}.