Last active
April 27, 2021 15:30
-
-
Save jerolan/1c6e4631fa17ae3654483c89f0c96c9f 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
interface Success<a> { | |
value: a; | |
} | |
interface Failure<e> { | |
error: e; | |
} | |
type Result<a, e> = Success<a> | Failure<e>; | |
const unit = <a>(a: a): Success<a> => ({ value: a }); | |
const fail = <e>(e: e): Failure<e> => ({ error: e }); | |
function isSuccess(result: Result<any, any>): result is Success<any>{ | |
return "value" in result; | |
} | |
function isFailure(result: Result<any, any>): result is Failure<any>{ | |
return "error" in result; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment