ex_ex v0.1.0 ExEx.Map

Functions that extend the capabilities of the built-in Map module.

Link to this section Summary

Functions

Converts the map’s keys from strings to atoms

Removes keys from the map for which the respective value is nil

Sanitizes structs more thoroughly than Map.from_struct/1

Converts the map’s keys from atoms to strings

Link to this section Functions

Link to this function atomize_keys(map)

Converts the map’s keys from strings to atoms.

If the keys are already atoms, then they are preserved.

Examples

iex> ExEx.Map.atomize_keys(%{"foo": "bar", "baz": 123})
%{foo: "bar", baz: 123}
Link to this function drop_nil_values(map)

Removes keys from the map for which the respective value is nil.

Examples

iex> ExEx.Map.drop_nil_values(%{“foo”: nil, “bar”: 123}) %{bar: 123}

Link to this function from_struct(struct)

Sanitizes structs more thoroughly than Map.from_struct/1.

This is intended for use cases when the struct will be serialized and cannot contain Ecto syntax such as #Ecto.Schema.Metadata<:built, "media_metadata">.

Link to this function stringify_keys(map)

Converts the map’s keys from atoms to strings.

If the keys are already strings, then they are preserved.

Examples

iex> ExEx.Map.stringify_keys(%{foo: "bar", baz: 123})
%{"foo" => "bar", "baz" => 123}