MutableReactiveSet

A mutable set that also exposes a StateFlow via asStateFlow, allowing for reactive observation of its contents.

It delegates MutableSet functionality to an internal set and emits an immutable Set snapshot to its collectors whenever the set is modified. This enables reactive programming patterns where observers can automatically respond to changes in the set's contents while maintaining set semantics (no duplicate elements).

Example:

val activeUsers = reactiveSetOf("alice", "bob")

// Observe all changes to the set
activeUsers.asStateFlow().collect { users ->
println("Active users: $users")
} // Immediately emits: "Active users: [alice, bob]"

// Standard set operations
activeUsers.add("charlie") // Triggers emission: [alice, bob, charlie]
activeUsers.add("alice") // No emission (duplicate element)
activeUsers.remove("bob") // Triggers emission: [alice, charlie]

// Batch operations for multiple changes
activeUsers.batchNotify {
addAll(setOf("david", "eve"))
remove("alice")
} // Single emission: [charlie, david, eve]

// Set-specific operations
val otherUsers = setOf("frank", "charlie")
activeUsers.retainAll(otherUsers) // Triggers emission: [charlie]
println(activeUsers.contains("david")) // false

Parameters

E

The type of elements contained in the set.

Properties

Link copied to clipboard
abstract override val size: Int

Functions

Link copied to clipboard
abstract override fun add(element: E): Boolean
Link copied to clipboard
abstract override fun addAll(elements: Collection<E>): Boolean
Link copied to clipboard
abstract fun asStateFlow(): StateFlow<Set<E>>

Returns the collection's content as a StateFlow of an immutable collection IC type.

Link copied to clipboard
abstract fun batchNotify(block: MutableSet<E>.() -> Unit)

Executes a block of modifications on the underlying mutable collection and notifies observers only once after the block has completed.

Link copied to clipboard
abstract suspend fun batchNotifyAsync(block: suspend MutableSet<E>.() -> Unit)

Executes a suspending block of modifications on the underlying mutable collection and notifies observers only once after the block has completed.

Link copied to clipboard
abstract override fun clear()
Link copied to clipboard
abstract operator override fun contains(element: E): Boolean
Link copied to clipboard
abstract override fun containsAll(elements: Collection<E>): Boolean
Link copied to clipboard
abstract override fun isEmpty(): Boolean
Link copied to clipboard
abstract operator override fun iterator(): MutableIterator<E>
Link copied to clipboard
abstract override fun remove(element: E): Boolean
Link copied to clipboard
abstract override fun removeAll(elements: Collection<E>): Boolean
Link copied to clipboard
abstract override fun retainAll(elements: Collection<E>): Boolean
Link copied to clipboard

Returns a new MutableReactiveList filled with all elements of this collection.

Link copied to clipboard

Returns a new MutableReactiveSet filled with all elements of this collection.