about lambdas
Michael
pr at m1xa.com
Thu Jan 3 13:54:38 PST 2013
Thanks guys)
>
> auto With(alias fun, I)(I o) // maybe add a template constraint
> here
> {
> static if(isAssignable!(I, typeof(null)))
> return o is null ? null : fun(o);
> else
> return fun(o);
> }
>
> foreach(p; persons)
> p.With!(x => x.address);
>
Now if I want add a somewhat task into expression "x =>
x.address", for example "writeln(x.address)", a code should be
rewritten like
>
> foreach(p; persons)
> p.With!(x => {writeln(x.address); return x.address;}());
>
As I understand, right part of expression above - "{ ... }()" is
anonymous function (or delegate, or closure) that immediately
called in lambda expression. Right? Is right behaviour?
More information about the Digitalmars-d
mailing list