updateKey method

ImmortalMap<K, V> updateKey(
  1. K key,
  2. K update(
    1. V value
    )
)

Returns a copy of this map where the key of the entry with key is replaced by applying update to its value if already present.

Overwrites a previous value in the copied map if an entry for the resulting key was already present.

Returns the map unchanged if key is not present.

Implementation

ImmortalMap<K, V> updateKey(K key, K Function(V value) update) => lookup(key)
    .map((value) => remove(key).add(update(value), value))
    .orElse(this);