你好我有这个数组
temp=[%{"a"=>1},%{"b"=>2}]
total=%{"c"=>3,"d"=>4}
我如何添加临时总值,所以我以
结尾 total=%{"a"=>1,"b"=>2,"c"=>3,"d"=>4}
答案 0 :(得分:9)
您可以使用total
作为列表中所有值的Enum.reduce/3和Map.merge/2的初始值。
Enum.reduce(temp, total, fn (map, acc) -> Map.merge(acc, map) end)
返回:
%{"a" => 1, "b" => 2, "c" => 3, "d" => 4}