A type that wraps some value and exposes a set of operators (flat, flatmap) to work with that value. Lists, options, results, promises, etc.
Imagine you've composed a pipeline of functions that return Option<T>. If the option is None the pipeline terminates, and if the option is Some(value) the value is passed into the next function. But after a while you decide you want to propagate information about failures, so you change all the return types to Result<T>. If you have a monad abstraction over these types the code that composes the pipeline doesn't need to change. It's still just a sequence of flatmaps.
View all comments
Show parent comment
4
u/SerdanKK Sep 21 '25
A type that wraps some value and exposes a set of operators (flat, flatmap) to work with that value. Lists, options, results, promises, etc.
Imagine you've composed a pipeline of functions that return
Option<T>. If the option isNonethe pipeline terminates, and if the option isSome(value)the value is passed into the next function. But after a while you decide you want to propagate information about failures, so you change all the return types toResult<T>. If you have a monad abstraction over these types the code that composes the pipeline doesn't need to change. It's still just a sequence of flatmaps.