Hi All,
I could use some help working with nested structures. I have this map:
%{
tasks: [
%{completed: false, date_added: "3.18.2021", id: 1, name: "walk the dog"},
%{completed: false, date_added: "3.18.2021", id: 2, name: "cook dinner"},
%{completed: false, date_added: "3.18.2021", id: 3, name: "laundry"}
]
}
I want to pass that map into function, along with an integer. If there’s a task with the same ID then the number that gets passed in, I want to update that map so that the “completed” field is changed to true and everything else is left unchanged.
Here’s what I have so far where I can update the map, but I’m not sure how to attach it back to the original list of maps.
def complete_item(list, item_id) do
for items_in_list <- list[:tasks], Map.get(items_in_list, :id) == item_id, do: Map.put(items_in_list, :completed, true)
end