Skip to content

Instantly share code, notes, and snippets.

@PatilShreyas
Last active Jun 23, 2022
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