Created
January 13, 2013 12:38
-
-
Save pazworld/4523875 to your computer and use it in GitHub Desktop.
Maybe monad written in JavaScript.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Maybe monad. | |
var Maybe = { | |
Just: function(a) { | |
this.value = a; | |
this.bind = function(f) { return f(this.value); }; | |
}, | |
None: function() { | |
this.bind = function() { return this; }; | |
}, | |
return: function(a) { return new Maybe.Just(a); } | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment