Maybe monad in Javascript
In the same vein as my previous post on Functional Pattern Matching, I’ve knocked up a quick and dirty Maybe monad, based on Scala’s Option class.
This encapsulates testing for null (or undefined), so that you can do something like this incredibly contrived example:
This will only print out the title of the book if one was found (assuming db.query returns null if none was found).