StrawHat v0.5.0 StrawHat.Utils.Map View Source
Functions for transforming maps, keys and values.
Link to this section Summary
Functions
Transforms a map
's String.t
keys to atom()
keys
Transforms a map
's String.t
values to atom()
values
Recursively traverse a map and invoke a function for each key/ value pair that transforms the map
Recursively traverse a map and invoke a function for each key and a function for each value that transform the map
Transforms a map
's atom()
keys to String.t
keys
Link to this section Functions
atomize_keys(map, options \\ [only_existing: true]) View Source
Transforms a map
's String.t
keys to atom()
keys.
options
is a keyword list of options. The available option is::only_existing
which is set totrue
will only convert the binary key to an atom if the atom already exists. The default isfalse
.
atomize_values(map, options \\ [only_existing: false]) View Source
Transforms a map
's String.t
values to atom()
values.
options
is a keyword list of options. The available option is::only_existing
which is set totrue
will only convert the binary value to an atom if the atom already exists. The default isfalse
.
deep_map(map, function) View Source
Recursively traverse a map and invoke a function for each key/ value pair that transforms the map.
Examples
iex> map = %{a: "a", b: %{c: "c"}}
iex> StrawHat.Utils.Map.deep_map map, fn {k, v} ->
...> {k, String.upcase(v)}
...> end
%{a: "A", b: %{c: "C"}}
deep_map(map, key_function, value_function) View Source
Recursively traverse a map and invoke a function for each key and a function for each value that transform the map.
key_function
is a function or function reference that is called for each key of the provided map and any keys of any submapsvalue_function
is a function or function reference that is called for each value of the provided map and any values of any submaps
stringify_keys(map) View Source
Transforms a map
's atom()
keys to String.t
keys.