Live data from Hacker News

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

github.com

1–10 of 148 posts

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

#5
Its all a problem of formatting, for me this is simple to read.

  const { status } = await
    send(
      capitalize(greeting)
      + "!"
    )
But i would not concat things in a method call, bad style.

  const message = capitalize(greeting) + "!"
  const { status } = await send(message)
The example from the page is a little bit too simple.

With complex operations a pipe-method would make more sense.

But i will wait for the native pipeline-operator https://github.com/tc39/proposal-pipeline-operator> instead using now a function.

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

#6

  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.

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

#7

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, I really don't understand this library

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

#9
I had a hard time reading the example until I applied the "normal" JS indentation, that would also likely be applied by Prettier and the likes.

  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
  )

It's certainly a nice usage of JavaScript's Proxy object and the resulting syntax is simple to grasp. Also glad to see the TS definitions in there. Well done!
Post reply on HN