Norbi
04/11/2023, 7:13 AMDeepRecursiveFunction
?
fun s() = sequence<Int> {
val f = DeepRecursiveFunction<Int, Unit> {
yield(it) // Compile error: Restricted suspending functions can only invoke member or extension suspending functions on their restricted coroutine scope
if (it < 1000) {
callRecursive(it + 1)
}
}
f(1)
}
ephemient
04/11/2023, 7:26 AM@Suppress("ILLEGAL_RESTRICTED_SUSPENDING_FUNCTION_CALL")
to bypass the compiler error, it won't worksequence outer@{
sequence inner@{
this@outer.yield(Unit)
}
}
it has to be the actual same scope under @RestrictsSuspension
Norbi
04/11/2023, 7:51 AMephemient
04/11/2023, 8:40 PMprivate fun f(n: Int): Sequence<Int> = sequence {
yield(n)
if (n < 1000) {
yieldAll(f(n + 1))
}
}
fun s(): Sequence<Int> = f(1)