mapState

fun <T, R> StateFlow<T>.mapState(transform: (T) -> R): StateFlow<R>

Returns a read-only StateFlow view whose value is transform applied to this flow's value.

The view is not backed by a coroutine: reading StateFlow.value applies transform to the source's current value, and collection maps the source with equality conflation. transform must be fast and pure; it runs on every value read and every source emission.