map_rewire v0.2.0 MapRewire
MapRewire provides functions and operators to bulk rekey maps.
iex> %{"id" => "234923409", "title" => "asdf"} <~> ~w(title=>name id=>shopify_id)
{:ok, %{"id" => "234923409", "title" => "asdf"}, %{"shopify_id" => "234923409", "name" => "asdf"}}
Link to this section Summary
Types
The shape of MapRewire transformation rules. These rules may be specified in
one of several ways. Transforms specified as strings are in the form
left=>right (note that there are no spaces around the arrow)
Functions
Remaps the map content and replaces the key if it matches with an item in
list. This makes MapRewire.rewire/2 act as an operator
Remaps the map content and replaces the key if it matches with an item in
list
Link to this section Types
The shape of MapRewire transformation rules. These rules may be specified in
one of several ways. Transforms specified as strings are in the form
left=>right (note that there are no spaces around the arrow).
As a string with multiple transforms separated by whitespace:
"title=>name id=>shopify_id"As a list of strings with one transform per string:
["title=>name", "id=>shopify_id"]As any enumerable that iterates as tuples:
[title: :name, id: :shopify_id] [{"title", "name"}, {"id", "shopify_id"}] %{"title" => :name, "id" => :shopify_id}
Link to this section Functions
Remaps the map content and replaces the key if it matches with an item in
list. This makes MapRewire.rewire/2 act as an operator.
rewire(map(), transform_rules(), keyword()) :: {:ok, old :: map(), new :: map()}
Remaps the map content and replaces the key if it matches with an item in
list.
iex> MapRewire.rewrite(%{"id"=>"234923409", "title"=>"asdf"}, ~w(title=>name id=>shopify_id))
{:ok, %{"id" => "234923409", "title" => "asdf"}, %{"shopify_id" => "234923409", "name" => "asdf"}}