Create a gist now

Instantly share code, notes, and snippets.

Monad in Javascript
From Doug Crockford's talk 'Monads and Gonads'
Doug calls this a Macroid - a JavaScript version of a macro.
Its purpose is to create the monad unit function for a specific monad type
function MONAD (){
return function unit (value) {
var monad = Object.create(null);
monad.bind = function (func) {
return func(value);
return monad;
// create an identity monad
var identity = MONAD();
var monad = identity('Hello World');