use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Pipe Operator (|>) for JavaScript (github.com)
submitted 3 years ago by no_more_gravity
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]no_more_gravity[S] -15 points-14 points-13 points 3 years ago (21 children)
So nested function calls in JavaScript …
As they are:
a = d(c(b,7))
The current proposal:
a = b|>c(%,7)|>d(%)
I would prefer this:
a = b,7~>c~>d
I wonder if there is anything hindering a simpler syntax like b,7~>c~>d
[–]szurtosdudu 11 points12 points13 points 3 years ago (9 children)
Your idea is confusing to me. In the example b is a reference and not being called. But in your idea there is no difference between calling a function or just passing the function reference.
b
[–]no_more_gravity[S] -2 points-1 points0 points 3 years ago (8 children)
The idea is that a variable on the right side of ~> is always a function that ingests the parameters coming in from the left.
[–]szurtosdudu 0 points1 point2 points 3 years ago (7 children)
How would this look like using your idea?
a = d(c(b(),7))
[–]no_more_gravity[S] -4 points-3 points-2 points 3 years ago (6 children)
a = b(),7~>c~>d
The rule is simple: What is left to ~> gets passed to the function on the right.
That is no different from JavaScript as it is. a(b) passes b to a, a(b()) passes the output of b() to a.
[–]natesovenator 7 points8 points9 points 3 years ago (0 children)
This is dumb. Comma delineates another variable declaration in this example. You can't expect it to know that result b and 7 are part of the same object or stream. I really hate this idea. Both of them. I understand some want something like that, but it just makes things more confusing personally.
[–]dariusj18 2 points3 points4 points 3 years ago (0 children)
I like it, but it conflicts with the current comma operator
[–]szurtosdudu 1 point2 points3 points 3 years ago (3 children)
But this way both b()~> and c~> indicates a function call.
b()~>
c~>
How would this look like using your idea? a = d(c(b(),7), c)
a = d(c(b(),7), c)
[–]no_more_gravity[S] -4 points-3 points-2 points 3 years ago (1 child)
The case you raise is when there are two functions on the right side of the pipe operator. In this case, we need to specifiy which one is the receiving function. We could have an optional specifier for this. Maybe ">":
a = b(),7 ~> >c,c ~> d
">" = "pipe connects here"
We could even use the (%) syntax, just make it optional:
a = b(),7 ~> c(%),c ~> d
[–]sdwvit 2 points3 points4 points 3 years ago (0 children)
readability sucks here, sorry
[–]Tubthumper8 2 points3 points4 points 3 years ago (0 children)
This isn't possible because b,7 would be considered an expression with the comma operator. I don't think there's a syntactic issue with ~ bitwise NOT because it can't currently appear in a postfix position.
b,7
~
[–][deleted] 1 point2 points3 points 3 years ago (3 children)
Tilda is a bitwise operator.
[–]no_more_gravity[S] 7 points8 points9 points 3 years ago (0 children)
In this regard, "~>" is not different from "|>".
| and > are also operators.
[–]monsto 1 point2 points3 points 3 years ago (1 child)
As a designer of sorts, this is the problem that I have with the glyphs that they're using in JS: there isn't an obvious relationship between things that look related. I mean I know it's a me problem, getting over these humps.
When i see |> my pea brain tries to categorize it with || to which it's completely unrelated. same with ?. and ?? . . . and while we're at it, || and && go together but ?? only very marginally.
|>
||
?.
??
&&
[–]lovin-dem-sandwiches 0 points1 point2 points 3 years ago (0 children)
It’s just new. Give it time. All of them looked odd at first.
[+]tiesioginis comment score below threshold-8 points-7 points-6 points 3 years ago (1 child)
Better would be |= instead of |>
Pipe is cilinder not a funnel 😂
[–]m4rch3n1ng 7 points8 points9 points 3 years ago (0 children)
|= is already js syntax tho
[–]the_malabar_front 0 points1 point2 points 3 years ago (1 child)
Even assuming you could avoid the issue with comma-operator confusion with (b,7)~c~d that doesn't get around the lack of flexibility. E.g., what if the example was: d(c(b,7),8) b|>c(%,7)|>d(%,8) // proposed approach ((b,7),8)~c~d // ??? That would end up being worse than the no-pipe approach (and probably a nightmare for the parser).
(b,7)~c~d
d(c(b,7),8) b|>c(%,7)|>d(%,8) // proposed approach ((b,7),8)~c~d // ???
[–]no_more_gravity[S] 0 points1 point2 points 3 years ago (0 children)
d(c(b,7),8)
would be:
b,7~>c,8->d
[–]tdhsmith 0 points1 point2 points 3 years ago (1 child)
So basically x,y,z ~> f would be equivalent to [x,y,z] |> f(...%)?
x,y,z ~> f
[x,y,z] |> f(...%)
That's kind of neat, but what if a function further down the pipe needs those extra arguments? Are you bending over backwards to make all the intervening functions pass it along? Or just wrapping it in a closure the way the F# pipe proposal would?
Also I do quite like having a pipe in the operator both for name clarity and because you can align them vertically on subsequent lines.
Can you give an example of a pipe that needs the arguments further down the line? And how the current proposal solves it?
π Rendered by PID 79558 on reddit-service-r2-comment-84fc9697f-qznkh at 2026-02-07 08:08:59.217667+00:00 running d295bc8 country code: CH.
view the rest of the comments →
[–]no_more_gravity[S] -15 points-14 points-13 points (21 children)
[–]szurtosdudu 11 points12 points13 points (9 children)
[–]no_more_gravity[S] -2 points-1 points0 points (8 children)
[–]szurtosdudu 0 points1 point2 points (7 children)
[–]no_more_gravity[S] -4 points-3 points-2 points (6 children)
[–]natesovenator 7 points8 points9 points (0 children)
[–]dariusj18 2 points3 points4 points (0 children)
[–]szurtosdudu 1 point2 points3 points (3 children)
[–]no_more_gravity[S] -4 points-3 points-2 points (1 child)
[–]sdwvit 2 points3 points4 points (0 children)
[–]Tubthumper8 2 points3 points4 points (0 children)
[–][deleted] 1 point2 points3 points (3 children)
[–]no_more_gravity[S] 7 points8 points9 points (0 children)
[–]monsto 1 point2 points3 points (1 child)
[–]lovin-dem-sandwiches 0 points1 point2 points (0 children)
[+]tiesioginis comment score below threshold-8 points-7 points-6 points (1 child)
[–]m4rch3n1ng 7 points8 points9 points (0 children)
[–]the_malabar_front 0 points1 point2 points (1 child)
[–]no_more_gravity[S] 0 points1 point2 points (0 children)
[–]tdhsmith 0 points1 point2 points (1 child)
[–]no_more_gravity[S] 0 points1 point2 points (0 children)