Skip to content

Instantly share code, notes, and snippets.

@danielpetrov
Created January 17, 2017 09:59
Show Gist options
  • Select an option

  • Save danielpetrov/c843dc4fca62adc0d764d189892f99f5 to your computer and use it in GitHub Desktop.

Select an option

Save danielpetrov/c843dc4fca62adc0d764d189892f99f5 to your computer and use it in GitHub Desktop.
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