MapTools
Provides extended utility functions for working with maps, which are not covered in vanilla elixir.
- key_replace: replace one or multiple key names of a map
- get_by_path: retrieve a value from a nested map
-
merge_recursive: merge two maps recursively with two different approaches
- existing keys will be overwritten
- existing keys will be accumulated
-
remove_nil: as the name says, removes all
nilvalue entries from a map
Examples
iex> MapTools.key_replace(%{a: 1, b: 2, c: 3}, %{a: :alpha, b: :beta})
%{alpha: 1, beta: 2, c: 3}iex> MapTools.merge_recursive(%{a: 1, b: %{c: 2}}, %{a: 3, b: %{d: 4}})
%{a: 3, b: %{c: 2, d: 4}}iex> MapTools.remove_nil(%{a: 1, b: nil, c: 3})
%{a: 1, c: 3}Installation
If available in Hex, the package can be installed
by adding map_tools to your list of dependencies in mix.exs:
def deps do
[
{:map_tools, "~> 1.0.0"}
]
endDocumentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/map_tools.