Hello i have this array
temp=[%{"a"=>1},%{"b"=>2}]
total=%{"c"=>3,"d"=>4}
how do i add temp to total so i end with
total=%{"a"=>1,"b"=>2,"c"=>3,"d"=>4}
You can use total
as the initial value for Enum.reduce/3 and Map.merge/2 all of the values in your list.
Enum.reduce(temp, total, fn (map, acc) -> Map.merge(acc, map) end)
Returns:
%{"a" => 1, "b" => 2, "c" => 3, "d" => 4}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With