lambda syntax with curly braces

sigod via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Aug 10 06:57:48 PDT 2015


 From docs:
> The following part => AssignExpression is rewritten to 
> FunctionLiteralBody:
> { return AssignExpression ; }

So, I wonder what happens when curly braces already in place?

Consider this example:
```
import std.algorithm;
import std.stdio;

void main() {
     [1,2,3,4,5]
         .each!(a => { // remove `=>` and you'll get output
             writeln(a);
         });
}
```

This code compiles and doesn't output anything. Which is very 
counterintuitive for me, because my main experience with lambdas 
was in C#. Where it's perfectly fine to write `identifiers => { 
/* some code */ }`.



More information about the Digitalmars-d-learn mailing list