What is and what is a monad?

12
  

I remember that at university I was explained what a monad , but time passed and I no longer know what it is. This is also due to the little contact I have with functional languages.

In programming, what is a monad ? What is its usefulness?

Can you give an example of a usage?

    
asked by anonymous 05.12.2016 / 13:15

1 answer

1

A Monad, in short, is simply a wrapper of any value.

Example:

function Maybe(value) {
  return {
    value: value
  }
}

const maybeString = Maybe('Novo Post No Blog')
maybeString.value // 'Novo Post No Blog'

const maybeNull = Maybe(null)
maybeNull.value // null
    
05.12.2016 / 13:29