Useful (useful v0.3.0)

A Library of Useful functions for building Elixir Apps.

Link to this section Summary

Functions

atomize_map_keys/1 converts a Map with different keys to a map with just atom keys. Works recursively for nested maps. Inspired by stackoverflow.com/questions/31990134

flatten_map/1 flattens a Map of any depth/nesting for easier processing. Deeply nested maps are denoted by "" (double underscore) e.g: %{name: Alex, detail: %{age: 17}} becomes `%{name: Alex, detailage: 17}` this makes it easy to see what the data structure was before flattening. Map keys are converted to Atom for simpler access and consistency. Inspired by: https://stackoverflow.com/questions/39401947/flatten-nested-map

stringy_map/1 converts a Map of any depth/nesting into a string. Deeply nested maps are denoted by "__" (double underscore). See flatten_map/1 for more details.

Link to this section Functions

Link to this function

atomize_map_keys(map)

atomize_map_keys/1 converts a Map with different keys to a map with just atom keys. Works recursively for nested maps. Inspired by stackoverflow.com/questions/31990134

Examples

iex> Useful.atomize_map_keys(%{"name" => "alex", id: 1})
%{id: 1, name: "alex"}

iex> Useful.atomize_map_keys(%{"name" => "alex", data: %{ "age" => 17}})
%{name: "alex", data: %{age: 17}}
Link to this function

flatten_map(map)

flatten_map/1 flattens a Map of any depth/nesting for easier processing. Deeply nested maps are denoted by "" (double underscore) e.g: %{name: Alex, detail: %{age: 17}} becomes `%{name: Alex, detailage: 17}` this makes it easy to see what the data structure was before flattening. Map keys are converted to Atom for simpler access and consistency. Inspired by: https://stackoverflow.com/questions/39401947/flatten-nested-map

Examples

iex> map = %{name: "alex", data: %{age: 17, height: 185}}
iex> Useful.flatten_map(map)
%{data__age: 17, data__height: 185, name: "alex"}
Link to this function

stringify_map(map)

stringy_map/1 converts a Map of any depth/nesting into a string. Deeply nested maps are denoted by "__" (double underscore). See flatten_map/1 for more details.

Examples

iex> map = %{name: "alex", data: %{age: 17, height: 185}}
iex> Useful.stringify_map(map)
"data__age: 17, data__height: 185, name: alex"
Link to this function

stringify_tuple(arg)