I have a list of maps as below and I would like to modify the map based on its index within the list. Hopefully it makes sense. Sample maps below.
Btw Coming from other programming languages where a collection is mutable I find it a bit hard to perform with similar operations in Elixir. Once I “get it” it is then easy… until next problem
my_list = %{
data: %{
items: [
%{k: "aaa", s: %{}},
%{k: "bbb", s: %{}},
%{k: "ccc", s: %{}},
]
}
}
Now I’ve got other collection that I iterate through that contains “index” of specific map that I want to update:
coll = [
%{"1" => "child of bbb"}
]
So it’s saying “find a 2 map in items” and modify its “s” map to include the “child”, so it then becomes:
my_list = %{
data: %{
items: [
%{k: "aaa", s: %{}},
%{k: "bbb", s: %{k: "child of bbb"}},
%{k: "ccc", s: %{}},
]
}
}
Can someone help please?
I looked at various functions like Kernel.update_in/3
or Kernel.put_in/2
but I’m not sure how I get to find the given map (and update it) by the index.