batch Update
Executes a block of modifications on the underlying mutable collection and notifies observers only once after the block has completed.
This is useful for performing multiple additions, removals, or other mutations in a single, atomic operation, preventing multiple emissions from the StateFlow.
Example:
val list = reactiveListOf<String>()
list.batchUpdate {
add("Apple")
add("Banana")
remove("OldFruit")
} // Observers are notified only once here.Content copied to clipboard
Parameters
block
A lambda function with the mutable collection as its receiver, where modifications can be performed.