Show HN: A JavaScript function that looks and behaves like a pipe operator
71–80 of 148 posts
Re: Show HN: A JavaScript function that looks and behaves like a pipe operator
#72Earlier 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.
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
#73bravo! loved it. I am so eagerly waiting for pipe function. your take on it meanwhile looks good to me.
Re: Show HN: A JavaScript function that looks and behaves like a pipe operator
#74I'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.
Re: Show HN: A JavaScript function that looks and behaves like a pipe operator
#75Earlier 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?
Re: Show HN: A JavaScript function that looks and behaves like a pipe operator
#76I 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+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
| gpg --dearmor \
| sudo tee /etc/apt/keyrings/docker.gpg \
> /dev/nullRe: Show HN: A JavaScript function that looks and behaves like a pipe operator
#77 >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
#78Earlier 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.
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
#79Reminds 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…
Re: Show HN: A JavaScript function that looks and behaves like a pipe operator
#80The 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 .
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.