indifferent v0.5.0 Indifferent.Access
Summary
Functions
Fetch an indifferent key
Get the value under an indifferent key
Invoked in order to access the value stored under key
in the given term term
,
defaulting to default
if not present
Get and update a value under an indifferent key
Pop the value under an indifferent key
Functions
Fetch an indifferent key.
Examples
iex> Indifferent.Access.fetch(%{"a" => 1}, :a)
{:ok, 1}
iex> Indifferent.Access.fetch(%{"a" => 1}, :b)
:error
Get the value under an indifferent key
Examples
iex> Indifferent.Access.get(%{"a" => 1}, :a)
1
iex> Indifferent.Access.get(%{a: 1}, "a")
1
iex> Indifferent.Access.get(%{a: 1}, "a")
1
Invoked in order to access the value stored under key
in the given term term
,
defaulting to default
if not present.
This function should return the value under the key key
in term
if there’s
such key, otherwise default
.
For most data structures, this can be implemented using fetch/2
internally;
for example:
def get(structure, key, default) do
case fetch(structure, key) do
{:ok, value} -> value
:error -> default
end
end
See the Map.get/3
and Keyword.get/3
implementations for more examples.
Callback implementation for Access.get/3
.