Hacker News new | ask | show | jobs
by ezekg 1203 days ago
Because that's not how the pipe operator works in any other language.
3 comments

In Clojure it does:

    (-> "Hello, World"
        string/uppercase
        (string/split #",")
        first
        string/trim)
        
`->` is a threading-first macro, and `->>` is a threading last macro. More here: https://clojure.org/guides/threading_macros
Beat me to it while I was typing! Alas, I’m on mobile and your example is a better illustration of the point.
As someone else, it does in Clojure (which is what I wrote most of the time). But even if it didnt, does it matter? If there is a better way, the way is better, no matter if it exists in other languages or not.

If all languages tried to be the same, most of them would be boring.

Of course it is, at least conceptually. See various lisps’ threading macros (which are of course functions over code; but they correspond exactly to mapping over a series of functions, each one supplying input to the next).
I totally agree, I shouldn't have been so absolute in my statement. But JS is not a lisp. The |> foo bar baz syntax doesn't jive with any other syntax in JS, but foo |> bar |> baz does.