# Syntax upgrade to the pipeline operator proposal

**URL:** <https://es.discourse.group/t/syntax-upgrade-to-the-pipeline-operator-proposal/1073>\
**Category:** 🦋 Proposals\
**Created:** [November 7, 2021, 3:54am UTC](https://es.discourse.group/t/syntax-upgrade-to-the-pipeline-operator-proposal/1073 "2021-11-07T03:54:26Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![jithujoshyjy](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/jithujoshyjy/32/399_2.png) [@jithujoshyjy](https://es.discourse.group/u/jithujoshyjy)\
**Post date:** [November 7, 2021, 3:54am UTC](https://es.discourse.group/t/syntax-upgrade-to-the-pipeline-operator-proposal/1073/1 "2021-11-07T03:54:26Z")

</div>

#### Proposal: [GitHub - tc39/proposal-pipeline-operator: A proposal for adding a useful pipe operator to JavaScript.](https://github.com/tc39/proposal-pipeline-operator)

The pipeline proposal is great and all but it comes with it's own syntax budget; Mainly '%' has a special meaning in pipeline expressions, which I think increases the parse time quite a bit.

Another drawback is that pipeline expressions cannot be nested neatly.

```javascript
foo |> f(%.call(_, bar |> /* <details> */ ))

/**
details: What if we want to access the outer '%' in here??
*/

```

here's another approach:

```javascript
const superhero = [] as powers
    |> grantPower("nightvision", powers)
    |> make("invincible", powers)
    |> powers.map(x => x.toUpperCase())

```

But I should say that the readme of the proposal criticises temporary variables a lot. The `as` binding here behaves more like the parameter of a function, the key difference being that it's reactive. `as` is just a stand-in, any other operator might well work.

Edit:

One interesting thought that stuck me is that this method can co-exist and connect F# and Hack pipelines.

```javascript
// F# version

foo
    |> functionX
    |> functionY
    |> functionZ

// Hacky version😅
foo as arg
    |> functionX(arg)
    |> functionY(arg)
    |> functionZ(arg)

// each `arg` kind of remains reactive like Iterable.next()

```

Back to smart pipelines😊  
(this sort of changes the pipeline operator to pipeline construct, hope no one notices this!)

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [November 7, 2021, 4:06am UTC](https://es.discourse.group/t/syntax-upgrade-to-the-pipeline-operator-proposal/1073/2 "2021-11-07T04:06:18Z")

</div>

Issues with active proposals are best filed on the proposal itself.

---

<div class="post-metadata">

**Author:** ![theScottyJam](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/thescottyjam/32/616_2.png) [@theScottyJam](https://es.discourse.group/u/theScottyJam)\
**Post date:** [November 7, 2021, 6:05am UTC](https://es.discourse.group/t/syntax-upgrade-to-the-pipeline-operator-proposal/1073/3 "2021-11-07T06:05:18Z")

</div>

You may be interested in this specific thread on that proposal, about adding the ability to name the topic variable: [Named placeholders · Issue #203 · tc39/proposal-pipeline-operator · GitHub](https://github.com/tc39/proposal-pipeline-operator/issues/203)

---

<div class="post-metadata">

**Author:** ![jithujoshyjy](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/jithujoshyjy/32/399_2.png) [@jithujoshyjy](https://es.discourse.group/u/jithujoshyjy)\
**Post date:** [November 7, 2021, 8:57am UTC](https://es.discourse.group/t/syntax-upgrade-to-the-pipeline-operator-proposal/1073/4 "2021-11-07T08:57:29Z")

</div>

I just wanted to know the advantages and/or criticism of this idea. Just wanted to see the thoughts of the community.

---

<div class="post-metadata">

**Author:** ![theScottyJam](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/thescottyjam/32/616_2.png) [@theScottyJam](https://es.discourse.group/u/theScottyJam)\
**Post date:** [November 7, 2021, 2:54pm UTC](https://es.discourse.group/t/syntax-upgrade-to-the-pipeline-operator-proposal/1073/5 "2021-11-07T14:54:56Z")

</div>

Well, I would like the ability to be able to name the hack token somehow, as it could be nice to provide that name as context for how some of the pipeline steps work.

However, I don't think naming the hack token once for the entire pipeline is as useful. The meaning of the token would normally change between each pipeline step, so you can normally only give it bland names like "data" or "value", at which point, the value in naming the hack token would only be for nested pipelines.

So, my preference would be to have the ability to name an individual pipeline step when I think it's important to provide a little more context to that individual step, or if I know I'm going to be using a nested pipeline with that single step.

Something like this:

```javascript
const specialGroupAbilities = getUsers()
  |> %.groups
  |> %.filter(g => isSpecial(g)) as specialGroups
  |> getAbilitiesFrom(specialGroups)

```

Or any of the other syntax suggestions they provided in the thread I linked to.

---

<div class="post-metadata">

**Author:** ![jithujoshyjy](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/jithujoshyjy/32/399_2.png) [@jithujoshyjy](https://es.discourse.group/u/jithujoshyjy)\
**Post date:** [November 7, 2021, 3:13pm UTC](https://es.discourse.group/t/syntax-upgrade-to-the-pipeline-operator-proposal/1073/6 "2021-11-07T15:13:36Z")

</div>

> [@theScottyJam](#):
>
> However, I don't think naming the hack token once for the entire pipeline is as useful. The meaning of the token would normally change between each pipeline step, so you can normally only give it bland names like "data" or "value", at which point, the value in naming the hack token would only be for nested pipelines.
> 
> So, my preference would be to have the ability to name an individual pipeline step when I think it's important to provide a little more context to that individual step, or if I know I'm going to be using a nested pipeline with that single step.

The reason for that is better seen [here](https://github.com/tc39/proposal-pipeline-operator/issues/203#issuecomment-918608219) as said by @tabatkins  
(the last paragraph)  
My preference for identifiers over some punctuator like '%' or '^' has also to do with the grammar and parsing.  
currently the grammar would be:

```javascript
<value> (|> <pipeline_expression>)+

```

notice the **\<pipeline\_expression\>** , it's additional baggage; considering the named token approach the grammar looks like:

```javascript
<value> (as <identifier>)? (|> <expression>)+

```

way easier to parse because it uses a normal expression.

Thanks for providing your thought! @theScottyJam

---

<div class="post-metadata">

**Author:** ![theScottyJam](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/thescottyjam/32/616_2.png) [@theScottyJam](https://es.discourse.group/u/theScottyJam)\
**Post date:** [November 7, 2021, 4:54pm UTC](https://es.discourse.group/t/syntax-upgrade-to-the-pipeline-operator-proposal/1073/7 "2021-11-07T16:54:16Z")

</div>

Are you saying that you would always be required to give a name to the topic variable? It's not an optional thing? So that parsing can be easier?

If it's required, then I would defer to tabatkin's other paragraphs from the same comment you linked to, about how it's not always possible to provide useful names to the topic variable, and he would rather come up with a standard name than having people invent their own meaningless name everywhere ("x", "value", "data", etc). I also don't think engine implementors are afraid of getting their hands dirty and working with a grammar that's a little more complicated, if that's the kind of grammar the JavaScript community wants. I mean, I'm all for a simpler grammar, but I care more about the end-user experience (though, I'm probably biased here because I don't actually have to work with the grammar).

---

<div class="post-metadata">

**Author:** ![aclaymore](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/aclaymore/32/501_2.png) [@aclaymore](https://es.discourse.group/u/aclaymore)\
**Post date:** [November 7, 2021, 6:46pm UTC](https://es.discourse.group/t/syntax-upgrade-to-the-pipeline-operator-proposal/1073/8 "2021-11-07T18:46:17Z")

</div>

> [@jithujoshyjy](#):
>
> way easier to parse because it uses a normal expression.

The current draft spec shows that pipe adds the `%` into `PrimaryExpression`.

JS parsers will likely use a flag to detect when the token is incorrectly used outside a pipeBody. This would not be particularly difficult.

---

<div class="post-metadata">

**Author:** ![jithujoshyjy](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/jithujoshyjy/32/399_2.png) [@jithujoshyjy](https://es.discourse.group/u/jithujoshyjy)\
**Post date:** [November 8, 2021, 3:45am UTC](https://es.discourse.group/t/syntax-upgrade-to-the-pipeline-operator-proposal/1073/9 "2021-11-08T03:45:45Z")

</div>

so something like:  
`const bar = foo(%);`  
can be parsed when outside a pipe? And then the parser throws an error?  
Ya that works too😅

> [@theScottyJam](#):
>
> Are you saying that you would always be required to give a name to the topic variable? It's not an optional thing?

I suggested that just for the sake of a neat grammar(and slightly for bringing in the F# pipeline, I mean I still like it😅). It could also be opt in and could help in nested pipelines.

---

<div class="post-metadata">

**Author:** ![claudiameadows](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/claudiameadows/32/126_2.png) [@claudiameadows](https://es.discourse.group/u/claudiameadows)\
**Post date:** [November 8, 2021, 8:21am UTC](https://es.discourse.group/t/syntax-upgrade-to-the-pipeline-operator-proposal/1073/10 "2021-11-08T08:21:51Z")

</div>

> [@jithujoshyjy](#):
>
> so something like:  
> `const bar = foo(%);`  
> can be parsed when outside a pipe? And then the parser throws an error?

Not quite that. It's more the parser would simply know whether it's parsing the RHS of a pipe expression in that context and, when it encounters a `%` as a standalone expression, rejects it if it's not. It won't actually process the final `)` or `;` in that case.

---

<div class="post-metadata">

**Author:** ![aclaymore](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/aclaymore/32/501_2.png) [@aclaymore](https://es.discourse.group/u/aclaymore)\
**Post date:** [November 8, 2021, 8:59am UTC](https://es.discourse.group/t/syntax-upgrade-to-the-pipeline-operator-proposal/1073/11 "2021-11-08T08:59:51Z")

</div>

> [@claudiameadows](#):
>
> It won't actually process the final `)` or `;` in that case

Depends on the parser. A parser like eslint might continue to parse after an error, so that it can report as many errors as possible. Rather than just the first one.

In TypeScript, `a << #field` will be accepted by the parser, and then a post-parse step walks the tree and emits an error. It is done this way so that the parser doesn’t have to special case parsing `#field in a`.

---

<div class="post-metadata">

**Author:** ![aclaymore](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/aclaymore/32/501_2.png) [@aclaymore](https://es.discourse.group/u/aclaymore)\
**Post date:** [November 8, 2021, 9:03am UTC](https://es.discourse.group/t/syntax-upgrade-to-the-pipeline-operator-proposal/1073/12 "2021-11-08T09:03:15Z")

</div>

> [@jithujoshyjy](#):
>
> slightly for bringing in the F# pipeline, I mean I still like it

You might be interested in [GitHub - tc39/proposal-function-helpers: A withdrawn proposal for standardizing some useful, popular helper functions into JavaScript’s Function object.](https://github.com/tc39-transfer/proposal-function-helpers#functionpipe) which proposes a `pipe` function.

```javascript
// f# style 
return v |> f |> g |> h;
// becomes
return pipe(v, f, g, h);
// or
return v |> pipe(%, f, g, h);

```

---

<div class="post-metadata">

**Author:** ![claudiameadows](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/claudiameadows/32/126_2.png) [@claudiameadows](https://es.discourse.group/u/claudiameadows)\
**Post date:** [November 17, 2021, 7:47am UTC](https://es.discourse.group/t/syntax-upgrade-to-the-pipeline-operator-proposal/1073/13 "2021-11-17T07:47:02Z")

</div>

Was speaking from the perspective of an engine parser. But it's also worth noting that ESLint isn't like JSHint - it won't actually lint files with syntax errors. (It defers to Acorn, and it doesn't use Acorn's loose parser.)

---

<div class="post-metadata">

**Author:** ![jschoi](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/jschoi/32/917_2.png) [@jschoi](https://es.discourse.group/u/jschoi)\
**Post date:** [November 17, 2021, 2:52pm UTC](https://es.discourse.group/t/syntax-upgrade-to-the-pipeline-operator-proposal/1073/14 "2021-11-17T14:52:00Z")

</div>

Note for others: The Function-helpers proposal was rejected by the Committee last month for being too broad. It has been split up into multiple proposals, including a [proposal devoted to a pipe function](https://github.com/js-choi/proposal-function-pipe-flow).

---

<div class="post-metadata">

**Author:** ![fabiocroldan](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/fabiocroldan/32/481_2.png) [@fabiocroldan](https://es.discourse.group/u/fabiocroldan)\
**Post date:** [January 29, 2025, 1:16pm UTC](https://es.discourse.group/t/syntax-upgrade-to-the-pipeline-operator-proposal/1073/15 "2025-01-29T13:16:53Z")

</div>

Hello Jordan, I made this proporsal related to this topic.

> [@Object.prototype.pipe() - Universal Method Chaining in JavaScript](https://es.discourse.group/t/object-prototype-pipe-universal-method-chaining-in-javascript/2292):
>
> Object.prototype.pipe() - Universal Method Chaining in JavaScript Status Stage: -1 (Strawperson) Platform: es.discourse.group Category: Proposals Author Fabio Roldan Synopsis A proposal to add a .pipe() method to Object.prototype enabling universal method chaining across all JavaScript values. Motivation JavaScript lacks a universal way to chain operations that works consistently across all types. While method chaining is common with objects and arrays, working with primitive values often re…
