View Source MessageStore.MapExtra (message_store v3.2.0)
An extra functions for Map data type.
Link to this section Summary
Functions
Fetches the value for a specific path
in the given map, erroring out if map doesn't contain path
.
Fetches the value for a specific path
in the given map
.
Link to this section Functions
Fetches the value for a specific path
in the given map, erroring out if map doesn't contain path
.
If map contains path
, the corresponding value is returned.
If map doesn't contain path
, a PathError
exception is raised.
examples
Examples
iex> a = %{a: 1, b: %{c: 2}}
iex> MapExtra.fetch_in!(a, [:a])
1
Fetches the value for a specific path
in the given map
.
If map
contains the given path
then its value is returned in the shape of {:ok, value}
.
If map
doesn't contain path
, :error is returned.
examples
Examples
iex> a = %{a: 1, b: %{c: 2}}
iex> MapExtra.fetch_in(a, [:a])
{:ok, 1}
iex> a = %{a: 1, b: %{c: 2}}
iex> MapExtra.fetch_in(a, [:b, :c])
{:ok, 2}
iex> a = %{a: 1, b: %{c: 2}}
iex> MapExtra.fetch_in(a, [:b, :d])
:error