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, very right.Show HN: A JavaScript function that looks and behaves like a pipe operator
11–20 of 148 posts
Re: Show HN: A JavaScript function that looks and behaves like a pipe operator
#12Still 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
#13The 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.
Some kind of pipe operator can make this easier to read by arranging the operations linearly from left to right (or top to bottom as is the case with this library). Although in my opinion this library has its own readability issues.
Re: Show HN: A JavaScript function that looks and behaves like a pipe operator
#14 status = greeting+"!" ~> capitalize ~> send
This would need 2 changes to JS:1: ~> being a pipe operator
2: Calling an async function from within an async function implies await
Without 2, it would look like this:
status = greeting+"!" ~> capitalize ~> await sendRe: Show HN: A JavaScript function that looks and behaves like a pipe operator
#15This would be my preferred syntax: status = greeting+"!" ~> capitalize ~> send This would need 2 changes to JS: 1: ~> being a pipe operator 2: Calling an async function from within an async function implies await Without 2, it would look like this: status = greeting+"!" ~> capitalize ~> await send
Re: Show HN: A JavaScript function that looks and behaves like a pipe operator
#16This would be my preferred syntax: status = greeting+"!" ~> capitalize ~> send This would need 2 changes to JS: 1: ~> being a pipe operator 2: Calling an async function from within an async function implies await Without 2, it would look like this: status = greeting+"!" ~> capitalize ~> await send
Re: Show HN: A JavaScript function that looks and behaves like a pipe operator
#17The 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.
Props to the author for trying out something neat, but this is probably a bit to clever for my liking.
Re: Show HN: A JavaScript function that looks and behaves like a pipe operator
#18Its 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-…
const { status } = await send(`${capitalize(greeting)}!`)
console.log(status)
It does reduce the number of discrete operations to make the pipe example look more impressive, though.
Re: Show HN: A JavaScript function that looks and behaves like a pipe operator
#19Re: Show HN: A JavaScript function that looks and behaves like a pipe operator
#20Honestly, 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…