I JavaScript, has a spread-like operator for optional elements been considered? Something like:

['a', ?'b']
=> ['a', 'b']

['a', ?null]
=> ['a']

I know you can emulate this with a spread + conditional + array literal, but I think this could be way simpler to understand.

@rauschma or any other JavaScript experts

@acjay @rauschma Combined with Promise.all() you could have a nice conditional set of parallel tasks!

@aismallard @rauschma I agree. Something like this?

Promise.all([
? condition1 ? task1() : null,
? condition2 ? task2() : null,
? condition3 ? task3() : null,
])

Follow

@aismallard @rauschma

If so, it raises a couple interesting points:

- Having it be null-based requires the explicit null in the false branch of the conditional. A falsey-based version (e.g. prefix &) would allow for something even more streamlined.

- Although not applicable to Promise.all, I can imagine similar syntax for conditional arguments to variadic functions.

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.