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 – Hack vs. F#

50 pointsby jashkenasover 3 years ago

9 comments

johnfnover 3 years ago
The thing about the pipeline operator that strikes me is how toylike all the examples are. Look at this article for example - it’s a bunch of examples of adding and exponentiating numbers, as if you couldn’t do that already in a single line of code.<p>My suspicion is that once you move away from toy examples, most pipeline operator use cases are already covered by chaining class methods on classes. I suppose you could argue that the pipeline operator allows you to operate across multiple different data types, but I further suspect that handling many different data types with a single function is an annoying thing to get right and this won’t come up in practice all too often.<p>To be fair, the case of pulling in only the methods you need on rxjs seems somewhat useful… but do we really need a whole new operator just for that? And isn’t that the point of ::?
评论 #28530928 未加载
评论 #28531463 未加载
评论 #28531059 未加载
评论 #28534899 未加载
评论 #28531078 未加载
Kaze404over 3 years ago
I&#x27;ve wanted a pipeline operator in JavaScript for a while now. Working with Elm and Elixir has made me think of problems in terms of data transformation, and the pipeline operator is the biggest reason why. &quot;Take X then do Y, Z, J, K, L and finally send it over to the client&quot; makes what would be complicated code be only as complicated as the reader wants, as they can inspect the functions they care about (assuming they even want to).
abecedariusover 3 years ago
If you&#x27;re inventing a special shorthand for functions like foo(42, ^), then why only in the context of a pipe? Make up some punctuation to introduce or surround this kind of expression, then use it anywhere. Less to learn, more useful.
评论 #28531573 未加载
评论 #28531729 未加载
评论 #28531622 未加载
评论 #28531545 未加载
junonover 3 years ago
I don&#x27;t see how any of this is more readable than:<p><pre><code> let v = first(); v = second(v, 10); v = third(x, y, v); return v; </code></pre> Why do we need a new operator for this?
评论 #28531682 未加载
评论 #28531424 未加载
评论 #28531341 未加载
评论 #28531313 未加载
ibraheemdevover 3 years ago
I would love the pipeline operator in Ruby, but unfortunately the unstable feature [0] was removed:<p><pre><code> 1.. |&gt; take 10 |&gt; map {|e| e*2} |&gt; (x) </code></pre> &gt; After experiments, |&gt; have caused more confusion and controversy far more than I expected. I still value the chaining operator, but drawbacks are bigger than the benefit. So I just give up the idea now. Maybe we would revisit the idea in the future (with different operator appearance).<p>[0]: <a href="https:&#x2F;&#x2F;bugs.ruby-lang.org&#x2F;issues&#x2F;15799" rel="nofollow">https:&#x2F;&#x2F;bugs.ruby-lang.org&#x2F;issues&#x2F;15799</a>
rangunaover 3 years ago
&gt; little hard on the eyes<p>Understatement of the year, that&#x27;s the worst token I&#x27;ve seen in all my years of working with javascript and I hope it doesn&#x27;t go through.
rk06over 3 years ago
I don&#x27;t get one thing.<p>if pipe() works for RxJs, and hackpipe is not better, then why don&#x27;t you simply stick with pipe()?<p>Just because one operator is there, doesn&#x27;t mean you have to use it.<p>JS classes are notoriously under powered, so much that both react and vue prefer functions over class components<p>Besides, it is possible that RxJs (and other libraries) may modify how they work to better utilise hack pipe
jasperryover 3 years ago
I had never seen Hack&#x27;s pipeline before, which uses an explicit marker ^ to indicate which argument the piped object goes to. This seems like a really cool idea--you can wire functions together any way you want without having to create lambdas. Do any other languages use anything like this?
评论 #28531690 未加载
评论 #28531390 未加载
评论 #28531560 未加载
评论 #28531409 未加载
评论 #28532516 未加载
nsonhaover 3 years ago
cons miss the most important downside of F# proposal which is the runtime optimization aspect of requiring extra lambda functions.<p>I went through the github issue the other day, syntax aside, the two proposal boil down to functions vs expressions (no extra functions)