>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...
Show HN: A JavaScript function that looks and behaves like a pipe operator
91–100 of 148 posts
Re: Show HN: A JavaScript function that looks and behaves like a pipe operator
#92Earlier 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…
Re: Show HN: A JavaScript function that looks and behaves like a pipe operator
#93Earlier 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.
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
#94Earlier 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.
Re: Show HN: A JavaScript function that looks and behaves like a pipe operator
#95I love it!! Innovative idea, love webdevs ranting in the comments too, how dare you threaten their precious abominations called JavaScript!?
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, //…
Re: Show HN: A JavaScript function that looks and behaves like a pipe operator
#97Earlier 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.
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
#98The 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.
Re: Show HN: A JavaScript function that looks and behaves like a pipe operator
#99Re: Show HN: A JavaScript function that looks and behaves like a pipe operator
#100Earlier 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?