Live data from Hacker News

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

github.com

71–80 of 148 posts

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

#72
post #22

Earlier quoted context omitted.

The difference is that they want to turn a = d(c(b,7)) into a = b |> c(%,7) |> d(%) and I would like to see it turn into a = b,7 ~> c ~> d

Does JS have a splat operator? So: a = (b, 7) |> c(*%) |> d(%) Too much operator soup I guess.

Yeah, it is the ellipsis:

  a = b |> c(...%, 7) |> d(%)
Spaciousness helps here a bit, but still way too many syntax, I agree.

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

#74

I've used the Remeda package to preserve type information in pipes in Typescript: https://remedajs.com/ . There may be better implementations (fp-ts?), but I like Remeda's docs.

Thanks for linking Remeda! I also dislike the docs for fp-ts and that's killed adoption.

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

#75
post #40

Earlier quoted context omitted.

In this case the variable is the documentation of the code. You don't have to write something like "this is the message", you can see it.

What if it isn't a message? What if "msg" is already used for another variable?

`greetingMsg`? `greeting`? Naming the other one differently? Splitting the work done with that message and the work done with this message into their own functions?

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

#76

I can see this being useful but boy does it look ugly

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

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

#77
>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,       // automatic promise chaining + getting property  Promise {200}
  >V (console.log), // automatic promise chaining + global function call  logs 200 )
This cursed abomination is a joke isn't it?

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

#78

Earlier quoted context omitted.

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

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

We should be cautious about syntaxes that force us to allocate names. Sometimes.

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

#79
post #63

Reminds me of something I tried hacking together in python for fun from functools import partial class Pipeable: def __init__(self, fn): self.fn = fn def __ror__(self, lhs): return self.fn(lhs) def pipeable(fn): return lambda *args: Pipeable(partial(fn, *args)) filter = pipeable(filter) map = pipeable(map) list = pipeable(list) sum = pipeable(sum) min = pipeable(min) max = pipeable(max) any = pipeable(any) # Usage: r…

Ooh, I love this style of operator overload. Really clever.

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

#80

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 .

Is it? I think it's an implementation of the pipe operator rather than satire of it. Javascript doesn't provide the flexibility to extend the language with pipe operators (though tools like Babel will let you use the pipe operator already).

The clunky syntax removes all the benefits of the pipe operator. The entire thing is syntactic sugar, wrapping it in confusing functions just breaks the entire concept.

Post reply on HN