News for hackers. Stuff that matters.
Re:Pipe Operator (|>) For JavaScript by xnorswap on Friday January 20, 2023 @10:48AM (#34454649)
Is either proposal compatible with later adding a backward pipe <| operator?

If so I think that should be a consideration, even if in practice there isn't massive value in a backward pipe operator in javascript. It would be a shame to later want to add it and have to add another layer of kludge and messy syntax.

Re:Pipe Operator (|>) For JavaScript by ubertaco on Friday January 20, 2023 @10:58AM (#34454831)
Yeah, F# has a backward pipe operator, and it works like this:

    a_value |> (fun a b -> a + b) <| b_value
In F#, this works because of automatic function currying. Not sure how that would apply to Javascript, though. Without function currying, what would this even mean?

   a_value |> ((a, b) => a + b) <| b_value
...since there's no currying, you'd just immediately invoke the function that sits "in the middle" with `a` set to `a_value`, but `b` set to `undefined`.

The Hack-style proposal though...I don't think it would work with a backward-pipe operator at all. Not without adding a _second_ special-case symbol, at least.

Re:Pipe Operator (|>) For JavaScript by WastingMyTime89 on Friday January 20, 2023 @11:13AM (#34455152)
For the non initiated amongst us who might be confused, F# has first class functions and everything is curried.

The expression you see is evaluated left-to-right. (|>) is a function taking a_value and (fun a b -> a+b) as arguments and applying a_value to the function. This returns a function taking b as an argument (that’s called a partial application). (<|) is once again a function taking the resulting function and b_value as arguments and applying b_value to its first argument which finally returns the wanted results.

The issue with unary function doesn't exist in F# because every functions can be seen as a unary function returning a function taking one less argument thanks to partial application. That's the beauty of currying.

Re:Pipe Operator (|>) For JavaScript by cjbgkagh on Friday January 20, 2023 @11:01AM (#34454878)
The tie-fighter infix|> <|. |>(+)<|

Then there are ||>, |||> and <|, <||. As well as >> and <<.

Would be nice to use computational expressions for async and generators. (https://es.discourse.group/t/add-computation-expressions-fro...).

This proposal reminds me of Scala with anonymous parameters '_'. Could I use more than one '%' for curried functions. xs.reduce(_+_)? Though I guess for perf reasons it might make sense to keep things as tuples so it would be xs.reduce(%[0]+%[1]).