Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
# my blog : https://trangell.com/fa/
# public : http://iranonrails.ir
nested = %{
buttercup: %{
actor: %{
first: "Robin",
last: "Wright"
},
role: "princess"
},
westley: %{
actor: %{
first: "Cary",
last: "Ewles" # typo!
},
role: "farm boy"
}
}
IO.inspect get_in(nested, [:buttercup])
# => %{actor: %{first: "Robin", last: "Wright"}, role: "princess"}
IO.inspect get_in(nested, [:buttercup, :actor])
# => %{first: "Robin", last: "Wright"}
IO.inspect get_in(nested, [:buttercup, :actor, :first])
# => "Robin"
IO.inspect put_in(nested, [:westley, :actor, :last], "Elwes")
# => %{buttercup: %{actor: %{first: "Robin", last: "Wright"}, role: "princess"},
# => westley: %{actor: %{first: "Cary", last: "Elwes"}, role: "farm boy"}}
get_in
put_in
update_in
get_and_update_in
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment