Is this: Object.keys(envars) .map(envar => `${envar}=${envars[envar]}`) .join(' ') |> `$ ${%}` |> chalk.dim(%, 'node', args.join(' ')) |> console.log(%); Really better than: console.log(chalk.dim( `$ ${Object.keys(envars) .map(envar => `${envar}=${envars[envar]}`) .join(' ') }`, 'node', args.join(' ') )); That's the real-world example they have (I reformatted the second one slightly, because it looks better to me). N…
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 %.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);
And if you want to use your pipe as an expression or return it from the function , instead of ; might be better: let D;
return D= take(D) ,D= bake(D) ,D= serve(D);
Surprisingly semicolon auto-insertion doesn't interfere with this: let D;
return D= take(D)
,D= bake(D)
,D= serve(D);