putOrChange

inline fun <K, V> MutableMap<K, V>.putOrChange(key: K, valueOnPut: () -> V, transformOnChange: (currentValue: V) -> V): V

Depending on presence of value corresponding to the given key either puts new value calculated by valueOnPut or changes the present value with transformOnChange.

Return

result value corresponding to the key.

Parameters

key

key to check.

valueOnPut

lazily calculated value to put in case of absence of the key.

transformOnChange

transform to apply to current value corresponding to the key in case of its presence. Uses current value as a parameter.


inline fun <K, V> MutableMap<K, V>.putOrChange(key: K, valueOnPut: V, transformOnChange: (key: K, currentValue: V, newValue: V) -> V): V

Depending on presence of value corresponding to the given key either puts new value valueOnPut or changes the present value with transformOnChange.

Return

result value corresponding to the key.

Parameters

key

key to check.

valueOnPut

value to put in case of absence of the key.

transformOnChange

transform to apply to current value corresponding to the key in case of its presence. Uses the key, current value, and new value as parameters.