Message from JavaScript discussions

December 2017

— And u defined with the same name ... So still I haven't gotten iy

— 

A monad is a value / object / class instance (depending on language) that satisfies a few conditions:

Has a bind method (a callback that gets called with the encapsulated value)

A unit function exists, to encapsulate a value within a monad

Promises are JavaScript examples of monads, a value can be encapsulated (unit) with Promise.resolve(value), and promise objects have a bind method (.then())

— So any function that returns a Promise (or any other monad implemntation) is a monadic function

— Also, the bind method should return a new monad, with the transformed value

— I guess a function that gets passed into a monad could be considered monadic, but really that could be any function

Message permanent page

— For instance:

MyMonad(4).bind(addOne) would return MyMonad(5) (aka a monad that encapsulates the value 5)

Message permanent page

— Ok .
. that was awesome and brief ... Thanks TRGWII

— No problem :)

— And the REASON for wrapping values like this is to encapsulate a chain of functions, and to prevent impure values to enter a pure functional environment

Message permanent page

— There is no way to get the encapsulated value out of a monad in a pure functional environment

— What are its benefits ... Why do I need monads

— It's the only way to do IO and impure operations if you write pure functional code