Monads in PHP
Based on the work
of Tom Stuart
Monads are an
ordinary data type...
...you are already using them.
What is a Stack?
Operations and rules
We can implement however we like...
We can define
new operations...
Stack is a specification
Common interface
Derive new functionality
What is a Collection?
Operations and rules
We can (again) define
more operations...
Collection is a specification
Common interface
Derive new functionality
What are Stack and Collection?
Abstract data types
A little code to
prove the point...
Maybe, Many, Fluent → Monads
Monads are an abstract data type
Operations and rules
Where are we
already using this?
Monads are good
for repeated operations
Maybe →
repeated null-checking
Many →
repeated flatMap
Fluent →
repeated configuration
Promises →
repeated operations
on future values
jQuery →
repeated filtering and
mutating of elements
Query Builder →
repeated SQL building
When you see yourself repeating operations...
...think of how it could be a Monad.
And, tell your friends!