Fox.MapExt
Utility functions for common extension to maps
Summary
present_put(map, key, value) | Puts the given value to map if and only if the value
isn’t one of the following: |
present_update(map, key, update) | Runs the update function if and only if the map already has the given key |
value_map(map, f) | Maps over just the value of your map while keeping all the keys the same |
Functions
Specs:
Puts the given value to map if and only if the value
isn’t one of the following: nil
, ""
, %{}
Examples
%{dog: 1} |> present_put(:cat, %{})
%{dog: 1}
%{dog: 1} |> present_put(:cat, 1)
%{dog: 1, cat: 1}
Specs:
Runs the update function if and only if the map already has the given key.
Examples
%{dog: 1, cat: 2} |> present_update(:dog, &(&1 + 1))
# %{dog: 2, cat: 2}
%{dog: 1, cat: 3} |> present_update(:serenade, &(&1 * &1))
# %{dog: 1, cat: 3}
Specs:
Maps over just the value of your map while keeping all the keys the same
Examples
%{dog: 1, cat: 2} |> value_map(&(&1 + 2))
# %{dog: 3, cat: 4}