Created
February 1, 2014 07:49
-
-
Save dreamineering/8749383 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
| Maybe = function(value) { | |
| var Nothing = { | |
| bind: function(fn) { | |
| return this; | |
| }, | |
| isNothing: function() { | |
| return true; | |
| }, | |
| val: function() { | |
| throw new Error("cannot call val() nothing"); | |
| }, | |
| maybe: function(def, fn) { | |
| return def; | |
| } | |
| }; | |
| var Something = function(value) { | |
| return { | |
| bind: function(fn) { | |
| return Maybe(fn.call(this, value)); | |
| }, | |
| isNothing: function() { | |
| return false; | |
| }, | |
| val: function() { | |
| return value; | |
| }, | |
| maybe: function(def, fn) { | |
| return fn.call(this, value); | |
| } | |
| }; | |
| }; | |
| if (typeof value === 'undefined' || value === null) | |
| return Nothing; | |
| return Something(value); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment