getOrPut

inline fun <K, V> WeakMap<K, V>.getOrPut(key: K, defaultValue: () -> V): V(source)

Attempts to find the value associated with key.

If no value is associated with key, calls defaultValue, stores its result back into the map as well as returns it.

In a way, this is a sort of simple cache, where a new value is recomputed if the previous one has been deleted.

See also

Equivalent method for regular maps.