Re:Pipe Operator (|>) For JavaScript
by jameshart on Friday January 20, 2023 @01:44PM
(#34457723)
The thing I dislike about it most is the constantly-rebound % variable. It means something different in each line. In this case they have elected to keep it as a string throughout the pipe, but this ‘more pipey’ version of the code has it start out as an array then turn into a string halfway through the pipe, which feels dangerous (and is presumably why they didn’t take the example this far):
[ Parent
| on HN ]
Not really... F#-style pipeline syntax would be a bit more explicit about it, assuming you could use % for a variable name...
Object.keys(envars)
|> % => %.map(envar => `${envar}=${envars[envar]}`)
|> % => %.join(' ')
|> % => `$ ${%}`
|> % => chalk.dim(%, 'node', args.join(' '))
|> % => console.log(%);
To be honest, I've pretty much given up the hopes that TC39 would actually resolve pipelines and decorators at this point... I think it's been around a decade now.But then why would you call all those different variables ‘%’?
Reading this version though I also notice something else that the F# style enables that the Hack style doesn’t which is that it supports destructuring. So in F# style, I can more easily make pipe steps that pass on multiple values in a structured object or array, then access them easily down-pipe.
Unfortunately F# pipelines have been rejected a few times by TC39 to advance... I used it for a while via Babel/6to5, but I gave up (like with decorators) after many years of no advancement. I doubt I'll see either any time soon.