Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Short lambda function declaration #491

Closed
Claus1 opened this issue Aug 4, 2019 · 3 comments
Closed

Short lambda function declaration #491

Claus1 opened this issue Aug 4, 2019 · 3 comments

Comments

@Claus1
Copy link

Claus1 commented Aug 4, 2019

It is possible to make a short lambda _ for functions with 1 argument (like Scala, ..)
Now
var result = list.map((x) => convert(x));
Possible
var result = list.map(convert(_));
Most containers methods work with such lambdas and it would dramatically reduce syntax noise (garbage) in complex code.

@Claus1 Claus1 changed the title Short function declaration Short lambda function declaration Aug 4, 2019
@srawlins
Copy link
Member

srawlins commented Aug 4, 2019

Did you try

var result = list.map(convert);

?

@Claus1
Copy link
Author

Claus1 commented Aug 5, 2019

It works but short lambda _ has a direct reference to the object and such code is possible
var result = list.map(convert(_.field));
where the field is a field of argument.
or
var result = list.flter(_ > 0 && _ < 100);

@eernstg
Copy link
Member

eernstg commented Aug 5, 2019

Note that language issue #8 contains a summary of several ideas and discussions in this area.

@Claus1 Claus1 closed this as completed Aug 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants