Comparison to multiple values syntactic sugar

In ECMA I would use (variable === val1 || variable === val2 ...) to attempt to compare a variable to multiple values. I think it would be a lot more elegant to run

variable === | val1, val 2 |

and have it automatically expand.

I think this can be used as:

[val1, val2, ...].includes(variable)
1 Like

Still wouldn’t be able to do operations like <, >, etc. with include.

I think

[val1, val2, ... ].some(v => v > variable)

is a good alternative.

The proposed | val1, val2 | semantics implicitly relies on the context of | |. For example, how should they be evaluated?

f(| a, b |, c);
g(| a, b |, | c, d |);

It is also unclear whether | a, b | can be nested

val > | a, | b, c | |

or whether it can be the RHS of an assignment

var x = | 1, 2 |;
1 Like