News for hackers. Stuff that matters.
Re:Pipe Operator (|>) For JavaScript by scotty79 on Friday January 20, 2023 @01:05PM (#34457106)
I'll bite:

    let $= Object.keys(envars)
    .map(envar => `${envar}=${envars[envar]}`)
    .join(' ')
    $= `$ ${$}`
    $= chalk.dim($, 'node', args.join(' '))
    $= console.log($);
This is possible in current JS syntax.

You can also cram it into one line with semicolon:

    let $= Object.keys(envars)
    .map(envar => `${envar}=${envars[envar]}`)
    .join(' ') ;$= `$ ${$}` ;$= chalk.dim($, 'node', args.join(' ')) ;$= console.log($);
So it's basically Hack syntax for pipes with just ;$= instead of |> and $ instead of %. And you need to 'mark' the beginning of the pipeline with `let $=`

Additional 'benefit' is that until you leave the scope you can access output of the last pipe through $.

You can always use ;$= for consistency and pre-experess you intent to use the piping in the current scope by doing `let $;` ahead of time:

    let $;

    ;$= Object.keys(envars)
    .map(envar => `${envar}=${envars[envar]}`)
    .join(' ')
    ;$= `$ ${$}`
    ;$= chalk.dim($, 'node', args.join(' '))
    ;$= console.log($);
Full disclosure, I hate all of the above but I love Hack syntax with |> and %.

Also any valid JS name is good:

    let _= Object.keys(envars)
    .map(envar => `${envar}=${envars[envar]}`)
    .join(' ')
    _= `$ ${_}`
    _= chalk.dim(_, 'node', args.join(' '))
    _= console.log(_);
so you have a lot of flexibility in your pipes. :-D

To better confer the direction of the pipe you might even use the letter that is oriented to the right:

    let D;
    ;D= Object.keys(envars)
    .map(envar => `${envar}=${envars[envar]}`)
    .join(' ')
    ;D= `$ ${D}`
    ;D= chalk.dim(D, 'node', args.join(' '))
    ;D= console.log(D);
Re:Pipe Operator (|>) For JavaScript by notpushkin on Friday January 20, 2023 @03:13PM (#34459141)
;D
Re:Pipe Operator (|>) For JavaScript by scotty79 on Friday January 20, 2023 @03:38PM (#34459582)
Perfectly legal syntax. ;D
Re:Pipe Operator (|>) For JavaScript by moogly on Friday January 20, 2023 @04:03PM (#34459912)
This is the code equivalent of that "illegal LEGO techniques" thing to me.