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)

Reply via email to