proposal-pipeline-operator icon indicating copy to clipboard operation
proposal-pipeline-operator copied to clipboard

Use @ instead of % as % is already an operator

Open Mike96Angelo opened this issue 2 years ago • 3 comments

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 

Mike96Angelo avatar Jan 22 '23 16:01 Mike96Angelo

How does that interact with decorators?

ljharb avatar Jan 22 '23 16:01 ljharb

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.

Mike96Angelo avatar Jan 22 '23 16:01 Mike96Angelo

@ 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

MeguminSama avatar Jan 22 '23 18:01 MeguminSama

Please close this issue, as it was cleared in the previous comment.

bogdanbiv avatar Aug 05 '24 06:08 bogdanbiv