Three Unlikely Successful Features of D
bearophile
bearophileHUGS at lycos.com
Thu Mar 22 21:07:52 PDT 2012
Matt Peterson:
> It isn't mainline yet, but UFCS from git has made working with
> std.algorithm much nicer. Instead of something like
> array(filter!"a > 0"(map!((a){return somefunc(a);})(data)))
> where you can quickly drown in parenthesis and the order seems
> somewhat backwards, you can use data.map!((a){return
> somefunc(a);}).filter!"a > 0".array
I suggest to compile all your D2 code with -wi (or -w) and
-property.
And one bug of UFCS will be probably fixed by Hara
(http://d.puremagic.com/issues/show_bug.cgi?id=7722 ), so map and
filter will require an ending () (I have closed my
http://d.puremagic.com/issues/show_bug.cgi?id=7723 ).
So your last line is better written like this:
data.map!somefunc().filter!q{a > 0}().array()
This is indeed a significant improvement in D syntax for
functional-style code, because this reduced nesting a lot, making
such code significantly more readable.
Bye,
bearophile
More information about the Digitalmars-d
mailing list