Hacker News new | ask | show | jobs
by nticompass 260 days ago
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!!!"
2 comments

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.