You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 1, 2020. It is now read-only.
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.
In 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.
In case people are happy with this idea I may come back with a patch.
See scala/bug#10547
The text was updated successfully, but these errors were encountered: