DEV Community

Tom Sherman
Tom Sherman

Posted on • Originally published at github.com

Is a burrito a monad?

This post was originally posted on my blog.


As we all know, a monad is just a monoid in the category of endofunctors. This is intuitive to you and I, but what if you need to explain what a monad is in more practical terms. Well that's where the three laws of monads come in.

These three laws act as a test to tell if something is a monad - if that something passes the three laws, then it's a monad - simples.

Now to the main event, is a burrito monad? Well let's see if it obeys the three laws...

Left identity

Take your filling, put it in a burrito - toast it - take the filling back out - the filling is warm just as if you toasted the filling itself.

So the burrito passes the first law.

Right identity

Unwrap the burrito to get to the filling.

The burrito passes the second law.

Associativity

Putting hot sauce in your burrito and then toasting it is the same as toasting it and putting hot sauce in your burrito.

Thus the burrito passes the third law.

The burrito is a monad 🌯

Further reading

Burritos for the Hungry Mathematician by Ed Morehouse

Top comments (1)

Collapse
 
realtomaszkula profile image
Tomasz Kula

lmao