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

Comma-based syntax #179

Closed
ivan7237d opened this issue Feb 16, 2021 · 4 comments
Closed

Comma-based syntax #179

ivan7237d opened this issue Feb 16, 2021 · 4 comments

Comments

@ivan7237d
Copy link

ivan7237d commented Feb 16, 2021

It's a simple idea, so probably came up before in some discussion and was rejected, but since I couldn't find it discussed after searching through all the issues, let me bring it up here.

The idea is that instead of x |> a |> b |> c, the syntax would be x |> a, b, c. There are two reasons behind this syntax:

  • As with ponyfills like applyPipe(arg, f1, f2, f3), you will not have to put arrow functions in parens. Precedence-wise, a => b |> c would mean a => (b |> c). a |> b => c, d can only mean a |> (b => c), d.

  • Sometimes it's convenient to compose functions without applying them. Right now you can do this with a function like pipe(f1, f2, ...), and it's conceivable that in future there would be a separate JS operator for that. Either way, preferably it should be easy to move function chains back and forth between usages in function composition, and usages with pipeline operator. When these chains uniformly use the comma as the separator, this is taken care of.

I suspect there are some footguns or other flaws here, but the only one I see right away is that one could confuse the commas for the comma operator. A comma already has special meaning in contexts like let a, b though.

@ljharb
Copy link
Member

ljharb commented Feb 16, 2021

That meaning is still “a list of expressions” since variable declarations are expressions.

it would be very strange if the expression a, b, c meant something different inside a pipeline than outside it.

@ivan7237d
Copy link
Author

it would be very strange if the expression a, b, c meant something different inside a pipeline than outside it.

There's an interesting comment by @masaeedu, #96 (comment), pointing out that in the current proposal, |> already means different things depending on whether it occurs in the RHS of another |>.

@charmander
Copy link

@ivan7237d That was a misunderstanding based on reading it with the wrong associativity.

@tabatkins
Copy link
Collaborator

Closing this issue, as the proposal has advanced to stage 2 with Hack-style syntax.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants