https://kotlinlang.org logo
Title
m

marcinmoskala

10/12/2018, 10:36 AM
Is there any explanation?
e

elizarov

10/12/2018, 10:37 AM
var prime: Int
is captured into the lambda to be executed later.
I’ve hit the same ~1.5 years ago when prototyping channels for Kotlin.
(2 years ago, oh my!)
m

marcinmoskala

10/12/2018, 11:22 AM
I guessed that it is because of problems with capturing by lambda. Should I add it as an error or someone else already done it? This is build-in Kotlin problem so I think that issue tracker is the place.
i

ilya.gorbunov

10/14/2018, 3:29 PM
But is this related to suspending functions? I mean the problem is that a mutable variable is captured in
filter
plain lambda.
e

elizarov

10/14/2018, 6:45 PM
Yes. That is exactly the issue I’ve filed. In general, capturing mutable variable into a lambda that is executed “not in place” should be at least a warning. There are cases where it is Ok, though. It would be hard to distinguish them.
m

marcinmoskala

10/14/2018, 9:02 PM
😱 I see it now. @antonkeks This is even better puzzler!
i

ilya.gorbunov

10/15/2018, 4:45 PM
A simplified puzzler on this subject was already presented on the latest KotlinConf: https://github.com/angryziber/kotlin-puzzlers/blob/master/src/functions/closeCapture/CloseCapture.kts

https://youtu.be/Xq9vBZs0j-8?t=1796