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

at(key)
fetch(on, key)

Fetch an indifferent key.

Examples

iex> Indifferent.Access.fetch(%{"a" => 1}, :a)
{:ok, 1}

iex> Indifferent.Access.fetch(%{"a" => 1}, :b)
:error
get(on, key)

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
get(data, key, default)

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.

get_and_update(on, key, updater)

Get and update a value under an indifferent key

Examples

iex> Indifferent.Access.get_and_update(%{a: 1}, "a", fn x -> {x * 2, x * 4} end)
{2, %{a: 4}}
pop(on, key)

Pop the value under an indifferent key

Examples

iex> Indifferent.Access.pop(%{a: 1}, "a")
{1, %{}}