MutableProvider
A MutableProvider is a Provider that allows setting the value.
Usage examples:
1:
val provider0 = mutableProvider("Hello") // MutableProvider with initial value "Hello"
val provider1 = provider0.map { it + ", World!" } // Lazily maps the value of provider0 by appending ", World!" to it
println(provider1.get()) // "Hello, World!" (runs provider1 transform lambda)
provider0.set("Hi") // Sets the value of provider0 to "Hi", invalidating the cached value of provider1 without running the mapping lambda
println(provider1.get()) // "Hi, World!" (runs provider1 transform lambda)
2:
val provider0 = mutableProvider(1) // MutableProvider with initial value 1
val provider1 = provider0.map({ it * 2 }, { it / 2 }) // Lazily maps the value of provider0 by multiplying it with 2 and untransforming it by dividing by 2
println(provider1.get()) // "2" (runs provider1 transform lambda)
provider1.set(4) // Sets the value of provider1 to 4, invalidating the cached value of provider0 without running the mapping lambda
println(provider0.get()) // "2" (runs provider1 untransform lambda)
See also
Functions
Creates and returns a new Provider that flat-maps the elements of the Collection obtained from this into a collection created by makeCollection using the transform function.
Creates and returns a new MutableProvider that maps to the value of the MutableProvider returned by transform.
Creates and returns new MutableProvider that lazily maps to the value of the MutableProvider returned by transform.
Creates and returns a new MutableProvider that maps the value of this bi-directionally using the provided transform and untransform functions.
Creates and returns a new Provider that maps each element of the Collection obtained from this using the transform function and filters out all null results. The results are added to a collection created by makeCollection.
Creates and returns a new Provider that maps each element of the Collection obtained from this using the transform function and adds the results to a collection created by makeCollection.
Creates and returns a new Provider that maps non-null values of this using the transform function. Null values will be passed through without transformation.
Creates and returns a new MutableProvider that maps non-null values of this bi-directionally using the provided transform and untransform functions. Null values will be passed through without transformation.
Creates and returns a new Provider that observes the list of this and propagates changes appropriately.
Creates and returns a new Provider that observes the map of this and propagates changes appropriately.
Creates a new MutableProvider that returns a fallback value if the value of this is null. Conversely, if the returned provider's value is set a value equal to value, the value of this will be set to null.
Creates a new MutableProvider that returns a fallback value obtained through the lazyValue lambda if the value of this is null. Conversely, if the returned provider's value is set to a value equal to the one obtained through lazyValue, the value of this will be set to null.
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.
Creates and returns a new Provider that throws an IllegalArgumentException with a message generated by message if the value is null
.
Creates and returns a new Provider that throws an IllegalArgumentException with message if the value is null
.
Sets the value of this MutableProvider to value.
Creates and returns a new Provider that flat-maps the elements of the Collection obtained from this into a collection created by makeCollection using the transform function.
Creates and returns a new MutableProvider that maps to the value of the MutableProvider returned by transform.
Creates and returns new MutableProvider that lazily maps to the value of the MutableProvider returned by transform.
Creates and returns a new MutableProvider that maps the value of this bi-directionally using the provided transform and untransform functions.
Creates and returns a new Provider that maps each element of the Collection obtained from this using the transform function.
Creates and returns a new Provider that maps each element of the Collection obtained from this using the transform function and filters out all null results. The results are added to a collection created by makeCollection.
Creates and returns a new Provider that maps each element of the Collection obtained from this using the transform function and adds the results to a collection created by makeCollection.
Creates and returns a new Provider that maps non-null values of this using the transform function. Null values will be passed through without transformation.
Creates and returns a new MutableProvider that maps non-null values of this bi-directionally using the provided transform and untransform functions. Null values will be passed through without transformation.
Creates and returns a new Provider that observes the list of this and propagates changes appropriately.
Creates and returns a new Provider that observes the map of this and propagates changes appropriately.
Creates a new MutableProvider that returns a fallback value if the value of this is null. Conversely, if the returned provider's value is set a value equal to value, the value of this will be set to null.
Creates and returns a new Provider that returns a fallback value obtained through provider if the value of this is null.
Creates a new MutableProvider that returns a fallback value obtained through the lazyValue lambda if the value of this is null. Conversely, if the returned provider's value is set to a value equal to the one obtained through lazyValue, the value of this will be set to null.
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.
Creates and returns a new Provider that throws an IllegalArgumentException with a message generated by message if the value is null
.
Creates and returns a new Provider that throws an IllegalArgumentException with message if the value is null
.
Registers a function that will be called with the new value whenever the value of this Provider changes. If multiple threads update the value concurrently, intermediate subscriber invocations may be skipped, but the supplied value will always be the most recent one.
Registers a weak subscriber that will be called when the value of this Provider changes. If multiple threads update the value concurrently, subscriber invocations may be skipped, but the supplied value will always be the most recent one. The subscriber will be automatically removed when the owner is garbage collected.
Removes all weak observers under the given owner.
Removes a previously registered weak observer.
Removes a previously registered subscriber.
Removes all weak subscribers under the given owner.
Removes a previously registered weak subscriber.