Skip to content

Instantly share code, notes, and snippets.

@JamieMason
Created December 8, 2017 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamieMason/aa5d5ad63f888c7b9a9e07acced3d37c to your computer and use it in GitHub Desktop.
Save JamieMason/aa5d5ad63f888c7b9a9e07acced3d37c to your computer and use it in GitHub Desktop.
function Maybe(x) {
if (this instanceof Maybe === false) {
return new Maybe(x);
}
this.value = x;
}
Maybe.prototype.map = fn => (this.value == null ? this : new Maybe(fn(this.value)));
function Either(left, right) {
if (this instanceof Either === false) {
return new Either(left, right);
}
this.left = left;
this.right = right;
}
Either.prototype.map = f => (this.right == null ? this : new Either(this.left, f(this.right)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment