Live data from Hacker News

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

github.com

101–110 of 148 posts

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

#101

Earlier quoted context omitted.

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...

Ok, you aren't arguing for 'pure' functional programming, but I think you have sidestepped my question, then:

The pipe operator is just one part of functional programming, composing and applying functions

`f(g(x))` is still functional, and I would argue it exactly what is happening in the first example.

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

#102
I created something similar for Tcl called pipethread [0] [1], but using something closer to the pipe syntax.

It has a lot of interesting features that would be difficult to replicate in JavaScript.

[0] https://wiki.tcl-lang.org/page/pipethread

[1] http://www.rkeene.org/tmp/pipethread-presentation-withnotes....

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

#103

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.

Right - because this library tries to fake a new language syntax feature without the actual support for it, it ends up being the worst of both worlds. Even ignoring the lines-of-code explosion, the non-standard use of parens/spacing makes it incredible difficult for me to parse. Props to the author for trying out something neat, but this is probably a bit to clever for my liking.

Just an FYI to folks, there has been a proposal to add pipes to JavaScript for a few years:

https://github.com/tc39/proposal-pipeline-operator

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

#105

Earlier quoted context omitted.

Prepending doesn’t help its case. I like the R convention of pipe at end of line, indent on lines 2+

Interesting! I usually do exactly the opposite when I can. E. g. in Bash I would rather do this: curl -fsSL https://download.docker.com/linux/ubuntu/gpg \ | gpg --dearmor \ | sudo tee /etc/apt/keyrings/docker.gpg \ > /dev/null

I suppose it's just what you're used to, of course.

However, in R, you don't need to trailing slashes on new lines. Plus, their pipes are hideous: %>% or now |>.

I do kind of like how the pipe delimiter looks on the left.

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

#106
post #11

Honestly, if prototype pollution was not a problem for optimization and other things I’d just toss a Object.prototype.pipeTo = function(f) { return f(this) }; And call it a day. It does about 80% of what a pipe macro would do, has instant compatibility with other prototype methods and leads to very simple types. The only issue is that you have to define lambdas to call multivariable functions. D has got this very, ve…

Exactly right!

https://github.com/mlajtos/es1995

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

#107

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.

If you read all the text, it seems like the entire repo is intended to be a satire on https://github.com/tc39/proposal-pipeline-operator .

So what exactly does it satirize?

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

#108

Earlier quoted context omitted.

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...

Ok, you aren't arguing for 'pure' functional programming, but I think you have sidestepped my question, then: The pipe operator is just one part of functional programming, composing and applying functions `f(g(x))` is still functional, and I would argue it exactly what is happening in the first example.

Nobody said the first example _isn't_ functional. The point is that function composition f(g(x)) is very common in a functional paradigm and many functional languages have added a Pipeline operator as syntactic sugar for this use case.

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

#110
post #27

I like goofy projects like this one but I think that if you insist on having calls there, then might as well make it more explicit with something like this: pipe((p) => ([ "hello", p.concat("!"), send, p.status, console.log ])); Where `p` stands for Proxy to the previous result. Under the hood it would just return an object describing the name of the called method and arguments passed. The pipe function would then it…

Here's a very basic implementation:

https://github.com/Tade0/pipe/blob/master/pipe-sync.js

Post reply on HN