|
An alternative is to make the pipe operator a simple function application and provide syntax for creating simple pipeline functions. For example: left |> right
Would semantically translate to: right(left)
And you could define a pipeline function like so, where the following: const myPipeline = @[
one(@),
@.two(),
@ + three,
`${@} four`
]
Would translate to: const myPipeline = (value) => {
const _1 = one(value);
const _2 = _1.two();
const _3 = _2 + three;
const _4 = `${_3} four`;
return _4
}
Or: const myPipeline = (value) => `${one(value).two() + three} four`;
And you could define the placeholder value name (which would allow nesting): const myPipeline = @it [
one(@it),
@it.two(),
@it + three,
`${@it} four`,
]
You'd combine the two syntaxes to get immediately-invoked pipeline functions: // Using a modified example from the proposal:
envars |> @ [
Object.keys(@),
@.map(envar => `${envar}=${envars[envar]}`),
@.join(' '),
`$ ${@}`,
chalk.dim(@, 'node', args.join(' ')),
console.log(@),
]
This is better, in my opinion, than building the '%' placeholder syntax into the pipe operator. |