StrawHat v0.6.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

Link to this function

atomize_keys(map, options \\ [only_existing: true])

View Source
atomize_keys(map(), keyword()) :: map()

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 to true will only convert the binary key to an atom if the atom already exists. The default is false.
Link to this function

atomize_values(map, options \\ [only_existing: false])

View Source
atomize_values(map(), keyword()) :: map()

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 to true will only convert the binary value to an atom if the atom already exists. The default is false.
Link to this function

deep_map(map, function)

View Source
deep_map(Map.t(), function :: function()) :: Map.t()

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"}}
Link to this function

deep_map(map, key_function, value_function)

View Source
deep_map(Map.t(), key_function :: function(), value_function :: function()) ::
  Map.t()

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 submaps

  • value_function is a function or function reference that is called for each value of the provided map and any values of any submaps

Link to this function

stringify_keys(map)

View Source
stringify_keys(map()) :: map()

Transforms a map's atom() keys to String.t keys.