Live data from Hacker News

Working pipe operator today in pure JavaScript

github.com

101–109 of 109 posts

Re: Working pipe operator today in pure JavaScript

#101
post #72
post #58

Earlier quoted context omitted.

I suspect this was written with an LLM and the author didn't actually verify that the examples in the README worked.

Recently, I ripped usage examples out of a rust project's README.md, and put them in doc comments. Almost all of them were broken due to small changes over time, and I never remembered to update the readme. `cargo test` runs doc comments like mini integration tests, so now the examples never rot. I wish more languages and tools had this feature. It means having to go to the linked docs (which are automatically pushed…

FWIW it's possible to run readme examples automatically add part of tests: https://github.com/parallaxsecond/rust-cryptoki/blob/main/cr...

Re: Working pipe operator today in pure JavaScript

#102
post #94

Earlier quoted context omitted.

I always thought JS map filter reduce felt quite nice, especially playing around with data in the REPL. Java maps with all the conversions back and forth to streams are clumsy.

Well in JS you have to convert to arrays instead. You can't do `document.querySelectorAll(...).map(...)`.

That's the DOM API, it's not part of the language! They had reasons for querySelectorAll not returning an array.

Re: Working pipe operator today in pure JavaScript

#103

This kind of stuff is why C++ developers has an almost overly allergic reaction to operator overloading.

C++ is the reason people have that reaction. The quintessential example in introductory texts for operator overloading is using bit-shift operators to output text. I mean, come on - if that’s your example, don’t complain when people follow suit and get it wrong.

While that operator is also used for bit-shift, it is not the bit-shift operator. It's not that the bit-shift operator is used for stream direction, it's that the same operator is used for both stream direction and bit-shifts. And which code is operating on both high-level abstract streams and bit-shifts at the same time.

Re: Working pipe operator today in pure JavaScript

#104

I love the idea! The creativity of (ab)using JavaScript type coersion is really neat. I did something similar using proxies to create a chainable API. https://dev.to/sethcalebweeks/fluent-api-for-piping-standalo... const shuffle = (arr) => arr.sort(() => Math.random() - 0.5); const zipWith = (a, b, fn) => a.slice(0, Math.min(a.length, b.length)).map((x, i) => fn(x, b[i])); const log = (arr) => { console.log(arr); ret…

In another comment, I mentioned a vanilla JavaScript function I published in 2024 called Chute. https://github.com/gregabbott/chute

In a similar way to the featured project, Chute also uses proxies to work like a pipeline operator. But like in your reply, Chute uses a dot-notation style to chain and send data through a mix of functions and methods.

You might like to see how Chute uses proxies, as it requires no `chainWith` or similar setup step before use. Without setup, Chute can send data through global or local, top-level or nested, native or custom, unary, curried or non-unary functions and methods. It gives non-unary functions the current data at a specific argument position by using a custom-nameable placeholder variable.

The Chute page describes some more of its features: https://gregabbott.pages.dev/chute/

Re: Working pipe operator today in pure JavaScript

#105

Earlier quoted context omitted.

There is more than one proposal; the F#-style one doesn't have the (weird) placeholder syntax. > You can still make it work by adding it to the prototype This is exactly what we want to avoid!

wrap the object? Why would you want to avoid that? It's controversial syntactic sugar. Enforcing a convention locally seems ideal.

1. Wrapping is more code than using a built-in pipe operator

2. There is a run-time overhead to wrapping

IMO a design goal of programming langauges should be for the most readable code to also be the most performant.

Language features tend to be controversial until they are mainstream.

Re: Working pipe operator today in pure JavaScript

#106
post #73
post #48

Earlier quoted context omitted.

Is there a language that can’t be contorted in surprising ways that I’m unaware of?

I think that depends on the person, the language, and how familiar they are with the language. Someone's "what the fuck" is another's "obviously it can do that".

Reminder that Perl exists:

https://metacpan.org/dist/perlsecret/view/lib/perlsecret.pod...

Re: Working pipe operator today in pure JavaScript

#107
post #10

First example doesn't work though: const greeting = pipe('hello') | upper | ex('!!!') await greeting.run() // → "HELLO!!!" If you look at the tests file, it needs to be written like this to make it work: let greeting; (greeting = pipe('hello')) | upper | ex('!!!'); await greeting.run(); Which is not anymore as ergonomic.

[deleted]
Post reply on HN