Skip to content

Instantly share code, notes, and snippets.

@danielpetrov
Last active January 17, 2017 09:50
Show Gist options
  • Save danielpetrov/7c39de3c3e0d4c0b80e667a1832a061d to your computer and use it in GitHub Desktop.
Save danielpetrov/7c39de3c3e0d4c0b80e667a1832a061d to your computer and use it in GitHub Desktop.
var Container = function(x) {
this.value = x
}
var Functor = function(x) {
this.value = x
}
Functor.prototype.map = function(f) {
return new Container(f(this.__value)))
}
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