MutableObservable

A MutableObservable represents an extension of the Observable interface, designed to maintain mutable state and notify its observers when the state changes, which happens by setting current.

Type Parameters

T

The type of the value being observed and modified.

Properties

Link copied to clipboard
abstract override var current: T

The current state or value of the observable.

Link copied to clipboard

Whether any callback is currently registered.

Link copied to clipboard
abstract val observerCount: Int

How many callbacks are currently registered.

Functions

Link copied to clipboard
fun <T, C : Collection<T>, R, O> Observable<C>.combineLatestCollection(transformer: (T) -> Observable<R>, aggregator: (List<R>) -> O): Observable<O>

Maps every element of the current collection to an observable through transformer, and aggregates their current values through aggregator. The result is recomputed whenever the collection changes or any mapped observable emits; observables of elements leaving the collection are unsubscribed.

Link copied to clipboard
fun <T> Observable<Option<T>>.currentOrNull(): T?

Retrieves the current value of the observable if present, or null if no value is available.

Link copied to clipboard
abstract override fun dispose()

Unregisters every callback registered with this observable.

Link copied to clipboard
abstract fun <S> map(transform: (T) -> S): Observable<S>

Transforms the current observable into a new observable by applying the specified transformation function to its emitted values.

Link copied to clipboard
abstract fun <O, R> mergeWith(other: Observable<O>, merge: (T, O) -> R): Observable<R>

Combines the current observable with another observable, producing a new observable that emits values derived by applying the provided merge function to the current values of both observables.

Link copied to clipboard
abstract fun onChange(notifyOnRegistration: Boolean = true, callback: (T) -> Unit): Disposable

Registers callback to be invoked with every new value of this observable, and right away with the current one if notifyOnRegistration.

Link copied to clipboard
fun <T, R> Observable<T>.switchMap(transform: (T) -> Observable<R>): Observable<R>

Maps the current value of this Observable to an inner observable through transform, and mirrors the inner observable of the most recent value only: whenever this observable emits, the previous inner observable is unsubscribed and the new one is followed.