Created
January 17, 2013 01:33
-
-
Save dtchepak/4552765 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| exports.OptionMonad = { | |
| bind: function(f, m) { | |
| if (m.isEmpty) return m; | |
| else return f(m.value); | |
| }, | |
| unit: function(x) { return new exports.Option(x); }, | |
| } | |
| exports.Option = (function() { | |
| return function(x) { | |
| var is_empty = typeof x == 'undefined' || x == null | |
| return { value: x, isEmpty: is_empty, toString: function() { | |
| if (is_empty) return "{Empty}"; | |
| else return "{Just " + x + "}"; | |
| } }; | |
| }; | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment