https://kotlinlang.org logo
Title
l

Landry Norris

08/02/2022, 6:30 PM
yield
is a suspend function, so it can only be called within a suspend function or other coroutine context.
inner
is not marked as suspend, so it can’t call suspend functions.
m

Michael de Kaste

08/02/2022, 6:32 PM
So you can properly use buildMap, buildList, buildSet with inner functions, but you straight up can't with sequence?
l

Landry Norris

08/02/2022, 6:35 PM
None of those are suspend functions. You should be able to call them here. You can’t call
yield
, however, since it is a suspend function. You can use launch or runBlocking if you have to use it, depending on what you want to do.
Try marking inner as suspend
suspend fun inner() {
    yield(3)
}
e

ephemient

08/02/2022, 6:36 PM
that won't work due to `@RestrictsSuspension`; this will:
suspend fun SequenceScope<Int>.inner()
m

Michael de Kaste

08/02/2022, 6:37 PM
Seems a bit convoluted to achieve the same as what I usually would do with the other "builders" but that works @ephemient, thanks