Provider

sealed interface Provider<out T> : Supplier<T>

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.

Inheritors

Functions

Link copied to clipboard
abstract fun <R> flatMap(transform: (T) -> Provider<R>): Provider<R>

Creates and returns a new Provider that maps to the value of the Provider returned by transform.

Link copied to clipboard
inline fun <T, R> Provider<Collection<T>>.flatMapCollection(crossinline transform: (T) -> Iterable<R>): Provider<List<R>>

Creates and returns a new Provider that flat-maps the elements of the Collection obtained from this into a list using the transform function.

Link copied to clipboard
inline fun <T, R, C : MutableCollection<in R>> Provider<Collection<T>>.flatMapCollectionTo(crossinline makeCollection: (size: Int) -> C, crossinline transform: (T) -> Iterable<R>): Provider<C>

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.

Link copied to clipboard
abstract fun <R> flatMapMutable(transform: (T) -> MutableProvider<R>): MutableProvider<R>

Creates and returns a new MutableProvider that maps to the value of the MutableProvider returned by transform.

Link copied to clipboard

Creates and returns a new Provider that maps to the provider that is the value of this.

Link copied to clipboard

Creates and returns a new Provider that flattens the List of Lists obtained from this.

Link copied to clipboard
abstract fun get(): @UnsafeVariance T
Link copied to clipboard
@JvmName(name = "arrayGet")
operator fun <T> Provider<Array<T>>.get(index: Int): Provider<T>
@JvmName(name = "arrayGet")
operator fun <T> Provider<Array<T>>.get(index: Provider<Int>): Provider<T>
@JvmName(name = "listGet")
operator fun <T> Provider<List<T>>.get(index: Int): Provider<T>
@JvmName(name = "listGet")
operator fun <T> Provider<List<T>>.get(index: Provider<Int>): Provider<T>

Creates and returns a new Provider that maps to the element at index or throws NoSuchElementException.

Link copied to clipboard
@JvmName(name = "arrayGetCoerced")
fun <T> Provider<Array<T>>.getCoerced(index: Int): Provider<T>
@JvmName(name = "arrayGetCoerced")
fun <T> Provider<Array<T>>.getCoerced(index: Provider<Int>): Provider<T>
@JvmName(name = "listGetCoerced")
fun <T> Provider<List<T>>.getCoerced(index: Int): Provider<T>
@JvmName(name = "listGetCoerced")
fun <T> Provider<List<T>>.getCoerced(index: Provider<Int>): Provider<T>

Creates and returns a new Provider that maps to the element at index or the element at the closest valid index.

Link copied to clipboard
@JvmName(name = "arrayGetMod")
fun <T> Provider<Array<T>>.getMod(index: Int): Provider<T>
@JvmName(name = "arrayGetMod")
fun <T> Provider<Array<T>>.getMod(index: Provider<Int>): Provider<T>

Creates and returns a new Provider that maps to the element at index modulo the array size.

@JvmName(name = "listGetMod")
fun <T> Provider<List<T>>.getMod(index: Int): Provider<T>
@JvmName(name = "listGetMod")
fun <T> Provider<List<T>>.getMod(index: Provider<Int>): Provider<T>

Creates and returns a new Provider that maps to the element at index modulo the list size.

Link copied to clipboard
@JvmName(name = "arrayGetOrNull")
fun <T> Provider<Array<T>>.getOrNull(index: Int): Provider<T?>
@JvmName(name = "arrayGetOrNull")
fun <T> Provider<Array<T>>.getOrNull(index: Provider<Int>): Provider<T?>
@JvmName(name = "listGetOrNull")
fun <T> Provider<List<T>>.getOrNull(index: Int): Provider<T?>
@JvmName(name = "listGetOrNull")
fun <T> Provider<List<T>>.getOrNull(index: Provider<Int>): Provider<T?>

Creates and returns a new Provider that maps to the element at index or null if the index is out of bounds.

Link copied to clipboard
open operator fun <X> getValue(thisRef: X?, property: KProperty<*>?): T
Link copied to clipboard
abstract fun <R> lazyFlatMap(transform: (T) -> Provider<R>): Provider<R>

Creates and returns new Provider that lazily maps to the value of the Provider returned by transform.

Link copied to clipboard
abstract fun <R> lazyFlatMapMutable(transform: (T) -> MutableProvider<R>): MutableProvider<R>

Creates and returns new MutableProvider that lazily maps to the value of the MutableProvider returned by transform.

Link copied to clipboard
abstract fun <R> map(transform: (T) -> R): Provider<R>

Creates and returns a new Provider that maps the value of this using the transform function.

Link copied to clipboard
inline fun <T, R> Provider<Collection<T>>.mapEach(crossinline transform: (T) -> R): Provider<List<R>>

Creates and returns a new Provider that maps each element of the Collection obtained from this using the transform function.

Link copied to clipboard
inline fun <T, R : Any> Provider<Collection<T>>.mapEachNotNull(crossinline transform: (T) -> R?): Provider<List<R>>

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.

Link copied to clipboard
inline fun <T, R : Any, C : MutableCollection<in R>> Provider<Collection<T>>.mapEachNotNullTo(crossinline makeCollection: (size: Int) -> C, crossinline transform: (T) -> R?): Provider<C>

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.

Link copied to clipboard
inline fun <T, R, C : MutableCollection<in R>> Provider<Collection<T>>.mapEachTo(crossinline makeCollection: (size: Int) -> C, crossinline transform: (T) -> R): Provider<C>

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.

Link copied to clipboard
inline fun <T : Any, R> Provider<T?>.mapNonNull(crossinline transform: (T) -> R): Provider<R?>

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.

Link copied to clipboard
fun <K, V> Provider<List<Map<K, V>>>.mergeMaps(): Provider<Map<K, V>>

Creates and returns a new Provider that merges all Maps obtained from this into a single Map.

Link copied to clipboard
fun <K, V, M : MutableMap<in K, in V>> Provider<List<Map<K, V>>>.mergeMapsTo(makeMap: (size: Int) -> M): Provider<M>

Creates and returns a new Provider that merges all Maps obtained from this into a single Map, which is created by the makeMap function.

Link copied to clipboard
abstract fun observe(action: () -> Unit)

Registers a function that will be called whenever the value of this Provider changes.

Link copied to clipboard
abstract fun <R : Any> observeWeak(owner: R, action: (owner: R) -> Unit)

Registers a weak observer that will be called when the value of this Provider changes. The observer will be automatically removed when the owner is garbage collected.

Link copied to clipboard
fun <T> Provider<T?>.orElse(value: T): Provider<T>

Creates and returns a new Provider that returns a fallback value if the value of this is null.

fun <T> Provider<T?>.orElse(provider: Provider<T>): Provider<T>

Creates and returns a new Provider that returns a fallback value obtained through provider if the value of this is null.

@JvmName(name = "orElseNullable")
fun <T> Provider<T?>.orElse(provider: Provider<T>?): Provider<T?>

If provider is null, returns this. If provider is not null, creates and returns a new Provider that returns a fallback value obtained through provider if the value of this is null.

Link copied to clipboard
fun <T> Provider<T?>.orElseLazily(lazyValue: () -> T): Provider<T>

Creates and returns a new Provider that returns a fallback value obtained through provider if the value of this is null.

Link copied to clipboard
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.

Link copied to clipboard
inline fun <T> Provider<T>.require(crossinline condition: (T) -> Boolean, crossinline message: (T) -> String): Provider<T>

Creates and returns a new Provider that throws an IllegalArgumentException with a message generated by message if condition fails.

Link copied to clipboard
inline fun <T : Any> Provider<T?>.requireNotNull(crossinline message: () -> String): Provider<T>

Creates and returns a new Provider that throws an IllegalArgumentException with a message generated by message if the value is null.

fun <T : Any> Provider<T?>.requireNotNull(message: String = "Required value was null."): Provider<T>

Creates and returns a new Provider that throws an IllegalArgumentException with message if the value is null.

Link copied to clipboard
abstract fun <R> strongFlatMap(transform: (T) -> Provider<R>): Provider<R>

Creates and returns a new Provider that maps to the value of the Provider returned by transform.

Link copied to clipboard
inline fun <T, R> Provider<Collection<T>>.strongFlatMapCollection(crossinline transform: (T) -> Iterable<R>): Provider<List<R>>

