Skip to content

Instantly share code, notes, and snippets.

@PatilShreyas
Last active June 23, 2022 12:12
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 PatilShreyas/950e57a83a77a1655c8665859e0892c6 to your computer and use it in GitHub Desktop.
Save PatilShreyas/950e57a83a77a1655c8665859e0892c6 to your computer and use it in GitHub Desktop.
data class PreferenceState(...)
data class MultiplePreferenceState(val preferences: List<PreferenceState>)
class Preferences {
fun getPreferenceState(key: String): StateFlow<PreferenceState> { ... }
// Note: Return type becomes Flow<> and not StateFlow<>
fun getMultiplePreferenceState(keys: List<String>): Flow<MultiplePreferenceState> {
val prefStateFlows = keys.map { getPreferenceState(it) }.toTypedArray()
return combine(*prefStateFlows) { prefStates: Array<PreferenceState> ->
MultiplePreferenceState(prefStates.toList())
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment