movements = [%{iso: "usd", sum_total: 10, special: true}, %{iso: "usd", sum_total: 5, special: false}, %{iso: "euro", sum_total: 15, special: false}]
Enum.reduce movements, total, fn(mov, total_acc) ->
if mov[:special] do
# some code goes here
# this function returns a map
some_function(total_acc, mov, some_var)
else
# some code goes here
# this function returns a map to
some_other_function(total_acc, mov, some_other_var)
end
end
My problem is that my reduce always return the total map with the empty values (total = %{“usd” => 0, “euro” => 0}), nothing is updated.
Your problem might be with the functions some_function/3 and some_other_function/3 and not Enum.reduce/3 itself. My guess would be that they don’t return the updated total.