2 ms·
In Kotlin, does the “it” of a lambda hide a variable named “it” in the outer scope? Also, The compiler of a statically typed language can know that a lambda t
by projektfu 5y ago
In Kotlin, does the “it” of a lambda hide a variable named “it” in the outer scope?
Also,
The compiler of a statically typed language can know that a lambda that takes one argument is passed to a function that calls it with one argument. This would be hard to guarantee in Smalltalk so you’d need a convention that finding an undeclared variable “it” in the block converts the block to a one-argument block.
Finally, I imagine nullary lambdas in Kotlin are less common than no-argument blocks in Smalltalk.
- hota_mazi 5y ago> In Kotlin, does the “it” of a lambda hide a variable named “it” in the outer scope? Yes, which is why it's recommended to name your closure parameter (instead of using `it`) when you nest these.