Skip to content

Instantly share code, notes, and snippets.

@pvpshoot
Created December 27, 2016 13:13
Show Gist options
  • Save pvpshoot/8a37daf5f317602554b2bef2fee4e13b to your computer and use it in GitHub Desktop.
Save pvpshoot/8a37daf5f317602554b2bef2fee4e13b to your computer and use it in GitHub Desktop.
class Maybe{
constructor(val){
this._value = val;
}
static of = x => new Maybe(x);
isNothing = () => (this.__value === null || this.__value === undefined);
map = () => this.isNothing() ? Maybe.of(null) : Maybe.of(f(this.__value));
ap = other => this.isNothing() ? Maybe.of(null) : other.map(this.__value);
join = () => this.isNothing() ? Maybe.of(null) : this.__value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment