Fox.MapExt
Utility functions for common extension to maps
Summary
key_map(map, f) | |
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) |
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}