combined flow will join two flows together. But, f...
# getting-started
m
combined flow will join two flows together. But, from what I could test, it only emits a message when both flows had emitted a value. How can I make sure to start receiving even when one of the flows had not emitted yet? This is my test, btw:
Copy code
fun main() = runBlocking {
  	val numbersFlow = flowOf(1,2,3).onEach { delay(1000) }
    val lettersFlow = flowOf("A", "B","C").onEach { delay(2000) }

    numbersFlow.combine(lettersFlow) { number, letter ->
     "$number - $letter"
    }.collect {
        println(it)
    }
}

// 1 - A
// 2 - A
// 3 - A
// 3 - B
// 3 - C
e
Copy code
numbersFlow.onStart { emit(null) }.combine(
    lettersFlow.onStart { emit(null) }
) { number, letter ->
    ...
}
1
m
What would you want passed to the lambda for the flow that has not emitted anything yet?
👀 1
m
just a null value. That was perfect @ephemient!
Copy code
null - null
1 - null
2 - null
2 - A
3 - A
3 - B
3 - C