I have a list of map something like this
[
%{a: 1, b: 2, c: %{x: 1, y: 2}},
%{a: 3, b: 4, c: %{x: 2, y: 3}},
%{a: 5, b: 6, c: %{x: 3, y: 4}}
]
here I want to take the key “c” and add whatever is there on the map and return something like this
[
%{a: 1, b: 2, c: 3},
%{a: 3, b: 4, c: 5},
%{a: 5, b: 6, c: 7}
]
So what I did is something like this
a |> Enum.map(fn a -> a.c end) |> Enum.map(fn a -> Enum.reduce(a, 0, fn({_k, v}, acc) -> v + acc end) end)
First I’m mapping over the key “c” then I’m trying to map over the “c” values and adding them one by one. Its resulting me this [3, 5, 7]
But I’m not able to figure out the next step to achieve my solution. Also, this seems very expensive. Is there a better way?