get_in and Access
Access.key
Get a value by key. Useful for structs that don't implement the Access behaviour.
defstruct [:name, :breed]
end
[dog: %Dog]
|> get_in([:dog, Access.key(:name)])
# "Gwen"
Access.all
Access all elements in a list.
defstruct [:name, :breed]
end
[
dogs: [
%Dog,
%Dog
]
]
|> get_in([:dogs, Access.all(), Access.key(:name)])
# ["Gwen", "Clover"]
Access.at
Get an element from the list at an index.
[
numbers: [
[1, 2, 3, 4],
[5, 6, 7, 8]
]
]
|> get_in([:numbers, Access.all(), Access.at(1)])
# [2, 6]