ex_commons v0.1.3 ExCommons.Map

Helpers for Maps and Structs.

Link to this section Summary

Functions

Atomize keys deeply in a map.

Examples

Takes all keys from first maps and mirrors them with corresponding values in second map

Strips selected keys from maps, that can be in a list, or and embedded within. Will not strip keys from NaiveDateTime, and DateTime, unless given directly

Link to this section Functions

Link to this function atomize_keys(map)

Atomize keys deeply in a map.

Examples

iex> ExCommons.Map.atomize_keys(%{atom: %{“string” => true}}) %{atom: %{string: true}}

iex> ExCommons.Map.atomize_keys(%{“string” => %{“string” => true}}) %{string: %{string: true}}

Link to this function mirror(base, mirrored)

Takes all keys from first maps and mirrors them with corresponding values in second map.

Warning: Strips the __struct__ key.

Examples

iex> ExCommons.Map.mirror(%{}, %{nested: %{value: false}}) %{}

iex> ExCommons.Map.mirror(%{nested: %{value: true}}, %{nested: %{value: false}}) %{nested: %{value: false}}

iex> ExCommons.Map.mirror(%{nested: %{value: true}}, %{nested: %{value: false, other: nil}}) %{nested: %{value: false}}

iex> ExCommons.Map.mirror(%{nested: %{value: true}}, %{other: “test”, nested: %{value: false, other: nil}}) %{nested: %{value: false}}

Link to this function strip_keys(list, keys)
strip_keys(Map.t() | [Map.t()], [Atom.t()]) :: Map.t() | [Map.t()]

Strips selected keys from maps, that can be in a list, or and embedded within. Will not strip keys from NaiveDateTime, and DateTime, unless given directly.

Examples

iex> ExCommons.Map.strip_keys(%{}, []) %{}

iex> ExCommons.Map.strip_keys([%{key: :val}], [:key]) [%{}]

iex> ExCommons.Map.strip_keys(%{embed: %{layered: %{key: :val}}}, [:key]) %{embed: %{layered: %{}}}