Bunch v0.3.0 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
Moves value stored at old_key
to new_key
Works like move/3
, but fails if either old_key
is absent or new_key
is present
in map
Link to this section Functions
Link to this function
map_keys(map, f) View Source
Maps keys of map
using function f
.
Example
iex> Bunch.Map.map_keys(%{1 => :a, 2 => :b}, & &1+1)
%{2 => :a, 3 => :b}
Link to this function
map_values(map, f) View Source
Maps values of map
using function f
.
Example
iex> Bunch.Map.map_values(%{a: 1, b: 2}, & &1+1)
%{a: 2, b: 3}
Link to this function
move(map, old_key, new_key, default_value) View Source
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}
Link to this function
move!(map, old_key, new_key) View Source
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}