面试题答案
一键面试import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.runBlocking
fun createFlow(): Flow<Int> = flow {
(1..10).forEach {
emit(it)
}
}
fun main() = runBlocking {
createFlow()
.filter { it % 2 == 0 }
.map { it * it }
.reduce { acc, value -> acc + value }
.let { println(it) }
}