Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


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 to the repo's github pages) to see examples, but I think this is a reasonable tradeoff.


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


I wrote this with an LLM but manually changed the README. Thanks for pointing this out, it is now updated.


I 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!!!"


That’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.


Thanks for pointing this out, I updated the examples now to this syntax.


Seems similar to the problem encountered when making the stupid idea PyNQ:

https://github.com/IAmStoxe/PyNQ


That 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: