Allow any name in single parameter lambda functions

I’m not sure how allowing to use an arbitrary, undeclared name would be familiar to people coming from any other language, because I haven’t seen this feature anywhere else. In Haskell, the lambda parameter name is explicitly declared, so I’m not sure why this would be familiar to Haskell users.

Also, real code is never a single line. If I encountered such a line in an actual program, I’d have to spend a lot of time trying to understand where “name” comes from - is it a variable from an outer scope? inherited from a base class? imported via an alias? When I see “it”, it’s immediately clear what this means.

Not to mention all the confusion that would arise if you meant to refer to a specific function or variable from an outer scope, made a typo, and Kotlin would interpret it as the lambda parameter according to the “a parameter name to your liking” rule that you propose.

3 Likes