Skip to content

Instantly share code, notes, and snippets.

@mattrob33
Last active March 15, 2022 01:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattrob33/5bbca09e5be63d05dec9d37e22887ba7 to your computer and use it in GitHub Desktop.
Save mattrob33/5bbca09e5be63d05dec9d37e22887ba7 to your computer and use it in GitHub Desktop.
abstract class BaseViewModel: ViewModel() {
fun <T, K> StateFlow<T>.mapState(
transform: (data: T) -> K
): StateFlow<K> {
return mapState(
scope = viewModelScope,
transform = transform
)
}
fun <T, K> StateFlow<T>.mapState(
initialValue: K,
transform: suspend (data: T) -> K
): StateFlow<K> {
return mapState(
scope = viewModelScope,
initialValue = initialValue,
transform = transform
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment