Enum.reduce_while/3

defmodule Enum do
  def reduce_while(enumerable, acc, fun)
end

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

The return value for fun is expected to be

  • {:cont, acc} to continue the reduction with acc as the new accumulator or
  • {:halt, acc} to halt the reduction

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}.