replaceAndGet

fun <T> MutableStateFlow<T>.replaceAndGet(block: T.() -> T): T

This is a version of updateAndGet.

This is a simple helper for the common case where you want to copy() a data class:

data class Foo(val num: Int)

val stateFlow = MutableStateFlow(Foo(3))
val newValue = stateFlow.replaceAndGet { copy(num = 5) }

Return

The new value after replacing.