Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use @ instead of % as % is already an operator #289

Open
Mike96Angelo opened this issue Jan 22, 2023 · 3 comments
Open

Use @ instead of % as % is already an operator #289

Mike96Angelo opened this issue Jan 22, 2023 · 3 comments

Comments

@Mike96Angelo
Copy link

Mike96Angelo commented Jan 22, 2023

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 
@ljharb
Copy link
Member

ljharb commented Jan 22, 2023

How does that interact with decorators?

@Mike96Angelo
Copy link
Author

Mike96Angelo commented Jan 22, 2023

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.

@MeguminSama
Copy link

@ has been excluded as a topic reference, noted here:
#232 (comment)
#91 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants