
TypeScript 4 Design Patterns and Best Practices
By :

A monad is an object that adheres to specific rules and laws and allows the composition of other types of monads using a common API.
You can think of the monad as an object that exposes a set of methods that make it easier to compose other monads of the same type together. Usually, an object called a monad needs to follow what we call monadic laws, which we will explain later.
The main function of a monad is to allow the chaining of operations of any type of function, examine its value, extract it if it's a composite, perform the operation, and enclose it again in the same nested object.
It's quite hard to understand what a monad really is because it assumes you already know what a monad is, so we are going to explain what problems they solve. Hopefully, you will understand their value and how monads can be used to compose programs of any type.
We'll take the example function composition that we described previously. For two functions...