computeIfPresent

fun computeIfPresent(key: Key, remappingFunction: (Key, Value) -> Value?): Value?(source)

If the value for the specified key is present, attempts to compute a new mapping given the key and its current mapped value. This entire method invocation is performed atomically.

The remappingFunction is invoked exactly once if the key is present. If it returns null, the existing mapping is removed; otherwise, the map is updated to the new value.

Return

the new value associated with key, or null if none

Parameters

key

the key for which a value may be present

remappingFunction

the function used to compute a new value, if a mapping for key exists