Bunch v0.1.2 Bunch.Map View Source
A bunch of helper functions for manipulating maps.
Link to this section Summary
Functions
Maps keys of map
using function f
Maps values of map
using function f
Works like move/3
, but fails if either old_key
is absent or new_key
is present
in map
Moves value stored at old_key
to new_key
Link to this section Functions
Maps keys of map
using function f
.
Example
iex> Bunch.Map.map_keys(%{1 => :a, 2 => :b}, & &1+1)
%{2 => :a, 3 => :b}
Maps values of map
using function f
.
Example
iex> Bunch.Map.map_values(%{a: 1, b: 2}, & &1+1)
%{a: 2, b: 3}
Works like move/3
, but fails if either old_key
is absent or new_key
is present
in map
.
Example
iex> Bunch.Map.move!(%{a: 1, b: 2}, :a, :c)
%{b: 2, c: 1}
Moves value stored at old_key
to new_key
.
If old_key
is not present in map
, default_value
is stored at new_key
.
If new_key
is present in map
, it’s value is overwritten.
Examples
iex> Bunch.Map.move(%{a: 1, b: 2}, :a, :c, 3)
%{b: 2, c: 1}
iex> Bunch.Map.move(%{a: 1, b: 2}, :a, :b, 3)
%{b: 1}
iex> Bunch.Map.move(%{a: 1, b: 2}, :c, :b, 3)
%{a: 1, b: 3}