jargon

Comparison

MonadvsOption type

Monad

you had a value in a box, a function returning another box, and needed one box out rather than a box in a box.

A type that wraps a value along with an operation for chaining functions that themselves return the wrapped type — flatMap, bind, then — obeying a couple of laws. Promises, optionals, results and streams are all instances, which is why chaining them all feels the same. The useful, honest version for an interview is that it is a shared interface for sequencing computations in a context, not a metaphor about burritos.

Full entry →

Option type

the type says the value might not be there, so you cannot use it without saying what happens when it is not.

A type with two cases — a value or nothing — making absence explicit and forcing the caller to handle it. It is the type-system answer to the null reference, and it differs from a null object in being visible rather than invisible: an option makes the caller decide, a null object silently does nothing. Its cost is ceremony in a language without pattern matching or a decent option API.

Full entry →

Related comparisons