ovo_utils v0.1.0 OvoUtils.MapUtils View Source

Utility functions for common operations on maps.

Link to this section Summary

Functions

Converts string keys in maps to atoms

Converts all string keys in a map to camel case

Converts all string keys in a map to to snake case

Converts all string keys in a map to atom keys

Applies a transformation function on map keys

Link to this section Functions

Link to this function

atomise_string_keys(map) View Source

Converts string keys in maps to atoms.

Recursively traverses nested maps and lists.

Note

Expects every key of all nested maps to be strings.

Examples

iex> %{"a" => "foo", "b" => "bar"} |> MapUtils.atomise_string_keys()
%{a: "foo", b: "bar"}
Link to this function

camelize_string_keys(map) View Source

Converts all string keys in a map to camel case.

Recursively traverses nested maps and lists.

Examples

iex> %{"foo_bar" => "a", "bar_foo" => "b"} |> MapUtils.camelize_string_keys()
%{"fooBar" => "a", "barFoo" => "b"}
Link to this function

snakify_string_keys(map) View Source

Converts all string keys in a map to to snake case.

Recursively traverses nested maps and lists.

Examples

iex> %{"fooBar" => "a", "barFoo" => "b"} |> MapUtils.snakify_string_keys()
%{"foo_bar" => "a", "bar_foo" => "b"}
Link to this function

stringify_atom_keys(map) View Source

Converts all string keys in a map to atom keys.

Recursively traverses nested maps and lists.

Examples

iex> %{a: "foo", b: "bar"} |> MapUtils.stringify_atom_keys()
%{"a" => "foo", "b" => "bar"}
Link to this function

transform_keys(map, transformation) View Source

Applies a transformation function on map keys.

Recursively traverses nested maps and lists.

Examples

iex> %{"a" => "foo", "b" => "bar"} |> MapUtils.transform_keys(fn key -> key <> "_new" end)
%{"a_new" => "foo", "b_new" => "bar"}