Enum.reduce can do that quite nicely (you need to aggregate the dynamic not overwrite it on each iteration).
Enum.reduce