Skip to content
RED SAG Skills
hardStudy question · answer published in Android interview questions, so no pointskotlin-flowkotlin-coroutines

Collecting a cold Flow twice

What does this Kotlin program print, one value per line?

val numbers = flow {
  println("start")
  emit(1)
  emit(2)
}

fun main() = runBlocking {
  numbers.collect { println(it) }
  numbers.take(1).collect { println(it) }
}
Choose one answer

Discussion 0

Join free to post in the discussion.

Related questions