Closed jpike88 closed 5 years ago
Why not ternary operator, which is available as of today?
x ? y : a ? b : z
or for better readability
x ? y : (a ? b : z)
Sure, this is still nested... but chaining does not make sense from my point of view, since the return value would have to be something you can only invoke else-statements on. If-else as fluent API looks - aside from readability - not very logical and expectable to me.
First of all, thanks for the suggestion. I agree with @queequac though. The if
function was from before the ternary operator was supported, and really only still exists for backward compatibility. Chaining if/else calls looks kind of cool, but I don't think the complexity needed to support that is worth it for something that's probably going away eventually.
Damn, I have expressions that chain up to 10 ternary operators already.
I have a bunch of if statements to evaluate like an if...else if... else statement.
Would be great to be able to do something like this, instead of nesting loads of if statements:
if(x, y).else(a, b).else(z)