Skip to content

Instantly share code, notes, and snippets.

@PatilShreyas
Last active June 23, 2022 12:12
Embed
What would you like to do?
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