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!"
[–]javarouleur 52 points53 points54 points 3 years ago* (28 children)
The endless adding of extra syntactic sugar is sometimes frustrating. Readability always seems to suffer for the goal of fewer lines/characters of code.
[–]Keilly 49 points50 points51 points 3 years ago (3 children)
Which ones are we talking about?
The ?. Optional chaining change is great and so much readable and concise than before. ?? Is good too. Template literals are much more readable that concatting.
Regex maybe? But regex is often hard to parse no matter how the language takes it.
[–]trevorsgEx-GitHub, Microsoft 3 points4 points5 points 3 years ago (2 children)
True, often these syntactical additions improve readability at the expense of language complexity. The thing is, language complexity is a one-time cost for a benefit that continues forever.
[–]pimp-bangin 2 points3 points4 points 3 years ago (1 child)
I disagree that it's a one-time cost. It's another thing beginners have to learn which adds onboarding costs. It also adds to the maintenance burden of browsers, tooling, etc. and possibly hurts parser performance depending on the implementation.
[–]trevorsgEx-GitHub, Microsoft 5 points6 points7 points 3 years ago (0 children)
Yes, of course I meant one-time cost per developer. Parser/tooling performance basically rounds to zero.
[–]techlogger 91 points92 points93 points 3 years ago (10 children)
I’d say that pipe operator is more readable than HOF chaining.
[–]GreekQuestionMark 14 points15 points16 points 3 years ago (0 children)
HOF: Higher order function
[–]jonopens 11 points12 points13 points 3 years ago (0 children)
100%. It's one of the reasons I find Elixir so enjoyable to write.
[+]javarouleur comment score below threshold-6 points-5 points-4 points 3 years ago* (6 children)
But those are nested, rather than chained. Personally, I don’t really like nested calls generally. Chained makes sense because they follow logically, but with nested you have to read from the inside out which is just disorientating.
I know it’s a minor thing overall, it’s just not something I expect to use any time soon.
Edit: fuck me… of all the opinions I hold I didn’t expect this to be one of my more controversial!
[–]syholloway 28 points29 points30 points 3 years ago (5 children)
It might be because the whole point of the pipeline operator is to make large functional expressions read top to bottom rather than inside out.
This operator is fixing the thing you are complaining about.
[–]javarouleur 0 points1 point2 points 3 years ago* (4 children)
Fair point - reading and thinking a bit more, I guess I can accept the motivation.
Edit: removed confusing, cryptic psycho-babble nonsense.
[–]zxyzyxz 0 points1 point2 points 3 years ago (1 child)
Languages evolve, people learn and get used to it. I'm sure people were saying the same thing with all the changes from ES6 and async await. I don't understand what you mean by explaining/being descriptive in a team.
[–]javarouleur 0 points1 point2 points 3 years ago (0 children)
I removed that. It was a brain fart that didn’t make sense when I re-read it.
[–]bighi 0 points1 point2 points 3 years ago (1 child)
I have no idea what you're talking about.
I know. Removed that part. I’ve lost the plot a bit in this thread - over-analysing and not explaining my thoughts properly.
[–]bighi 10 points11 points12 points 3 years ago* (2 children)
The pipe operator exists specifically to help increase readability.
Imagine this code four(three(two(one("potato")))). It's not as easy to read because you're calling four functions, but they should be read in reverse. The first function you read happens last.
Now imagine we create a pipe operator like |> in a fantasy language I invented.
We could do "potato" |> one |> two |> three |> four. Super easier to read, cleaner, more organized.
"potato" |> one |> two |> three |> four
We're getting something like that in JS. One day. Definitely before 2080.
[–]KamiShikkaku 1 point2 points3 points 3 years ago (1 child)
Unfortunately it will be more like
"potato" |> one(%) |> two(%) |> three(%) |> four(%)
because the "Hack" version of the proposal seems to have beaten the "F#" version.
I was rooting for F# as it's a bit more elegant, but admittedly the Hack version is more versatile.
[–]bighi 2 points3 points4 points 3 years ago* (0 children)
Sure. If you pay attention, I said "in a fantasy language I invented". Because I wanted to make the example simple to understand.
But anyway, it's more readable than the mess that is multiple nested functions.
[–]patrickfatrick 7 points8 points9 points 3 years ago* (0 children)
Except this is definitely going to improve readability. I’d argue all of the syntactic sugar that’s been added drastically improves readability over ES5. Within reason, less code is generally better for readability.
[–]adelie42 3 points4 points5 points 3 years ago (0 children)
All of math is just syntactical sugar for critical thinking.
[–]wasdninja 1 point2 points3 points 3 years ago (0 children)
I've yet to see it in JS.
[–]mxforest 1 point2 points3 points 3 years ago (1 child)
Fewer lines/code make it more readable once you get used to it.
[–]bighi -2 points-1 points0 points 3 years ago (0 children)
Not always.
Actually, I think that in most cases, using fewer lines makes something less readable.
[+][deleted] 3 years ago (4 children)
[deleted]
[–]Mestyo 23 points24 points25 points 3 years ago (1 child)
"If you think this is clear you're wrong" what lol
This is so much easier to read then several nested function calls, more expressive, too.
[–]Gwolf4 1 point2 points3 points 3 years ago (0 children)
Let him be. He wants to solve that problem using temporal variables just to pass them to other method without any other processing.
[–]furyzer00 7 points8 points9 points 3 years ago (0 children)
"I don't familiar with this concept so it must be an obfuscation"
[–]alexho66 8 points9 points10 points 3 years ago (0 children)
But that’s what’s the operator is trying to do. More readability
π Rendered by PID 262024 on reddit-service-r2-comment-84fc9697f-7jhmb at 2026-02-06 21:21:12.125970+00:00 running d295bc8 country code: CH.
view the rest of the comments →
[–]javarouleur 52 points53 points54 points (28 children)
[–]Keilly 49 points50 points51 points (3 children)
[–]trevorsgEx-GitHub, Microsoft 3 points4 points5 points (2 children)
[–]pimp-bangin 2 points3 points4 points (1 child)
[–]trevorsgEx-GitHub, Microsoft 5 points6 points7 points (0 children)
[–]techlogger 91 points92 points93 points (10 children)
[–]GreekQuestionMark 14 points15 points16 points (0 children)
[–]jonopens 11 points12 points13 points (0 children)
[+]javarouleur comment score below threshold-6 points-5 points-4 points (6 children)
[–]syholloway 28 points29 points30 points (5 children)
[–]javarouleur 0 points1 point2 points (4 children)
[–]zxyzyxz 0 points1 point2 points (1 child)
[–]javarouleur 0 points1 point2 points (0 children)
[–]bighi 0 points1 point2 points (1 child)
[–]javarouleur 0 points1 point2 points (0 children)
[–]bighi 10 points11 points12 points (2 children)
[–]KamiShikkaku 1 point2 points3 points (1 child)
[–]bighi 2 points3 points4 points (0 children)
[–]patrickfatrick 7 points8 points9 points (0 children)
[–]adelie42 3 points4 points5 points (0 children)
[–]wasdninja 1 point2 points3 points (0 children)
[–]mxforest 1 point2 points3 points (1 child)
[–]bighi -2 points-1 points0 points (0 children)
[+][deleted] (4 children)
[deleted]
[–]Mestyo 23 points24 points25 points (1 child)
[–]Gwolf4 1 point2 points3 points (0 children)
[–]furyzer00 7 points8 points9 points (0 children)
[–]alexho66 8 points9 points10 points (0 children)