Files
kotlin-fork/compiler/testData/codegen/box/inlineClasses/unboxResultParameterWhenCapturingToCrossinlineLambda.kt
T
Ivan Kylchik c7435ba760 Replace all occurrences of WITH_RUNTIME with WITH_STDLIB
We are going to deprecate `WITH_RUNTIME` directive. The main reason
behind this change is that `WITH_STDLIB` directive better describes
its meaning, specifically it will add kotlin stdlib to test's classpath.
2021-11-17 15:26:38 +03:00

40 lines
939 B
Kotlin
Vendored

// WITH_STDLIB
import kotlin.coroutines.*
interface Flow<out T> {
suspend fun collect(collector: FlowCollector<T>)
}
interface FlowCollector<in T> {
suspend fun emit(value: T)
}
suspend inline fun <T> Flow<T>.collect(crossinline action: suspend (value: T) -> Unit): Unit =
collect(object : FlowCollector<T> {
override suspend fun emit(value: T) = action(value)
})
fun builder(c: suspend () -> Unit) {
c.startCoroutine(Continuation(EmptyCoroutineContext) {
it.getOrThrow()
})
}
fun box(): String {
val flow: Flow<Result<String>> = object : Flow<Result<String>> {
override suspend fun collect(collector: FlowCollector<Result<String>>) {
collector.emit(Result.success("OK"))
}
}
var res = "FAIL"
builder {
flow.collect { result ->
result.onSuccess { text ->
res = text
}
}
}
return res
}