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

Link to this type transform_rules()
transform_rules() ::
  String.t()
  | [String.t()]
  | keyword()
  | map()
  | [{String.t() | atom(), String.t() | atom()}]

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).

  1. As a string with multiple transforms separated by whitespace:

    "title=>name id=>shopify_id"
  2. As a list of strings with one transform per string:

    ["title=>name", "id=>shopify_id"]
  3. 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

Link to this function data <~> transforms

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.

Link to this function rewire(content, rules, options \\ [])
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"}}