computeOnOrElse

inline fun <K, V, R> Map<K, V>.computeOnOrElse(key: K, defaultResult: () -> R, compute: (value: V) -> R): R

Computes the given lambda compute on value corresponding to the provided key or computes the given lambda defaultResult if the key is not present.

Return

result of compute lambda if the key is present or result of defaultResult otherwise.

Parameters

key

key which corresponding value will be used if it's present.

compute

lambda that is computed on the value corresponding to the key.

defaultResult

lambda that is computed if the key is not present.


inline fun <K, V, R> Map<K, V>.computeOnOrElse(key: K, defaultResult: R, compute: (key: K, value: V) -> R): R

Computes the given lambda compute on value corresponding to the provided key or computes the given lambda defaultResult if the key is not present.

Return

result of compute lambda if the key is present or defaultResult otherwise.

Parameters

key

key which corresponding value will be used if it's present.

compute

lambda that is computed on the value corresponding to the key.

defaultResult

default result that is returned in case of the key's absence.