Flows, Channels and Reactive Streams
Harry
· 23 Sep 2026
· 3 views
Log in to track your progress and mark lessons complete.
Sponsored
Cold Flows
fun orders() = flow {
for (id in 1..5) {
delay(200)
emit("ORD-$id")
}
}
runBlocking {
orders().filter { it.endsWith("2") }
.map { it.lowercase() }
.collect { println(it) }
}Flow Operators You Will Use
- map/filter - transform like collections, lazily.
- debounce - search-as-you-type without storms.
- combine/zip - merge cart plus pricing streams.
- catch/retry - errors as flow stages, not crashes.
Hot Flows: StateFlow and SharedFlow
val cartCount = MutableStateFlow(0) // UI state holder
cartCount.value = 3 // collectors update instantlyStateFlow powers modern Android UI state; SharedFlow powers one-shot events like snackbars.
Channels (One-to-One Pipes)
Use channels for worker pipelines and backpressure hand-offs; prefer Flow for observable data. Most app code never needs raw channels.
- Flow equals coroutines plus reactive streams.
- StateFlow for state, SharedFlow for events.
- Operators compose; collectors trigger execution.