unthrown 3.0.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +5 -7
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +5 -7
- package/dist/index.mjs.map +1 -1
- package/docs/index.md +61 -61
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -469,11 +469,7 @@ var AsyncRes = class AsyncRes {
|
|
|
469
469
|
return this.promise.then((r) => r.unwrapOr(fallback));
|
|
470
470
|
}
|
|
471
471
|
unwrapOrElse(f) {
|
|
472
|
-
return this.promise.then((r) =>
|
|
473
|
-
if (r.tag === "Ok") return r.value;
|
|
474
|
-
if (r.tag === "Defect") throw r.cause;
|
|
475
|
-
return f(r.error);
|
|
476
|
-
});
|
|
472
|
+
return this.promise.then((r) => r.unwrapOrElse(f));
|
|
477
473
|
}
|
|
478
474
|
getOrNull() {
|
|
479
475
|
return this.promise.then((r) => r.getOrNull());
|
|
@@ -735,8 +731,10 @@ function foldArray(results) {
|
|
|
735
731
|
let firstErr;
|
|
736
732
|
let firstDefect;
|
|
737
733
|
const values = [];
|
|
738
|
-
for (const r of results) if (r.tag === "Defect")
|
|
739
|
-
|
|
734
|
+
for (const r of results) if (r.tag === "Defect") {
|
|
735
|
+
firstDefect ??= r;
|
|
736
|
+
break;
|
|
737
|
+
} else if (r.tag === "Err") firstErr ??= r;
|
|
740
738
|
else values.push(r.value);
|
|
741
739
|
return firstDefect ?? firstErr ?? Ok(values);
|
|
742
740
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -191,7 +191,7 @@ type ResultMethods<T, E> = {
|
|
|
191
191
|
recoverDefect<U, E2>(f: (cause: unknown) => Result$1<U, E2>): Result$1<T | U, E | E2>;
|
|
192
192
|
/**
|
|
193
193
|
* Run a side effect on a present `Defect`'s cause (e.g. logging) and pass the
|
|
194
|
-
* `Defect` through unchanged.
|
|
194
|
+
* `Defect` through unchanged. If `f` throws, the throw becomes a new `Defect`.
|
|
195
195
|
*
|
|
196
196
|
* @param f - the side effect over the unknown cause.
|
|
197
197
|
*/
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/constructors.ts","../src/core.ts","../src/do.ts","../src/defect.ts","../src/interop.ts","../src/facade.ts","../src/tagged.ts"],"mappings":";;AAQA;;;;;KAAY,QAAA,oBAA4B,CAAA,GAAI,CAAA,CAAE,CAAA;;;;;;;AAAC;AAU/C;KAAY,KAAA,2BAAgC,QAAA,CAAS,IAAA,CAAK,CAAA,EAAG,CAAA,qBAAsB,CAAA,GAAI,CAAA;;;;;;;;;;KAW3E,aAAA;EAXgC;;;;;;;;AAA4C;EAqBtF,GAAA,IAAO,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,CAAA,GAAI,QAAA,CAAO,CAAA,EAAG,CAAA;EAVf;;;;;;;;;;EAqBvB,OAAA,QAAe,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,QAAA,CAAO,CAAA,EAAG,EAAA,IAAM,QAAA,CAAO,CAAA,EAAG,CAAA,GAAI,EAAA;EAAP;;;;;;;;EASvD,GAAA,CAAI,CAAA,GAAI,KAAA,EAAO,CAAA,YAAa,QAAA,CAAO,CAAA,EAAG,CAAA;EAiBO;;;;;;;;;;;;;;;;EAA7C,OAAA,KAAY,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,QAAA,UAAgB,EAAA,IAAM,QAAA,CAAO,CAAA,EAAG,CAAA,GAAI,EAAA;EAuB9D;;;;;;;;;;;;;;;;;;;EAHH,IAAA,0BACE,IAAA,EAAM,CAAA,EACN,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,QAAA,CAAO,CAAA,EAAG,EAAA,IAC1B,QAAA,CAAO,KAAA,CAAM,CAAA,EAAG,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;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/constructors.ts","../src/core.ts","../src/do.ts","../src/defect.ts","../src/interop.ts","../src/facade.ts","../src/tagged.ts"],"mappings":";;AAQA;;;;;KAAY,QAAA,oBAA4B,CAAA,GAAI,CAAA,CAAE,CAAA;;;;;;;AAAC;AAU/C;KAAY,KAAA,2BAAgC,QAAA,CAAS,IAAA,CAAK,CAAA,EAAG,CAAA,qBAAsB,CAAA,GAAI,CAAA;;;;;;;;;;KAW3E,aAAA;EAXgC;;;;;;;;AAA4C;EAqBtF,GAAA,IAAO,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,CAAA,GAAI,QAAA,CAAO,CAAA,EAAG,CAAA;EAVf;;;;;;;;;;EAqBvB,OAAA,QAAe,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,QAAA,CAAO,CAAA,EAAG,EAAA,IAAM,QAAA,CAAO,CAAA,EAAG,CAAA,GAAI,EAAA;EAAP;;;;;;;;EASvD,GAAA,CAAI,CAAA,GAAI,KAAA,EAAO,CAAA,YAAa,QAAA,CAAO,CAAA,EAAG,CAAA;EAiBO;;;;;;;;;;;;;;;;EAA7C,OAAA,KAAY,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,QAAA,UAAgB,EAAA,IAAM,QAAA,CAAO,CAAA,EAAG,CAAA,GAAI,EAAA;EAuB9D;;;;;;;;;;;;;;;;;;;EAHH,IAAA,0BACE,IAAA,EAAM,CAAA,EACN,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,QAAA,CAAO,CAAA,EAAG,EAAA,IAC1B,QAAA,CAAO,KAAA,CAAM,CAAA,EAAG,CAAA,EAAG,CAAA,GAAI,CAAA,GAAI,EAAA;EA6CQ;;;;;;;;;;;;;;EA9BtC,GAAA,sBAAyB,IAAA,EAAM,CAAA,EAAG,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,CAAA,GAAI,QAAA,CAAO,KAAA,CA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;EACrC,EAAA,GAAK,KAAA,EAAO,CAAA,KAAM,CAAA;EAClB,MAAA,GAAS,KAAA,cAAmB,CAAA;AAAA,YAClB,CAAA,YAAa,KAAA,EAAO,OAAA,CAAQ,CAAA;EAAK,IAAA,EAAM,CAAA;AAAA,OAAS,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAgC5C,SAAA;EAAyB,IAAA;AAAA,MACvC,MAAA,EAAQ,QAAA,CAAO,CAAA,EAAG,CAAA,GAClB,QAAA,EAAU,WAAA,CAAY,CAAA,EAAG,CAAA,EAAG,CAAA,IAC3B,CAAA;AAAA,iBACa,SAAA;EAAyB,IAAA;AAAA,MACvC,MAAA,EAAQ,aAAA,CAAY,CAAA,EAAG,CAAA,GACvB,QAAA,EAAU,WAAA,CAAY,CAAA,EAAG,CAAA,EAAG,CAAA,IAC3B,OAAA,CAAQ,CAAA"}
|
package/dist/index.d.mts
CHANGED
|
@@ -191,7 +191,7 @@ type ResultMethods<T, E> = {
|
|
|
191
191
|
recoverDefect<U, E2>(f: (cause: unknown) => Result$1<U, E2>): Result$1<T | U, E | E2>;
|
|
192
192
|
/**
|
|
193
193
|
* Run a side effect on a present `Defect`'s cause (e.g. logging) and pass the
|
|
194
|
-
* `Defect` through unchanged.
|
|
194
|
+
* `Defect` through unchanged. If `f` throws, the throw becomes a new `Defect`.
|
|
195
195
|
*
|
|
196
196
|
* @param f - the side effect over the unknown cause.
|
|
197
197
|
*/
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/constructors.ts","../src/core.ts","../src/do.ts","../src/defect.ts","../src/interop.ts","../src/facade.ts","../src/tagged.ts"],"mappings":";;AAQA;;;;;KAAY,QAAA,oBAA4B,CAAA,GAAI,CAAA,CAAE,CAAA;;;;;;;AAAC;AAU/C;KAAY,KAAA,2BAAgC,QAAA,CAAS,IAAA,CAAK,CAAA,EAAG,CAAA,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;;;iBKsCgB,aAAA,4BACd,EAAA,MAAQ,IAAA,EAAM,CAAA,KAAM,CAAA,EACpB,OAAA,GAAU,KAAA,WAAgB,MAAA,GAAS,KAAA,cAAmB,MAAA,KAAW,CAAA,OAC5D,IAAA,EAAM,CAAA,KAAM,QAAA,CAAO,CAAA,EAAG,OAAA,CAAQ,CAAA,EAAG,MAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA0CxB,WAAA,OACd,OAAA,EAAS,OAAA,CAAQ,CAAA,WAAY,OAAA,CAAQ,CAAA,IACrC,OAAA,GAAU,KAAA,WAAgB,MAAA,GAAS,KAAA,cAAmB,MAAA,KAAW,CAAA,GAChE,aAAA,CAAY,CAAA,EAAG,OAAA,CAAQ,CAAA,EAAG,MAAA;;;;;;;;;;;;;iBAuBb,eAAA,IACd,OAAA,EAAS,OAAA,CAAQ,CAAA,WAAY,OAAA,CAAQ,CAAA,KACpC,aAAA,CAAY,CAAA;;;;;;;;;;;;;;;;;;KAuCV,KAAA,gFAGc,EAAA,aAAe,EAAA,aAAe,EAAA;;KAG5C,YAAA,GAAe,MAAM,SAAS,QAAA;;KAE9B,iBAAA,GAAoB,MAAM,SAAS,aAAA;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/constructors.ts","../src/core.ts","../src/do.ts","../src/defect.ts","../src/interop.ts","../src/facade.ts","../src/tagged.ts"],"mappings":";;AAQA;;;;;KAAY,QAAA,oBAA4B,CAAA,GAAI,CAAA,CAAE,CAAA;;;;;;;AAAC;AAU/C;KAAY,KAAA,2BAAgC,QAAA,CAAS,IAAA,CAAK,CAAA,EAAG,CAAA,qBAAsB,CAAA,GAAI,CAAA;;;;;;;;;;KAW3E,aAAA;EAXgC;;;;;;;;AAA4C;EAqBtF,GAAA,IAAO,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,CAAA,GAAI,QAAA,CAAO,CAAA,EAAG,CAAA;EAVf;;;;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,WAAA,CAAY,CAAA,EAAG,CAAA,EAAG,CAAA,IAC3B,OAAA,CAAQ,CAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -468,11 +468,7 @@ var AsyncRes = class AsyncRes {
|
|
|
468
468
|
return this.promise.then((r) => r.unwrapOr(fallback));
|
|
469
469
|
}
|
|
470
470
|
unwrapOrElse(f) {
|
|
471
|
-
return this.promise.then((r) =>
|
|
472
|
-
if (r.tag === "Ok") return r.value;
|
|
473
|
-
if (r.tag === "Defect") throw r.cause;
|
|
474
|
-
return f(r.error);
|
|
475
|
-
});
|
|
471
|
+
return this.promise.then((r) => r.unwrapOrElse(f));
|
|
476
472
|
}
|
|
477
473
|
getOrNull() {
|
|
478
474
|
return this.promise.then((r) => r.getOrNull());
|
|
@@ -734,8 +730,10 @@ function foldArray(results) {
|
|
|
734
730
|
let firstErr;
|
|
735
731
|
let firstDefect;
|
|
736
732
|
const values = [];
|
|
737
|
-
for (const r of results) if (r.tag === "Defect")
|
|
738
|
-
|
|
733
|
+
for (const r of results) if (r.tag === "Defect") {
|
|
734
|
+
firstDefect ??= r;
|
|
735
|
+
break;
|
|
736
|
+
} else if (r.tag === "Err") firstErr ??= r;
|
|
739
737
|
else values.push(r.value);
|
|
740
738
|
return firstDefect ?? firstErr ?? Ok(values);
|
|
741
739
|
}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/core.ts","../src/constructors.ts","../src/do.ts","../src/defect.ts","../src/interop.ts","../src/facade.ts","../src/tagged.ts"],"sourcesContent":["// unthrown — the runtime engine.\n//\n// `Result` is the PUBLIC discriminated union (tag/value/error/cause + methods).\n// `Res` is a method holder only: its prototype carries the implementations, and\n// instances are built by `okRes`/`errRes`/`defectRes` with `Object.create` +\n// the variant type — so a builder returns a value that already *is* a union\n// member (no `as unknown as`). `Res` is never exported from `index.ts`.\n// `AsyncRes` wraps a `Promise<Result>` constructed never to reject and operates\n// purely on the public union (via `r.tag`). See CLAUDE.md → \"Internal design\".\n//\n// Type-changing pass-throughs (e.g. `map` reusing an `Err` as a differently-typed\n// `Result`) all funnel through the single `passThrough` helper — one sound\n// `as unknown as` in one place, rather than boxed's inline cast at every branch.\n// The only other casts are the builders' construction (`as OkView`/…) and the\n// `bind`/`let` scope merge (a computed key can't be spelled at the type level).\n\nimport type { AsyncResult, Bound, DefectView, ErrView, OkView, Result } from \"./types.js\";\n\n/**\n * Thrown by a {@link Result}'s `unwrap` / `unwrapErr` when the assertion is\n * wrong on a *modeled* result — `unwrap()` on an `Err`, or `unwrapErr()` on an\n * `Ok`.\n *\n * @remarks\n * The offending value is exposed two ways: the typed {@link UnwrapError.error}\n * property for programmatic access, and the standard `Error.cause` for the\n * runtime and devtools to chain — when `E` is an `Error` (e.g. a `TaggedError`)\n * its original stack is printed under \"caused by\".\n *\n * A `Defect` is never wrapped in an `UnwrapError`: its original cause is\n * re-thrown (with its original stack) instead.\n *\n * @typeParam E - the type of the {@link UnwrapError.error} it carries.\n */\nexport class UnwrapError<E = unknown> extends Error {\n /**\n * The offending value: the `Err` error for `unwrap()`, or the `Ok` value for\n * `unwrapErr()`.\n */\n readonly error: E;\n constructor(error: E) {\n super(\"unthrown: called unwrap on a non-matching Result\", { cause: error });\n this.name = \"UnwrapError\";\n this.error = error;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * Method holder for {@link Result}. Never instantiated with `new` and never\n * exported; the builders below attach its prototype to plain objects. Every\n * method types `this` as the public `Result` union, so it narrows on `tag`.\n *\n * @internal\n */\nclass Res<T, E> {\n map<U>(this: Result<T, E>, f: (value: T) => U): Result<U, E> {\n if (this.tag !== \"Ok\") return passThrough(this);\n try {\n return okRes(f(this.value));\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n flatMap<U, E2>(this: Result<T, E>, f: (value: T) => Result<U, E2>): Result<U, E | E2> {\n if (this.tag !== \"Ok\") return passThrough(this);\n try {\n return f(this.value);\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n tap(this: Result<T, E>, f: (value: T) => void): Result<T, E> {\n if (this.tag !== \"Ok\") return this;\n try {\n f(this.value);\n return this;\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n flatTap<E2>(this: Result<T, E>, f: (value: T) => Result<unknown, E2>): Result<T, E | E2> {\n if (this.tag !== \"Ok\") return this;\n try {\n const r = f(this.value);\n // Keep the original value on success; an Err/Defect from `f` short-circuits.\n return r.tag === \"Ok\" ? this : passThrough(r);\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n bind<K extends string, U, E2>(\n this: Result<T, E>,\n name: K,\n f: (scope: T) => Result<U, E2>,\n ): Result<Bound<T, K, U>, E | E2> {\n if (this.tag !== \"Ok\") return passThrough(this);\n try {\n const r = f(this.value);\n if (r.tag !== \"Ok\") return passThrough(r);\n // The merged scope can't be spelled at the type level (a computed key\n // widens to an index signature), so the constructed Ok is cast to `Bound`.\n return okRes({ ...scopeOf(this.value), [name]: r.value }) as unknown as Result<\n Bound<T, K, U>,\n E | E2\n >;\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n let<K extends string, U>(\n this: Result<T, E>,\n name: K,\n f: (scope: T) => U,\n ): Result<Bound<T, K, U>, E> {\n if (this.tag !== \"Ok\") return passThrough(this);\n try {\n return okRes({ ...scopeOf(this.value), [name]: f(this.value) }) as unknown as Result<\n Bound<T, K, U>,\n E\n >;\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n as<U>(this: Result<T, E>, value: U): Result<U, E> {\n if (this.tag !== \"Ok\") return passThrough(this);\n return okRes(value);\n }\n\n mapErr<E2>(this: Result<T, E>, f: (error: E) => E2): Result<T, E2> {\n if (this.tag !== \"Err\") return passThrough(this);\n try {\n return errRes(f(this.error));\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n orElse<U, E2>(this: Result<T, E>, f: (error: E) => Result<U, E2>): Result<T | U, E2> {\n if (this.tag !== \"Err\") return passThrough(this);\n try {\n return f(this.error);\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n recover<U>(this: Result<T, E>, f: (error: E) => U): Result<T | U, never> {\n if (this.tag !== \"Err\") return passThrough(this);\n try {\n return okRes(f(this.error));\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n tapErr(this: Result<T, E>, f: (error: E) => void): Result<T, E> {\n if (this.tag !== \"Err\") return this;\n try {\n f(this.error);\n return this;\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n flatTapErr<E2>(this: Result<T, E>, f: (error: E) => Result<unknown, E2>): Result<T, E | E2> {\n if (this.tag !== \"Err\") return this;\n try {\n const r = f(this.error);\n // Keep the original error on the effect's success; an Err/Defect threads through.\n return r.tag === \"Ok\" ? this : passThrough(r);\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n recoverDefect<U, E2>(\n this: Result<T, E>,\n f: (cause: unknown) => Result<U, E2>,\n ): Result<T | U, E | E2> {\n if (this.tag !== \"Defect\") return this;\n try {\n return f(this.cause);\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n tapDefect(this: Result<T, E>, f: (cause: unknown) => void): Result<T, E> {\n if (this.tag !== \"Defect\") return this;\n try {\n f(this.cause);\n return this;\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n match<R>(\n this: Result<T, E>,\n cases: {\n ok: (value: T) => R;\n err: (error: E) => R;\n defect: (cause: unknown) => R;\n },\n ): R {\n switch (this.tag) {\n case \"Ok\":\n return cases.ok(this.value);\n case \"Err\":\n return cases.err(this.error);\n case \"Defect\":\n return cases.defect(this.cause);\n }\n }\n\n unwrap(this: Result<T, E>): T {\n switch (this.tag) {\n case \"Ok\":\n return this.value;\n case \"Err\":\n throw new UnwrapError(this.error);\n case \"Defect\":\n throw this.cause; // rethrow original cause, original stack\n }\n }\n\n unwrapErr(this: Result<T, E>): E {\n switch (this.tag) {\n case \"Err\":\n return this.error;\n case \"Ok\":\n throw new UnwrapError(this.value);\n case \"Defect\":\n throw this.cause;\n }\n }\n\n unwrapOr(this: Result<T, E>, fallback: T): T {\n if (this.tag === \"Ok\") return this.value;\n if (this.tag === \"Defect\") throw this.cause;\n return fallback;\n }\n\n unwrapOrElse(this: Result<T, E>, f: (error: E) => T): T {\n if (this.tag === \"Ok\") return this.value;\n if (this.tag === \"Defect\") throw this.cause;\n return f(this.error);\n }\n\n getOrNull(this: Result<T, E>): T | null {\n if (this.tag === \"Ok\") return this.value;\n if (this.tag === \"Defect\") throw this.cause;\n return null;\n }\n\n getOrUndefined(this: Result<T, E>): T | undefined {\n if (this.tag === \"Ok\") return this.value;\n if (this.tag === \"Defect\") throw this.cause;\n return undefined;\n }\n\n isOk(this: Result<T, E>): this is OkView<T, E> {\n return this.tag === \"Ok\";\n }\n\n isErr(this: Result<T, E>): this is ErrView<E, T> {\n return this.tag === \"Err\";\n }\n\n isDefect(this: Result<T, E>): this is DefectView<T, E> {\n return this.tag === \"Defect\";\n }\n\n toAsync(this: Result<T, E>): AsyncResult<T, E> {\n return new AsyncRes<T, E>(Promise.resolve(this));\n }\n}\n\nconst RESULT_PROTO = Res.prototype;\n\n/**\n * Construct an `Ok` result — a plain object on the {@link Res} prototype.\n *\n * @internal\n */\nexport function okRes<T, E>(value: T): Result<T, E> {\n return Object.assign(Object.create(RESULT_PROTO), {\n tag: \"Ok\" as const,\n value,\n }) as OkView<T, E>;\n}\n\n/**\n * Construct an `Err` result.\n *\n * @internal\n */\nexport function errRes<T, E>(error: E): Result<T, E> {\n return Object.assign(Object.create(RESULT_PROTO), {\n tag: \"Err\" as const,\n error,\n }) as ErrView<E, T>;\n}\n\n/**\n * Construct a `Defect` result.\n *\n * @internal\n */\nexport function defectRes<T, E>(cause: unknown): Result<T, E> {\n return Object.assign(Object.create(RESULT_PROTO), {\n tag: \"Defect\" as const,\n cause,\n }) as DefectView<T, E>;\n}\n\n/**\n * Type guard: is `x` a {@link Result} (any of `Ok` / `Err` / `Defect`)?\n *\n * @remarks\n * Unlike {@link isOk} / {@link isErr} / {@link isDefect}, which narrow a value\n * already known to be a `Result`, this narrows from `unknown` — useful at an\n * untyped boundary. It checks the value carries the `Result` prototype, so a\n * look-alike plain object (`{ tag: \"Ok\" }`) is **not** matched. An `AsyncResult`\n * is not a `Result` and returns `false`.\n *\n * @returns `true` when `x` is a `Result` produced by this library.\n */\nexport function isResult(x: unknown): x is Result<unknown, unknown> {\n return x instanceof Res;\n}\n\n/**\n * Reuse a non-matching variant (an `Err` or `Defect`) as a differently-typed\n * `Result`, with no runtime work. Sound because the passed-through variant\n * carries no value of the changed success type, so retyping it is a no-op — only\n * the phantom type parameter moves. This is the single sanctioned home for that\n * assertion (the same one boxed applies inline at every pass-through); every\n * combinator's short-circuit branch funnels through here instead of casting.\n *\n * @internal\n */\nfunction passThrough<T, E>(self: Result<unknown, unknown>): Result<T, E> {\n return self as unknown as Result<T, E>;\n}\n\n/**\n * Validate that a `bind`/`let` scope is a real (non-null) object before merging a\n * key into it.\n *\n * @remarks\n * Do-notation accumulates an **object** scope: a chain starts at `Do()` (an\n * empty object) and every `bind`/`let` returns an object, so in typed code the\n * scope is always an object. The method lives on the general `Result` surface,\n * though, so a primitive `Ok` (e.g. `Ok(5).bind(...)`, or a chain whose value was\n * `map`-ped away from its scope) could reach it. Rather than let `{ ...5 }`\n * silently collapse to `{}` and drop the prior scope, we throw here — the\n * surrounding `try` turns it into a `Defect`, surfacing the misuse as the\n * bug it is (a defect is a bug, not an absent value). A `this: object` constraint\n * was rejected: TypeScript does not hard-enforce a constraint inferred solely\n * from `this`, and it breaks `AsyncRes implements AsyncResult`.\n *\n * @internal\n */\nfunction scopeOf(value: unknown): object {\n if (typeof value !== \"object\" || value === null) {\n throw new TypeError(\"bind/let requires an object scope — start a do-chain with Do()\");\n }\n return value;\n}\n\n/**\n * The sole runtime implementation of {@link AsyncResult}: wraps a\n * `Promise<Result>` constructed never to reject. Operates on the public `Result`\n * union (via `tag`), never on `Res` internals. Never re-exported from `index.ts`.\n *\n * @internal\n */\nexport class AsyncRes<T, E> implements AsyncResult<T, E> {\n constructor(private readonly promise: Promise<Result<T, E>>) {}\n\n // oxlint-disable-next-line no-thenable -- AsyncResult is an intentional (success-only) thenable so `await` collapses it to a Result; see the Awaitable type. onrejected is still forwarded so a hypothetical internal rejection settles the await instead of hanging — though the internal promise never rejects.\n then<R1 = Result<T, E>, R2 = never>(\n onfulfilled?: ((value: Result<T, E>) => R1 | PromiseLike<R1>) | null,\n onrejected?: ((reason: unknown) => R2 | PromiseLike<R2>) | null,\n ): PromiseLike<R1 | R2> {\n return this.promise.then(onfulfilled, onrejected);\n }\n\n map<U>(f: (value: T) => U): AsyncResult<U, E> {\n return new AsyncRes<U, E>(\n this.promise.then((r) => {\n if (r.tag !== \"Ok\") return passThrough(r);\n try {\n return okRes(f(r.value));\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n flatMap<U, E2>(f: (value: T) => Result<U, E2> | AsyncResult<U, E2>): AsyncResult<U, E | E2> {\n return new AsyncRes<U, E | E2>(\n this.promise.then(async (r) => {\n if (r.tag !== \"Ok\") return passThrough(r);\n try {\n return await f(r.value);\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n tap(f: (value: T) => void): AsyncResult<T, E> {\n return new AsyncRes<T, E>(\n this.promise.then((r) => {\n if (r.tag !== \"Ok\") return r;\n try {\n f(r.value);\n return r;\n } catch (cause) {\n return defectRes<T, E>(cause);\n }\n }),\n );\n }\n\n flatTap<E2>(\n f: (value: T) => Result<unknown, E2> | AsyncResult<unknown, E2>,\n ): AsyncResult<T, E | E2> {\n return new AsyncRes<T, E | E2>(\n this.promise.then(async (r) => {\n if (r.tag !== \"Ok\") return passThrough(r);\n try {\n const inner = await f(r.value);\n // Keep the original value on success; an Err/Defect from `f` wins.\n return inner.tag === \"Ok\" ? r : passThrough(inner);\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n bind<K extends string, U, E2>(\n name: K,\n f: (scope: T) => Result<U, E2> | AsyncResult<U, E2>,\n ): AsyncResult<Bound<T, K, U>, E | E2> {\n return new AsyncRes<Bound<T, K, U>, E | E2>(\n this.promise.then(async (r) => {\n if (r.tag !== \"Ok\") return passThrough(r);\n try {\n const inner = await f(r.value);\n if (inner.tag !== \"Ok\") return passThrough(inner);\n return okRes({ ...scopeOf(r.value), [name]: inner.value }) as unknown as Result<\n Bound<T, K, U>,\n E | E2\n >;\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n let<K extends string, U>(name: K, f: (scope: T) => U): AsyncResult<Bound<T, K, U>, E> {\n return new AsyncRes<Bound<T, K, U>, E>(\n this.promise.then((r) => {\n if (r.tag !== \"Ok\") return passThrough(r);\n try {\n return okRes({ ...scopeOf(r.value), [name]: f(r.value) }) as unknown as Result<\n Bound<T, K, U>,\n E\n >;\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n as<U>(value: U): AsyncResult<U, E> {\n return new AsyncRes<U, E>(\n this.promise.then((r) => (r.tag === \"Ok\" ? okRes<U, E>(value) : passThrough(r))),\n );\n }\n\n mapErr<E2>(f: (error: E) => E2): AsyncResult<T, E2> {\n return new AsyncRes<T, E2>(\n this.promise.then((r) => {\n if (r.tag !== \"Err\") return passThrough(r);\n try {\n return errRes(f(r.error));\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n orElse<U, E2>(f: (error: E) => Result<U, E2> | AsyncResult<U, E2>): AsyncResult<T | U, E2> {\n return new AsyncRes<T | U, E2>(\n this.promise.then(async (r) => {\n if (r.tag !== \"Err\") return passThrough(r);\n try {\n return await f(r.error);\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n recover<U>(f: (error: E) => U): AsyncResult<T | U, never> {\n return new AsyncRes<T | U, never>(\n this.promise.then((r) => {\n if (r.tag !== \"Err\") return passThrough(r);\n try {\n return okRes<T | U, never>(f(r.error));\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n tapErr(f: (error: E) => void): AsyncResult<T, E> {\n return new AsyncRes<T, E>(\n this.promise.then((r) => {\n if (r.tag !== \"Err\") return r;\n try {\n f(r.error);\n return r;\n } catch (cause) {\n return defectRes<T, E>(cause);\n }\n }),\n );\n }\n\n flatTapErr<E2>(\n f: (error: E) => Result<unknown, E2> | AsyncResult<unknown, E2>,\n ): AsyncResult<T, E | E2> {\n return new AsyncRes<T, E | E2>(\n this.promise.then(async (r) => {\n if (r.tag !== \"Err\") return passThrough(r);\n try {\n const inner = await f(r.error);\n // Keep the original error on success; an Err/Defect from `f` wins.\n return inner.tag === \"Ok\" ? passThrough(r) : passThrough(inner);\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n recoverDefect<U, E2>(\n f: (cause: unknown) => Result<U, E2> | AsyncResult<U, E2>,\n ): AsyncResult<T | U, E | E2> {\n return new AsyncRes<T | U, E | E2>(\n this.promise.then(async (r) => {\n if (r.tag !== \"Defect\") return r;\n try {\n return await f(r.cause);\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n tapDefect(f: (cause: unknown) => void): AsyncResult<T, E> {\n return new AsyncRes<T, E>(\n this.promise.then((r) => {\n if (r.tag !== \"Defect\") return r;\n try {\n f(r.cause);\n return r;\n } catch (cause) {\n return defectRes<T, E>(cause);\n }\n }),\n );\n }\n\n match<R>(cases: {\n ok: (value: T) => R;\n err: (error: E) => R;\n defect: (cause: unknown) => R;\n }): Promise<R> {\n return this.promise.then((r) => r.match(cases));\n }\n\n unwrap(): Promise<T> {\n return this.promise.then((r) => r.unwrap());\n }\n unwrapErr(): Promise<E> {\n return this.promise.then((r) => r.unwrapErr());\n }\n unwrapOr(fallback: T): Promise<T> {\n return this.promise.then((r) => r.unwrapOr(fallback));\n }\n unwrapOrElse(f: (error: E) => T): Promise<T> {\n return this.promise.then((r) => {\n if (r.tag === \"Ok\") return r.value;\n if (r.tag === \"Defect\") throw r.cause;\n return f(r.error);\n });\n }\n getOrNull(): Promise<T | null> {\n return this.promise.then((r) => r.getOrNull());\n }\n getOrUndefined(): Promise<T | undefined> {\n return this.promise.then((r) => r.getOrUndefined());\n }\n}\n","// Result constructors and the standalone narrowing guards.\n\nimport { errRes, okRes } from \"./core.js\";\nimport type { DefectView, ErrView, OkView, Result } from \"./types.js\";\n\n/**\n * Construct a successful {@link Result}.\n *\n * @typeParam T - the success value type.\n * @param value - the success value to wrap.\n *\n * @example\n * ```ts\n * import { Ok } from \"unthrown\";\n * Ok(42).unwrap(); // 42\n * ```\n */\nexport function Ok<T>(value: T): Result<T, never> {\n return okRes(value);\n}\n\n/**\n * Construct a failed {@link Result} carrying a **modeled** error.\n *\n * @typeParam E - the modeled error type.\n * @param error - the domain error to wrap.\n *\n * @example\n * ```ts\n * import { Err } from \"unthrown\";\n * Err(\"not_found\").unwrapErr(); // \"not_found\"\n * ```\n */\nexport function Err<E>(error: E): Result<never, E> {\n return errRes(error);\n}\n\n/**\n * Type guard: narrow a {@link Result} to its `Ok` variant, exposing `.value`.\n *\n * @returns `true` when `r` is `Ok`.\n *\n * @example\n * ```ts\n * import { isOk, type Result } from \"unthrown\";\n * declare const r: Result<number, string>;\n * if (isOk(r)) r.value; // number, narrowed\n * ```\n */\nexport function isOk<T, E>(r: Result<T, E>): r is OkView<T, E> {\n return r.tag === \"Ok\";\n}\n/**\n * Type guard: narrow a {@link Result} to its `Err` variant, exposing `.error`.\n *\n * @returns `true` when `r` is `Err`.\n */\nexport function isErr<T, E>(r: Result<T, E>): r is ErrView<E, T> {\n return r.tag === \"Err\";\n}\n/**\n * Type guard: narrow a {@link Result} to its `Defect` variant, exposing `.cause`.\n *\n * @returns `true` when `r` is a `Defect`.\n */\nexport function isDefect<T, E>(r: Result<T, E>): r is DefectView<T, E> {\n return r.tag === \"Defect\";\n}\n","// Do-notation entry point. The `bind` / `let` steps live on the `Result` /\n// `AsyncResult` method surface (core.ts); `Do()` just seeds an empty object\n// scope to grow.\n\nimport { Ok } from \"./constructors.js\";\nimport type { Result } from \"./types.js\";\n\n/**\n * Start a do-notation chain with an empty object scope, grown step by step with\n * `bind` (for `Result`-returning steps) and `let` (for pure values).\n *\n * @remarks\n * Capitalised because `do` is a reserved word. Each step receives the scope\n * accumulated so far; the error types union across `bind`s, and a throw in any\n * step becomes a `Defect`. To go asynchronous, lift the chain with `toAsync()`\n * (then a `bind` may return an `AsyncResult`).\n *\n * @example\n * ```ts\n * import { Do, Ok } from \"unthrown\";\n *\n * const result = Do()\n * .bind(\"user\", () => findUser(id)) // Result<User, NotFound>\n * .bind(\"org\", ({ user }) => findOrg(user.orgId)) // Result<Org, NotFound>\n * .let(\"label\", ({ user, org }) => `${user.name} @ ${org.name}`)\n * .map(({ user, org, label }) => render(user, org, label));\n * // Result<View, NotFound>\n * ```\n */\nexport function Do(): Result<{}, never> {\n return Ok({});\n}\n","// Defect marker plumbing.\n\nconst DEFECT: unique symbol = Symbol(\"unthrown/Defect\");\n\n/**\n * The opaque marker a `qualify` function returns to triage a cause as\n * **unexpected**.\n *\n * @remarks\n * `qualify` (passed to {@link fromPromise} / {@link fromThrowable}) returns\n * `E | Defect`: either a modeled domain error, or a `Defect` produced by the\n * injected `defect` helper to say \"this failure is not modeled\". A `Defect` is\n * opaque — it carries the original cause for the boundary to convert into the\n * third runtime state of a `Result`. It is **not** a public value; the only way\n * to mint one is the `defect` helper the boundary passes to `qualify`.\n *\n * @internal\n */\nexport type Defect = {\n readonly [DEFECT]: true;\n readonly cause: unknown;\n};\n\n/**\n * Wrap a cause as a `Defect` marker — the value returned from a `qualify`\n * function when a failure is **not** a modeled domain error. The boundary\n * (`fromPromise` / `fromThrowable`) passes this in as `qualify`'s second\n * argument, so domain code never imports it.\n *\n * @param cause - the original thrown/rejected value.\n * @returns an opaque Defect marker carrying `cause`.\n *\n * @internal\n */\nexport function defect(cause: unknown): Defect {\n return { [DEFECT]: true, cause };\n}\n\n/**\n * Internal guard for the qualify-time marker. Distinct from the public\n * {@link isDefect} state guard — this one narrows the `E | Defect` union a\n * `qualify` function returns, not a `Result`.\n *\n * @internal\n */\nexport function isDefectMarker(x: unknown): x is Defect {\n return (\n typeof x === \"object\" && x !== null && (x as Record<PropertyKey, unknown>)[DEFECT] === true\n );\n}\n","// Boundary interop and aggregation. Every throwing/rejecting boundary is forced\n// through `qualify`, which triages each cause into a modeled `E` or a `Defect`;\n// there is no path that yields `unknown` in `E`.\n\nimport { AsyncRes, defectRes, errRes, okRes } from \"./core.js\";\nimport { type Defect, defect, isDefectMarker } from \"./defect.js\";\nimport { Err, Ok } from \"./constructors.js\";\nimport type { AsyncErrOf, AsyncOkOf, AsyncResult, ErrOf, OkOf, Result } from \"./types.js\";\n\n/**\n * Bridge a nullable value into a {@link Result}: absence becomes a **modeled**\n * `Err`. The sanctioned alternative to an `Option` type.\n *\n * @remarks\n * `null` and `undefined` map to `Err(onAbsent())`; any other value (including\n * falsy ones like `0`, `\"\"`, `false`) maps to `Ok`.\n *\n * @typeParam T - the (nullable) value type.\n * @typeParam E - the error produced when the value is absent.\n * @param value - the possibly-absent value.\n * @param onAbsent - lazily produces the error for the absent case.\n *\n * @example\n * ```ts\n * import { fromNullable } from \"unthrown\";\n * fromNullable(map.get(key), () => \"missing\").unwrap();\n * ```\n */\nexport function fromNullable<T, E>(\n value: T | null | undefined,\n onAbsent: () => E,\n): Result<NonNullable<T>, E> {\n return value === null || value === undefined ? Err(onAbsent()) : Ok(value as NonNullable<T>);\n}\n\n/**\n * Wrap a throwing synchronous function so it returns a {@link Result} instead of\n * throwing.\n *\n * @remarks\n * `qualify` **must** triage every thrown cause into a modeled error `E` or a\n * `Defect` (via the injected `defect` helper, its second argument) — there is no\n * path that leaves `unknown` in `E`. A throw inside `qualify` itself is treated\n * as a `Defect`.\n *\n * The modeled error type is `Exclude<R, Defect>` — the `Defect` arm of\n * `qualify`'s return is **subtracted** from `E`, never inferred into it. So a\n * `qualify` that returns *only* `defect(cause)` yields `E = never` (a Defect is\n * out-of-band and must not pollute the error channel); reach for\n * {@link fromSafePromise} when every failure is a Defect.\n *\n * @typeParam A - the wrapped function's argument tuple.\n * @typeParam T - the wrapped function's return type.\n * @typeParam R - `qualify`'s return type; the modeled error `E` is\n * `Exclude<R, Defect>` (its `Defect` arm, if any, is subtracted).\n * @param fn - the throwing function to wrap.\n * @param qualify - triages a thrown `cause` into a modeled `E`, or marks it\n * unmodeled by returning `defect(cause)` (the helper passed as its second arg).\n * @returns a function with the same arguments returning `Result<T, E>`.\n *\n * @example\n * ```ts\n * import { fromThrowable } from \"unthrown\";\n * const parse = fromThrowable(JSON.parse, (cause, defect) => defect(cause));\n * parse(\"{}\").unwrap();\n * ```\n */\nexport function fromThrowable<A extends unknown[], T, R>(\n fn: (...args: A) => T,\n qualify: (cause: unknown, defect: (cause: unknown) => Defect) => R,\n): (...args: A) => Result<T, Exclude<R, Defect>> {\n type E = Exclude<R, Defect>;\n const triage = qualify as (cause: unknown, defect: (cause: unknown) => Defect) => E | Defect;\n return (...args: A): Result<T, E> => {\n try {\n return Ok(fn(...args)) as Result<T, E>;\n } catch (cause) {\n return qualifyToResult<T, E>(cause, triage);\n }\n };\n}\n\n/**\n * Wrap a `Promise` (or a thunk producing one) as an {@link AsyncResult}, forcing\n * every rejection to be triaged.\n *\n * @remarks\n * `qualify` **must** map each rejection cause into a modeled error `E` or a\n * `Defect` (via the injected `defect` helper, its second argument). The returned\n * `AsyncResult`'s internal promise never rejects; `await`-ing it always yields a\n * `Result`. A throw inside `qualify` is itself a `Defect`.\n *\n * The modeled error type is `Exclude<R, Defect>` — the `Defect` arm of\n * `qualify`'s return is **subtracted** from `E`, never inferred into it. So a\n * `qualify` that returns *only* `defect(cause)` yields `E = never`; when every\n * rejection is a Defect, prefer {@link fromSafePromise}.\n *\n * @typeParam T - the resolved value type.\n * @typeParam R - `qualify`'s return type; the modeled error `E` is\n * `Exclude<R, Defect>` (its `Defect` arm, if any, is subtracted).\n * @param promise - the promise, or a thunk returning one.\n * @param qualify - triages a rejection `cause` into a modeled `E`, or marks it\n * unmodeled by returning `defect(cause)` (the helper passed as its second arg).\n *\n * @example\n * ```ts\n * import { fromPromise } from \"unthrown\";\n * const user = await fromPromise(fetchUser(id), (cause, defect) =>\n * cause instanceof NotFoundError ? (\"not_found\" as const) : defect(cause),\n * );\n * ```\n */\nexport function fromPromise<T, R>(\n promise: Promise<T> | (() => Promise<T>),\n qualify: (cause: unknown, defect: (cause: unknown) => Defect) => R,\n): AsyncResult<T, Exclude<R, Defect>> {\n type E = Exclude<R, Defect>;\n const triage = qualify as (cause: unknown, defect: (cause: unknown) => Defect) => E | Defect;\n const p = typeof promise === \"function\" ? Promise.resolve().then(promise) : promise;\n const settled: Promise<Result<T, E>> = p.then(\n (value) => okRes<T, E>(value),\n (cause) => qualifyToResult<T, E>(cause, triage),\n );\n return new AsyncRes<T, E>(settled);\n}\n\n/**\n * Wrap a `Promise` asserted **not** to fail in any modeled way: any rejection\n * becomes a `Defect`.\n *\n * @remarks\n * Use this only when a rejection genuinely indicates a bug rather than an\n * anticipated outcome — the error channel is `never`, so there is nothing to\n * triage. (`await`-ing still yields a `Result`; it never throws.)\n *\n * @typeParam T - the resolved value type.\n * @param promise - the promise, or a thunk returning one.\n */\nexport function fromSafePromise<T>(\n promise: Promise<T> | (() => Promise<T>),\n): AsyncResult<T, never> {\n const p = typeof promise === \"function\" ? Promise.resolve().then(promise) : promise;\n const settled: Promise<Result<T, never>> = p.then(\n (value) => okRes<T, never>(value),\n (cause) => defectRes<T, never>(cause),\n );\n return new AsyncRes<T, never>(settled);\n}\n\nfunction qualifyToResult<T, E>(\n cause: unknown,\n qualify: (cause: unknown, defect: (cause: unknown) => Defect) => E | Defect,\n): Result<T, E> {\n try {\n const q = qualify(cause, defect);\n return isDefectMarker(q) ? defectRes<T, E>(q.cause) : errRes<T, E>(q);\n } catch (qErr) {\n // a throw inside qualify is itself a Defect\n return defectRes<T, E>(qErr);\n }\n}\n\n/**\n * The success channel of {@link all} / {@link allAsync}: a **positional tuple**\n * for a fixed-length input (including the empty tuple), or a homogeneous\n * **array** for a dynamic one.\n *\n * @remarks\n * The split keys off the input's `length`: a fixed tuple has a literal length\n * (`number extends Rs[\"length\"]` is false → keep the positional `Ts`), while a\n * general array has `length: number` (→ collapse to `Ts[number][]`). Checking\n * length rather than `Rs extends [unknown, ...unknown[]]` keeps `all([])` typed\n * as `Result<[], …>` instead of `Result<never[], …>`.\n *\n * @typeParam Rs - the tuple/array of input `Result` types.\n * @typeParam Ts - per-element extracted success types (`OkOf` for `all`,\n * `AsyncOkOf` for `allAsync`).\n * @internal\n */\ntype AllOk<\n Rs extends readonly unknown[],\n Ts extends readonly unknown[],\n> = number extends Rs[\"length\"] ? Ts[number][] : Ts;\n\n/** A record of `Result`s — the input to {@link allFromDict}. */\ntype ResultRecord = Record<string, Result<unknown, unknown>>;\n/** A record of `AsyncResult`s — the input to {@link allFromDictAsync}. */\ntype AsyncResultRecord = Record<string, AsyncResult<unknown, unknown>>;\n\n/**\n * Fold an array of settled `Result`s: first `Err` wins, any `Defect` dominates,\n * else `Ok` of the values array.\n *\n * @internal\n */\nfunction foldArray(results: readonly Result<unknown, unknown>[]): Result<unknown, unknown> {\n let firstErr: Result<unknown, unknown> | undefined;\n let firstDefect: Result<unknown, unknown> | undefined;\n const values: unknown[] = [];\n for (const r of results) {\n if (r.tag === \"Defect\") firstDefect ??= r;\n else if (r.tag === \"Err\") firstErr ??= r;\n else values.push(r.value);\n }\n return firstDefect ?? firstErr ?? Ok(values);\n}\n\n/**\n * Fold a record of settled `Result`s with the same rules, else `Ok` of the\n * record of values. Keys are written with `Object.defineProperty` so a\n * caller-supplied `\"__proto__\"` key cannot pollute the prototype.\n *\n * @internal\n */\nfunction foldRecord(results: ResultRecord): Result<unknown, unknown> {\n let firstErr: Result<unknown, unknown> | undefined;\n let firstDefect: Result<unknown, unknown> | undefined;\n const values: Record<string, unknown> = {};\n for (const [key, r] of Object.entries(results)) {\n if (r.tag === \"Defect\") firstDefect ??= r;\n else if (r.tag === \"Err\") firstErr ??= r;\n else\n Object.defineProperty(values, key, {\n value: r.value,\n enumerable: true,\n writable: true,\n configurable: true,\n });\n }\n return firstDefect ?? firstErr ?? Ok(values);\n}\n\n/**\n * Collect a tuple/array of {@link Result}s into a single `Result` of all their\n * success values.\n *\n * @remarks\n * Short-circuits on the **first** `Err` (later entries are not inspected for\n * their error); any `Defect` present **dominates**, winning even over an earlier\n * `Err`. A **fixed tuple** keeps its positional types — `all([Ok(1), Ok(\"a\")])`\n * is `Result<[number, string], …>` — while a **dynamic array** `Result<T, E>[]`\n * collapses to `Result<T[], E>` with no cast. For a **record** keyed by name,\n * use {@link allFromDict}.\n *\n * @example\n * ```ts\n * import { all, Ok } from \"unthrown\";\n * all([Ok(1), Ok(\"a\"), Ok(true)]).unwrap(); // [1, \"a\", true] (typed [number, string, boolean])\n * all([Ok(1), Ok(2)] as Result<number, never>[]).unwrap(); // number[]\n * ```\n */\nexport function all<Rs extends readonly Result<unknown, unknown>[]>(\n results: readonly [...Rs],\n): Result<AllOk<Rs, { [K in keyof Rs]: OkOf<Rs[K]> }>, ErrOf<Rs[number]>> {\n return foldArray(results) as unknown as Result<\n AllOk<Rs, { [K in keyof Rs]: OkOf<Rs[K]> }>,\n ErrOf<Rs[number]>\n >;\n}\n\n/**\n * Collect a **record** of {@link Result}s into a single `Result` of a record of\n * their success values — `allFromDict({ a: Result<A, E>, b: Result<B, E> })` is\n * `Result<{ a: A; b: B }, E>`. The named counterpart of {@link all}, for\n * parallel work you'd rather not tuple.\n *\n * @remarks\n * Same folding rules as {@link all}: first `Err` short-circuits, any `Defect`\n * dominates. This is **not** error accumulation.\n *\n * @example\n * ```ts\n * import { allFromDict, Ok } from \"unthrown\";\n * allFromDict({ id: Ok(1), name: Ok(\"ada\") }).unwrap(); // { id: 1, name: \"ada\" }\n * ```\n */\nexport function allFromDict<R extends ResultRecord>(\n results: R,\n): Result<{ [K in keyof R]: OkOf<R[K]> }, ErrOf<R[keyof R]>> {\n return foldRecord(results) as unknown as Result<\n { [K in keyof R]: OkOf<R[K]> },\n ErrOf<R[keyof R]>\n >;\n}\n\n/**\n * The asynchronous counterpart of {@link all}: combine a tuple/array of\n * {@link AsyncResult}s into one `AsyncResult` of all their success values.\n *\n * @remarks\n * The inputs are resolved **concurrently** (order preserved); the resolved\n * `Result`s are then folded with the same rules as {@link all} — first `Err`\n * short-circuits, any `Defect` dominates. As ever, the returned `AsyncResult`'s\n * internal promise never rejects. For a **record**, use {@link allFromDictAsync}.\n *\n * @example\n * ```ts\n * import { allAsync, fromSafePromise } from \"unthrown\";\n * await allAsync([fromSafePromise(a()), fromSafePromise(b())]);\n * ```\n */\nexport function allAsync<Rs extends readonly AsyncResult<unknown, unknown>[]>(\n results: readonly [...Rs],\n): AsyncResult<AllOk<Rs, { [K in keyof Rs]: AsyncOkOf<Rs[K]> }>, AsyncErrOf<Rs[number]>> {\n // Each AsyncResult is a (never-rejecting) thenable, so Promise.all adopts them;\n // `foldArray` then applies the all() rules. The internal promise never rejects.\n const settled = Promise.all(results).then((resolved) =>\n foldArray(resolved as readonly Result<unknown, unknown>[]),\n );\n return new AsyncRes(settled) as unknown as AsyncResult<\n AllOk<Rs, { [K in keyof Rs]: AsyncOkOf<Rs[K]> }>,\n AsyncErrOf<Rs[number]>\n >;\n}\n\n/**\n * The asynchronous counterpart of {@link allFromDict}: combine a record of\n * {@link AsyncResult}s into one `AsyncResult` of a record of their values.\n *\n * @remarks\n * Resolved concurrently (order preserved), folded with the {@link all} rules,\n * and the internal promise never rejects.\n *\n * @example\n * ```ts\n * import { allFromDictAsync, fromSafePromise } from \"unthrown\";\n * await allFromDictAsync({ a: fromSafePromise(a()), b: fromSafePromise(b()) });\n * ```\n */\nexport function allFromDictAsync<R extends AsyncResultRecord>(\n results: R,\n): AsyncResult<{ [K in keyof R]: AsyncOkOf<R[K]> }, AsyncErrOf<R[keyof R]>> {\n const entries = Object.entries(results);\n const settled = Promise.all(entries.map(([, ar]) => ar)).then((resolved) => {\n // Null-proto accumulator: pairing resolved values back to keys can't pollute.\n const byKey: ResultRecord = Object.create(null) as ResultRecord;\n entries.forEach(([key], i) => {\n byKey[key] = resolved[i] as Result<unknown, unknown>;\n });\n return foldRecord(byKey);\n });\n return new AsyncRes(settled) as unknown as AsyncResult<\n { [K in keyof R]: AsyncOkOf<R[K]> },\n AsyncErrOf<R[keyof R]>\n >;\n}\n","// Result facade — a discoverable namespace alias for the standalone entry\n// points. The free functions remain the primary, tree-shakeable API; this\n// object is a separate export, so `import { Ok }` never pulls it in. The value\n// `Result` and the type `Result<T, E>` (types.ts) share a name — the\n// companion-object pattern. See CLAUDE.md → \"Internal design\".\n\nimport { Err, isDefect, isErr, isOk, Ok } from \"./constructors.js\";\nimport { isResult } from \"./core.js\";\nimport { Do } from \"./do.js\";\nimport {\n all,\n allAsync,\n allFromDict,\n allFromDictAsync,\n fromNullable,\n fromPromise,\n fromSafePromise,\n fromThrowable,\n} from \"./interop.js\";\nimport type { AsyncResult as AsyncResultType, Result as ResultType } from \"./types.js\";\n\n/**\n * Companion object grouping the **`Result`-producing** entry points under a\n * single, discoverable namespace: {@link Result.Ok}, {@link Result.Err},\n * {@link Result.Do}, {@link Result.fromNullable}, {@link Result.fromThrowable},\n * {@link Result.all}, {@link Result.allFromDict}, {@link Result.isOk},\n * {@link Result.isErr}, {@link Result.isDefect}, {@link Result.isResult}.\n *\n * @remarks\n * Purely additive sugar — each member **is** the corresponding free function.\n * The free functions remain the primary, tree-shakeable API; importing only\n * `{ Ok }` never pulls this object in. The value `Result` and the type\n * {@link Result} share one name (the companion-object pattern).\n *\n * The **async** entry points live on the sibling {@link AsyncResult} companion\n * (`AsyncResult.fromPromise`, `AsyncResult.all`, …), grouped by what they\n * return — a static lives in exactly one namespace.\n *\n * @example\n * ```ts\n * import { Result } from \"unthrown\";\n * Result.Ok(1).flatMap((n) => Result.Ok(n + 1)).unwrap(); // 2\n * ```\n */\nexport const Result = {\n Ok,\n Err,\n Do,\n fromNullable,\n fromThrowable,\n all,\n allFromDict,\n isOk,\n isErr,\n isDefect,\n isResult,\n} as const;\n\n// Re-alias the Result type into this module so a single `export { Result }`\n// (from index.ts) carries BOTH the companion object above and the type — value\n// and type sharing one name, declaration-merged in one place.\nexport type Result<T, E> = ResultType<T, E>;\n\n/**\n * Companion object grouping the **`AsyncResult`-producing** entry points under\n * the matching namespace: {@link AsyncResult.fromPromise},\n * {@link AsyncResult.fromSafePromise}, {@link AsyncResult.all},\n * {@link AsyncResult.allFromDict}.\n *\n * @remarks\n * The async sibling of {@link Result}. Statics are grouped by what they\n * **return**, so `fromPromise`/`fromSafePromise` and the async aggregates sit\n * here rather than on {@link Result}; the namespace already conveys \"async\", so\n * the aggregates drop the `Async` suffix (`AsyncResult.all` is the free function\n * `allAsync`; `AsyncResult.allFromDict` is `allFromDictAsync`). Like\n * {@link Result}, the free functions remain the primary, tree-shakeable API; the\n * value `AsyncResult` and the type {@link AsyncResult} share one name.\n *\n * @example\n * ```ts\n * import { AsyncResult } from \"unthrown\";\n * const user = await AsyncResult.fromPromise(fetchUser(id), (c, defect) => defect(c));\n * ```\n */\nexport const AsyncResult = {\n fromPromise,\n fromSafePromise,\n all: allAsync,\n allFromDict: allFromDictAsync,\n} as const;\n\n// Re-alias the AsyncResult type into this module (same companion-object pattern\n// as Result above) so one `export { AsyncResult }` carries value + type.\nexport type AsyncResult<T, E> = AsyncResultType<T, E>;\n","// The TaggedError convention (à la Effect's `Data.TaggedError`) and an\n// exhaustive, zero-dependency fold over a tagged error union.\n\nimport type { AsyncResult, Result } from \"./types.js\";\n\ntype Props = Record<string, unknown>;\n\n/**\n * The instance shape produced by a {@link TaggedError} class: an `Error` plus a\n * `_tag` discriminant and the (readonly) payload fields.\n *\n * @typeParam Tag - the string literal discriminant.\n * @typeParam A - the payload object type.\n */\nexport type TaggedErrorInstance<Tag extends string, A extends Props> = Error &\n Readonly<A> & { readonly _tag: Tag };\n\n/**\n * The class constructor returned by {@link TaggedError}. Generic in its payload:\n * apply it with an instantiation expression at the `extends` site.\n *\n * @remarks\n * When the payload is empty, the constructor takes **no** arguments (the\n * `keyof A extends never ? void : A` trick); otherwise it takes the payload.\n *\n * @typeParam Tag - the string literal discriminant.\n */\nexport type TaggedErrorConstructor<Tag extends string> = {\n new <A extends Props = {}>(args: keyof A extends never ? void : A): TaggedErrorInstance<Tag, A>;\n};\n\n/**\n * Build a base class for a tagged error — a class extending `Error` with a\n * `_tag` string discriminant, in the style of Effect's `Data.TaggedError`.\n *\n * @remarks\n * Extend the returned class to declare a concrete error. Supply the payload with\n * an instantiation expression; omit it for a payload-less error. A `message`\n * field in the payload is forwarded to `Error`. The `_tag` always reflects\n * `tag` and cannot be overridden by the payload.\n *\n * `_tag` is the discriminant used by {@link matchTags}; `Error.name` is the\n * human-facing label in stack traces and logs. By default they coincide, but\n * they can be **decoupled** with `options.name` — so a tag can be namespaced for\n * collision-safety (`\"@my-lib/RetryableError\"`) without that slash-prefixed\n * string leaking into `Error.name`:\n *\n * ```ts\n * class RetryableError extends TaggedError(\"@my-lib/RetryableError\", {\n * name: \"RetryableError\",\n * })<{ message: string }> {}\n *\n * const e = new RetryableError({ message: \"boom\" });\n * e._tag; // \"@my-lib/RetryableError\" — namespaced discriminant\n * e.name; // \"RetryableError\" — clean display name\n * ```\n *\n * @typeParam Tag - the string literal discriminant.\n * @param tag - the discriminant value; also the default error `name`.\n * @param options - optional overrides. `options.name` sets `Error.name`\n * independently of `tag` (defaults to `tag`).\n *\n * @example\n * ```ts\n * class NotFound extends TaggedError(\"NotFound\") {}\n * class HttpError extends TaggedError(\"HttpError\")<{ status: number }> {}\n *\n * new NotFound()._tag; // \"NotFound\"\n * new HttpError({ status: 500 }).status; // 500\n * ```\n */\nexport function TaggedError<Tag extends string>(\n tag: Tag,\n options?: { readonly name?: string },\n): TaggedErrorConstructor<Tag> {\n const displayName = options?.name ?? tag;\n class TaggedErrorBase extends Error {\n readonly _tag!: Tag;\n\n constructor(props?: Props) {\n super(typeof props?.[\"message\"] === \"string\" ? (props[\"message\"] as string) : undefined);\n if (props) Object.assign(this, props);\n // The tag is authoritative — assign it after the payload so it can't be\n // clobbered. `name` is the display label, independent of the discriminant.\n (this as { _tag: Tag })._tag = tag;\n this.name = displayName;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n }\n\n return TaggedErrorBase as unknown as TaggedErrorConstructor<Tag>;\n}\n\n/**\n * The handler object {@link matchTags} requires: a branch per error tag, plus\n * `Ok` and `Defect`. Miss a tag and it will not compile — the exhaustiveness is\n * enforced by the type, with no `.exhaustive()` to forget.\n *\n * @typeParam T - the success value type.\n * @typeParam E - the tagged error union.\n * @typeParam R - the folded result type.\n */\nexport type TagHandlers<T, E extends { _tag: string }, R> = {\n Ok: (value: T) => R;\n Defect: (cause: unknown) => R;\n} & { [K in E[\"_tag\"]]: (error: Extract<E, { _tag: K }>) => R };\n\n/**\n * Exhaustively fold a {@link Result} (or {@link AsyncResult}) whose error type is\n * a tagged union, dispatching each error to the handler matching its `_tag`.\n *\n * @remarks\n * The `handlers` object must provide `Ok`, `Defect`, and exactly one function\n * per error tag; each tag's handler receives the narrowed error variant. A\n * missing tag is a compile error. For an `AsyncResult`, the fold resolves to a\n * `Promise<R>`.\n *\n * @typeParam T - the success value type.\n * @typeParam E - the tagged error union (`E extends { _tag: string }`).\n * @typeParam R - the folded result type.\n * @param result - the result to fold.\n * @param handlers - one branch per channel/tag.\n *\n * @example\n * ```ts\n * class NotFound extends TaggedError(\"NotFound\") {}\n * class Forbidden extends TaggedError(\"Forbidden\")<{ user: string }> {}\n *\n * declare const r: Result<number, NotFound | Forbidden>;\n * matchTags(r, {\n * Ok: (n) => `got ${n}`,\n * Defect: (cause) => `bug: ${String(cause)}`,\n * NotFound: () => \"404\",\n * Forbidden: (e) => `403 for ${e.user}`,\n * });\n * ```\n */\nexport function matchTags<T, E extends { _tag: string }, R>(\n result: Result<T, E>,\n handlers: TagHandlers<T, E, R>,\n): R;\nexport function matchTags<T, E extends { _tag: string }, R>(\n result: AsyncResult<T, E>,\n handlers: TagHandlers<T, E, R>,\n): Promise<R>;\nexport function matchTags<T, E extends { _tag: string }, R>(\n result: Result<T, E> | AsyncResult<T, E>,\n handlers: TagHandlers<T, E, R>,\n): R | Promise<R> {\n const onErr = (error: E): R => {\n const handler = handlers[error._tag as E[\"_tag\"]] as unknown as (e: E) => R;\n return handler(error);\n };\n // Both Result and AsyncResult share `match`; the cast picks one signature for\n // the call while the public overloads keep the return type correct.\n return (result as Result<T, E>).match({ ok: handlers.Ok, err: onErr, defect: handlers.Defect });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAkCA,IAAa,cAAb,cAA8C,MAAM;;;;;CAKlD;CACA,YAAY,OAAU;EACpB,MAAM,oDAAoD,EAAE,OAAO,MAAM,CAAC;EAC1E,KAAK,OAAO;EACZ,KAAK,QAAQ;EACb,OAAO,eAAe,MAAM,IAAI,OAAO,SAAS;CAClD;AACF;;;;;;;;AASA,IAAM,MAAN,MAAgB;CACd,IAA2B,GAAkC;EAC3D,IAAI,KAAK,QAAQ,MAAM,OAAO,YAAY,IAAI;EAC9C,IAAI;GACF,OAAO,MAAM,EAAE,KAAK,KAAK,CAAC;EAC5B,SAAS,OAAO;GACd,OAAO,UAAU,KAAK;EACxB;CACF;CAEA,QAAmC,GAAmD;EACpF,IAAI,KAAK,QAAQ,MAAM,OAAO,YAAY,IAAI;EAC9C,IAAI;GACF,OAAO,EAAE,KAAK,KAAK;EACrB,SAAS,OAAO;GACd,OAAO,UAAU,KAAK;EACxB;CACF;CAEA,IAAwB,GAAqC;EAC3D,IAAI,KAAK,QAAQ,MAAM,OAAO;EAC9B,IAAI;GACF,EAAE,KAAK,KAAK;GACZ,OAAO;EACT,SAAS,OAAO;GACd,OAAO,UAAU,KAAK;EACxB;CACF;CAEA,QAAgC,GAAyD;EACvF,IAAI,KAAK,QAAQ,MAAM,OAAO;EAC9B,IAAI;GACF,MAAM,IAAI,EAAE,KAAK,KAAK;GAEtB,OAAO,EAAE,QAAQ,OAAO,OAAO,YAAY,CAAC;EAC9C,SAAS,OAAO;GACd,OAAO,UAAU,KAAK;EACxB;CAC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CACzB;CACA;CACA,KAAK;CACL,aAAa;AACf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AClBA,SAAgB,YACd,KACA,SAC6B;CAC7B,MAAM,cAAc,SAAS,QAAQ;CACrC,MAAM,wBAAwB,MAAM;EAClC;EAEA,YAAY,OAAe;GACzB,MAAM,OAAO,QAAQ,eAAe,WAAY,MAAM,aAAwB,KAAA,CAAS;GACvF,IAAI,OAAO,OAAO,OAAO,MAAM,KAAK;GAGpC,KAAwB,OAAO;GAC/B,KAAK,OAAO;GACZ,OAAO,eAAe,MAAM,IAAI,OAAO,SAAS;EAClD;CACF;CAEA,OAAO;AACT;AAsDA,SAAgB,UACd,QACA,UACgB;CAChB,MAAM,SAAS,UAAgB;EAC7B,MAAM,UAAU,SAAS,MAAM;EAC/B,OAAO,QAAQ,KAAK;CACtB;CAGA,OAAQ,OAAwB,MAAM;EAAE,IAAI,SAAS;EAAI,KAAK;EAAO,QAAQ,SAAS;CAAO,CAAC;AAChG"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/core.ts","../src/constructors.ts","../src/do.ts","../src/defect.ts","../src/interop.ts","../src/facade.ts","../src/tagged.ts"],"sourcesContent":["// unthrown — the runtime engine.\n//\n// `Result` is the PUBLIC discriminated union (tag/value/error/cause + methods).\n// `Res` is a method holder only: its prototype carries the implementations, and\n// instances are built by `okRes`/`errRes`/`defectRes` with `Object.create` +\n// the variant type — so a builder returns a value that already *is* a union\n// member (no `as unknown as`). `Res` is never exported from `index.ts`.\n// `AsyncRes` wraps a `Promise<Result>` constructed never to reject and operates\n// purely on the public union (via `r.tag`). See CLAUDE.md → \"Internal design\".\n//\n// Type-changing pass-throughs (e.g. `map` reusing an `Err` as a differently-typed\n// `Result`) all funnel through the single `passThrough` helper — one sound\n// `as unknown as` in one place, rather than boxed's inline cast at every branch.\n// The only other casts are the builders' construction (`as OkView`/…) and the\n// `bind`/`let` scope merge (a computed key can't be spelled at the type level).\n\nimport type { AsyncResult, Bound, DefectView, ErrView, OkView, Result } from \"./types.js\";\n\n/**\n * Thrown by a {@link Result}'s `unwrap` / `unwrapErr` when the assertion is\n * wrong on a *modeled* result — `unwrap()` on an `Err`, or `unwrapErr()` on an\n * `Ok`.\n *\n * @remarks\n * The offending value is exposed two ways: the typed {@link UnwrapError.error}\n * property for programmatic access, and the standard `Error.cause` for the\n * runtime and devtools to chain — when `E` is an `Error` (e.g. a `TaggedError`)\n * its original stack is printed under \"caused by\".\n *\n * A `Defect` is never wrapped in an `UnwrapError`: its original cause is\n * re-thrown (with its original stack) instead.\n *\n * @typeParam E - the type of the {@link UnwrapError.error} it carries.\n */\nexport class UnwrapError<E = unknown> extends Error {\n /**\n * The offending value: the `Err` error for `unwrap()`, or the `Ok` value for\n * `unwrapErr()`.\n */\n readonly error: E;\n constructor(error: E) {\n super(\"unthrown: called unwrap on a non-matching Result\", { cause: error });\n this.name = \"UnwrapError\";\n this.error = error;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * Method holder for {@link Result}. Never instantiated with `new` and never\n * exported; the builders below attach its prototype to plain objects. Every\n * method types `this` as the public `Result` union, so it narrows on `tag`.\n *\n * @internal\n */\nclass Res<T, E> {\n map<U>(this: Result<T, E>, f: (value: T) => U): Result<U, E> {\n if (this.tag !== \"Ok\") return passThrough(this);\n try {\n return okRes(f(this.value));\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n flatMap<U, E2>(this: Result<T, E>, f: (value: T) => Result<U, E2>): Result<U, E | E2> {\n if (this.tag !== \"Ok\") return passThrough(this);\n try {\n return f(this.value);\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n tap(this: Result<T, E>, f: (value: T) => void): Result<T, E> {\n if (this.tag !== \"Ok\") return this;\n try {\n f(this.value);\n return this;\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n flatTap<E2>(this: Result<T, E>, f: (value: T) => Result<unknown, E2>): Result<T, E | E2> {\n if (this.tag !== \"Ok\") return this;\n try {\n const r = f(this.value);\n // Keep the original value on success; an Err/Defect from `f` short-circuits.\n return r.tag === \"Ok\" ? this : passThrough(r);\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n bind<K extends string, U, E2>(\n this: Result<T, E>,\n name: K,\n f: (scope: T) => Result<U, E2>,\n ): Result<Bound<T, K, U>, E | E2> {\n if (this.tag !== \"Ok\") return passThrough(this);\n try {\n const r = f(this.value);\n if (r.tag !== \"Ok\") return passThrough(r);\n // The merged scope can't be spelled at the type level (a computed key\n // widens to an index signature), so the constructed Ok is cast to `Bound`.\n return okRes({ ...scopeOf(this.value), [name]: r.value }) as unknown as Result<\n Bound<T, K, U>,\n E | E2\n >;\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n let<K extends string, U>(\n this: Result<T, E>,\n name: K,\n f: (scope: T) => U,\n ): Result<Bound<T, K, U>, E> {\n if (this.tag !== \"Ok\") return passThrough(this);\n try {\n return okRes({ ...scopeOf(this.value), [name]: f(this.value) }) as unknown as Result<\n Bound<T, K, U>,\n E\n >;\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n as<U>(this: Result<T, E>, value: U): Result<U, E> {\n if (this.tag !== \"Ok\") return passThrough(this);\n return okRes(value);\n }\n\n mapErr<E2>(this: Result<T, E>, f: (error: E) => E2): Result<T, E2> {\n if (this.tag !== \"Err\") return passThrough(this);\n try {\n return errRes(f(this.error));\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n orElse<U, E2>(this: Result<T, E>, f: (error: E) => Result<U, E2>): Result<T | U, E2> {\n if (this.tag !== \"Err\") return passThrough(this);\n try {\n return f(this.error);\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n recover<U>(this: Result<T, E>, f: (error: E) => U): Result<T | U, never> {\n if (this.tag !== \"Err\") return passThrough(this);\n try {\n return okRes(f(this.error));\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n tapErr(this: Result<T, E>, f: (error: E) => void): Result<T, E> {\n if (this.tag !== \"Err\") return this;\n try {\n f(this.error);\n return this;\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n flatTapErr<E2>(this: Result<T, E>, f: (error: E) => Result<unknown, E2>): Result<T, E | E2> {\n if (this.tag !== \"Err\") return this;\n try {\n const r = f(this.error);\n // Keep the original error on the effect's success; an Err/Defect threads through.\n return r.tag === \"Ok\" ? this : passThrough(r);\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n recoverDefect<U, E2>(\n this: Result<T, E>,\n f: (cause: unknown) => Result<U, E2>,\n ): Result<T | U, E | E2> {\n if (this.tag !== \"Defect\") return this;\n try {\n return f(this.cause);\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n tapDefect(this: Result<T, E>, f: (cause: unknown) => void): Result<T, E> {\n if (this.tag !== \"Defect\") return this;\n try {\n f(this.cause);\n return this;\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n match<R>(\n this: Result<T, E>,\n cases: {\n ok: (value: T) => R;\n err: (error: E) => R;\n defect: (cause: unknown) => R;\n },\n ): R {\n switch (this.tag) {\n case \"Ok\":\n return cases.ok(this.value);\n case \"Err\":\n return cases.err(this.error);\n case \"Defect\":\n return cases.defect(this.cause);\n }\n }\n\n unwrap(this: Result<T, E>): T {\n switch (this.tag) {\n case \"Ok\":\n return this.value;\n case \"Err\":\n throw new UnwrapError(this.error);\n case \"Defect\":\n throw this.cause; // rethrow original cause, original stack\n }\n }\n\n unwrapErr(this: Result<T, E>): E {\n switch (this.tag) {\n case \"Err\":\n return this.error;\n case \"Ok\":\n throw new UnwrapError(this.value);\n case \"Defect\":\n throw this.cause;\n }\n }\n\n unwrapOr(this: Result<T, E>, fallback: T): T {\n if (this.tag === \"Ok\") return this.value;\n if (this.tag === \"Defect\") throw this.cause;\n return fallback;\n }\n\n unwrapOrElse(this: Result<T, E>, f: (error: E) => T): T {\n if (this.tag === \"Ok\") return this.value;\n if (this.tag === \"Defect\") throw this.cause;\n return f(this.error);\n }\n\n getOrNull(this: Result<T, E>): T | null {\n if (this.tag === \"Ok\") return this.value;\n if (this.tag === \"Defect\") throw this.cause;\n return null;\n }\n\n getOrUndefined(this: Result<T, E>): T | undefined {\n if (this.tag === \"Ok\") return this.value;\n if (this.tag === \"Defect\") throw this.cause;\n return undefined;\n }\n\n isOk(this: Result<T, E>): this is OkView<T, E> {\n return this.tag === \"Ok\";\n }\n\n isErr(this: Result<T, E>): this is ErrView<E, T> {\n return this.tag === \"Err\";\n }\n\n isDefect(this: Result<T, E>): this is DefectView<T, E> {\n return this.tag === \"Defect\";\n }\n\n toAsync(this: Result<T, E>): AsyncResult<T, E> {\n return new AsyncRes<T, E>(Promise.resolve(this));\n }\n}\n\nconst RESULT_PROTO = Res.prototype;\n\n/**\n * Construct an `Ok` result — a plain object on the {@link Res} prototype.\n *\n * @internal\n */\nexport function okRes<T, E>(value: T): Result<T, E> {\n return Object.assign(Object.create(RESULT_PROTO), {\n tag: \"Ok\" as const,\n value,\n }) as OkView<T, E>;\n}\n\n/**\n * Construct an `Err` result.\n *\n * @internal\n */\nexport function errRes<T, E>(error: E): Result<T, E> {\n return Object.assign(Object.create(RESULT_PROTO), {\n tag: \"Err\" as const,\n error,\n }) as ErrView<E, T>;\n}\n\n/**\n * Construct a `Defect` result.\n *\n * @internal\n */\nexport function defectRes<T, E>(cause: unknown): Result<T, E> {\n return Object.assign(Object.create(RESULT_PROTO), {\n tag: \"Defect\" as const,\n cause,\n }) as DefectView<T, E>;\n}\n\n/**\n * Type guard: is `x` a {@link Result} (any of `Ok` / `Err` / `Defect`)?\n *\n * @remarks\n * Unlike {@link isOk} / {@link isErr} / {@link isDefect}, which narrow a value\n * already known to be a `Result`, this narrows from `unknown` — useful at an\n * untyped boundary. It checks the value carries the `Result` prototype, so a\n * look-alike plain object (`{ tag: \"Ok\" }`) is **not** matched. An `AsyncResult`\n * is not a `Result` and returns `false`.\n *\n * @returns `true` when `x` is a `Result` produced by this library.\n */\nexport function isResult(x: unknown): x is Result<unknown, unknown> {\n return x instanceof Res;\n}\n\n/**\n * Reuse a non-matching variant (an `Err` or `Defect`) as a differently-typed\n * `Result`, with no runtime work. Sound because the passed-through variant\n * carries no value of the changed success type, so retyping it is a no-op — only\n * the phantom type parameter moves. This is the single sanctioned home for that\n * assertion (the same one boxed applies inline at every pass-through); every\n * combinator's short-circuit branch funnels through here instead of casting.\n *\n * @internal\n */\nfunction passThrough<T, E>(self: Result<unknown, unknown>): Result<T, E> {\n return self as unknown as Result<T, E>;\n}\n\n/**\n * Validate that a `bind`/`let` scope is a real (non-null) object before merging a\n * key into it.\n *\n * @remarks\n * Do-notation accumulates an **object** scope: a chain starts at `Do()` (an\n * empty object) and every `bind`/`let` returns an object, so in typed code the\n * scope is always an object. The method lives on the general `Result` surface,\n * though, so a primitive `Ok` (e.g. `Ok(5).bind(...)`, or a chain whose value was\n * `map`-ped away from its scope) could reach it. Rather than let `{ ...5 }`\n * silently collapse to `{}` and drop the prior scope, we throw here — the\n * surrounding `try` turns it into a `Defect`, surfacing the misuse as the\n * bug it is (a defect is a bug, not an absent value). A `this: object` constraint\n * was rejected: TypeScript does not hard-enforce a constraint inferred solely\n * from `this`, and it breaks `AsyncRes implements AsyncResult`.\n *\n * @internal\n */\nfunction scopeOf(value: unknown): object {\n if (typeof value !== \"object\" || value === null) {\n throw new TypeError(\"bind/let requires an object scope — start a do-chain with Do()\");\n }\n return value;\n}\n\n/**\n * The sole runtime implementation of {@link AsyncResult}: wraps a\n * `Promise<Result>` constructed never to reject. Operates on the public `Result`\n * union (via `tag`), never on `Res` internals. Never re-exported from `index.ts`.\n *\n * @internal\n */\nexport class AsyncRes<T, E> implements AsyncResult<T, E> {\n constructor(private readonly promise: Promise<Result<T, E>>) {}\n\n // oxlint-disable-next-line no-thenable -- AsyncResult is an intentional (success-only) thenable so `await` collapses it to a Result; see the Awaitable type. onrejected is still forwarded so a hypothetical internal rejection settles the await instead of hanging — though the internal promise never rejects.\n then<R1 = Result<T, E>, R2 = never>(\n onfulfilled?: ((value: Result<T, E>) => R1 | PromiseLike<R1>) | null,\n onrejected?: ((reason: unknown) => R2 | PromiseLike<R2>) | null,\n ): PromiseLike<R1 | R2> {\n return this.promise.then(onfulfilled, onrejected);\n }\n\n map<U>(f: (value: T) => U): AsyncResult<U, E> {\n return new AsyncRes<U, E>(\n this.promise.then((r) => {\n if (r.tag !== \"Ok\") return passThrough(r);\n try {\n return okRes(f(r.value));\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n flatMap<U, E2>(f: (value: T) => Result<U, E2> | AsyncResult<U, E2>): AsyncResult<U, E | E2> {\n return new AsyncRes<U, E | E2>(\n this.promise.then(async (r) => {\n if (r.tag !== \"Ok\") return passThrough(r);\n try {\n return await f(r.value);\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n tap(f: (value: T) => void): AsyncResult<T, E> {\n return new AsyncRes<T, E>(\n this.promise.then((r) => {\n if (r.tag !== \"Ok\") return r;\n try {\n f(r.value);\n return r;\n } catch (cause) {\n return defectRes<T, E>(cause);\n }\n }),\n );\n }\n\n flatTap<E2>(\n f: (value: T) => Result<unknown, E2> | AsyncResult<unknown, E2>,\n ): AsyncResult<T, E | E2> {\n return new AsyncRes<T, E | E2>(\n this.promise.then(async (r) => {\n if (r.tag !== \"Ok\") return passThrough(r);\n try {\n const inner = await f(r.value);\n // Keep the original value on success; an Err/Defect from `f` wins.\n return inner.tag === \"Ok\" ? r : passThrough(inner);\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n bind<K extends string, U, E2>(\n name: K,\n f: (scope: T) => Result<U, E2> | AsyncResult<U, E2>,\n ): AsyncResult<Bound<T, K, U>, E | E2> {\n return new AsyncRes<Bound<T, K, U>, E | E2>(\n this.promise.then(async (r) => {\n if (r.tag !== \"Ok\") return passThrough(r);\n try {\n const inner = await f(r.value);\n if (inner.tag !== \"Ok\") return passThrough(inner);\n return okRes({ ...scopeOf(r.value), [name]: inner.value }) as unknown as Result<\n Bound<T, K, U>,\n E | E2\n >;\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n let<K extends string, U>(name: K, f: (scope: T) => U): AsyncResult<Bound<T, K, U>, E> {\n return new AsyncRes<Bound<T, K, U>, E>(\n this.promise.then((r) => {\n if (r.tag !== \"Ok\") return passThrough(r);\n try {\n return okRes({ ...scopeOf(r.value), [name]: f(r.value) }) as unknown as Result<\n Bound<T, K, U>,\n E\n >;\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n as<U>(value: U): AsyncResult<U, E> {\n return new AsyncRes<U, E>(\n this.promise.then((r) => (r.tag === \"Ok\" ? okRes<U, E>(value) : passThrough(r))),\n );\n }\n\n mapErr<E2>(f: (error: E) => E2): AsyncResult<T, E2> {\n return new AsyncRes<T, E2>(\n this.promise.then((r) => {\n if (r.tag !== \"Err\") return passThrough(r);\n try {\n return errRes(f(r.error));\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n orElse<U, E2>(f: (error: E) => Result<U, E2> | AsyncResult<U, E2>): AsyncResult<T | U, E2> {\n return new AsyncRes<T | U, E2>(\n this.promise.then(async (r) => {\n if (r.tag !== \"Err\") return passThrough(r);\n try {\n return await f(r.error);\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n recover<U>(f: (error: E) => U): AsyncResult<T | U, never> {\n return new AsyncRes<T | U, never>(\n this.promise.then((r) => {\n if (r.tag !== \"Err\") return passThrough(r);\n try {\n return okRes<T | U, never>(f(r.error));\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n tapErr(f: (error: E) => void): AsyncResult<T, E> {\n return new AsyncRes<T, E>(\n this.promise.then((r) => {\n if (r.tag !== \"Err\") return r;\n try {\n f(r.error);\n return r;\n } catch (cause) {\n return defectRes<T, E>(cause);\n }\n }),\n );\n }\n\n flatTapErr<E2>(\n f: (error: E) => Result<unknown, E2> | AsyncResult<unknown, E2>,\n ): AsyncResult<T, E | E2> {\n return new AsyncRes<T, E | E2>(\n this.promise.then(async (r) => {\n if (r.tag !== \"Err\") return passThrough(r);\n try {\n const inner = await f(r.error);\n // Keep the original error on success; an Err/Defect from `f` wins.\n return inner.tag === \"Ok\" ? passThrough(r) : passThrough(inner);\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n recoverDefect<U, E2>(\n f: (cause: unknown) => Result<U, E2> | AsyncResult<U, E2>,\n ): AsyncResult<T | U, E | E2> {\n return new AsyncRes<T | U, E | E2>(\n this.promise.then(async (r) => {\n if (r.tag !== \"Defect\") return r;\n try {\n return await f(r.cause);\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n tapDefect(f: (cause: unknown) => void): AsyncResult<T, E> {\n return new AsyncRes<T, E>(\n this.promise.then((r) => {\n if (r.tag !== \"Defect\") return r;\n try {\n f(r.cause);\n return r;\n } catch (cause) {\n return defectRes<T, E>(cause);\n }\n }),\n );\n }\n\n match<R>(cases: {\n ok: (value: T) => R;\n err: (error: E) => R;\n defect: (cause: unknown) => R;\n }): Promise<R> {\n return this.promise.then((r) => r.match(cases));\n }\n\n unwrap(): Promise<T> {\n return this.promise.then((r) => r.unwrap());\n }\n unwrapErr(): Promise<E> {\n return this.promise.then((r) => r.unwrapErr());\n }\n unwrapOr(fallback: T): Promise<T> {\n return this.promise.then((r) => r.unwrapOr(fallback));\n }\n unwrapOrElse(f: (error: E) => T): Promise<T> {\n return this.promise.then((r) => r.unwrapOrElse(f));\n }\n getOrNull(): Promise<T | null> {\n return this.promise.then((r) => r.getOrNull());\n }\n getOrUndefined(): Promise<T | undefined> {\n return this.promise.then((r) => r.getOrUndefined());\n }\n}\n","// Result constructors and the standalone narrowing guards.\n\nimport { errRes, okRes } from \"./core.js\";\nimport type { DefectView, ErrView, OkView, Result } from \"./types.js\";\n\n/**\n * Construct a successful {@link Result}.\n *\n * @typeParam T - the success value type.\n * @param value - the success value to wrap.\n *\n * @example\n * ```ts\n * import { Ok } from \"unthrown\";\n * Ok(42).unwrap(); // 42\n * ```\n */\nexport function Ok<T>(value: T): Result<T, never> {\n return okRes(value);\n}\n\n/**\n * Construct a failed {@link Result} carrying a **modeled** error.\n *\n * @typeParam E - the modeled error type.\n * @param error - the domain error to wrap.\n *\n * @example\n * ```ts\n * import { Err } from \"unthrown\";\n * Err(\"not_found\").unwrapErr(); // \"not_found\"\n * ```\n */\nexport function Err<E>(error: E): Result<never, E> {\n return errRes(error);\n}\n\n/**\n * Type guard: narrow a {@link Result} to its `Ok` variant, exposing `.value`.\n *\n * @returns `true` when `r` is `Ok`.\n *\n * @example\n * ```ts\n * import { isOk, type Result } from \"unthrown\";\n * declare const r: Result<number, string>;\n * if (isOk(r)) r.value; // number, narrowed\n * ```\n */\nexport function isOk<T, E>(r: Result<T, E>): r is OkView<T, E> {\n return r.tag === \"Ok\";\n}\n/**\n * Type guard: narrow a {@link Result} to its `Err` variant, exposing `.error`.\n *\n * @returns `true` when `r` is `Err`.\n */\nexport function isErr<T, E>(r: Result<T, E>): r is ErrView<E, T> {\n return r.tag === \"Err\";\n}\n/**\n * Type guard: narrow a {@link Result} to its `Defect` variant, exposing `.cause`.\n *\n * @returns `true` when `r` is a `Defect`.\n */\nexport function isDefect<T, E>(r: Result<T, E>): r is DefectView<T, E> {\n return r.tag === \"Defect\";\n}\n","// Do-notation entry point. The `bind` / `let` steps live on the `Result` /\n// `AsyncResult` method surface (core.ts); `Do()` just seeds an empty object\n// scope to grow.\n\nimport { Ok } from \"./constructors.js\";\nimport type { Result } from \"./types.js\";\n\n/**\n * Start a do-notation chain with an empty object scope, grown step by step with\n * `bind` (for `Result`-returning steps) and `let` (for pure values).\n *\n * @remarks\n * Capitalised because `do` is a reserved word. Each step receives the scope\n * accumulated so far; the error types union across `bind`s, and a throw in any\n * step becomes a `Defect`. To go asynchronous, lift the chain with `toAsync()`\n * (then a `bind` may return an `AsyncResult`).\n *\n * @example\n * ```ts\n * import { Do, Ok } from \"unthrown\";\n *\n * const result = Do()\n * .bind(\"user\", () => findUser(id)) // Result<User, NotFound>\n * .bind(\"org\", ({ user }) => findOrg(user.orgId)) // Result<Org, NotFound>\n * .let(\"label\", ({ user, org }) => `${user.name} @ ${org.name}`)\n * .map(({ user, org, label }) => render(user, org, label));\n * // Result<View, NotFound>\n * ```\n */\nexport function Do(): Result<{}, never> {\n return Ok({});\n}\n","// Defect marker plumbing.\n\nconst DEFECT: unique symbol = Symbol(\"unthrown/Defect\");\n\n/**\n * The opaque marker a `qualify` function returns to triage a cause as\n * **unexpected**.\n *\n * @remarks\n * `qualify` (passed to {@link fromPromise} / {@link fromThrowable}) returns\n * `E | Defect`: either a modeled domain error, or a `Defect` produced by the\n * injected `defect` helper to say \"this failure is not modeled\". A `Defect` is\n * opaque — it carries the original cause for the boundary to convert into the\n * third runtime state of a `Result`. It is **not** a public value; the only way\n * to mint one is the `defect` helper the boundary passes to `qualify`.\n *\n * @internal\n */\nexport type Defect = {\n readonly [DEFECT]: true;\n readonly cause: unknown;\n};\n\n/**\n * Wrap a cause as a `Defect` marker — the value returned from a `qualify`\n * function when a failure is **not** a modeled domain error. The boundary\n * (`fromPromise` / `fromThrowable`) passes this in as `qualify`'s second\n * argument, so domain code never imports it.\n *\n * @param cause - the original thrown/rejected value.\n * @returns an opaque Defect marker carrying `cause`.\n *\n * @internal\n */\nexport function defect(cause: unknown): Defect {\n return { [DEFECT]: true, cause };\n}\n\n/**\n * Internal guard for the qualify-time marker. Distinct from the public\n * {@link isDefect} state guard — this one narrows the `E | Defect` union a\n * `qualify` function returns, not a `Result`.\n *\n * @internal\n */\nexport function isDefectMarker(x: unknown): x is Defect {\n return (\n typeof x === \"object\" && x !== null && (x as Record<PropertyKey, unknown>)[DEFECT] === true\n );\n}\n","// Boundary interop and aggregation. Every throwing/rejecting boundary is forced\n// through `qualify`, which triages each cause into a modeled `E` or a `Defect`;\n// there is no path that yields `unknown` in `E`.\n\nimport { AsyncRes, defectRes, errRes, okRes } from \"./core.js\";\nimport { type Defect, defect, isDefectMarker } from \"./defect.js\";\nimport { Err, Ok } from \"./constructors.js\";\nimport type { AsyncErrOf, AsyncOkOf, AsyncResult, ErrOf, OkOf, Result } from \"./types.js\";\n\n/**\n * Bridge a nullable value into a {@link Result}: absence becomes a **modeled**\n * `Err`. The sanctioned alternative to an `Option` type.\n *\n * @remarks\n * `null` and `undefined` map to `Err(onAbsent())`; any other value (including\n * falsy ones like `0`, `\"\"`, `false`) maps to `Ok`.\n *\n * @typeParam T - the (nullable) value type.\n * @typeParam E - the error produced when the value is absent.\n * @param value - the possibly-absent value.\n * @param onAbsent - lazily produces the error for the absent case.\n *\n * @example\n * ```ts\n * import { fromNullable } from \"unthrown\";\n * fromNullable(map.get(key), () => \"missing\").unwrap();\n * ```\n */\nexport function fromNullable<T, E>(\n value: T | null | undefined,\n onAbsent: () => E,\n): Result<NonNullable<T>, E> {\n return value === null || value === undefined ? Err(onAbsent()) : Ok(value as NonNullable<T>);\n}\n\n/**\n * Wrap a throwing synchronous function so it returns a {@link Result} instead of\n * throwing.\n *\n * @remarks\n * `qualify` **must** triage every thrown cause into a modeled error `E` or a\n * `Defect` (via the injected `defect` helper, its second argument) — there is no\n * path that leaves `unknown` in `E`. A throw inside `qualify` itself is treated\n * as a `Defect`.\n *\n * The modeled error type is `Exclude<R, Defect>` — the `Defect` arm of\n * `qualify`'s return is **subtracted** from `E`, never inferred into it. So a\n * `qualify` that returns *only* `defect(cause)` yields `E = never` (a Defect is\n * out-of-band and must not pollute the error channel); reach for\n * {@link fromSafePromise} when every failure is a Defect.\n *\n * @typeParam A - the wrapped function's argument tuple.\n * @typeParam T - the wrapped function's return type.\n * @typeParam R - `qualify`'s return type; the modeled error `E` is\n * `Exclude<R, Defect>` (its `Defect` arm, if any, is subtracted).\n * @param fn - the throwing function to wrap.\n * @param qualify - triages a thrown `cause` into a modeled `E`, or marks it\n * unmodeled by returning `defect(cause)` (the helper passed as its second arg).\n * @returns a function with the same arguments returning `Result<T, E>`.\n *\n * @example\n * ```ts\n * import { fromThrowable } from \"unthrown\";\n * const parse = fromThrowable(JSON.parse, (cause, defect) => defect(cause));\n * parse(\"{}\").unwrap();\n * ```\n */\nexport function fromThrowable<A extends unknown[], T, R>(\n fn: (...args: A) => T,\n qualify: (cause: unknown, defect: (cause: unknown) => Defect) => R,\n): (...args: A) => Result<T, Exclude<R, Defect>> {\n type E = Exclude<R, Defect>;\n const triage = qualify as (cause: unknown, defect: (cause: unknown) => Defect) => E | Defect;\n return (...args: A): Result<T, E> => {\n try {\n return Ok(fn(...args)) as Result<T, E>;\n } catch (cause) {\n return qualifyToResult<T, E>(cause, triage);\n }\n };\n}\n\n/**\n * Wrap a `Promise` (or a thunk producing one) as an {@link AsyncResult}, forcing\n * every rejection to be triaged.\n *\n * @remarks\n * `qualify` **must** map each rejection cause into a modeled error `E` or a\n * `Defect` (via the injected `defect` helper, its second argument). The returned\n * `AsyncResult`'s internal promise never rejects; `await`-ing it always yields a\n * `Result`. A throw inside `qualify` is itself a `Defect`.\n *\n * The modeled error type is `Exclude<R, Defect>` — the `Defect` arm of\n * `qualify`'s return is **subtracted** from `E`, never inferred into it. So a\n * `qualify` that returns *only* `defect(cause)` yields `E = never`; when every\n * rejection is a Defect, prefer {@link fromSafePromise}.\n *\n * @typeParam T - the resolved value type.\n * @typeParam R - `qualify`'s return type; the modeled error `E` is\n * `Exclude<R, Defect>` (its `Defect` arm, if any, is subtracted).\n * @param promise - the promise, or a thunk returning one.\n * @param qualify - triages a rejection `cause` into a modeled `E`, or marks it\n * unmodeled by returning `defect(cause)` (the helper passed as its second arg).\n *\n * @example\n * ```ts\n * import { fromPromise } from \"unthrown\";\n * const user = await fromPromise(fetchUser(id), (cause, defect) =>\n * cause instanceof NotFoundError ? (\"not_found\" as const) : defect(cause),\n * );\n * ```\n */\nexport function fromPromise<T, R>(\n promise: Promise<T> | (() => Promise<T>),\n qualify: (cause: unknown, defect: (cause: unknown) => Defect) => R,\n): AsyncResult<T, Exclude<R, Defect>> {\n type E = Exclude<R, Defect>;\n const triage = qualify as (cause: unknown, defect: (cause: unknown) => Defect) => E | Defect;\n const p = typeof promise === \"function\" ? Promise.resolve().then(promise) : promise;\n const settled: Promise<Result<T, E>> = p.then(\n (value) => okRes<T, E>(value),\n (cause) => qualifyToResult<T, E>(cause, triage),\n );\n return new AsyncRes<T, E>(settled);\n}\n\n/**\n * Wrap a `Promise` asserted **not** to fail in any modeled way: any rejection\n * becomes a `Defect`.\n *\n * @remarks\n * Use this only when a rejection genuinely indicates a bug rather than an\n * anticipated outcome — the error channel is `never`, so there is nothing to\n * triage. (`await`-ing still yields a `Result`; it never throws.)\n *\n * @typeParam T - the resolved value type.\n * @param promise - the promise, or a thunk returning one.\n */\nexport function fromSafePromise<T>(\n promise: Promise<T> | (() => Promise<T>),\n): AsyncResult<T, never> {\n const p = typeof promise === \"function\" ? Promise.resolve().then(promise) : promise;\n const settled: Promise<Result<T, never>> = p.then(\n (value) => okRes<T, never>(value),\n (cause) => defectRes<T, never>(cause),\n );\n return new AsyncRes<T, never>(settled);\n}\n\nfunction qualifyToResult<T, E>(\n cause: unknown,\n qualify: (cause: unknown, defect: (cause: unknown) => Defect) => E | Defect,\n): Result<T, E> {\n try {\n const q = qualify(cause, defect);\n return isDefectMarker(q) ? defectRes<T, E>(q.cause) : errRes<T, E>(q);\n } catch (qErr) {\n // a throw inside qualify is itself a Defect\n return defectRes<T, E>(qErr);\n }\n}\n\n/**\n * The success channel of {@link all} / {@link allAsync}: a **positional tuple**\n * for a fixed-length input (including the empty tuple), or a homogeneous\n * **array** for a dynamic one.\n *\n * @remarks\n * The split keys off the input's `length`: a fixed tuple has a literal length\n * (`number extends Rs[\"length\"]` is false → keep the positional `Ts`), while a\n * general array has `length: number` (→ collapse to `Ts[number][]`). Checking\n * length rather than `Rs extends [unknown, ...unknown[]]` keeps `all([])` typed\n * as `Result<[], …>` instead of `Result<never[], …>`.\n *\n * @typeParam Rs - the tuple/array of input `Result` types.\n * @typeParam Ts - per-element extracted success types (`OkOf` for `all`,\n * `AsyncOkOf` for `allAsync`).\n * @internal\n */\ntype AllOk<\n Rs extends readonly unknown[],\n Ts extends readonly unknown[],\n> = number extends Rs[\"length\"] ? Ts[number][] : Ts;\n\n/** A record of `Result`s — the input to {@link allFromDict}. */\ntype ResultRecord = Record<string, Result<unknown, unknown>>;\n/** A record of `AsyncResult`s — the input to {@link allFromDictAsync}. */\ntype AsyncResultRecord = Record<string, AsyncResult<unknown, unknown>>;\n\n/**\n * Fold an array of settled `Result`s: first `Err` wins, any `Defect` dominates,\n * else `Ok` of the values array.\n *\n * @internal\n */\nfunction foldArray(results: readonly Result<unknown, unknown>[]): Result<unknown, unknown> {\n let firstErr: Result<unknown, unknown> | undefined;\n let firstDefect: Result<unknown, unknown> | undefined;\n const values: unknown[] = [];\n for (const r of results) {\n if (r.tag === \"Defect\") {\n firstDefect ??= r;\n break; // any Defect dominates — nothing later can change the outcome\n } else if (r.tag === \"Err\") firstErr ??= r;\n else values.push(r.value);\n }\n return firstDefect ?? firstErr ?? Ok(values);\n}\n\n/**\n * Fold a record of settled `Result`s with the same rules, else `Ok` of the\n * record of values. Keys are written with `Object.defineProperty` so a\n * caller-supplied `\"__proto__\"` key cannot pollute the prototype.\n *\n * @internal\n */\nfunction foldRecord(results: ResultRecord): Result<unknown, unknown> {\n let firstErr: Result<unknown, unknown> | undefined;\n let firstDefect: Result<unknown, unknown> | undefined;\n const values: Record<string, unknown> = {};\n for (const [key, r] of Object.entries(results)) {\n if (r.tag === \"Defect\") firstDefect ??= r;\n else if (r.tag === \"Err\") firstErr ??= r;\n else\n Object.defineProperty(values, key, {\n value: r.value,\n enumerable: true,\n writable: true,\n configurable: true,\n });\n }\n return firstDefect ?? firstErr ?? Ok(values);\n}\n\n/**\n * Collect a tuple/array of {@link Result}s into a single `Result` of all their\n * success values.\n *\n * @remarks\n * Short-circuits on the **first** `Err` (later entries are not inspected for\n * their error); any `Defect` present **dominates**, winning even over an earlier\n * `Err`. A **fixed tuple** keeps its positional types — `all([Ok(1), Ok(\"a\")])`\n * is `Result<[number, string], …>` — while a **dynamic array** `Result<T, E>[]`\n * collapses to `Result<T[], E>` with no cast. For a **record** keyed by name,\n * use {@link allFromDict}.\n *\n * @example\n * ```ts\n * import { all, Ok } from \"unthrown\";\n * all([Ok(1), Ok(\"a\"), Ok(true)]).unwrap(); // [1, \"a\", true] (typed [number, string, boolean])\n * all([Ok(1), Ok(2)] as Result<number, never>[]).unwrap(); // number[]\n * ```\n */\nexport function all<Rs extends readonly Result<unknown, unknown>[]>(\n results: readonly [...Rs],\n): Result<AllOk<Rs, { [K in keyof Rs]: OkOf<Rs[K]> }>, ErrOf<Rs[number]>> {\n return foldArray(results) as unknown as Result<\n AllOk<Rs, { [K in keyof Rs]: OkOf<Rs[K]> }>,\n ErrOf<Rs[number]>\n >;\n}\n\n/**\n * Collect a **record** of {@link Result}s into a single `Result` of a record of\n * their success values — `allFromDict({ a: Result<A, E>, b: Result<B, E> })` is\n * `Result<{ a: A; b: B }, E>`. The named counterpart of {@link all}, for\n * parallel work you'd rather not tuple.\n *\n * @remarks\n * Same folding rules as {@link all}: first `Err` short-circuits, any `Defect`\n * dominates. This is **not** error accumulation.\n *\n * @example\n * ```ts\n * import { allFromDict, Ok } from \"unthrown\";\n * allFromDict({ id: Ok(1), name: Ok(\"ada\") }).unwrap(); // { id: 1, name: \"ada\" }\n * ```\n */\nexport function allFromDict<R extends ResultRecord>(\n results: R,\n): Result<{ [K in keyof R]: OkOf<R[K]> }, ErrOf<R[keyof R]>> {\n return foldRecord(results) as unknown as Result<\n { [K in keyof R]: OkOf<R[K]> },\n ErrOf<R[keyof R]>\n >;\n}\n\n/**\n * The asynchronous counterpart of {@link all}: combine a tuple/array of\n * {@link AsyncResult}s into one `AsyncResult` of all their success values.\n *\n * @remarks\n * The inputs are resolved **concurrently** (order preserved); the resolved\n * `Result`s are then folded with the same rules as {@link all} — first `Err`\n * short-circuits, any `Defect` dominates. As ever, the returned `AsyncResult`'s\n * internal promise never rejects. For a **record**, use {@link allFromDictAsync}.\n *\n * @example\n * ```ts\n * import { allAsync, fromSafePromise } from \"unthrown\";\n * await allAsync([fromSafePromise(a()), fromSafePromise(b())]);\n * ```\n */\nexport function allAsync<Rs extends readonly AsyncResult<unknown, unknown>[]>(\n results: readonly [...Rs],\n): AsyncResult<AllOk<Rs, { [K in keyof Rs]: AsyncOkOf<Rs[K]> }>, AsyncErrOf<Rs[number]>> {\n // Each AsyncResult is a (never-rejecting) thenable, so Promise.all adopts them;\n // `foldArray` then applies the all() rules. The internal promise never rejects.\n const settled = Promise.all(results).then((resolved) =>\n foldArray(resolved as readonly Result<unknown, unknown>[]),\n );\n return new AsyncRes(settled) as unknown as AsyncResult<\n AllOk<Rs, { [K in keyof Rs]: AsyncOkOf<Rs[K]> }>,\n AsyncErrOf<Rs[number]>\n >;\n}\n\n/**\n * The asynchronous counterpart of {@link allFromDict}: combine a record of\n * {@link AsyncResult}s into one `AsyncResult` of a record of their values.\n *\n * @remarks\n * Resolved concurrently (order preserved), folded with the {@link all} rules,\n * and the internal promise never rejects.\n *\n * @example\n * ```ts\n * import { allFromDictAsync, fromSafePromise } from \"unthrown\";\n * await allFromDictAsync({ a: fromSafePromise(a()), b: fromSafePromise(b()) });\n * ```\n */\nexport function allFromDictAsync<R extends AsyncResultRecord>(\n results: R,\n): AsyncResult<{ [K in keyof R]: AsyncOkOf<R[K]> }, AsyncErrOf<R[keyof R]>> {\n const entries = Object.entries(results);\n const settled = Promise.all(entries.map(([, ar]) => ar)).then((resolved) => {\n // Null-proto accumulator: pairing resolved values back to keys can't pollute.\n const byKey: ResultRecord = Object.create(null) as ResultRecord;\n entries.forEach(([key], i) => {\n byKey[key] = resolved[i]!;\n });\n return foldRecord(byKey);\n });\n return new AsyncRes(settled) as unknown as AsyncResult<\n { [K in keyof R]: AsyncOkOf<R[K]> },\n AsyncErrOf<R[keyof R]>\n >;\n}\n","// Result facade — a discoverable namespace alias for the standalone entry\n// points. The free functions remain the primary, tree-shakeable API; this\n// object is a separate export, so `import { Ok }` never pulls it in. The value\n// `Result` and the type `Result<T, E>` (types.ts) share a name — the\n// companion-object pattern. See CLAUDE.md → \"Internal design\".\n\nimport { Err, isDefect, isErr, isOk, Ok } from \"./constructors.js\";\nimport { isResult } from \"./core.js\";\nimport { Do } from \"./do.js\";\nimport {\n all,\n allAsync,\n allFromDict,\n allFromDictAsync,\n fromNullable,\n fromPromise,\n fromSafePromise,\n fromThrowable,\n} from \"./interop.js\";\nimport type { AsyncResult as AsyncResultType, Result as ResultType } from \"./types.js\";\n\n/**\n * Companion object grouping the **`Result`-producing** entry points under a\n * single, discoverable namespace: {@link Result.Ok}, {@link Result.Err},\n * {@link Result.Do}, {@link Result.fromNullable}, {@link Result.fromThrowable},\n * {@link Result.all}, {@link Result.allFromDict}, {@link Result.isOk},\n * {@link Result.isErr}, {@link Result.isDefect}, {@link Result.isResult}.\n *\n * @remarks\n * Purely additive sugar — each member **is** the corresponding free function.\n * The free functions remain the primary, tree-shakeable API; importing only\n * `{ Ok }` never pulls this object in. The value `Result` and the type\n * {@link Result} share one name (the companion-object pattern).\n *\n * The **async** entry points live on the sibling {@link AsyncResult} companion\n * (`AsyncResult.fromPromise`, `AsyncResult.all`, …), grouped by what they\n * return — a static lives in exactly one namespace.\n *\n * @example\n * ```ts\n * import { Result } from \"unthrown\";\n * Result.Ok(1).flatMap((n) => Result.Ok(n + 1)).unwrap(); // 2\n * ```\n */\nexport const Result = {\n Ok,\n Err,\n Do,\n fromNullable,\n fromThrowable,\n all,\n allFromDict,\n isOk,\n isErr,\n isDefect,\n isResult,\n} as const;\n\n// Re-alias the Result type into this module so a single `export { Result }`\n// (from index.ts) carries BOTH the companion object above and the type — value\n// and type sharing one name, declaration-merged in one place.\nexport type Result<T, E> = ResultType<T, E>;\n\n/**\n * Companion object grouping the **`AsyncResult`-producing** entry points under\n * the matching namespace: {@link AsyncResult.fromPromise},\n * {@link AsyncResult.fromSafePromise}, {@link AsyncResult.all},\n * {@link AsyncResult.allFromDict}.\n *\n * @remarks\n * The async sibling of {@link Result}. Statics are grouped by what they\n * **return**, so `fromPromise`/`fromSafePromise` and the async aggregates sit\n * here rather than on {@link Result}; the namespace already conveys \"async\", so\n * the aggregates drop the `Async` suffix (`AsyncResult.all` is the free function\n * `allAsync`; `AsyncResult.allFromDict` is `allFromDictAsync`). Like\n * {@link Result}, the free functions remain the primary, tree-shakeable API; the\n * value `AsyncResult` and the type {@link AsyncResult} share one name.\n *\n * @example\n * ```ts\n * import { AsyncResult } from \"unthrown\";\n * const user = await AsyncResult.fromPromise(fetchUser(id), (c, defect) => defect(c));\n * ```\n */\nexport const AsyncResult = {\n fromPromise,\n fromSafePromise,\n all: allAsync,\n allFromDict: allFromDictAsync,\n} as const;\n\n// Re-alias the AsyncResult type into this module (same companion-object pattern\n// as Result above) so one `export { AsyncResult }` carries value + type.\nexport type AsyncResult<T, E> = AsyncResultType<T, E>;\n","// The TaggedError convention (à la Effect's `Data.TaggedError`) and an\n// exhaustive, zero-dependency fold over a tagged error union.\n\nimport type { AsyncResult, Result } from \"./types.js\";\n\ntype Props = Record<string, unknown>;\n\n/**\n * The instance shape produced by a {@link TaggedError} class: an `Error` plus a\n * `_tag` discriminant and the (readonly) payload fields.\n *\n * @typeParam Tag - the string literal discriminant.\n * @typeParam A - the payload object type.\n */\nexport type TaggedErrorInstance<Tag extends string, A extends Props> = Error &\n Readonly<A> & { readonly _tag: Tag };\n\n/**\n * The class constructor returned by {@link TaggedError}. Generic in its payload:\n * apply it with an instantiation expression at the `extends` site.\n *\n * @remarks\n * When the payload is empty, the constructor takes **no** arguments (the\n * `keyof A extends never ? void : A` trick); otherwise it takes the payload.\n *\n * @typeParam Tag - the string literal discriminant.\n */\nexport type TaggedErrorConstructor<Tag extends string> = {\n new <A extends Props = {}>(args: keyof A extends never ? void : A): TaggedErrorInstance<Tag, A>;\n};\n\n/**\n * Build a base class for a tagged error — a class extending `Error` with a\n * `_tag` string discriminant, in the style of Effect's `Data.TaggedError`.\n *\n * @remarks\n * Extend the returned class to declare a concrete error. Supply the payload with\n * an instantiation expression; omit it for a payload-less error. A `message`\n * field in the payload is forwarded to `Error`. The `_tag` always reflects\n * `tag` and cannot be overridden by the payload.\n *\n * `_tag` is the discriminant used by {@link matchTags}; `Error.name` is the\n * human-facing label in stack traces and logs. By default they coincide, but\n * they can be **decoupled** with `options.name` — so a tag can be namespaced for\n * collision-safety (`\"@my-lib/RetryableError\"`) without that slash-prefixed\n * string leaking into `Error.name`:\n *\n * ```ts\n * class RetryableError extends TaggedError(\"@my-lib/RetryableError\", {\n * name: \"RetryableError\",\n * })<{ message: string }> {}\n *\n * const e = new RetryableError({ message: \"boom\" });\n * e._tag; // \"@my-lib/RetryableError\" — namespaced discriminant\n * e.name; // \"RetryableError\" — clean display name\n * ```\n *\n * @typeParam Tag - the string literal discriminant.\n * @param tag - the discriminant value; also the default error `name`.\n * @param options - optional overrides. `options.name` sets `Error.name`\n * independently of `tag` (defaults to `tag`).\n *\n * @example\n * ```ts\n * class NotFound extends TaggedError(\"NotFound\") {}\n * class HttpError extends TaggedError(\"HttpError\")<{ status: number }> {}\n *\n * new NotFound()._tag; // \"NotFound\"\n * new HttpError({ status: 500 }).status; // 500\n * ```\n */\nexport function TaggedError<Tag extends string>(\n tag: Tag,\n options?: { readonly name?: string },\n): TaggedErrorConstructor<Tag> {\n const displayName = options?.name ?? tag;\n class TaggedErrorBase extends Error {\n readonly _tag!: Tag;\n\n constructor(props?: Props) {\n super(typeof props?.[\"message\"] === \"string\" ? (props[\"message\"] as string) : undefined);\n if (props) Object.assign(this, props);\n // The tag is authoritative — assign it after the payload so it can't be\n // clobbered. `name` is the display label, independent of the discriminant.\n (this as { _tag: Tag })._tag = tag;\n this.name = displayName;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n }\n\n return TaggedErrorBase as unknown as TaggedErrorConstructor<Tag>;\n}\n\n/**\n * The handler object {@link matchTags} requires: a branch per error tag, plus\n * `Ok` and `Defect`. Miss a tag and it will not compile — the exhaustiveness is\n * enforced by the type, with no `.exhaustive()` to forget.\n *\n * @typeParam T - the success value type.\n * @typeParam E - the tagged error union.\n * @typeParam R - the folded result type.\n */\nexport type TagHandlers<T, E extends { _tag: string }, R> = {\n Ok: (value: T) => R;\n Defect: (cause: unknown) => R;\n} & { [K in E[\"_tag\"]]: (error: Extract<E, { _tag: K }>) => R };\n\n/**\n * Exhaustively fold a {@link Result} (or {@link AsyncResult}) whose error type is\n * a tagged union, dispatching each error to the handler matching its `_tag`.\n *\n * @remarks\n * The `handlers` object must provide `Ok`, `Defect`, and exactly one function\n * per error tag; each tag's handler receives the narrowed error variant. A\n * missing tag is a compile error. For an `AsyncResult`, the fold resolves to a\n * `Promise<R>`.\n *\n * @typeParam T - the success value type.\n * @typeParam E - the tagged error union (`E extends { _tag: string }`).\n * @typeParam R - the folded result type.\n * @param result - the result to fold.\n * @param handlers - one branch per channel/tag.\n *\n * @example\n * ```ts\n * class NotFound extends TaggedError(\"NotFound\") {}\n * class Forbidden extends TaggedError(\"Forbidden\")<{ user: string }> {}\n *\n * declare const r: Result<number, NotFound | Forbidden>;\n * matchTags(r, {\n * Ok: (n) => `got ${n}`,\n * Defect: (cause) => `bug: ${String(cause)}`,\n * NotFound: () => \"404\",\n * Forbidden: (e) => `403 for ${e.user}`,\n * });\n * ```\n */\nexport function matchTags<T, E extends { _tag: string }, R>(\n result: Result<T, E>,\n handlers: TagHandlers<T, E, R>,\n): R;\nexport function matchTags<T, E extends { _tag: string }, R>(\n result: AsyncResult<T, E>,\n handlers: TagHandlers<T, E, R>,\n): Promise<R>;\nexport function matchTags<T, E extends { _tag: string }, R>(\n result: Result<T, E> | AsyncResult<T, E>,\n handlers: TagHandlers<T, E, R>,\n): R | Promise<R> {\n const onErr = (error: E): R => {\n const handler = handlers[error._tag as E[\"_tag\"]] as unknown as (e: E) => R;\n return handler(error);\n };\n // Both Result and AsyncResult share `match`; the cast picks one signature for\n // the call while the public overloads keep the return type correct.\n return (result as Result<T, E>).match({ ok: handlers.Ok, err: onErr, defect: handlers.Defect });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OAAO,eAAe,MAAM,IAAI,OAAO,SAAS;EAClD;CACF;CAEA,OAAO;AACT;AAsDA,SAAgB,UACd,QACA,UACgB;CAChB,MAAM,SAAS,UAAgB;EAC7B,MAAM,UAAU,SAAS,MAAM;EAC/B,OAAO,QAAQ,KAAK;CACtB;CAGA,OAAQ,OAAwB,MAAM;EAAE,IAAI,SAAS;EAAI,KAAK;EAAO,QAAQ,SAAS;CAAO,CAAC;AAChG"}
|
package/docs/index.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
### UnwrapError
|
|
10
10
|
|
|
11
|
-
Defined in: [packages/core/src/core.ts:35](https://github.com/btravstack/unthrown/blob/
|
|
11
|
+
Defined in: [packages/core/src/core.ts:35](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/core.ts#L35)
|
|
12
12
|
|
|
13
13
|
Thrown by a [Result](#result)'s `unwrap` / `unwrapErr` when the assertion is
|
|
14
14
|
wrong on a *modeled* result — `unwrap()` on an `Err`, or `unwrapErr()` on an
|
|
@@ -42,7 +42,7 @@ re-thrown (with its original stack) instead.
|
|
|
42
42
|
new UnwrapError<E>(error): UnwrapError<E>;
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
Defined in: [packages/core/src/core.ts:41](https://github.com/btravstack/unthrown/blob/
|
|
45
|
+
Defined in: [packages/core/src/core.ts:41](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/core.ts#L41)
|
|
46
46
|
|
|
47
47
|
###### Parameters
|
|
48
48
|
|
|
@@ -65,7 +65,7 @@ Error.constructor
|
|
|
65
65
|
| Property | Modifier | Type | Description | Inherited from | Defined in |
|
|
66
66
|
| ------ | ------ | ------ | ------ | ------ | ------ |
|
|
67
67
|
| <a id="cause"></a> `cause?` | `public` | `unknown` | - | `Error.cause` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es2022.error.d.ts:24 |
|
|
68
|
-
| <a id="error"></a> `error` | `readonly` | `E` | The offending value: the `Err` error for `unwrap()`, or the `Ok` value for `unwrapErr()`. | - | [packages/core/src/core.ts:40](https://github.com/btravstack/unthrown/blob/
|
|
68
|
+
| <a id="error"></a> `error` | `readonly` | `E` | The offending value: the `Err` error for `unwrap()`, or the `Ok` value for `unwrapErr()`. | - | [packages/core/src/core.ts:40](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/core.ts#L40) |
|
|
69
69
|
| <a id="message"></a> `message` | `public` | `string` | - | `Error.message` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1075 |
|
|
70
70
|
| <a id="name"></a> `name` | `public` | `string` | - | `Error.name` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1074 |
|
|
71
71
|
| <a id="stack"></a> `stack?` | `public` | `string` | - | `Error.stack` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1076 |
|
|
@@ -179,7 +179,7 @@ Error.prepareStackTrace
|
|
|
179
179
|
type AsyncErrOf<R> = R extends AsyncResult<unknown, infer E> ? E : never;
|
|
180
180
|
```
|
|
181
181
|
|
|
182
|
-
Defined in: [packages/core/src/types.ts:468](https://github.com/btravstack/unthrown/blob/
|
|
182
|
+
Defined in: [packages/core/src/types.ts:468](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/types.ts#L468)
|
|
183
183
|
|
|
184
184
|
Extract the error type `E` from an [AsyncResult](#asyncresult).
|
|
185
185
|
|
|
@@ -197,7 +197,7 @@ Extract the error type `E` from an [AsyncResult](#asyncresult).
|
|
|
197
197
|
type AsyncOkOf<R> = R extends AsyncResult<infer T, unknown> ? T : never;
|
|
198
198
|
```
|
|
199
199
|
|
|
200
|
-
Defined in: [packages/core/src/types.ts:462](https://github.com/btravstack/unthrown/blob/
|
|
200
|
+
Defined in: [packages/core/src/types.ts:462](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/types.ts#L462)
|
|
201
201
|
|
|
202
202
|
Extract the success type `T` from an [AsyncResult](#asyncresult).
|
|
203
203
|
|
|
@@ -215,7 +215,7 @@ Extract the success type `T` from an [AsyncResult](#asyncresult).
|
|
|
215
215
|
type AsyncResult<T, E> = AsyncResultType<T, E>;
|
|
216
216
|
```
|
|
217
217
|
|
|
218
|
-
Defined in: [packages/core/src/facade.ts:85](https://github.com/btravstack/unthrown/blob/
|
|
218
|
+
Defined in: [packages/core/src/facade.ts:85](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/facade.ts#L85)
|
|
219
219
|
|
|
220
220
|
Companion object grouping the **`AsyncResult`-producing** entry points under
|
|
221
221
|
the matching namespace: [AsyncResult.fromPromise](#property-frompromise),
|
|
@@ -254,7 +254,7 @@ const user = await AsyncResult.fromPromise(fetchUser(id), (c, defect) => defect(
|
|
|
254
254
|
type Awaitable<T> = object;
|
|
255
255
|
```
|
|
256
256
|
|
|
257
|
-
Defined in: [packages/core/src/types.ts:346](https://github.com/btravstack/unthrown/blob/
|
|
257
|
+
Defined in: [packages/core/src/types.ts:346](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/types.ts#L346)
|
|
258
258
|
|
|
259
259
|
A success-only thenable: awaitable, but deliberately **not** a full
|
|
260
260
|
`PromiseLike`.
|
|
@@ -281,7 +281,7 @@ being treated as a raw promise (e.g. dropped into `Promise.all`).
|
|
|
281
281
|
then<R>(onfulfilled?): PromiseLike<R>;
|
|
282
282
|
```
|
|
283
283
|
|
|
284
|
-
Defined in: [packages/core/src/types.ts:347](https://github.com/btravstack/unthrown/blob/
|
|
284
|
+
Defined in: [packages/core/src/types.ts:347](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/types.ts#L347)
|
|
285
285
|
|
|
286
286
|
###### Type Parameters
|
|
287
287
|
|
|
@@ -307,7 +307,7 @@ Defined in: [packages/core/src/types.ts:347](https://github.com/btravstack/unthr
|
|
|
307
307
|
type DefectView<T, E> = ResultMethods<T, E> & object;
|
|
308
308
|
```
|
|
309
309
|
|
|
310
|
-
Defined in: [packages/core/src/types.ts:289](https://github.com/btravstack/unthrown/blob/
|
|
310
|
+
Defined in: [packages/core/src/types.ts:289](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/types.ts#L289)
|
|
311
311
|
|
|
312
312
|
The `Defect` variant of a [Result](#result): an unmodeled failure carrying a `cause`.
|
|
313
313
|
|
|
@@ -315,8 +315,8 @@ The `Defect` variant of a [Result](#result): an unmodeled failure carrying a `ca
|
|
|
315
315
|
|
|
316
316
|
| Name | Type | Defined in |
|
|
317
317
|
| ------ | ------ | ------ |
|
|
318
|
-
| `cause` | `unknown` | [packages/core/src/types.ts:291](https://github.com/btravstack/unthrown/blob/
|
|
319
|
-
| `tag` | `"Defect"` | [packages/core/src/types.ts:290](https://github.com/btravstack/unthrown/blob/
|
|
318
|
+
| `cause` | `unknown` | [packages/core/src/types.ts:291](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/types.ts#L291) |
|
|
319
|
+
| `tag` | `"Defect"` | [packages/core/src/types.ts:290](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/types.ts#L290) |
|
|
320
320
|
|
|
321
321
|
#### Type Parameters
|
|
322
322
|
|
|
@@ -333,7 +333,7 @@ The `Defect` variant of a [Result](#result): an unmodeled failure carrying a `ca
|
|
|
333
333
|
type ErrOf<R> = R extends object ? E : never;
|
|
334
334
|
```
|
|
335
335
|
|
|
336
|
-
Defined in: [packages/core/src/types.ts:456](https://github.com/btravstack/unthrown/blob/
|
|
336
|
+
Defined in: [packages/core/src/types.ts:456](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/types.ts#L456)
|
|
337
337
|
|
|
338
338
|
Extract the error type `E` from a `Result`.
|
|
339
339
|
|
|
@@ -351,7 +351,7 @@ Extract the error type `E` from a `Result`.
|
|
|
351
351
|
type ErrView<E, T> = ResultMethods<T, E> & object;
|
|
352
352
|
```
|
|
353
353
|
|
|
354
|
-
Defined in: [packages/core/src/types.ts:284](https://github.com/btravstack/unthrown/blob/
|
|
354
|
+
Defined in: [packages/core/src/types.ts:284](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/types.ts#L284)
|
|
355
355
|
|
|
356
356
|
The `Err` variant of a [Result](#result): a modeled failure carrying an `error`.
|
|
357
357
|
|
|
@@ -359,8 +359,8 @@ The `Err` variant of a [Result](#result): a modeled failure carrying an `error`.
|
|
|
359
359
|
|
|
360
360
|
| Name | Type | Defined in |
|
|
361
361
|
| ------ | ------ | ------ |
|
|
362
|
-
| `error` | `E` | [packages/core/src/types.ts:286](https://github.com/btravstack/unthrown/blob/
|
|
363
|
-
| `tag` | `"Err"` | [packages/core/src/types.ts:285](https://github.com/btravstack/unthrown/blob/
|
|
362
|
+
| `error` | `E` | [packages/core/src/types.ts:286](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/types.ts#L286) |
|
|
363
|
+
| `tag` | `"Err"` | [packages/core/src/types.ts:285](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/types.ts#L285) |
|
|
364
364
|
|
|
365
365
|
#### Type Parameters
|
|
366
366
|
|
|
@@ -377,7 +377,7 @@ The `Err` variant of a [Result](#result): a modeled failure carrying an `error`.
|
|
|
377
377
|
type OkOf<R> = R extends object ? T : never;
|
|
378
378
|
```
|
|
379
379
|
|
|
380
|
-
Defined in: [packages/core/src/types.ts:450](https://github.com/btravstack/unthrown/blob/
|
|
380
|
+
Defined in: [packages/core/src/types.ts:450](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/types.ts#L450)
|
|
381
381
|
|
|
382
382
|
Extract the success type `T` from a `Result`.
|
|
383
383
|
|
|
@@ -395,7 +395,7 @@ Extract the success type `T` from a `Result`.
|
|
|
395
395
|
type OkView<T, E> = ResultMethods<T, E> & object;
|
|
396
396
|
```
|
|
397
397
|
|
|
398
|
-
Defined in: [packages/core/src/types.ts:279](https://github.com/btravstack/unthrown/blob/
|
|
398
|
+
Defined in: [packages/core/src/types.ts:279](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/types.ts#L279)
|
|
399
399
|
|
|
400
400
|
The `Ok` variant of a [Result](#result): a success carrying a `value`.
|
|
401
401
|
|
|
@@ -403,8 +403,8 @@ The `Ok` variant of a [Result](#result): a success carrying a `value`.
|
|
|
403
403
|
|
|
404
404
|
| Name | Type | Defined in |
|
|
405
405
|
| ------ | ------ | ------ |
|
|
406
|
-
| `tag` | `"Ok"` | [packages/core/src/types.ts:280](https://github.com/btravstack/unthrown/blob/
|
|
407
|
-
| `value` | `T` | [packages/core/src/types.ts:281](https://github.com/btravstack/unthrown/blob/
|
|
406
|
+
| `tag` | `"Ok"` | [packages/core/src/types.ts:280](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/types.ts#L280) |
|
|
407
|
+
| `value` | `T` | [packages/core/src/types.ts:281](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/types.ts#L281) |
|
|
408
408
|
|
|
409
409
|
#### Type Parameters
|
|
410
410
|
|
|
@@ -421,7 +421,7 @@ The `Ok` variant of a [Result](#result): a success carrying a `value`.
|
|
|
421
421
|
type Result<T, E> = ResultType<T, E>;
|
|
422
422
|
```
|
|
423
423
|
|
|
424
|
-
Defined in: [packages/core/src/facade.ts:45](https://github.com/btravstack/unthrown/blob/
|
|
424
|
+
Defined in: [packages/core/src/facade.ts:45](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/facade.ts#L45)
|
|
425
425
|
|
|
426
426
|
Companion object grouping the **`Result`-producing** entry points under a
|
|
427
427
|
single, discoverable namespace: [Result.Ok](#property-ok), [Result.Err](#property-err),
|
|
@@ -462,7 +462,7 @@ Result.Ok(1).flatMap((n) => Result.Ok(n + 1)).unwrap(); // 2
|
|
|
462
462
|
type TaggedErrorConstructor<Tag> = <A>(args) => TaggedErrorInstance<Tag, A>;
|
|
463
463
|
```
|
|
464
464
|
|
|
465
|
-
Defined in: [packages/core/src/tagged.ts:28](https://github.com/btravstack/unthrown/blob/
|
|
465
|
+
Defined in: [packages/core/src/tagged.ts:28](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/tagged.ts#L28)
|
|
466
466
|
|
|
467
467
|
The class constructor returned by [TaggedError](#taggederror). Generic in its payload:
|
|
468
468
|
apply it with an instantiation expression at the `extends` site.
|
|
@@ -496,7 +496,7 @@ When the payload is empty, the constructor takes **no** arguments (the
|
|
|
496
496
|
type TaggedErrorInstance<Tag, A> = Error & Readonly<A> & object;
|
|
497
497
|
```
|
|
498
498
|
|
|
499
|
-
Defined in: [packages/core/src/tagged.ts:15](https://github.com/btravstack/unthrown/blob/
|
|
499
|
+
Defined in: [packages/core/src/tagged.ts:15](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/tagged.ts#L15)
|
|
500
500
|
|
|
501
501
|
The instance shape produced by a [TaggedError](#taggederror) class: an `Error` plus a
|
|
502
502
|
`_tag` discriminant and the (readonly) payload fields.
|
|
@@ -505,7 +505,7 @@ The instance shape produced by a [TaggedError](#taggederror) class: an `Error` p
|
|
|
505
505
|
|
|
506
506
|
| Name | Type | Defined in |
|
|
507
507
|
| ------ | ------ | ------ |
|
|
508
|
-
| `_tag` | `Tag` | [packages/core/src/tagged.ts:16](https://github.com/btravstack/unthrown/blob/
|
|
508
|
+
| `_tag` | `Tag` | [packages/core/src/tagged.ts:16](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/tagged.ts#L16) |
|
|
509
509
|
|
|
510
510
|
#### Type Parameters
|
|
511
511
|
|
|
@@ -522,7 +522,7 @@ The instance shape produced by a [TaggedError](#taggederror) class: an `Error` p
|
|
|
522
522
|
type TagHandlers<T, E, R> = object & { [K in E["_tag"]]: (error: Extract<E, { _tag: K }>) => R };
|
|
523
523
|
```
|
|
524
524
|
|
|
525
|
-
Defined in: [packages/core/src/tagged.ts:103](https://github.com/btravstack/unthrown/blob/
|
|
525
|
+
Defined in: [packages/core/src/tagged.ts:103](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/tagged.ts#L103)
|
|
526
526
|
|
|
527
527
|
The handler object [matchTags](#matchtags) requires: a branch per error tag, plus
|
|
528
528
|
`Ok` and `Defect`. Miss a tag and it will not compile — the exhaustiveness is
|
|
@@ -532,8 +532,8 @@ enforced by the type, with no `.exhaustive()` to forget.
|
|
|
532
532
|
|
|
533
533
|
| Name | Type | Defined in |
|
|
534
534
|
| ------ | ------ | ------ |
|
|
535
|
-
| `Defect()` | (`cause`) => `R` | [packages/core/src/tagged.ts:105](https://github.com/btravstack/unthrown/blob/
|
|
536
|
-
| `Ok()` | (`value`) => `R` | [packages/core/src/tagged.ts:104](https://github.com/btravstack/unthrown/blob/
|
|
535
|
+
| `Defect()` | (`cause`) => `R` | [packages/core/src/tagged.ts:105](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/tagged.ts#L105) |
|
|
536
|
+
| `Ok()` | (`value`) => `R` | [packages/core/src/tagged.ts:104](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/tagged.ts#L104) |
|
|
537
537
|
|
|
538
538
|
#### Type Parameters
|
|
539
539
|
|
|
@@ -551,7 +551,7 @@ enforced by the type, with no `.exhaustive()` to forget.
|
|
|
551
551
|
const AsyncResult: object;
|
|
552
552
|
```
|
|
553
553
|
|
|
554
|
-
Defined in: [packages/core/src/facade.ts:85](https://github.com/btravstack/unthrown/blob/
|
|
554
|
+
Defined in: [packages/core/src/facade.ts:85](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/facade.ts#L85)
|
|
555
555
|
|
|
556
556
|
Companion object grouping the **`AsyncResult`-producing** entry points under
|
|
557
557
|
the matching namespace: [AsyncResult.fromPromise](#property-frompromise),
|
|
@@ -562,10 +562,10 @@ the matching namespace: [AsyncResult.fromPromise](#property-frompromise),
|
|
|
562
562
|
|
|
563
563
|
| Name | Type | Default value | Defined in |
|
|
564
564
|
| ------ | ------ | ------ | ------ |
|
|
565
|
-
| <a id="property-all"></a> `all()` | <`Rs`>(`results`) => `AsyncResult`<`AllOk`<`Rs`, \{ \[K in string \| number \| symbol\]: AsyncOkOf\<Rs\[K\]\> \}>, [`AsyncErrOf`](#asyncerrof)<`Rs`\[`number`\]>> | `allAsync` | [packages/core/src/facade.ts:88](https://github.com/btravstack/unthrown/blob/
|
|
566
|
-
| <a id="property-allfromdict"></a> `allFromDict()` | <`R`>(`results`) => `AsyncResult`<\{ \[K in string \| number \| symbol\]: AsyncOkOf\<R\[K\]\> \}, [`AsyncErrOf`](#asyncerrof)<`R`\[keyof `R`\]>> | `allFromDictAsync` | [packages/core/src/facade.ts:89](https://github.com/btravstack/unthrown/blob/
|
|
567
|
-
| <a id="property-frompromise"></a> `fromPromise()` | <`T`, `R`>(`promise`, `qualify`) => `AsyncResult`<`T`, `Exclude`<`R`, `Defect`>> | - | [packages/core/src/facade.ts:86](https://github.com/btravstack/unthrown/blob/
|
|
568
|
-
| <a id="property-fromsafepromise"></a> `fromSafePromise()` | <`T`>(`promise`) => `AsyncResult`<`T`, `never`> | - | [packages/core/src/facade.ts:87](https://github.com/btravstack/unthrown/blob/
|
|
565
|
+
| <a id="property-all"></a> `all()` | <`Rs`>(`results`) => `AsyncResult`<`AllOk`<`Rs`, \{ \[K in string \| number \| symbol\]: AsyncOkOf\<Rs\[K\]\> \}>, [`AsyncErrOf`](#asyncerrof)<`Rs`\[`number`\]>> | `allAsync` | [packages/core/src/facade.ts:88](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/facade.ts#L88) |
|
|
566
|
+
| <a id="property-allfromdict"></a> `allFromDict()` | <`R`>(`results`) => `AsyncResult`<\{ \[K in string \| number \| symbol\]: AsyncOkOf\<R\[K\]\> \}, [`AsyncErrOf`](#asyncerrof)<`R`\[keyof `R`\]>> | `allFromDictAsync` | [packages/core/src/facade.ts:89](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/facade.ts#L89) |
|
|
567
|
+
| <a id="property-frompromise"></a> `fromPromise()` | <`T`, `R`>(`promise`, `qualify`) => `AsyncResult`<`T`, `Exclude`<`R`, `Defect`>> | - | [packages/core/src/facade.ts:86](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/facade.ts#L86) |
|
|
568
|
+
| <a id="property-fromsafepromise"></a> `fromSafePromise()` | <`T`>(`promise`) => `AsyncResult`<`T`, `never`> | - | [packages/core/src/facade.ts:87](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/facade.ts#L87) |
|
|
569
569
|
|
|
570
570
|
#### Remarks
|
|
571
571
|
|
|
@@ -592,7 +592,7 @@ const user = await AsyncResult.fromPromise(fetchUser(id), (c, defect) => defect(
|
|
|
592
592
|
const Result: object;
|
|
593
593
|
```
|
|
594
594
|
|
|
595
|
-
Defined in: [packages/core/src/facade.ts:45](https://github.com/btravstack/unthrown/blob/
|
|
595
|
+
Defined in: [packages/core/src/facade.ts:45](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/facade.ts#L45)
|
|
596
596
|
|
|
597
597
|
Companion object grouping the **`Result`-producing** entry points under a
|
|
598
598
|
single, discoverable namespace: [Result.Ok](#property-ok), [Result.Err](#property-err),
|
|
@@ -604,17 +604,17 @@ single, discoverable namespace: [Result.Ok](#property-ok), [Result.Err](#propert
|
|
|
604
604
|
|
|
605
605
|
| Name | Type | Defined in |
|
|
606
606
|
| ------ | ------ | ------ |
|
|
607
|
-
| <a id="property-all-1"></a> `all()` | <`Rs`>(`results`) => `Result`<`AllOk`<`Rs`, \{ \[K in string \| number \| symbol\]: OkOf\<Rs\[K\]\> \}>, [`ErrOf`](#errof)<`Rs`\[`number`\]>> | [packages/core/src/facade.ts:51](https://github.com/btravstack/unthrown/blob/
|
|
608
|
-
| <a id="property-allfromdict-1"></a> `allFromDict()` | <`R`>(`results`) => `Result`<\{ \[K in string \| number \| symbol\]: OkOf\<R\[K\]\> \}, [`ErrOf`](#errof)<`R`\[keyof `R`\]>> | [packages/core/src/facade.ts:52](https://github.com/btravstack/unthrown/blob/
|
|
609
|
-
| <a id="property-do"></a> `Do()` | () => `Result`<\{ \}, `never`> | [packages/core/src/facade.ts:48](https://github.com/btravstack/unthrown/blob/
|
|
610
|
-
| <a id="property-err"></a> `Err()` | <`E`>(`error`) => `Result`<`never`, `E`> | [packages/core/src/facade.ts:47](https://github.com/btravstack/unthrown/blob/
|
|
611
|
-
| <a id="property-fromnullable"></a> `fromNullable()` | <`T`, `E`>(`value`, `onAbsent`) => `Result`<`NonNullable`<`T`>, `E`> | [packages/core/src/facade.ts:49](https://github.com/btravstack/unthrown/blob/
|
|
612
|
-
| <a id="property-fromthrowable"></a> `fromThrowable()` | <`A`, `T`, `R`>(`fn`, `qualify`) => (...`args`) => `Result`<`T`, `Exclude`<`R`, `Defect`>> | [packages/core/src/facade.ts:50](https://github.com/btravstack/unthrown/blob/
|
|
613
|
-
| <a id="property-isdefect"></a> `isDefect()` | <`T`, `E`>(`r`) => `r is DefectView<T, E>` | [packages/core/src/facade.ts:55](https://github.com/btravstack/unthrown/blob/
|
|
614
|
-
| <a id="property-iserr"></a> `isErr()` | <`T`, `E`>(`r`) => `r is ErrView<E, T>` | [packages/core/src/facade.ts:54](https://github.com/btravstack/unthrown/blob/
|
|
615
|
-
| <a id="property-isok"></a> `isOk()` | <`T`, `E`>(`r`) => `r is OkView<T, E>` | [packages/core/src/facade.ts:53](https://github.com/btravstack/unthrown/blob/
|
|
616
|
-
| <a id="property-isresult"></a> `isResult()` | (`x`) => `x is Result<unknown, unknown>` | [packages/core/src/facade.ts:56](https://github.com/btravstack/unthrown/blob/
|
|
617
|
-
| <a id="property-ok"></a> `Ok()` | <`T`>(`value`) => `Result`<`T`, `never`> | [packages/core/src/facade.ts:46](https://github.com/btravstack/unthrown/blob/
|
|
607
|
+
| <a id="property-all-1"></a> `all()` | <`Rs`>(`results`) => `Result`<`AllOk`<`Rs`, \{ \[K in string \| number \| symbol\]: OkOf\<Rs\[K\]\> \}>, [`ErrOf`](#errof)<`Rs`\[`number`\]>> | [packages/core/src/facade.ts:51](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/facade.ts#L51) |
|
|
608
|
+
| <a id="property-allfromdict-1"></a> `allFromDict()` | <`R`>(`results`) => `Result`<\{ \[K in string \| number \| symbol\]: OkOf\<R\[K\]\> \}, [`ErrOf`](#errof)<`R`\[keyof `R`\]>> | [packages/core/src/facade.ts:52](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/facade.ts#L52) |
|
|
609
|
+
| <a id="property-do"></a> `Do()` | () => `Result`<\{ \}, `never`> | [packages/core/src/facade.ts:48](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/facade.ts#L48) |
|
|
610
|
+
| <a id="property-err"></a> `Err()` | <`E`>(`error`) => `Result`<`never`, `E`> | [packages/core/src/facade.ts:47](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/facade.ts#L47) |
|
|
611
|
+
| <a id="property-fromnullable"></a> `fromNullable()` | <`T`, `E`>(`value`, `onAbsent`) => `Result`<`NonNullable`<`T`>, `E`> | [packages/core/src/facade.ts:49](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/facade.ts#L49) |
|
|
612
|
+
| <a id="property-fromthrowable"></a> `fromThrowable()` | <`A`, `T`, `R`>(`fn`, `qualify`) => (...`args`) => `Result`<`T`, `Exclude`<`R`, `Defect`>> | [packages/core/src/facade.ts:50](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/facade.ts#L50) |
|
|
613
|
+
| <a id="property-isdefect"></a> `isDefect()` | <`T`, `E`>(`r`) => `r is DefectView<T, E>` | [packages/core/src/facade.ts:55](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/facade.ts#L55) |
|
|
614
|
+
| <a id="property-iserr"></a> `isErr()` | <`T`, `E`>(`r`) => `r is ErrView<E, T>` | [packages/core/src/facade.ts:54](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/facade.ts#L54) |
|
|
615
|
+
| <a id="property-isok"></a> `isOk()` | <`T`, `E`>(`r`) => `r is OkView<T, E>` | [packages/core/src/facade.ts:53](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/facade.ts#L53) |
|
|
616
|
+
| <a id="property-isresult"></a> `isResult()` | (`x`) => `x is Result<unknown, unknown>` | [packages/core/src/facade.ts:56](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/facade.ts#L56) |
|
|
617
|
+
| <a id="property-ok"></a> `Ok()` | <`T`>(`value`) => `Result`<`T`, `never`> | [packages/core/src/facade.ts:46](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/facade.ts#L46) |
|
|
618
618
|
|
|
619
619
|
#### Remarks
|
|
620
620
|
|
|
@@ -642,7 +642,7 @@ Result.Ok(1).flatMap((n) => Result.Ok(n + 1)).unwrap(); // 2
|
|
|
642
642
|
function all<Rs>(results): Result<AllOk<Rs, { [K in string | number | symbol]: OkOf<Rs[K]> }>, ErrOf<Rs[number]>>;
|
|
643
643
|
```
|
|
644
644
|
|
|
645
|
-
Defined in: [packages/core/src/interop.ts:
|
|
645
|
+
Defined in: [packages/core/src/interop.ts:254](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/interop.ts#L254)
|
|
646
646
|
|
|
647
647
|
Collect a tuple/array of [Result](#result)s into a single `Result` of all their
|
|
648
648
|
success values.
|
|
@@ -688,7 +688,7 @@ all([Ok(1), Ok(2)] as Result<number, never>[]).unwrap(); // number[]
|
|
|
688
688
|
function allAsync<Rs>(results): AsyncResult<AllOk<Rs, { [K in string | number | symbol]: AsyncOkOf<Rs[K]> }>, AsyncErrOf<Rs[number]>>;
|
|
689
689
|
```
|
|
690
690
|
|
|
691
|
-
Defined in: [packages/core/src/interop.ts:
|
|
691
|
+
Defined in: [packages/core/src/interop.ts:304](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/interop.ts#L304)
|
|
692
692
|
|
|
693
693
|
The asynchronous counterpart of [all](#all): combine a tuple/array of
|
|
694
694
|
[AsyncResult](#asyncresult)s into one `AsyncResult` of all their success values.
|
|
@@ -731,7 +731,7 @@ await allAsync([fromSafePromise(a()), fromSafePromise(b())]);
|
|
|
731
731
|
function allFromDict<R>(results): Result<{ [K in string | number | symbol]: OkOf<R[K]> }, ErrOf<R[keyof R]>>;
|
|
732
732
|
```
|
|
733
733
|
|
|
734
|
-
Defined in: [packages/core/src/interop.ts:
|
|
734
|
+
Defined in: [packages/core/src/interop.ts:279](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/interop.ts#L279)
|
|
735
735
|
|
|
736
736
|
Collect a **record** of [Result](#result)s into a single `Result` of a record of
|
|
737
737
|
their success values — `allFromDict({ a: Result<A, E>, b: Result<B, E> })` is
|
|
@@ -774,7 +774,7 @@ allFromDict({ id: Ok(1), name: Ok("ada") }).unwrap(); // { id: 1, name: "ada" }
|
|
|
774
774
|
function allFromDictAsync<R>(results): AsyncResult<{ [K in string | number | symbol]: AsyncOkOf<R[K]> }, AsyncErrOf<R[keyof R]>>;
|
|
775
775
|
```
|
|
776
776
|
|
|
777
|
-
Defined in: [packages/core/src/interop.ts:
|
|
777
|
+
Defined in: [packages/core/src/interop.ts:332](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/interop.ts#L332)
|
|
778
778
|
|
|
779
779
|
The asynchronous counterpart of [allFromDict](#allfromdict): combine a record of
|
|
780
780
|
[AsyncResult](#asyncresult)s into one `AsyncResult` of a record of their values.
|
|
@@ -816,7 +816,7 @@ function Do(): Result<{
|
|
|
816
816
|
}, never>;
|
|
817
817
|
```
|
|
818
818
|
|
|
819
|
-
Defined in: [packages/core/src/do.ts:30](https://github.com/btravstack/unthrown/blob/
|
|
819
|
+
Defined in: [packages/core/src/do.ts:30](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/do.ts#L30)
|
|
820
820
|
|
|
821
821
|
Start a do-notation chain with an empty object scope, grown step by step with
|
|
822
822
|
`bind` (for `Result`-returning steps) and `let` (for pure values).
|
|
@@ -854,7 +854,7 @@ const result = Do()
|
|
|
854
854
|
function Err<E>(error): Result<never, E>;
|
|
855
855
|
```
|
|
856
856
|
|
|
857
|
-
Defined in: [packages/core/src/constructors.ts:34](https://github.com/btravstack/unthrown/blob/
|
|
857
|
+
Defined in: [packages/core/src/constructors.ts:34](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/constructors.ts#L34)
|
|
858
858
|
|
|
859
859
|
Construct a failed [Result](#result) carrying a **modeled** error.
|
|
860
860
|
|
|
@@ -889,7 +889,7 @@ Err("not_found").unwrapErr(); // "not_found"
|
|
|
889
889
|
function fromNullable<T, E>(value, onAbsent): Result<NonNullable<T>, E>;
|
|
890
890
|
```
|
|
891
891
|
|
|
892
|
-
Defined in: [packages/core/src/interop.ts:29](https://github.com/btravstack/unthrown/blob/
|
|
892
|
+
Defined in: [packages/core/src/interop.ts:29](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/interop.ts#L29)
|
|
893
893
|
|
|
894
894
|
Bridge a nullable value into a [Result](#result): absence becomes a **modeled**
|
|
895
895
|
`Err`. The sanctioned alternative to an `Option` type.
|
|
@@ -932,7 +932,7 @@ fromNullable(map.get(key), () => "missing").unwrap();
|
|
|
932
932
|
function fromPromise<T, R>(promise, qualify): AsyncResult<T, Exclude<R, Defect>>;
|
|
933
933
|
```
|
|
934
934
|
|
|
935
|
-
Defined in: [packages/core/src/interop.ts:113](https://github.com/btravstack/unthrown/blob/
|
|
935
|
+
Defined in: [packages/core/src/interop.ts:113](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/interop.ts#L113)
|
|
936
936
|
|
|
937
937
|
Wrap a `Promise` (or a thunk producing one) as an [AsyncResult](#asyncresult), forcing
|
|
938
938
|
every rejection to be triaged.
|
|
@@ -984,7 +984,7 @@ const user = await fromPromise(fetchUser(id), (cause, defect) =>
|
|
|
984
984
|
function fromSafePromise<T>(promise): AsyncResult<T, never>;
|
|
985
985
|
```
|
|
986
986
|
|
|
987
|
-
Defined in: [packages/core/src/interop.ts:139](https://github.com/btravstack/unthrown/blob/
|
|
987
|
+
Defined in: [packages/core/src/interop.ts:139](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/interop.ts#L139)
|
|
988
988
|
|
|
989
989
|
Wrap a `Promise` asserted **not** to fail in any modeled way: any rejection
|
|
990
990
|
becomes a `Defect`.
|
|
@@ -1019,7 +1019,7 @@ triage. (`await`-ing still yields a `Result`; it never throws.)
|
|
|
1019
1019
|
function fromThrowable<A, T, R>(fn, qualify): (...args) => Result<T, Exclude<R, Defect>>;
|
|
1020
1020
|
```
|
|
1021
1021
|
|
|
1022
|
-
Defined in: [packages/core/src/interop.ts:68](https://github.com/btravstack/unthrown/blob/
|
|
1022
|
+
Defined in: [packages/core/src/interop.ts:68](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/interop.ts#L68)
|
|
1023
1023
|
|
|
1024
1024
|
Wrap a throwing synchronous function so it returns a [Result](#result) instead of
|
|
1025
1025
|
throwing.
|
|
@@ -1074,7 +1074,7 @@ parse("{}").unwrap();
|
|
|
1074
1074
|
function isDefect<T, E>(r): r is DefectView<T, E>;
|
|
1075
1075
|
```
|
|
1076
1076
|
|
|
1077
|
-
Defined in: [packages/core/src/constructors.ts:66](https://github.com/btravstack/unthrown/blob/
|
|
1077
|
+
Defined in: [packages/core/src/constructors.ts:66](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/constructors.ts#L66)
|
|
1078
1078
|
|
|
1079
1079
|
Type guard: narrow a [Result](#result) to its `Defect` variant, exposing `.cause`.
|
|
1080
1080
|
|
|
@@ -1105,7 +1105,7 @@ Type guard: narrow a [Result](#result) to its `Defect` variant, exposing `.cause
|
|
|
1105
1105
|
function isErr<T, E>(r): r is ErrView<E, T>;
|
|
1106
1106
|
```
|
|
1107
1107
|
|
|
1108
|
-
Defined in: [packages/core/src/constructors.ts:58](https://github.com/btravstack/unthrown/blob/
|
|
1108
|
+
Defined in: [packages/core/src/constructors.ts:58](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/constructors.ts#L58)
|
|
1109
1109
|
|
|
1110
1110
|
Type guard: narrow a [Result](#result) to its `Err` variant, exposing `.error`.
|
|
1111
1111
|
|
|
@@ -1136,7 +1136,7 @@ Type guard: narrow a [Result](#result) to its `Err` variant, exposing `.error`.
|
|
|
1136
1136
|
function isOk<T, E>(r): r is OkView<T, E>;
|
|
1137
1137
|
```
|
|
1138
1138
|
|
|
1139
|
-
Defined in: [packages/core/src/constructors.ts:50](https://github.com/btravstack/unthrown/blob/
|
|
1139
|
+
Defined in: [packages/core/src/constructors.ts:50](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/constructors.ts#L50)
|
|
1140
1140
|
|
|
1141
1141
|
Type guard: narrow a [Result](#result) to its `Ok` variant, exposing `.value`.
|
|
1142
1142
|
|
|
@@ -1175,7 +1175,7 @@ if (isOk(r)) r.value; // number, narrowed
|
|
|
1175
1175
|
function isResult(x): x is Result<unknown, unknown>;
|
|
1176
1176
|
```
|
|
1177
1177
|
|
|
1178
|
-
Defined in: [packages/core/src/core.ts:338](https://github.com/btravstack/unthrown/blob/
|
|
1178
|
+
Defined in: [packages/core/src/core.ts:338](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/core.ts#L338)
|
|
1179
1179
|
|
|
1180
1180
|
Type guard: is `x` a [Result](#result) (any of `Ok` / `Err` / `Defect`)?
|
|
1181
1181
|
|
|
@@ -1209,7 +1209,7 @@ is not a `Result` and returns `false`.
|
|
|
1209
1209
|
function matchTags<T, E, R>(result, handlers): R;
|
|
1210
1210
|
```
|
|
1211
1211
|
|
|
1212
|
-
Defined in: [packages/core/src/tagged.ts:138](https://github.com/btravstack/unthrown/blob/
|
|
1212
|
+
Defined in: [packages/core/src/tagged.ts:138](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/tagged.ts#L138)
|
|
1213
1213
|
|
|
1214
1214
|
Exhaustively fold a [Result](#result) (or [AsyncResult](#asyncresult)) whose error type is
|
|
1215
1215
|
a tagged union, dispatching each error to the handler matching its `_tag`.
|
|
@@ -1261,7 +1261,7 @@ matchTags(r, {
|
|
|
1261
1261
|
function matchTags<T, E, R>(result, handlers): Promise<R>;
|
|
1262
1262
|
```
|
|
1263
1263
|
|
|
1264
|
-
Defined in: [packages/core/src/tagged.ts:142](https://github.com/btravstack/unthrown/blob/
|
|
1264
|
+
Defined in: [packages/core/src/tagged.ts:142](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/tagged.ts#L142)
|
|
1265
1265
|
|
|
1266
1266
|
Exhaustively fold a [Result](#result) (or [AsyncResult](#asyncresult)) whose error type is
|
|
1267
1267
|
a tagged union, dispatching each error to the handler matching its `_tag`.
|
|
@@ -1315,7 +1315,7 @@ matchTags(r, {
|
|
|
1315
1315
|
function Ok<T>(value): Result<T, never>;
|
|
1316
1316
|
```
|
|
1317
1317
|
|
|
1318
|
-
Defined in: [packages/core/src/constructors.ts:18](https://github.com/btravstack/unthrown/blob/
|
|
1318
|
+
Defined in: [packages/core/src/constructors.ts:18](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/constructors.ts#L18)
|
|
1319
1319
|
|
|
1320
1320
|
Construct a successful [Result](#result).
|
|
1321
1321
|
|
|
@@ -1350,7 +1350,7 @@ Ok(42).unwrap(); // 42
|
|
|
1350
1350
|
function TaggedError<Tag>(tag, options?): TaggedErrorConstructor<Tag>;
|
|
1351
1351
|
```
|
|
1352
1352
|
|
|
1353
|
-
Defined in: [packages/core/src/tagged.ts:72](https://github.com/btravstack/unthrown/blob/
|
|
1353
|
+
Defined in: [packages/core/src/tagged.ts:72](https://github.com/btravstack/unthrown/blob/6af2083f66eff6f878bfea8d336602c60827f96e/packages/core/src/tagged.ts#L72)
|
|
1354
1354
|
|
|
1355
1355
|
Build a base class for a tagged error — a class extending `Error` with a
|
|
1356
1356
|
`_tag` string discriminant, in the style of Effect's `Data.TaggedError`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unthrown",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "Explicit errors as values, with a separate defect (panic) channel",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"defect",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"docs"
|
|
30
30
|
],
|
|
31
31
|
"type": "module",
|
|
32
|
+
"sideEffects": false,
|
|
32
33
|
"main": "./dist/index.cjs",
|
|
33
34
|
"module": "./dist/index.mjs",
|
|
34
35
|
"types": "./dist/index.d.mts",
|
|
@@ -48,7 +49,7 @@
|
|
|
48
49
|
"devDependencies": {
|
|
49
50
|
"@types/node": "24.13.2",
|
|
50
51
|
"@vitest/coverage-v8": "4.1.8",
|
|
51
|
-
"tsdown": "0.22.
|
|
52
|
+
"tsdown": "0.22.3",
|
|
52
53
|
"typedoc": "0.28.19",
|
|
53
54
|
"typedoc-plugin-markdown": "4.12.0",
|
|
54
55
|
"typescript": "6.0.3",
|