Last active
April 24, 2017 12:39
-
-
Save shahryarjb/c24e3320ba1c6fb591726a008c93eb47 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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