UNPKG

@onrails/result

Version:

Tagged Result / ResultAsync for railway-oriented TypeScript — pure tagged unions, neverthrow-shaped compat shim, FL-friendly

40 lines (37 loc) 726 B
'use strict'; // src/internal/dual.ts var err = (error) => ({ _tag: "Err", error }); var isErr = (result) => result._tag === "Err"; // src/try-gen.ts var ErrSignal = class { constructor(error) { this.error = error; } error; _tag = "ErrSignal"; }; var yieldResult = (result) => { if (isErr(result)) { throw new ErrSignal(result.error); } return result.value; }; var $ = yieldResult; var tryGen = (fn) => { try { return fn(); } catch (error) { if (error instanceof ErrSignal) { return err(error.error); } throw error; } }; exports.$ = $; exports.tryGen = tryGen; exports.yieldResult = yieldResult; //# sourceMappingURL=try-gen.cjs.map //# sourceMappingURL=try-gen.cjs.map