Created
January 17, 2017 09:59
-
-
Save danielpetrov/c843dc4fca62adc0d764d189892f99f5 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
| var Monad = function(x) { | |
| this.value = x | |
| } | |
| Monad.prototype.of = function(x) { | |
| return new Container(x) | |
| } | |
| Monad.prototype.isNothing = function() { | |
| return (this.__value === null || this.__value === undefined) | |
| } | |
| Monad.prototype.map = function(f) { | |
| return this.isNothing() ? new Maybe(null) : Maybe.of(f(this.__value)) | |
| } | |
| Monad.prototype.join = function() { | |
| return this.isNothing() ? Monad.of(null) : this.__value | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment