AtomicMap

class AtomicMap<K, V> : Map<K, V>

A Map that allows for thread safe, atomic mutation. Returned collections such as entries and iterator reference a snapshot of when they were accessed, and are not mutated when the map is.

Although mutable, this class intentionally does not implement MutableMap. Mutation must use designated mutator functions (mutate, snapshotAndMutate, mutateAndSnapshot).

Constructors

Link copied to clipboard
constructor(initial: PersistentMap<K, V>)

Construct an AtomicMap with initial mappings.

Properties

Link copied to clipboard
open override val entries: ImmutableSet<Map.Entry<K, V>>
Link copied to clipboard
open override val keys: ImmutableSet<K>
Link copied to clipboard
open override val size: Int
Link copied to clipboard
val snapshot: ImmutableMap<K, V>

Returns the current value of this map as an immutable snapshot.

Link copied to clipboard
val snapshots: StateFlow<ImmutableMap<K, V>>

Returns this map as a StateFlow. Each mutation will cause a new emission on this flow.

Link copied to clipboard
open override val values: ImmutableCollection<V>

Functions

Link copied to clipboard
open override fun containsKey(key: K): Boolean
Link copied to clipboard
open override fun containsValue(value: V): Boolean
Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open operator override fun get(key: K): V?
Link copied to clipboard
inline fun <K, V> AtomicMap<K, V>.getOrPut(key: K, defaultValue: () -> V): V

Atomic version of MutableMap.getOrPut. defaultValue can be evaluated multiple times if a concurrent edit occurs.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
open override fun isEmpty(): Boolean
Link copied to clipboard
inline fun mutate(mutator: MutableMap<K, V>.() -> Unit)

Mutates this map atomically. mutator can be evaluated multiple times if a concurrent edit occurs.

Link copied to clipboard
inline fun mutateAndSnapshot(mutator: MutableMap<K, V>.() -> Unit): ImmutableMap<K, V>

Mutates this map atomically and returns the new snapshot. mutator can be evaluated multiple times if a concurrent edit occurs.

Link copied to clipboard
inline fun snapshotAndMutate(mutator: MutableMap<K, V>.() -> Unit): ImmutableMap<K, V>

Mutates this map atomically and returns the previous snapshot. mutator can be evaluated multiple times if a concurrent edit occurs.

Link copied to clipboard
fun <K, V> Map<K, V>.toJsObject(transform: (Map.Entry<K, V>) -> Pair<String, dynamic>): dynamic

Convert a map to a Plain Old JavaScript Object by transforming the keys to strings and the values to any of the JavaScript types. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#javascript_types

Link copied to clipboard
open override fun toString(): String