How would I be able to update the “value” of the map that has “key” => “mathematics”? I’m a little confused as to where to begin, especially since the map is so nested. I tried playing around with some Map and Enum functions to do it and
current_tasks =
%{
“resource” => “4234234”
“name” => “To Do”
“definitions” => [
%{
"description" => “school”,
"enabled" => false,
"key" => “mathematics”,
"value" => “calculus”
},
%{
"description" => “school”,
"enabled" => true,
"key" => “english”,
"value" => “intro to poetry”
},
%{
"description" => “school”,
"enabled" => false,
"key" => “foreign language”,
"value" => “spanish”
},
]
}
I tried to do something like this but kept running into some issues with how to move forward/condense it. Note that this code below does throw a functionclauseerror due to the 3rd arg in Map.update!, but that’s not what confuses me.
new_env =
Enum.each(current_env["definitions"], fn map ->
case map["key"] do
"mathematics" -> Map.update!(map, "value", "math")
_ -> IO.inspect "not it"
end
end)
Any thoughts on how I can condense solution above and make it a lot better would be nice, as I am new to learning elixir, this has me stumped and I don’t want to brute force anything when I know there are others who can help me make it more elegant.