tstosc
Version:
A transpiler that convert TypeScript to SuperCollider's SCLang.
51 lines (48 loc) • 977 B
JavaScript
;
class Result {
whether_ok;
value;
static createOk(value) {
return new Result(true, value);
}
static createErr(value) {
return new Result(false, value);
}
static fromOk(result) {
if (result.isErr()) {
throw TypeError(`The result is Err.`);
}
return result;
}
static fromErr(result) {
if (result.isOk()) {
throw TypeError(`The result is Ok.`);
}
return result;
}
isOk() {
return this.whether_ok;
}
isErr() {
return !this.whether_ok;
}
unwrapOk() {
if (this.isErr()) {
throw TypeError(`The result is Err. Error is:
${JSON.stringify(this.unwrapErr())}`);
}
return this.value;
}
unwrapErr() {
if (this.isOk()) {
throw TypeError(`The result is Ok. Value is:
${JSON.stringify(this.unwrapOk())}`);
}
return this.value;
}
constructor(whether_ok, value) {
this.whether_ok = whether_ok;
this.value = value;
}
}
exports.Result = Result;