@consolidados/results
Version:
Result types, ease and simple
27 lines (25 loc) • 843 B
JavaScript
;
// src/helpers/match.ts
function match(matcher, cases) {
if ("isOk" in matcher && matcher.isOk()) {
if (!cases.Ok) throw new Error("Missing case for Ok");
return cases.Ok(matcher.unwrap());
}
if ("isErr" in matcher && matcher.isErr()) {
if (!cases.Err) throw new Error("Missing case for Err");
return cases.Err(matcher.unwrapErr());
}
if ("isSome" in matcher && matcher.isSome()) {
if (!cases.Some) throw new Error("Missing case for Some");
return cases.Some(matcher.unwrap());
}
if ("isNone" in matcher && matcher.isNone()) {
if (!cases.None) throw new Error("Missing case for None");
return cases.None();
}
throw new Error("Invalid matcher or missing case");
}
global.match = match;
exports.match = match;
//# sourceMappingURL=match.cjs.map
//# sourceMappingURL=match.cjs.map