Created
April 24, 2017 13:04
-
-
Save shahryarjb/5a2359d92d85e3ae016cbae0480ec5c3 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 | |
cast = [ | |
%{ | |
character: "Buttercup", | |
actor: %{ | |
first: "Robin", | |
last: "Wright" | |
}, | |
role: "princess" | |
}, | |
%{ | |
character: "Westley", | |
actor: %{ | |
first: "Cary", | |
last: "Elwes" | |
}, | |
role: "farm boy" | |
} | |
] | |
IO.inspect get_in(cast, [Access.all(), :character]) | |
#=> ["Buttercup", "Westley"] | |
IO.inspect get_in(cast, [Access.at(1), :role]) | |
#=> "farm boy" | |
IO.inspect get_and_update_in(cast, [Access.all(), :actor, :last], | |
fn (val) -> {val, String.upcase(val)} end) | |
#=> {["Wright", "Ewes"], | |
# [%{actor: %{first: "Robin", last: "WRIGHT"}, character: "Buttercup", | |
# role: "princess"}, | |
# %{actor: %{first: "Cary", last: "EWES"}, character: "Westley", | |
# role: "farm boy"}]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment