This is a generalization of the current Stream.chunk_by/2 function.
Example:
1..10
|> Stream.chunk_by([], fn i, acc ->
if rem(i, 2) == 0, do: {Enum.reverse([i | acc]), []}, else: {[], [i | acc]}
end, fn acc -> Enum.reverse(acc) end)
|> Enum.to_list
#=> [[1, 2], [3, 4], [5, 6], [7, 8], ...]
This is a generalization of the current Stream.chunk_by/2 function.
Example: