Skip to content

Instantly share code, notes, and snippets.

@jerolan
Last active April 27, 2021 15:30
Show Gist options
  • Select an option

  • Save jerolan/1c6e4631fa17ae3654483c89f0c96c9f to your computer and use it in GitHub Desktop.

Select an option

Save jerolan/1c6e4631fa17ae3654483c89f0c96c9f to your computer and use it in GitHub Desktop.
interface Success<a> {
kind: "success";
value: a;
}
interface Failure<e> {
kind: "failure";
error: e;
}
type Result<a, e> = Success<a> | Failure<e>;
const unit = <a>(a: a): Success<a> => ({ kind: "success", value: a });
const fail = <e>(e: e): Failure<e> => ({ kind: "failure", error: e });
function isSuccess(result: Result<any, any>): result is Success<any>{
return "value" in result;
}
function isError(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