Created
September 6, 2016 06:49
-
-
Save savelichalex/0830ef0cb5bfdb01912c344dea37dab4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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