Open ceremcem opened 3 years ago
For comparison, currently possible patterns:
Cascade with conditional:
a
..x!
(if foo then ..y! else ..)
..z!
var x$, y$, z$;
x$ = a;
y$ = x$.x();
z$ = foo ? y$.y() : y$;
z$.z();
Pipe-chaining accessor functions:
a
|> (.x!)
|> -> if foo then it.y! else it
|> (.z!)
(function(it){
return it.z();
})(
function(it){
if (foo) {
return it.y();
} else {
return it;
}
}(
function(it){
return it.x();
}(
a)));
The suggested syntax would be clearer.
I think it would be nice to have conditional function chaining, like the following:
...which will be compiled to:
This feature will be useful when we need a conditional middle step on a long function chain.