Mutable Reactive Map
A mutable map that also exposes a StateFlow via asStateFlow, allowing for reactive observation of its contents.
It delegates MutableMap functionality to an internal map and emits an immutable Map snapshot to its collectors whenever the map is modified. This enables reactive programming patterns where observers can automatically respond to changes in the map's contents.
Example:
val userMap = reactiveMapOf("name" to "Alice", "age" to "25")
// Observe all changes to the map
userMap.asStateFlow().collect { map ->
println("User data updated: $map")
} // Immediately emits: "User data updated: {name=Alice, age=25}"
// Observe specific key changes
userMap.valueAsFlow("name").collect { name ->
println("Name changed to: $name")
} // Immediately emits: "Name changed to: Alice"
// Modify the map - triggers reactive updates
userMap["city"] = "NYC" // Triggers both flows above
userMap.remove("age") // Triggers map flow, name flow unaffectedParameters
The type of keys in the map.
The type of values in the map.
Functions
Returns the collection's content as a StateFlow of an immutable collection IC type.
Executes a block of modifications on the underlying mutable collection and notifies observers only once after the block has completed.
Executes a suspending block of modifications on the underlying mutable collection and notifies observers only once after the block has completed.
Returns a new MutableReactiveMap filled with all elements of this collection.
Creates a Flow that emits the value associated with the specified key whenever this map changes.