orElseNew

fun <T> Provider<T?>.orElseNew(newValue: () -> T): Provider<T>

Creates a new Provider that returns a fallback value which is re-created through the newValue lambda every time the value of this is set to null.

newValue should be a pure function.

The returned provider will only be stored in a WeakReference in the parent provider (this).


fun <T> MutableProvider<T?>.orElseNew(newValue: () -> T): MutableProvider<T>

Creates a new MutableProvider that returns a fallback value which is re-created through the newValue lambda every time the value of this is set to null. Conversely, if the returned provider's value is set to a value equal to one returned by newValue, the value of this will be set to null.

For mutable data types, it is required that the newValue lambda returns a new instance every time it is called, and that all of those instances are equal to each other.

newValue should be a pure function.

The returned provider will only be stored in a WeakReference in the parent provider (this).