4 ms·
If you understand promises you pretty much understand monads already since promises are more or less a type of monad. Monads represent computation contexts. In
by knubie 5y ago
If you understand promises you pretty much understand monads already since promises are more or less a type of monad.
Monads represent computation contexts. In the case of promises, the computation is preformed in the context of a value that will be available some time in the future (or not at all in some cases).
my_promise.then(compute_result)
Another context could be a list, where the computation is performed on each value in the list
my_list.then(increment)
Or the context could be that the value is maybe null
maybe_string.then(uppercase)
How the computation is actually performed depends entirely on the monad. Usually .then is called .bind or .flat_map because it will automatically unwrap nested monads.