Last active
March 2, 2017 06:33
-
-
Save ccorcos/0e42f1ea0cf9a24c306319ee7355391c 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 Result { | |
constructor(value, rest) { | |
this.value = value | |
this.rest = rest | |
} | |
} | |
class Success extends Result { | |
map(fn) { | |
return new Success(fn(this.value), this.rest) | |
} | |
bimap(s, f) { | |
return new Success(s(this.value), this.rest) | |
} | |
chain(fn) { | |
return fn(this.value, this.rest) | |
} | |
fold(s, f) { | |
return s(this.value, this.rest) | |
} | |
} | |
class Failure extends Result { | |
map(fn) { | |
return this | |
} | |
bimap(s, f) { | |
return new Failure(f(this.value), this.rest) | |
} | |
chain(fn) { | |
return this | |
} | |
fold(s, f) { | |
return f(this.value, this.rest) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment