Rant after trying Rust a bit
Adam D. Ruppe via Digitalmars-d
digitalmars-d at puremagic.com
Thu Jul 23 14:00:33 PDT 2015
On Thursday, 23 July 2015 at 20:48:34 UTC, Ziad Hatahet wrote:
> The ternary operator becomes much harder to read the moment you
> have more than the simple if/else case.
I think it is actually kinda pretty:
auto x = (condition_1) ? 1
: (condition_2) ? 2
: (condition_3) ? 3
: 4;
> val x = {
> val ys = foo()
> ys.map(...).filter(...).exists(...)
> }
auto x = {
auto ys = foo();
return ys.map(...).filter(...).exists(...);
}();
Before you get too worried about the (), I'd point out that this
is a very common pattern in Javascript (for like everything...)
and while everybody hates JS, most every uses it too; this patten
is good enough for usefulness.
(or for that you could prolly just write foo().map()... directly
but i get your point)
More information about the Digitalmars-d
mailing list