loadingStateOf

suspend fun <T> loadingStateOf(block: suspend () -> T): LoadingState<T>

Runs block and wraps its outcome as LoadingState.Loaded or LoadingState.Failed (classified through LoadingError.from). Coroutine cancellation is rethrown, never reported as a failure.

updateState { copy(items = LoadingState.Loading) }
val items = loadingStateOf { repository.fetchItems() }
updateState { copy(items = items) }