4 ms·
First example doesn't work though: const greeting = pipe('hello') | upper | ex('!!!') await greeting.run() // → "HELLO!!!" If you look
by Ciantic 1y ago
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.
- byteknight 1y agoSeems similar to the problem encountered when making the stupid idea PyNQ: https://github.com/IAmStoxe/PyNQ https://github.com/IAmStoxe/PyNQ
- md224 1y agoI suspect this was written with an LLM and the author didn't actually verify that the examples in the README worked.
- deleted 1y ago[deleted]
- dymk 1y agoRecently, 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 to the repo's github pages) to see examples, but I think this is a reasonable tradeoff.
- Thom2000 1y agoFWIW it's possible to run readme examples automatically add part of tests: https://github.com/parallaxsecond/rust-cryptoki/blob/main/cryptoki/src/lib.rs#L3 https://github.com/parallaxsecond/rust-cryptoki/blob/main/cr...
- urvader 1y agoI wrote this with an LLM but manually changed the README. Thanks for pointing this out, it is now updated.
- nticompass 1y agoI was playing with it, and you can do this, which looks a little better. const greeting = pipe('hello'); greeting | upper | ex('!!!'); await greeting.run(); // → "HELLO!!!" Since it uses the "Symbol.toPrimitive" method, you can use any operator (not just "bitwise OR" (|)). const greeting = pipe('hello'); greeting / upper * ex('!!!'); await greeting.run(); // → "HELLO!!!"
- urvader 1y agoThanks for pointing this out, I updated the examples now to this syntax.
- hinkley 1y agoThat’s not better because it implies these are all destructive function calls. Mutating your inputs is not functional programming. And pipes are effectively compact list comprehensions. Comprehensions without FP is Frankensteinian.
- hinkley 1y agoThat is a big enough DX problem that I would veto using this on a project. You’ve implied what I’ll state clearly: Pipes are for composing transformations, one per line, so that reading comprehension doesn’t nosedive too fast with accumulation of subsequent operations. Chaining on the same line is shit for readying and worst for git merges and PR reviews.
- deleted 1y ago[deleted]