getOrPut

abstract suspend fun <T> getOrPut(key: DependencyKey, defaultValue: suspend () -> T): T(source)

Retrieves the value associated with the specified key if it exists. If the key does not already have an associated value, the result of invoking the defaultValue function will be stored and returned as the value for the given key.

Report a problem

Return

the value associated with the key, either retrieved from the existing association or newly computed and stored.

Parameters

key

the dependency key used to look up or store the value.

defaultValue

a lambda function that provides a default value to store and return if the key is not found.