Re:Pipe Operator (|>) For JavaScript
by galaxyLogic on Friday January 20, 2023 @06:38PM
(#34461762)
Why not use |> for that?
[ Parent
| on HN ]
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.