News for hackers. Stuff that matters.
Re:Pipe Operator (|>) For JavaScript by galaxyLogic on Friday January 20, 2023 @11:02AM (#34454909)
Wouldn't it be better to use '->' as the operator? This is about dataflow so an arrow would represent that nicely. Whereas '|>' doesn't really "mean" anything. An arrow means that something flows in the direction of the arrow.
Re:Pipe Operator (|>) For JavaScript by BeefWellington on Friday January 20, 2023 @11:57AM (#34455987)
Not only that but I can't be the only person who finds -> vastly easier to type than |>.
Re:Pipe Operator (|>) For JavaScript by vorotato on Friday January 20, 2023 @12:44PM (#34456744)
I also pushed for this in TC39 which was shut down for seemingly no reason. Since only one language with almost no user base uses |> to mean expressions, people are guaranteed to get the wrong idea about how it works. It almost seems like intentional misleading.
Re:Pipe Operator (|>) For JavaScript by hajile on Friday January 20, 2023 @01:43PM (#34457705)
Sure, but I'd rather reserve that for a pattern-matching switch statement.
Re:Pipe Operator (|>) For JavaScript by galaxyLogic on Friday January 20, 2023 @06:38PM (#34461762)
Why not use |> for that?
Re:Pipe Operator (|>) For JavaScript by hajile on Friday January 20, 2023 @08:58PM (#34462994)
It's more common for pattern matching Java's new syntax, Erlang, Elixir, StandardML (fat arrow), F#, Kotlin, Ocaml, Haskell, Rust (fat arrow), Ada (fat arrow), Scala (fat arrow), Zig (fat arrow), and probably a bunch of others too.

That's a lot of prior art for people to be comfortable with and as the fat arrow already has another meaning, overloading it in pattern matching might complicate things.

Re:Pipe Operator (|>) For JavaScript by galaxyLogic on Friday January 20, 2023 @11:04PM (#34463768)
Right but then it would not be the same as in those other languages which use fat arrow anyway.

Another syntax for pattern-matching could be simply ':' instead of the arrow.

In the early days of Smalltalk the Smalltalk return statement was simply '^'. That could also be suitable for pattern matching. The idea would be that the switch statement returns something meaning pushing it up from the expression to whoever called it. So '^' might be good for that. Whereas pushing the results to the right to the next expression could be ->.

Just my preferences.