Skip to content

Commit

Permalink
Explain why arrow functions require parentheses
Browse files Browse the repository at this point in the history
Fixes #1.
  • Loading branch information
mAAdhaTTah committed Apr 15, 2018
1 parent 1d66d29 commit 7a39712
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ let newScore = boundScore(0, 100, add(7, double(person.score)));

As you can see, because the pipeline operator always pipes a single result value, it plays very nicely with the single-argument arrow function syntax. Because the pipeline operator's semantics are pure and simple, JavaScript engines can optimize away the arrow function, as the [Babel plugin](babel) currently does.

### Arrow Functions & Parentheses

Note that every arrow function needs to be wrapped in parentheses. The full discussion can be found [here](https://github.com/tc39/proposal-pipeline-operator/pull/70) and [here](https://github.com/tc39/proposal-pipeline-operator/issues/104), but the short version is that this:

```js
x |> a => b |> a
```

...is ambiguous, and neither of the potential solutions are necessarily intuitive. Requiring parentheses ensures the way it's intended to be parsed is clear.

## Use with Methods

When a pipeline is applied to method, the receiver of the method is bound to its current value. That is:
Expand Down

0 comments on commit 7a39712

Please sign in to comment.