Creates and returns a new Provider that flat-maps the elements of the Collection obtained from this into a list using the transform function.

Link copied to clipboard
inline fun <T, R, C : MutableCollection<in R>> Provider<Collection<T>>.strongFlatMapCollectionTo(crossinline makeCollection: (size: Int) -> C, crossinline transform: (T) -> Iterable<R>): Provider<C>

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.

Link copied to clipboard
abstract fun <R> strongFlatMapMutable(transform: (T) -> MutableProvider<R>): MutableProvider<R>

Creates and returns a new MutableProvider that maps to the value of the MutableProvider returned by transform.

Link copied to clipboard

Creates and returns a new Provider that maps to the provider that is the value of this.

Link copied to clipboard

Creates and returns a new Provider that flattens the List of Lists obtained from this.

Link copied to clipboard
@JvmName(name = "strongArrayGet")
fun <T> Provider<Array<T>>.strongGet(index: Int): Provider<T>
@JvmName(name = "strongArrayGet")
fun <T> Provider<Array<T>>.strongGet(index: Provider<Int>): Provider<T>
@JvmName(name = "strongListGet")
fun <T> Provider<List<T>>.strongGet(index: Int): Provider<T>
@JvmName(name = "strongListGet")
fun <T> Provider<List<T>>.strongGet(index: Provider<Int>): Provider<T>

Creates and returns a new Provider that maps to the element at index or throws NoSuchElementException.

Link copied to clipboard
@JvmName(name = "strongArrayGetCoerced")
fun <T> Provider<Array<T>>.strongGetCoerced(index: Int): Provider<T>
@JvmName(name = "strongArrayGetCoerced")
fun <T> Provider<Array<T>>.strongGetCoerced(index: Provider<Int>): Provider<T>
@JvmName(name = "strongListGetCoerced")
fun <T> Provider<List<T>>.strongGetCoerced(index: Int): Provider<T>
@JvmName(name = "strongListGetCoerced")
fun <T> Provider<List<T>>.strongGetCoerced(index: Provider<Int>): Provider<T>

Creates and returns a new Provider that maps to the element at index or the element at the closest valid index.

Link copied to clipboard
@JvmName(name = "strongArrayGetMod")
fun <T> Provider<Array<T>>.strongGetMod(index: Int): Provider<T>
@JvmName(name = "strongArrayGetMod")
fun <T> Provider<Array<T>>.strongGetMod(index: Provider<Int>): Provider<T>

Creates and returns a new Provider that maps to the element at index modulo the array size.

@JvmName(name = "strongListGetMod")
fun <T> Provider<List<T>>.strongGetMod(index: Int): Provider<T>
@JvmName(name = "strongListGetMod")
fun <T> Provider<List<T>>.strongGetMod(index: Provider<Int>): Provider<T>

Creates and returns a new Provider that maps to the element at index modulo the list size.

Link copied to clipboard
@JvmName(name = "strongArrayGetOrNull")
fun <T> Provider<Array<T>>.strongGetOrNull(index: Int): Provider<T?>
@JvmName(name = "strongArrayGetOrNull")
fun <T> Provider<Array<T>>.strongGetOrNull(index: Provider<Int>): Provider<T?>
@JvmName(name = "strongListGetOrNull")
fun <T> Provider<List<T>>.strongGetOrNull(index: Int): Provider<T?>
@JvmName(name = "strongListGetOrNull")
fun <T> Provider<List<T>>.strongGetOrNull(index: Provider<Int>): Provider<T?>

Creates and returns a new Provider that maps to the element at index or null if the index is out of bounds.

Link copied to clipboard
abstract fun <R> strongLazyFlatMap(transform: (T) -> Provider<R>): Provider<R>

Creates and returns new Provider that lazily maps to the value of the Provider returned by transform.

Link copied to clipboard
abstract fun <R> strongLazyFlatMapMutable(transform: (T) -> MutableProvider<R>): MutableProvider<R>

Creates and returns new MutableProvider that lazily maps to the value of the MutableProvider returned by transform.

Link copied to clipboard
abstract fun <R> strongMap(transform: (T) -> R): Provider<R>

Creates and returns a new Provider that maps the value of this using the transform function.

Link copied to clipboard
inline fun <T, R> Provider<Collection<T>>.strongMapEach(crossinline transform: (T) -> R): Provider<List<R>>

Creates and returns a new Provider that maps each element of the Collection obtained from this using the transform function.

Link copied to clipboard
inline fun <T, R : Any> Provider<Collection<T>>.strongMapEachNotNull(crossinline transform: (T) -> R?): Provider<List<R>>

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.

Link copied to clipboard
inline fun <T, R : Any, C : MutableCollection<in R>> Provider<Collection<T>>.strongMapEachNotNullTo(crossinline makeCollection: (size: Int) -> C, crossinline transform: (T) -> R?): Provider<C>

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.

Link copied to clipboard
inline fun <T, R, C : MutableCollection<in R>> Provider<Collection<T>>.strongMapEachTo(crossinline makeCollection: (size: Int) -> C, crossinline transform: (T) -> R): Provider<C>

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.

Link copied to clipboard
inline fun <T : Any, R> Provider<T?>.strongMapNonNull(crossinline transform: (T) -> R): Provider<R?>

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.

Link copied to clipboard

Creates and returns a new Provider that merges all Maps obtained from this into a single Map.

Link copied to clipboard
fun <K, V, M : MutableMap<in K, in V>> Provider<List<Map<K, V>>>.strongMergeMapsTo(makeMap: (size: Int) -> M): Provider<M>

Creates and returns a new Provider that merges all Maps obtained from this into a single Map, which is created by the makeMap function.

Link copied to clipboard
fun <T> Provider<T?>.strongOrElse(value: T): Provider<T>

Creates and returns a new Provider that returns a fallback value if the value of this is null.

fun <T> Provider<T?>.strongOrElse(provider: Provider<T>): Provider<T>

Creates and returns a new Provider that returns a fallback value obtained through provider if the value of this is null.

@JvmName(name = "strongOrElseNullable")
fun <T> Provider<T?>.strongOrElse(provider: Provider<T>?): Provider<T?>

If provider is null, returns this. If provider is not null, creates and returns a new Provider that returns a fallback value obtained through provider if the value of this is null.

Link copied to clipboard
fun <T> Provider<T?>.strongOrElseLazily(lazyValue: () -> T): Provider<T>

Creates and returns a new Provider that returns a fallback value obtained through provider if the value of this is null.

Link copied to clipboard
fun <T> Provider<T?>.strongOrElseNew(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.

Link copied to clipboard
inline fun <T> Provider<T>.strongRequire(crossinline condition: (T) -> Boolean, crossinline message: (T) -> String): Provider<T>

Creates and returns a new Provider that throws an IllegalArgumentException with a message generated by message if condition fails.

Link copied to clipboard
inline fun <T : Any> Provider<T?>.strongRequireNotNull(crossinline message: () -> String): Provider<T>

Creates and returns a new Provider that throws an IllegalArgumentException with a message generated by message if the value is null.

fun <T : Any> Provider<T?>.strongRequireNotNull(message: String = "Required value was null."): Provider<T>

Creates and returns a new Provider that throws an IllegalArgumentException with message if the value is null.

Link copied to clipboard
abstract fun subscribe(action: (value: T) -> Unit)

Registers a function that will be called with the new value whenever the value of this Provider changes.

Link copied to clipboard
abstract fun <R : Any> subscribeWeak(owner: R, action: (owner: R, value: T) -> Unit)

Registers a weak subscriber that will be called when the value of this Provider changes. The subscriber will be automatically removed when the owner is garbage collected.

Link copied to clipboard
abstract fun unobserve(action: () -> Unit)

Removes a previously registered observer.

Link copied to clipboard
abstract fun <R : Any> unobserveWeak(owner: R)

Removes all weak observers under the given owner.

abstract fun <R : Any> unobserveWeak(owner: R, action: (R) -> Unit)

Removes a previously registered weak observer.

Link copied to clipboard
abstract fun unsubscribe(action: (T) -> Unit)

Removes a previously registered subscriber.

Link copied to clipboard
abstract fun <R : Any> unsubscribeWeak(owner: R)

Removes all weak subscribers under the given owner.

abstract fun <R : Any> unsubscribeWeak(owner: R, action: (R, T) -> Unit)

Removes a previously registered weak subscriber.