LiveScript
LiveScript copied to clipboard
Feature request: Conditional function chaining
I think it would be nice to have conditional function chaining, like the following:
a
.x!
.y! if foo
.z!
...which will be compiled to:
var x$;
x$ = a;
x$ = x$.x();
if (foo) {
x$ = x$.y();
}
x$ = x$.z();
This feature will be useful when we need a conditional middle step on a long function chain.
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.