Skip to content

Instantly share code, notes, and snippets.

@jerolan
Last active April 27, 2021 15:30
Show Gist options
  • Save jerolan/1c6e4631fa17ae3654483c89f0c96c9f to your computer and use it in GitHub Desktop.
Save jerolan/1c6e4631fa17ae3654483c89f0c96c9f to your computer and use it in GitHub Desktop.
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