Explaining Monads like a Normal Person
Programming on main, yeah. This is a blogging site. Skip if you aren't into this.
If you look up the Wikipedia article on Monads, or any kind of explanation, they always overcomplicate the hell out of it.
"monads are a way to structure computations as a sequence of steps, where each step not only produces a value but also some extra information about the-"
what the hell are you talking about
You wanna know what monads are? They're actually stupid simple.
Any "object" is a combination of behavior and state. For example, a struct both holds data and has methods that act on it:
A monad is just an object that lets you give it behavior at runtime:
That's literally it. You give it a function to do, and it does it on the value it holds.
You'll often see these used for optional values - things that may or may not be what you expect at runtime:
"Optional<T>" (the value T could be present or absent)
"Either<X, Y>" (the value is either an X or a Y, but we don't know which yet)
You define behavior to be executed only if it's the right type, and it does nothing if it's the wrong type, all without you having to check.
You just tell it to do something regardless and it handles it:
It really is that simple. I hate how much bs people throw into it trying to explain these things.















