3 ms·
I'll bite: let _= Object.keys(envars).map(envar => `${envar}=${envars[envar]}`).join(' ') _= `$ ${_}` _= chalk.dim(_, 'node', args.join(' ')) _
by scotty79 4y ago
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 %.
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);
- notpushkin 4y ago;D
- scotty79 4y ago;D is perfectly legal syntax too. Btw I think I'll name this operator duck ,D= Maybe the pipe syntax extension will be introduced if we threaten to make duck operator a thing?
- moogly 4y agoThis is the code equivalent of that "illegal LEGO techniques" thing to me.