map_rewire v0.1.1 MapRewire

Syntactic sugar to simply bulk rekey maps. MapRewire takes two arguments, data (map) and transformation (list of transformations / string of transformations separated by whitespace).

  1. Main Syntax: left<~>right (content<~>transformation). Left value is the map that holds the data and keys you would like to update, Right value is an Elixir List that contains a string for each of the keys that you would like to update.
  2. Transformation Syntax: left=>right (from=>to). Left is the original key, right is the new key.
  3. Return Syntax: [left, right] ([ original, rekeyed ]). left is the original map. right is the new, rekeyed, map.

Link to this section Summary

Functions

Macro syntax sugar to enable calling rewire in an elixir like way

Maps over the Enum content and replaces the key if it matches with an item in list

Link to this section Functions

Link to this macro data <~> transforms (macro)

Macro syntax sugar to enable calling rewire in an elixir like way.

Input params:

  1. data is passed as content
  2. transforms is passed as list or binary.

Output:

[left, right] ([ original, rekeyed ]). left is the original map. right is the new, rekeyed, map.

Link to this function rewire(content, list)

Maps over the Enum content and replaces the key if it matches with an item in list.

Example 1:

MapRewire.rewrite(%{"id"=>"234923409", "title"=>"asdf"}, ~w(title=>name id=>shopify_id))

Example 2:

MapRewire.rewrite(%{"id"=>"234923409"}, ['id=>shopify_id'])