-
Notifications
You must be signed in to change notification settings - Fork 107
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
Details of draft specification #52
Comments
I haven’t looked at the spec proper yet, but everything in this summary looks great to me—though part of me wonders if it's worth bothering to handle That last point about preserving the binding for object methods is an especially nice touch. |
Is there a way to spread an array into the RHS? Given: const str = 'hello world!\r\n';
[/\r\n/g, '\n'] |> str.replace.apply; Would have a |
@bmeck That almost works, except the first argument to const str = 'hello world!\r\n';
[/\r\n/g, '\n'] |> str.replace.apply.bind(str); (Cue an angry mob saying "Why isn't this proposal doing the entire bind operator, which would solve this!) You could also use this proposal in conjunction with the partial application proposal: const str = 'hello world!\r\n';
[/\r\n/g, '\n'] |> str.replace(...); cc @rbuckton |
cc @claudepache |
@littledan seems fine, can also use a lambda [0,1,2] |> $ => console.log(...$) |
Kinda; I think you need parens around the arrow function in this grammar, unfortunately (and the above would be a SyntaxError). |
An issue, if we support arrow function on the RHS without parens around it, is the semantics of x |> _ => 2 * _
|> f Because the body of an arrow function may be an Assignment Expression like |
@claudepache I believe this specification doesn't support un-parenthized arrow functions, and that example would be a SyntaxError. What do you think of that as a resolution? |
@littledan Yes, a SyntaxError is probably the best outcome in such a case. The proposed spec text of PR #51 seems fine. |
@claudepache @littledan I'm not an expert on JS grammar... could you explain why @claudepache's example does not parse to the following? x |> (_ => 2 * _ |> f) |
@gilbert Because |
What would be the implications of adding |
@gilbert I know if that would be the syntax you want, since the body of the arrow function would include any following pipeline operators. But maybe that would all work out reasonably anyway; I need to think about it more. |
Thanks for your feedback here. I merged this draft specification. |
In PR #51 , I wrote some spec text. I'd be interested in feedback on the details here. In particular:
|>
is treated directly as a function; even if it is a |CallExpression|, the result of evaluating that |CallExpression| is treated as the function, rather than slotting the left argument into the arguments list. That isx |> y(z)
is similar in semantics toy(z)(x)
. (see Alternate syntax #4)|>
sits between the ternary operator and||
. It is left-associative. (see Operator Precedence - Higher or Lowest? #23)eval
through pipeline are indirect eval.|>
is evaluated before the right one.|>
has a receiver, it is used for the call, with rules similar to a method call. That isx |> y.z
getsy
as a receiver, just as if it were writteny.z(x)
.Any thoughts?
Note to positive or negative reacts: tell me why in this thread!
The text was updated successfully, but these errors were encountered: