Skip to content

Instantly share code, notes, and snippets.

@johnhunter johnhunter/monad.js

Created Nov 7, 2013
What would you like to do?
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');
You can’t perform that action at this time.