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