re: A concatenated iterator example in Kotlin VIEW POST


Hm...what about

fun countAll(nodes: List<Node>): Int
    = nodes.size + nodes.sumBy { countAll(it.children) }


I'm more curious about how you came up with that flamegraph :) Looks useful.


Hi Max A. That recursive version is definitely more efficient than my tail recursive one as its stack size is smaller and doesn't have the overhead of the accumulation. What I wanted to focus on is the iteration across multiple lists and couldn't come up with a better example. Regarding the profiling tool, it's a pretty useful one and it's here:

Enjoy :)

code of conduct - report abuse