News for hackers. Stuff that matters.
Re:Monads you can understand (2015) by BerislavLopac on Sunday March 03, 2019 @06:41AM (#19293996)
As a programmer with 20+ years of experience with various non-functional languages I have been trying to understand monads, and the main problem has always been that most of the explanations are similar long-winded diatribes making things even more complicated by using terminology that needs further explaining (rarely given) itself.

After many such articles, my main -- very generalised, I'm aware -- conclusion is that monad is basically a programming construct that a) contains some data and b) has some associated operations to be performed on that data.

Basically, a monad is an object.

Re:Monads you can understand (2015) by aksx on Sunday March 03, 2019 @01:26PM (#19295917)
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.