hawklike
08/06/2025, 7:15 AMmap
, filter
or combine
make hot flow cold, because their internal implementation is basically this:
return flow {
collect { value ->
emit(transform(value))
}
}
So, are the following examples correct?
val stateFlowA = MutableStateFlow("A")
val flowA: Flow<String> = stateFlowA // Is Hot flow
val stateFlowB = MutableStateFlow("B")
val flowB: Flow<String> = stateFlowB.map { it } // Is Cold flow
val flowC: Flow<String> = combine(stateFlowA, stateFlowB) { a, b -> "$a $b" } // Is Cold flow
Thank you đCLOVIS
08/06/2025, 7:57 AMCLOVIS
08/06/2025, 7:57 AM.sharedIn
or .stateIn
streetsofboston
08/06/2025, 11:34 AMCLOVIS
08/06/2025, 12:13 PMprintln
in the .map
, you'll see it isn't executed until someone subscribes, so it's coldstreetsofboston
08/06/2025, 12:19 PMZach Klippenstein (he/him) [MOD]
08/06/2025, 3:25 PM