// WITH_COROUTINES // NO_CHECK_LAMBDA_INLINING // WITH_RUNTIME // FILE: inlined.kt interface Flow { suspend fun collect(collector: FlowCollector) } interface FlowCollector { suspend fun emit(value: T) } inline suspend fun Flow.collect(crossinline action: suspend (value: T) -> Unit): Unit = collect(object : FlowCollector { override suspend fun emit(value: T) = action(value) }) inline fun Flow.transform( crossinline transform: suspend FlowCollector.(value: T) -> Unit ): Flow = flow { collect { value -> return@collect transform(value) } } inline fun Flow.map(crossinline transform: suspend (value: T) -> R): Flow = transform { value -> return@transform emit(transform(value)) } public fun flow(block: suspend FlowCollector.() -> Unit): Flow = SafeFlow(block) private class SafeFlow(private val block: suspend FlowCollector.() -> Unit) : Flow { override suspend fun collect(collector: FlowCollector) { collector.block() } } // FILE: inlineSite.kt import kotlin.coroutines.* import helpers.* fun Flow.abc() = map { line -> try { line } catch (e: Exception) { e.message!! } } fun builder(c: suspend () -> Unit) { c.startCoroutine(EmptyContinuation) } fun box(): String { var res = "FAIL" builder { flow { emit("OK") }.abc().collect { res = it } } return res }