Most people start to grasp monads with the so called “wrapped metaphor”. It works well with
Either a and
Maybe, but it can become a problem with other monads, like
IO for instance. If you have a wrapped value, why wouldn’t you be able to extract it?
A more general intuition could be “computational context which encodes sequentiality”… which doesn’t make sense until it does.
I’ve found the best way to get rid of the intuition of wrapped values is by looking at how the continuation monad works. After all, it’s The Mother of all Monads.
A few days ago, I came upon an article about Monads in PHP by Anthony Ferrara, which was quite interesting (I have a sweet spot for monads in php). Unfortunately, the implementation proposed in the article had two issues:
- the monad interface has an
Please note you need a basic understanding of monads to play with it. Else, it could be a bit daunting.
Implement the continuation monad in JS