Skip to content

Instantly share code, notes, and snippets.

@shahryarjb
Last active April 24, 2017 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shahryarjb/c24e3320ba1c6fb591726a008c93eb47 to your computer and use it in GitHub Desktop.
Save shahryarjb/c24e3320ba1c6fb591726a008c93eb47 to your computer and use it in GitHub Desktop.
# 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