Monads
Learn the formal definition of monads with the corresponding PHP code.
We'll cover the following...
Definition of monads
Monads are versatile functors built on top of polymorphic concepts, and complete a genealogy of type-classes. The versatility of monads is such that they allow programmers to write context-rich maps. With a monad, it is possible to compose branching logic (like that seen in the Maybe and Either sum types), computations (I/O-bound and CPU-bound code), and effects (the integer residue of a print call for instance). Like functors, monads follow the laws of the calculus from which they originate. The cornerstone monad principles are the mathematical forms of associativity, left-identity, and right-identity. They are as follows:
Law | Mathematical Representation |
---|---|
Left identity |