Hello i want to sum up all count and all val keys, to a new map which contains the accumulated values of both keys.
This is what i've done so far:
list = [
%{count: 1, val: 12},
%{count: 3, val: 7},
%{count: 1, val: 5},
%{count: 2, val: 3},
%{count: 2, val: 5},
%{count: 1, val: 3}
]
x = &%{count: &1, val: &1}
sumCount = list |> Enum.reduce(0, &(&1.count + &2)) |> x.() |> IO.inspect()
I get this result:
#ouput:
%{count: 10, val: 10}
But I need this result:
%{count: 10, val: 35}
I just know how to sum up just one key. Should I sum up the keys seperately in two functions? I think thats not performant, considering the list will have even more values/maps or maybe some more keys. Is there a efficient way to sum up all the keys at once?