Show HN: A JavaScript function that looks and behaves like a pipe operator
1–10 of 148 posts
Re: Show HN: A JavaScript function that looks and behaves like a pipe operator
#2Nice idea, there is also @babel/plugin-proposal-pipeline-operator which would require much less changes in the code if pipeline operator is introduced in the future. But it requires working babel.
Re: Show HN: A JavaScript function that looks and behaves like a pipe operator
#3)))))
Re: Show HN: A JavaScript function that looks and behaves like a pipe operator
#4Still prefer
pipe([
f,
g,
h,
])(123);
Or, you know, a functional language.Re: Show HN: A JavaScript function that looks and behaves like a pipe operator
#5Its 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
#7The 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
#8[deleted]
Re: Show HN: A JavaScript function that looks and behaves like a pipe operator
#9I 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!Re: Show HN: A JavaScript function that looks and behaves like a pipe operator
#10I can see this being useful but boy does it look ugly