The Maybe and Either Monads
Learn about different types of monads in functional programming.
We'll cover the following...
Sum types are especially useful for adding flow control to error handling. In Maybe and Either sum types, we have two monads that are presentable as type-classes in PHP. They’re versatile functors that can carry values in their objects to which computations/functions can be bound through functor methods. Their suitability for cleaner error handling is such that they encapsulate two subtypes for success and error values that are transformable using the bind
and map
method operations.
The Maybe monad
The Maybe monad is a sum type that stands out because a value defined or used within its context is either Just
or Nothing
(Some
or Nothing
in other domains). This duality means that, depending on the ...