Kernel.update_in
You're seeing just the function
update_in
, go back to Kernel module for more information.
Specs
Updates a key in a nested structure.
Uses the Access
module to traverse the structures
according to the given keys
, unless the key
is a
function. If the key is a function, it will be invoked
as specified in get_and_update_in/3
.
data
is a nested structure (that is, a map, keyword
list, or struct that implements the Access
behaviour).
The fun
argument receives the value of key
(or nil
if key
is not present) and the result replaces the value
in the structure.
Examples
iex> users = %{"john" => %{age: 27}, "meg" => %{age: 23}}
iex> update_in(users, ["john", :age], &(&1 + 1))
%{"john" => %{age: 28}, "meg" => %{age: 23}}
In case any of the entries in the middle returns nil
,
an error will be raised when trying to access it next.