Is it possible to somehow create a sequence from inside of a
DeepRecursiveFunction
?
Copy code
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)
}
e
ephemient
04/11/2023, 7:26 AM
no, it's there for a reason. SequenceScope and DeepRecursiveScope handle suspension differently and don't mix
btw you don't need DeepRecursiveFunction here anyway. the sequence builder is transformed by the compiler into a state machine just other suspend functions
Copy code
private fun f(n: Int): Sequence<Int> = sequence {
yield(n)
if (n < 1000) {
yieldAll(f(n + 1))
}
}
fun s(): Sequence<Int> = f(1)