View Source Flamel.Map (flamel v0.1.0)
A bunch of helper functions for Maps
Summary
Functions
Converts the top level keys in a map from string to atoms
Get a value from a map whether the key is a string or atom
Safely get a value out of Map/Struct
Converts the top level keys in a map from atoms to strings
Functions
Converts the top level keys in a map from string to atoms
Examples
iex> Flamel.Map.atomize_keys(%{"first_name" => "Thomas", "dob" => "07/01/1981"})
%{first_name: "Thomas", dob: "07/01/1981"}
iex> Flamel.Map.atomize_keys(%{"person" => %{"first_name" => "Thomas", "dob" => "07/01/1981"}})
%{person: %{first_name: "Thomas", dob: "07/01/1981"}}
iex> Flamel.Map.atomize_keys(%{first_name: "Thomas", dob: "07/01/1981"})
%{first_name: "Thomas", dob: "07/01/1981"}
Get a value from a map whether the key is a string or atom
Examples
iex> Flamel.Map.indifferent_get(%{test: "value"}, "test") "value"
iex> Flamel.Map.indifferent_get(%{test: "value"}, :test) "value"
iex> Flamel.Map.indifferent_get(%{"test" => "value"}, :test) "value"
iex> Flamel.Map.indifferent_get(%{"test" => "value"}, "test") "value"
iex> Flamel.Map.indifferent_get(%{"test" => "value"}, "does-not-exist", "default") "default"
Safely get a value out of Map/Struct
Converts the top level keys in a map from atoms to strings
Examples
iex> Flamel.Map.stringify_keys(%{a: 1, b: 2})
%{"a" => 1, "b" => 2}
iex> Flamel.Map.stringify_keys(%{a: 1, b: 2, c: %{d: 3, e: 4}})
%{"a" => 1, "b" => 2, "c" => %{"d" => 3, "e" => 4}}
iex> Flamel.Map.stringify_keys(%{"a" => 1, "b" => 2})
%{"a" => 1, "b" => 2}