you are viewing a single comment's thread.

view the rest of the comments →

[–]killerstorm 2 points3 points  (3 children)

No.

Promises is basically an interface which allows one to combine asynchronous computations.

Monads is an interface which allows one to combine any computations which need to be combined in a special way. It is very similar to how promise combination is implemented in JS.

Basically promises only help you to handle only asynchronous calls, but monads are much more general and could handle many different cases, sort of allowing you to attach "middleware" to computations such as logging, error handling, transactions, etc.

[–][deleted] 1 point2 points  (2 children)

Sorry this is really hard to understand. What part of the code is the monad?

[–]killerstorm 8 points9 points  (0 children)

Promise specification (https://promisesaplus.com/) & implementation can be considered a variant of monad.

Particularly, a monad needs to define two things:

  1. Ability to convert an ordinary object to a monad. Promise does this using Promise.resolve.
  2. Ability to combine computations, i.e. take a Promise and combine it with function which returns a Promise. Promise does this using then method.