Provider
A Provider is a thread-safe, lazily-evaluated, reactive data source that holds a single value of type T.
Using map, flatMap, and various extension functions, atomic data transformations can be modelled.
Additionally, it is also possible to subscribe to and observe providers. Note that subscribing disables the lazy evaluation of the provider, as the value will need to be calculated immediately when an update happens in order to propagate it to the subscribers.
It is important that all data transformation functions are pure, meaning that they are side effect free and do not access any mutable external state, in order to maintain the integrity of lazy evaluation. It is especially important that they do not resolve any other provider's value, as doing so may risk deadlocks. To properly operate on the values of multiple providers, combine them first via combinedProvider.
Usage example:
val provider0 = provider { "Hello" } // Provider with lazy value of "Hello"
val provider1 = provider0.map { it + ", World!" } // Lazily maps the value of provider by appending ", World!" to it
println(provider1.get()) // "Hello, World!" (runs lambdas above)
println(provider1.get()) // "Hello, World!" (cached value)
See also
Inheritors
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 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 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
.
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 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 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.