Enum.reduce refactor with multi

If you need results of previous steps consider Ecto.Multi.run and Ecto.Multi.merge. Those should give you options to do what you need to do.

Edit: Maybe I’ve misunderstood the question a bit. Your reduce function can hold any value, so it can hold a multi struct and the summed amouns:

Enum.reduce(orders, %{order: order, multi: multi}, fn x, %{order: order, multi: multi} -> 
  # To stuff
  %{order: order, multi: multi}
end)