Transformers v0.1.0 Transformers View Source

Transforms nested maps and list of maps

Link to this section Summary

Functions

Returns map (or list of maps) with keys deeply-transformed with the provided function

Returns map (or list of maps) with values deeply-transformed with the provided function

Link to this section Functions

Link to this function transform_keys(map, func) View Source

Returns map (or list of maps) with keys deeply-transformed with the provided function.

Examples

Camelize keys:

iex> data = %{"key_one" => 1, "key_two" => 2}
iex> Transformers.transform_keys(data, &Macro.camelize/1)
%{"KeyOne" => 1, "KeyTwo" => 2}

Lists and nested maps are traversed and transformed as well:

iex> data = %{"the_list" => [%{"map_one" => 1}, %{"map_two" => 2}]}
iex> Transformers.transform_keys(data, &Macro.camelize/1)
%{"TheList" => [%{"MapOne" => 1}, %{"MapTwo" => 2}]}
Link to this function transform_values(map, func) View Source

Returns map (or list of maps) with values deeply-transformed with the provided function.

Examples

Upcase values:

iex> data = %{"one" => "One", "two" => "Two"}
iex> Transformers.transform_values(data, &String.upcase/1)
%{"one" => "ONE", "two" => "TWO"}

Lists and nested maps are traversed and transformed as well:

iex> data = %{"list" => [%{"one" => "One"}, %{"two" => "Two"}]}
iex> Transformers.transform_values(data, &String.upcase/1)
%{"list" => [%{"one" => "ONE"}, %{"two" => "TWO"}]}