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

Functions with multiple arguments #59

Closed
fahad19 opened this issue Sep 28, 2017 · 2 comments
Closed

Functions with multiple arguments #59

fahad19 opened this issue Sep 28, 2017 · 2 comments
Labels

Comments

@fahad19
Copy link

fahad19 commented Sep 28, 2017

Currently

The spec suggests function with multiple arguments be used like this:

Base functions:

function double(x) {
  return x * 2;
}

function add(x, y) {
  return x + y;
}

Pipe operator usage:

const score = 10;

const newScore = score
  |> double
  |> _ => add(7, _)

console.log(newScore); // 27;

Proposed change

Instead of writing extra function wrappers for passing arguments, the operator can always make sure the output from previous function as fed as the first argument of next function.

const newScore = score
  |> double // output of `score` is first argument: `double(10)`
  |> add(7) // output of `double(10)` is first argument: `add(20, 7)`

console.log(newScore); // 27

This is how Elixir works: https://hexdocs.pm/elixir/Kernel.html#%7C%3E/2


If TC39 is interested in this, I am happy to send a PR for improving this spec further.

@gilbert
Copy link
Collaborator

gilbert commented Sep 28, 2017

Closing as a subset duplicate of #55

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

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

No branches or pull requests

2 participants