News for hackers. Stuff that matters.
Re:Kotlin for Data Analysis by yen223 on Thursday August 29, 2024 @01:03AM (#41387517)
The mechanism in Kotlin that allows them to limit yield() to a sequence{} block , without introducing a new keyword, is pretty dang cool.
Re:Kotlin for Data Analysis by rbehrends on Thursday August 29, 2024 @04:51AM (#41388711)
What happens under the hood is that a `sequence {}` call creates an instance of `SequenceScope`, which has `yield()` and `yieldAll()` methods. When executing the block, `this` will reference that particular instance and `yield()` is essentially `this.yield()` and will call the method on the scope instance.

The actual functionality is then provided by the coroutine system, though a lot of the heavy lifting is done by the optimizer to eliminate all or most of the runtime overhead.