ObservableMutableSet

class ObservableMutableSet<T>(initial: Iterable<T> = emptyList()) : AbstractObservable<Set<T>> , ObservableSet<T>

A mutable observable set implementation, which allows for observing changes to the set and provides notifications when its contents are modified. This class supports addition, removal, and observation of modifications to the set.

Type Parameters

T

The type of elements maintained by this set.

Constructors

Link copied to clipboard
constructor(initial: Iterable<T> = emptyList())

Types

Link copied to clipboard
object Companion

A companion object for the ObservableMutableSet class, providing handy factories.

Properties

Link copied to clipboard
open override val current: Set<T>

The current value: while observed, the latest value published; otherwise, a freshly computed one. Observables holding their own state may read it directly.

Link copied to clipboard

Whether any callback is currently registered.

Link copied to clipboard
override val observerCount: Int

How many callbacks are currently registered.

Link copied to clipboard
open override val size: Observable<Int>

Emits the set size whenever it changes.

Functions

Link copied to clipboard
fun add(item: T)

Adds an item to the observable set. If the item does not already exist in the set, it will be added, and observers of the set will be notified of the change.

Link copied to clipboard
fun clearAndAddAll(items: Set<T>)

Replaces the contents of this set with items. The observers of the set are notified once, if the contents change, and the observers of an item only if the presence of that item changes.

Link copied to clipboard
fun <T, R, O> ObservableSet<T>.combineLatest(transformer: (T) -> Observable<R>, aggregator: (Iterable<R>) -> O): Observable<O>

Combines the content of an ObservableSet into a single observable by applying a mapping function to each element and aggregating the results. This function generates a single observable that emits every time the underlying set of contents is changed, or some of the values (which are in turn observables) emit a changes, triggering the re-evaluation of the aggregation function.

Link copied to clipboard
open override fun containsItem(item: T): Observable<Boolean>

Observes the membership status of a specific item in the set. The returned observable will emit true if the item is a member of the set, and false otherwise. Emits updates whenever the membership status changes.

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
open override fun dispose()

Unregisters every callback registered with this observable.

Link copied to clipboard
fun <T, O> ObservableSet<T>.flatMap(transformer: (T) -> Observable<O>): Observable<Option<O>>

Transforms an ObservableSet of type T into a single Observable of type arrow.core.Option<O> by fusing the individual observables obtained from each item in the set.

Link copied to clipboard

Converts this ObservableSet of observables into a unique observable that emits when either this set would have changed (addition/removal of members) or one of its members emits a value.

Link copied to clipboard
open override fun <S> map(transform: (Set<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
open override fun <O, R> mergeWith(other: Observable<O>, merge: (Set<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
open override fun onChange(notifyOnRegistration: Boolean = true, callback: (Set<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 remove(item: T): Boolean

Removes the specified item from the observable set. If the item exists in the set, it will be removed, and observers of the set will be notified of the change.

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.

Link copied to clipboard

Combines this observable set with another, producing a new observable set that represents the union of both sets.