Enum.split_with/2
splits an enumerable into two lists based on the return value of a function. I would like to know if it is possible to do the same with a stream and get two streams instead of getting two lists and consuming the whole stream. In other words, how could I implement a Stream.split_with/2
function ?
iex(1)> 1..10 |> Stream.map(&(&1)) |> Enum.split_with(fn x -> Integer.mod(x,2) == 0 end)
{[2, 4, 6, 8, 10], [1, 3, 5, 7, 9]}
iex(1)> 1..10 |> Stream.map(&(&1)) |> Stream.split_with(fn x -> Integer.mod(x,2) == 0 end)
{#Stream<...>, #Stream<...>}