Re:Kotlin 1.0.5 is here
by sdegutis on Tuesday November 08, 2016 @08:20PM
(#12905391)
But does .forEach compile to an efficient for-loop in Kotlin?
[ Parent
| on HN ]
Re:Kotlin 1.0.5 is here
by nostrademons on Wednesday November 09, 2016 @02:42AM
(#12907273)
Not completely sure about the internals of the Kotlin compiler, but I believe it does. You can do a non-local return (i.e. return from the top-level function, not the lambda passed to .forEach) from inside them. This would be very difficult if the body were not inlined, because you'd need to store a lexical stack of return addresses and ensure that the closure never escapes the HOF. (I think it actually does perform this escape analysis; I've gotten error messages before when trying to pass a lambda with a non-local return into a functional argument that wasn't one of the basic collection iterators.)