ObservableMutableMap

open class ObservableMutableMap<K, V>(initial: Map<K, V> = emptyMap()) : AbstractObservable<Map<K, V>> , ObservableMap<K, V> (source)

A class that represents an observable, mutable map. Allows observation of map changes, including addition, removal, modifications of key-value pairs, and observation of particular keys for their value changes.

Type Parameters

K

The type of keys maintained by the map.

V

The type of mapped values.

Constructors

Link copied to clipboard
constructor(initial: Map<K, V> = emptyMap())

Types

Link copied to clipboard

Simple utility function for the ObservableMaps.

Properties

Link copied to clipboard
open override val current: Map<K, V>

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
Link copied to clipboard
override val observerCount: Int

Functions

Link copied to clipboard
fun clearAndPutAll(from: Map<K, V>)

Replaces the whole content of this map with from, like doing a clear followed by a putAll, * but without notifying per-key observers for keys that remain present (unless their value 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()
Link copied to clipboard
open operator override fun get(key: K): Observable<Option<V>>
Link copied to clipboard
open override fun <S> map(transform: (Map<K, V>) -> S): Observable<S>
Link copied to clipboard
open override fun <O, R> mergeWith(other: Observable<O>, merge: (Map<K, V>, O) -> R): Observable<R>
Link copied to clipboard
open override fun onChange(notifyOnRegistration: Boolean, callback: (Map<K, V>) -> Unit): Disposable
Link copied to clipboard
fun put(key: K, value: V)

Adds the specified key-value pair to the map. If the key already exists, the value is updated. Observers are notified if the value changes.

Link copied to clipboard
fun remove(key: K): V?

Removes the mapping for the specified key from the map, if it exists. Notifies observers if the key had an associated value before removal.

Link copied to clipboard
operator fun set(key: K, value: V)
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
fun <K, V> ObservableMutableMap<K, V>.updateOrNull(key: K, valueUpdate: V.() -> Unit): V?

Updates the value associated with the given key in the map by applying the provided transformation function. If the key does not exist or its current value is null, no operation is performed, and null is returned.

Link copied to clipboard
fun <K, V> ObservableMutableMap<K, V>.upsertValue(key: K, valueUpdate: (V?) -> V)

Inserts or updates a key-value pair in the ObservableMutableMap. If the key already exists, its value is updated using the provided transformation function. If the key does not exist, a new key-value pair is added with the value derived from the transformation function.