Live data from Hacker News

Show HN: A JavaScript function that looks and behaves like a pipe operator

github.com

91–100 of 148 posts

Re: Show HN: A JavaScript function that looks and behaves like a pipe operator

#91

>The following example code is a bit hard to read: >const { status } = await send(capitalize(greeting) + "!") >console.log(status) No it's not hard to read. >Make it less nested, more vertical, by using the V "pipe": >V( greeting, // initial value "hi" >V (capitalize), // custom function call "Hi" >V .concat("!"), // String method `concat` call "Hi!" >V (send), // custom async function call Promise { } >V .status, //…

Is functional programming a joke? YMMV...

I don't think the first example is less pure than the second, what makes you think it is?

Re: Show HN: A JavaScript function that looks and behaves like a pipe operator

#92

Earlier quoted context omitted.

Not hard: msg can be derived from the parameter name of the send() function and status is a fixed attribute of the result.

Even worse - you’re polluting your local namespace with names decided on by other code . I’m obviously not being serious about naming being hard in this example. But there are cases where the pattern of using return object property names as variables comes back to bite uou. Even in this case, what if the response object from ‘send()’ also has a ‘msg’ property? Changing const { status } into const { status, msg } is a…

Still not hard: In that case, instead of msg use sendMsg AND/OR in the second statement use { status, msg: resultMsg }, or just result and later result.msg.

Re: Show HN: A JavaScript function that looks and behaves like a pipe operator

#93
post #33

Earlier quoted context omitted.

> the non-standard use of parens/spacing makes it incredible difficult for me to parse. Same here. Not to mention this wouldn't work in a codebase with an autoformatter.The idea/API is clever. So, a pretty cool experiment I suppose

Author here. Thanks for your nice comment. I added a note to say it does work with autoformatters too. Actually someone in a comment below said he or she prefers the autoformatted syntax.

Oh, that's good to know! I haven't tried it and assumed an auto formatter might misalign some of it or put things on the same line, so the visual "downward arrow" appearance would be lost

Edit: I just checked the docs again and while it does look a bit "misaligned" at the start, I do think it looks more readable with the autoformatted version. Pretty cool!

Re: Show HN: A JavaScript function that looks and behaves like a pipe operator

#94
post #32

Earlier quoted context omitted.

I agree with the author that it’s a little confusing, but that’s why I wouldn’t write code like that. const msg = capitalize(greeting) + “!”; const { status } = await send(msg); console.log(status); Now it’s perfectly readable, no weird shenanigans required.

But at what cost? You had to name two intermediate variables - and naming things is hard.

Code is read many more times than it is written. Put in the minute or two to devise good intermediate variable names, and that will pay back manyfold every time someone needs to read and understand it.

Re: Show HN: A JavaScript function that looks and behaves like a pipe operator

#95
post #86

I love it!! Innovative idea, love webdevs ranting in the comments too, how dare you threaten their precious abominations called JavaScript!?

Haha thanks! Yes haters gonna hate. If you like it, use it; if you don’t, simply don’t use it ;)

Re: Show HN: A JavaScript function that looks and behaves like a pipe operator

#96

>The following example code is a bit hard to read: >const { status } = await send(capitalize(greeting) + "!") >console.log(status) No it's not hard to read. >Make it less nested, more vertical, by using the V "pipe": >V( greeting, // initial value "hi" >V (capitalize), // custom function call "Hi" >V .concat("!"), // String method `concat` call "Hi!" >V (send), // custom async function call Promise { } >V .status, //…

Someone decided to create a solution and then started looking for problems that will fit it. Finding none, they invented one.

Re: Show HN: A JavaScript function that looks and behaves like a pipe operator

#97
post #60

Earlier quoted context omitted.

The strength of the pipeline operators comes when you have to do method chaining things like: const foo = capitalize(underline(reverse(exclaim(indent(value))))); I already forgot the amount of parentheses I needed to close with while typing that.

No worries your ide will help you for the parentheses.

IDEs and linters should not be a crutch methinks because not everyone uses the same IDE or text editor. Either way, it will still be awkward to read.

Better that you either avoid that pattern or at least indent it in such a way that its not so visually confusing. Or yknow use a pipe operator.

Re: Show HN: A JavaScript function that looks and behaves like a pipe operator

#98
post #32

The following example code is a bit hard to read: const { status } = await send(capitalize(greeting) + "!") console.log(status) I disagree, I find this example code very easy to read because it reads like idiomatic Javascript. Unlike this library.

I agree with the author that it’s a little confusing, but that’s why I wouldn’t write code like that. const msg = capitalize(greeting) + “!”; const { status } = await send(msg); console.log(status); Now it’s perfectly readable, no weird shenanigans required.

This is clean JavaScript syntax in my opinion and should be what people strive for. It's perfectly readable, it's faster, it does async correctly without any unnecessary computation, can be typed and will have a normal stack trace. Piping is cool when done right, but can introduce complexity fast. Elixir is a good example where it works wonderfully.

Re: Show HN: A JavaScript function that looks and behaves like a pipe operator

#99

Earlier quoted context omitted.

Unfortunately I’m not getting satire vibes from that blurb. I’m only more scared for JavaScript. I love JavaScript but this pipe thing is horrific.

Tell that to Unix/FP lovers.

hahaha i mean this implementation. piping things in the shell is great

Re: Show HN: A JavaScript function that looks and behaves like a pipe operator

#100

Earlier quoted context omitted.

Is functional programming a joke? YMMV...

I don't think the first example is less pure than the second, what makes you think it is?

Purely functional programming is a subset of functional programming (see F# for instance). I was referring to the pipe operator syntax common to many functional programming languages like Haskell, F#, OCaml, Elixir, Elm and so on...
Post reply on HN