TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

TC39 Pipeline Operator

6 pointsby 0xedbover 3 years ago

1 comment

linkddover 3 years ago
I fell in love with Elixir&#x27;s pipeline operator. It would be a joy to see it come to Javascript&#x2F;Typescript.<p>I think the explicit &quot;^&quot; in one of the proposals can be a good idea.<p>Python&#x27;s badly designed interface comes to mind:<p><pre><code> (lambda i: i * 2) |&gt; map([1, 2, 3]) </code></pre> vs<p><pre><code> [1, 2, 3] |&gt; map(lambda i: i * 2, ^) </code></pre> But since &quot;^&quot; is already a binary operator, I would rather use &quot;&amp;1&quot; (like in Elixir).<p>This would have the benefit of being consistent with a later partial function application syntax:<p><pre><code> const add = (a, b, c) =&gt; a + b + c const f = add(1, &amp;1, &amp;2) f(2, 3) === 6 </code></pre> Note also that for promises, I think, a global then function should be provided:<p><pre><code> const promise = new Promise(...) |&gt; then(&amp;1, async result =&gt; ...)</code></pre>