Is there any explanation?
# coroutines
m
Is there any explanation?
e
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
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
But is this related to suspending functions? I mean the problem is that a mutable variable is captured in
filter
plain lambda.
e
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
😱 I see it now. @antonkeks This is even better puzzler!
i
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