Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Well, you need something to indicate the beginning of a lambda. So you can think of "[]" as serving that role, instead of "lambda" in Python or "\" in Haskell.


You can use C# fat arrow syntax, it even allows removing the braces for single expression lambdas which is the most common from anyway.


> removing the braces

If I have learned anything over the years, it's that removing the braces anywhere is the introduction of a bug during a rewrite waiting to happen.


It really works without any issues in C# from my experience.

Statemends like :

    list.Where(e => e.Property == ExpectedValue).Select(e => e.Property)
is much cleaner than something like :

    list.Where([](auto e) { return e.Property == ExpectedValue; }).Select([](auto e) { return e.Property; });
Braces and capture declaration adds 0 value here and it's ~80% of the use cases I see for lambdas.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: