jargon

Comparison

MonadvsRailway-oriented programming

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 →

Railway-oriented programming

each step either continues the happy path or diverts to the failure track, and no step checks whether the last one worked.

Composing a sequence of operations that each return a result type, so a failure at any step short-circuits the rest without an explicit check between them. The two-rail metaphor is Scott Wlaschin's and it is what makes result types practical instead of tedious. The mechanism underneath is a monadic bind, which is worth knowing but not worth leading with when explaining it to a team.

Full entry →

Related comparisons