proposal-pipeline-operator
proposal-pipeline-operator copied to clipboard
Use @ instead of % as % is already an operator
Since % is the modulus operator I think it we be better to use a different symbol, perhaps @
let even = 8 |> @ % 2 === 0; // 8 % 2 === 0
In some other programming languages that have the pipe operator they support piping is both directions:
let a = 3
|> square(@)
// let a = square(3)
let b = square(@)
<| 2
// let b = square(2)
There is some confusion if both are use in the same expression:
let a = 1 |> add(@, @) <| 2
// let a = add(1, 2) or is it add(2, 1)
to get over this confusion we can add the corresponding < or > to the @
let a = 1 |> add(@>, <@) <| 2
// let a = add(1, 2) no more confusion
let a = 1 |> add(<@, @>) <| 2
// let a = add(2, 1) no more confusion
How does that interact with decorators?
Since decorators require two arguments @<expression that results in a decorator function> <thing to decorate> we can determine that an @ that receives no arguments that follows a |> can be treated as an injection point instead of a decorator.
if we allow directional piping and use directional injection points (@>, <@) there is no conflict with decorators at all.
@ has been excluded as a topic reference, noted here:
https://github.com/tc39/proposal-pipeline-operator/issues/232#issuecomment-1218520231
https://github.com/tc39/proposal-pipeline-operator/issues/91#issuecomment-1084946624
Please close this issue, as it was cleared in the previous comment.