toggle

fun MutableStateFlow<Boolean>.toggle(): Boolean

Flips the boolean value and returns the new value.

The update is atomic with respect to concurrent updates; the flip may be recomputed under contention but is applied exactly once.