Hacker News new | ask | show | jobs
by Veedrac 3206 days ago
> So, is there a simple and universal way to compose these functions?

proceeds to add layers of complexity

Why not just write a function to compose them? Argue against the competition, not strawmen.

1 comments

Most code that is written has effects - null returns, error returns, exceptions, IO, etc., etc. We can write a custom function to compose every pair of functions we write, but some clever people figured out there were patterns to this madness - map, flatMap, lift, return, etc. - and it's far more efficient to write those patterns once and reuse them.

Essentially, it's DRY at a higher level of abstraction.

You still have to write each composition operator separately; writing the code to compose null returns doesn't give you the code to compose IO. Only difference is whether they have separate names.
That's not the only difference. You get to reuse any code written using only those names (that interface).