Hacker News new | ask | show | jobs
by aksx 2669 days ago
that's a good generalization but has one small thing missing.

The main benefit of a monad is composition. It allows a programmer to chain computation and put some logic in the chaining. It's the difference between

    f(g(h(x)))
and

    h(x).then(g).then(f)
the '.then' method has some inbuilt logic, for to ability to add that logic we 'embellish' the return type of h (or put it in a container like Promise<>).

To equate it to java's Optionals, the flatMap is a good example, it takes an optional and applies some logic and decides to call the second function.