replace

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

A version of update where the current value is passed via this.

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))
stateFlow.replace { copy(num = 5) }