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…
Working pipe operator today in pure JavaScript
101–109 of 109 posts
Re: Working pipe operator today in pure JavaScript
#102Earlier 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(...)`.
Re: Working pipe operator today in pure JavaScript
#103This 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.
Re: Working pipe operator today in pure JavaScript
#104I 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 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
#105Earlier 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.
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
#106Earlier 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".
https://metacpan.org/dist/perlsecret/view/lib/perlsecret.pod...
Re: Working pipe operator today in pure JavaScript
#107First 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.
Re: Working pipe operator today in pure JavaScript
#108Further proof that JavaScript accidentally became the new C++. “Aren’t you surprised that this syntax works?” is not praise for a language design.
Re: Working pipe operator today in pure JavaScript
#109I am wondering if it could be useful for libraries:
grid.columns.name.format(v => v | trim | truncate | bold)
form.fields.name.validate(v => v | trim | required | email)