Why does Flow.reduce require an accumulator function, rather than just a value?

Why does Flow.reduce require an accumulator function, rather than just a value?

I.e. fn -> [] instead of just []

reduce(flow, acc_fun, reducer_fun)

Because it is used once per window when that starts, so the idea is to have initialise that as late as possible.

2 Likes

ah, a lazy thunk type thing… but shurely, the lib could do this for you and not need any extra cognitive overhead… (?)

Of course it could. It would be simple as:

def reduce(flow, acc_fun, reducer_fun) when is_function(acc_fun, 0) do
  # what is now
end

def reduce(flow, acc, reducer_fun), do: reduce(flow, fn -> acc end, reducer_fun)

However I am not sure if this wouldn’t introduce even more confusion.

2 Likes

at least it’s consistent w Enum - maybe you’re trying to impart different semantics with this though, which is fair enough.