we are trying to parallelize processing operation with Flow and run into the situation when small datasets resulted in empty output.
The concise version of the problematic section is following:
defmodule TestFlow do
alias Experimental.Flow
def test(range) do
range
|> Flow.from_enumerable()
|> Flow.reduce(fn -> %{even: [], odd: []} end, fn(number, acc) ->
push_number(number, acc)
end)
|> Enum.into(%{})
end
defp push_number(number, acc) do
if rem(number, 2) == 0 do
%{even: [number | acc.even], odd: acc.odd}
else
%{even: acc.even, odd: [number | acc.odd]}
end
end
end
What would an idiomatic solution to collecting Flow.reduce results into a map?