28 lines
588 B
Elixir
28 lines
588 B
Elixir
|
cast = [
|
||
|
%{
|
||
|
character: "Buttercup",
|
||
|
actor: %{
|
||
|
first: "Robin",
|
||
|
last: "Wright"
|
||
|
},
|
||
|
role: "princess"
|
||
|
},
|
||
|
%{
|
||
|
character: "Westley",
|
||
|
actor: %{
|
||
|
first: "Cary",
|
||
|
last: "Elwes"
|
||
|
},
|
||
|
role: "farm boy"
|
||
|
}
|
||
|
]
|
||
|
|
||
|
# returns character fields from all structs
|
||
|
IO.inspect get_in(cast, [Access.all(), :character])
|
||
|
|
||
|
# role of element with index 1
|
||
|
IO.inspect get_in(cast, [Access.at(1), :role])
|
||
|
|
||
|
# return new dict, but with uppercased actor.last
|
||
|
IO.inspect get_and_update_in(cast, [Access.all(), :actor, :last], fn (val) -> {val, String.upcase(val)} end)
|