Updating deeply nested elixir maps
In some cases it is necessary to update a deeply nested attribute in a map. I went searching for a way to do this and came across several approaches, the one that worked for me was this, a combination of Kernel.put_in and Access.key, here I’m using it to update a socket struct nested assigns map.
put_in(socket, Enum.map([:assigns, :beacon_live_data, :form_submitted], &Access.key(&1, %{})), true) The put_in function is pretty easy to understand, it Puts a value in a nested structure via the given path.
read more