morphix v0.0.1 Morphix

Summary

Functions

Takes a map as an argument and returns the same map, with all string keys (including keys in nested maps) converted to atom keys

Takes a map as an argument and returns the same map with string keys converted to atom keys. Does not examine nested maps

Takes a map and returns a flattened version of that map. If the map has nested maps (or the maps nested maps have nested maps, etc.) morphiflat moves all nested key/value pairs to the top level, discarding the original keys

Functions

atomorphiform(map)

Takes a map as an argument and returns the same map, with all string keys (including keys in nested maps) converted to atom keys.

Examples:

iex> Morphix.atomorphiform(%{:this => %{map: %{"has" => "a", :nested => "string", :for =>  %{a: :key}}}, "the" =>  %{"other" => %{map: :does}}, as: "well"})
{:ok,%{this: %{map: %{has: "a", nested: "string", for: %{a: :key}}}, the: %{other: %{map: :does}}, as: "well"} }
atomorphify(map)

Takes a map as an argument and returns the same map with string keys converted to atom keys. Does not examine nested maps.

Examples

iex> Morphix.atomorphify(%{"this" => "map", "has" => %{"string" => "keys"}})
{:ok, %{this: "map", has: %{"string" => "keys"}}}

iex> Morphix.atomorphify(%{1 => "2", "1" => 2, "one" => :two})
{:ok, %{1 => "2", "1": 2, one: :two}}

iex> Morphix.atomorphify(%{"a" => "2", :a => 2, 'a'  => :two})
{:ok, %{:a => 2, 'a' => :two }}
morphiflat(map)

Takes a map and returns a flattened version of that map. If the map has nested maps (or the maps nested maps have nested maps, etc.) morphiflat moves all nested key/value pairs to the top level, discarding the original keys.

Examples:

iex> Morphix.morphiflat %{this: %{nested: :map, inner: %{twonested: :map, is: "now flat"}}}
{:ok, %{nested: :map, twonested: :map, is: "now flat"}}

In the example, the key :this is discarded, along with the key inner, because they both point to map values.