-
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
Pipeline with spread operator? #61
Comments
I don't see a big reason for this as arrow function pretty much solve the issue already: // ...[100, 200] |> Math.max
[100, 200]
|> _ => Math.max(..._)
// ...(...[10, 20] |> ((a, b) => [a + 5, b + 5])) |> console.log
[10, 20]
|> ([a, b]) => [a + 5, b + 5]
|> _ => console.log(..._)
// console.log will also work correctly now. (It's not bound and would be missing a this in your example) Adding the extra spread syntax is confusing to read, and the alternative is easier to read. ALSO: const apply = (fn, ctx = null) => args => fn.apply(ctx, args);
// ...[100, 200] |> Math.max
[100, 200]
|> apply(Math.max)
// ...(...[10, 20] |> ((a, b) => [a + 5, b + 5])) |> console.log
[10, 20]
|> apply((a, b) => [a + 5, b + 5])
|> apply(console.log, console) Here the apply function will also help with context. I'm all for adding functions like this to JS eventually, but I don't think we should add syntax unless it actually helps. |
I'm 👎 on this. This looks like too much magic and confusion for what can already be done with arrow functions inline, or using a helper function for. |
OK, seems like a lot of opposition to this proposal, so closing this issue. |
As mentioned in #23 (comment), this proposal will be more powerful when it supports spread operator
...
. In short, make something like the followingequivalent to the following.
This change will fantastically make the pipeline able to pass more than one argument to the callee.
I suspect whether this would be legal when it chained more than one times. Obviously the following is valid,
but it would be nice to have something like the following
and it's equivalent to the following.
Note that, since the spread operator is not a general unary operator and something like
foo = ...bar;
is not permitted syntactically, I think this kind of extension will result in a syntax extension of spread operator itself.The text was updated successfully, but these errors were encountered: