<@U3ZLHBTLG> Coroutines don’t immediately allow re...
# coroutines
e
@louiscad Coroutines don’t immediately allow recursive methods without StackOverflow, but you can use Kotlin coroutines machinery to transform any recursive algorithm that uses call stack into one that uses heap to maintain its stack, thus supporting much deeper recursion without running out of resources. I wrote a prototype at one point. See this gist: https://gist.github.com/elizarov/d715c9564288c2635bb55687e7341717
👍 2
l
That's what I thought, since a
suspend fun
can suspend... or return, in which case it adds up to the stack
e
As an example (included in this gist), we can write a recursive function in direct style that computes a sum over a tree without running into StackOverflow.
l
without running into StackOverflow.
Unless you got a question 😅
🙂 1
stackoverflow 3
🧌 1