Monad
ELI5 — The Vibe Check
A monad is a design pattern for chaining operations that have extra 'context' — like maybe-empty values, async results, or errors. Everyone who understands monads is contractually obligated to write a terrible tutorial about them. They're burritos. No wait, they're boxes. No, they're just flatMap.
Real Talk
A mathematical structure from category theory used in functional programming to sequence computations that involve context (optionality, errors, async, state). A monad is a type M
Show Me The Code
// Promise is a monad! .then() is bind/flatMap
fetch('/api/user')
.then(res => res.json()) // flatMap
.then(user => fetch(user.url)) // flatMap
.then(res => res.json()); // flatMap
When You'll Hear This
"Once you realize Promise.then is just monadic bind, everything clicks." / "You don't need to understand category theory to use monads — you already use them every day with Promises and arrays."
Related Terms
Functor
A functor is a box you can map over. Array? Functor. Optional? Functor. Promise? Functor.
Option Type
Option type is the type system's way of saying 'this might have a value, or it might be empty, and you MUST handle both cases.
Promise
A Promise is JavaScript's way of saying 'I'll give you a value eventually — it's not ready yet, but I promise.
Result Type
Result type is like a delivery that's either your package (Ok) or a note explaining why it failed (Err).