Situations when we need to refer lambda argument more than once so we can't use _ are very common. It would be great to have similar shorthand syntax in Scala.
It's possible to introduce new syntax in line with tuple value accessors style:
Such a change should be relatively easy to implement and it should be pretty much safe for existing codebase.
In unlikely case of name conflict (someone has defined val _1 = 1 or imported tuple members) compiler may throw an error (preferred) or do shadowing + throw a warning.
As well it's possible to keep full backward compatibility by following simple rule: when you have lambda typed with arrow apply current logic, when lambda is typed without arrow shadow context with lambda named args.
I case people are happy with this idea I may come back with a patch.
Let's consider these statements:
Scala is ultimately expressive, but for case (1) some other languages provide better syntax, usually with a predefined name like
it
:At the same time in scala we may use shorthand syntax with positional arguments:
Situations when we need to refer lambda argument more than once so we can't use
_
are very common. It would be great to have similar shorthand syntax in Scala.It's possible to introduce new syntax in line with tuple value accessors style:
Such a change should be relatively easy to implement and it should be pretty much safe for existing codebase.
In unlikely case of name conflict (someone has defined
val _1 = 1
or imported tuple members) compiler may throw an error (preferred) or do shadowing + throw a warning.As well it's possible to keep full backward compatibility by following simple rule: when you have lambda typed with arrow apply current logic, when lambda is typed without arrow shadow context with lambda named args.
I case people are happy with this idea I may come back with a patch.
See https://github.com/scala/bug/issues/10547