Skip to content

Instantly share code, notes, and snippets.

@mattrob33
Last active Mar 15, 2022
Embed
What would you like to do?
fun <T, K> StateFlow<T>.mapState(
scope: CoroutineScope,
transform: (data: T) -> K
): StateFlow<K> {
return mapLatest {
transform(it)
}
.stateIn(scope, SharingStarted.Eagerly, transform(value))
}
fun <T, K> StateFlow<T>.mapState(
scope: CoroutineScope,
initialValue: K,
transform: suspend (data: T) -> K
): StateFlow<K> {
return mapLatest {
transform(it)
}
.stateIn(scope, SharingStarted.Eagerly, initialValue)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment