Skip to content

Instantly share code, notes, and snippets.

@savelichalex
Created September 6, 2016 06:49
Show Gist options
  • Save savelichalex/0830ef0cb5bfdb01912c344dea37dab4 to your computer and use it in GitHub Desktop.
Save savelichalex/0830ef0cb5bfdb01912c344dea37dab4 to your computer and use it in GitHub Desktop.
class Either<T> {
right: ?T
left: ?string
constructor(right: ?T, left: ?string) {
this.right = right;
this.left = left;
}
static right<U>(data: U) {
return new Either(data, null);
}
static left(error) {
return new Either(null, error);
}
then(bind) {
return this.left != null ?
Either.left(this.left) :
bind(this.right);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment