Created
April 14, 2025 13:07
-
-
Save karanahuja-android/67793edcac8160c93138b03738ef7972 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.* | |
import kotlinx.coroutines.flow.* | |
fun main() = runBlocking { | |
val userFlow = MutableStateFlow("User 1") | |
val settingsFlow = MutableStateFlow("Dark Mode") | |
// Combine two flows | |
userFlow.combine(settingsFlow) { user, settings -> | |
"User: $user, Settings: $settings" | |
}.collect { combinedData -> | |
println(combinedData) | |
} | |
// Update flows to see combination in action | |
delay(100) | |
userFlow.value = "User 2" | |
delay(100) | |
settingsFlow.value = "Light Mode" | |
delay(100) | |
userFlow.value = "User 3" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment