View Source Ext.LenientMap (ext v1.3.0)
Ext.LenientMap
provides helper functions related to Map
by treating
string and atom keys as equivalent.
Summary
Functions
Delete a specific key from the map
.
Returns the value for a specific key from the map
.
Returns the value for a specific key and delete it from the map
.
Functions
Delete a specific key from the map
.
If the map
has both the atom and string keys, both of them will be deleted.
Examples
iex> Ext.LenientMap.delete(%{a: 1, b: 2}, :a)
%{b: 2}
iex> Ext.LenientMap.delete(%{"a" => 1, "b" => 2}, :a)
%{"b" => 2}
iex> Ext.LenientMap.delete(%{"a" => 1, :a => 2, "b" => 3}, :a)
%{"b" => 3}
iex> Ext.LenientMap.delete(%{a: 1, b: 2}, :c)
%{a: 1, b: 2}
Returns the value for a specific key from the map
.
If a value can be found using both the atom and string keys, the value given by the atom key is returned.
Examples
iex> Ext.LenientMap.get(%{a: 1, b: 2}, :a)
1
iex> Ext.LenientMap.get(%{"a" => 1, "b" => 2}, :a)
1
iex> Ext.LenientMap.get(%{"a" => 1, :a => 2, "b" => 3}, :a)
2
iex> Ext.LenientMap.get(%{a: 1, b: 2}, :c)
nil
iex> Ext.LenientMap.get(%{a: 1, b: 2}, :c, :not_found)
:not_found
Returns the value for a specific key and delete it from the map
.
If a value can be found using both the atom and string keys, the value given by the atom key is returned, but both entries are dropped from the map.
Examples
iex> Ext.LenientMap.get_and_delete(%{a: 1, b: 2}, :a)
{1, %{b: 2}}
iex> Ext.LenientMap.get_and_delete(%{"a" => 1, "b" => 2}, :a)
{1, %{"b" => 2}}
iex> Ext.LenientMap.get_and_delete(%{"a" => 1, :a => 2, "b" => 3}, :a)
{2, %{"b" => 3}}
iex> Ext.LenientMap.get_and_delete(%{a: 1, b: 2}, :c)
{nil, %{a: 1, b: 2}}
iex> Ext.LenientMap.get_and_delete(%{a: 1, b: 2}, :c, :not_found)
{:not_found, %{a: 1, b: 2}}