unthrown 5.0.0-beta.7 → 5.0.0-beta.8

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/README.md CHANGED
@@ -14,7 +14,7 @@ No peer dependencies — the exhaustive error matcher is built-in and exported a
14
14
  `match` / `P` / `tag`.
15
15
 
16
16
  ```ts
17
- import { fromPromise, P, TaggedError } from "unthrown";
17
+ import { fromPromise, tag, TaggedError } from "unthrown";
18
18
 
19
19
  class NotFound extends TaggedError("NotFound") {} // our modeled domain failure
20
20
  class NotFoundError extends Error {} // what `fetchUser` rejects with on a 404
@@ -25,7 +25,8 @@ const user = fromPromise(fetchUser(id), (cause, defect) =>
25
25
 
26
26
  const status = await user.match({
27
27
  ok: () => 200,
28
- errCases: (matcher) => matcher.with(P._, () => 404), // `errCases` takes the exhaustive matcher
28
+ // `errCases` takes the exhaustive matcher — every case of E named:
29
+ errCases: (matcher) => matcher.with(tag("NotFound"), () => 404),
29
30
  defect: () => 500,
30
31
  });
31
32
  ```
package/dist/index.cjs CHANGED
@@ -117,8 +117,10 @@ Object.freeze(MatcherImpl.prototype);
117
117
  * @remarks
118
118
  * This is unthrown's own matcher (the former ts-pattern re-export): the same
119
119
  * call-site shape, with exhaustiveness computed by plain `Exclude` over the
120
- * builder's `Remaining` parameter. A `P._` catch-all is provably exhaustive
121
- * even over an unresolved generic input.
120
+ * builder's `Remaining` parameter. Name every case of the input union; the
121
+ * `P._` catch-all is the escape hatch, and is provably exhaustive even over an
122
+ * unresolved generic input — one of the two cases it is irreplaceable for (see
123
+ * {@link P}).
122
124
  *
123
125
  * @category Constructors
124
126
  */
@@ -133,9 +135,18 @@ const universal = pattern(() => true);
133
135
  /**
134
136
  * The pattern namespace (unthrown's own; the former ts-pattern `P`):
135
137
  *
136
- * - `P._` / `P.any` — the universal catch-all. Matches anything, and (because
137
- * its phantom type is `unknown`) makes the builder provably exhaustive even
138
- * when the matched input is an unresolved type parameter.
138
+ * - `P._` / `P.any` — the universal catch-all, and an **escape hatch** rather
139
+ * than the default: matching the error channel means naming its cases, so
140
+ * reach for this only where they cannot be named. Matches anything, and
141
+ * (because its phantom type is `unknown`) makes the builder provably
142
+ * exhaustive even when the matched input is an unresolved type parameter.
143
+ * Two situations are legitimate: a **helper generic in `E`**, where no arm
144
+ * list can prove exhaustiveness against an unresolved type parameter; and an
145
+ * **`E` that is a single type**, not a union of cases (a validator's issues
146
+ * array, say), where one arm _is_ the enumeration. `@unthrown/oxlint`'s
147
+ * `no-catch-all-pattern` (in its `recommended` preset) flags every other use;
148
+ * keep the deliberate ones behind a targeted `oxlint-disable` saying which of
149
+ * the two it is.
139
150
  * - `P.instanceOf(Cls)` — an `instanceof` check, narrowing to the class
140
151
  * instance type (for union members that are not tagged, e.g. a third-party
141
152
  * error class).
@@ -507,7 +518,7 @@ function defectRes(cause) {
507
518
  *
508
519
  * @example
509
520
  * ```ts
510
- * import { isResult, Ok } from "unthrown";
521
+ * import { isResult, Ok, P } from "unthrown";
511
522
  *
512
523
  * isResult(Ok(1)); // => true
513
524
  * isResult({ tag: "Ok" }); // => false (look-alike, wrong prototype)
@@ -515,6 +526,9 @@ function defectRes(cause) {
515
526
  *
516
527
  * const x: unknown = Ok(1);
517
528
  * if (isResult(x))
529
+ * // `E` is `unknown` here — an untyped boundary has no cases to enumerate,
530
+ * // so the `P._` escape hatch is the only arm that can terminate the match:
531
+ * // oxlint-disable-next-line unthrown/no-catch-all-pattern -- untyped boundary: `E` is `unknown`
518
532
  * x.match({ ok: () => 1, errCases: (m) => m.with(P._, () => 0), defect: () => -1 });
519
533
  * ```
520
534
  *
package/dist/index.d.cts CHANGED
@@ -127,12 +127,18 @@ type PinTooLate = {
127
127
  */
128
128
  type Matcher<E, Remaining, O, Declared = Unset> = {
129
129
  /**
130
- * The catch-all arm: `.with(P._, handler)` / `.with(P.any, handler)`. A
131
- * **state transition**, not a computation — it returns `Matcher<E, never, …>`
132
- * with the remaining cases literally `never`, so the builder is provably
133
- * exhaustive even when `E` is an unresolved type parameter (a lazily-deferred
134
- * `Exclude<E, unknown>` would not resolve there). This is what lets a
135
- * boundary helper generic in `E` terminate with the catch-all (issue #145).
130
+ * The catch-all arm: `.with(P._, handler)` / `.with(P.any, handler)` — the
131
+ * wildcard **escape hatch**, not the way to handle a concrete error union
132
+ * (name those cases; `@unthrown/oxlint`'s `no-catch-all-pattern`, in its
133
+ * `recommended` preset, flags the wildcard).
134
+ *
135
+ * It is a **state transition**, not a computation — it returns
136
+ * `Matcher<E, never, …>` with the remaining cases literally `never`, so the
137
+ * builder is provably exhaustive even when `E` is an unresolved type
138
+ * parameter (a lazily-deferred `Exclude<E, unknown>` would not resolve
139
+ * there). That is what makes it irreplaceable for a helper generic in `E`:
140
+ * it can terminate a match no arm list could (issue #145) — one of the two
141
+ * sanctioned uses (see {@link P}).
136
142
  */
137
143
  with<O2>(pattern: UniversalPattern, handler: (value: Remaining) => BranchReturn<Declared, O2>): Matcher<E, never, O | O2, Declared>;
138
144
  /**
@@ -208,8 +214,10 @@ declare class NonExhaustiveError extends Error {
208
214
  * @remarks
209
215
  * This is unthrown's own matcher (the former ts-pattern re-export): the same
210
216
  * call-site shape, with exhaustiveness computed by plain `Exclude` over the
211
- * builder's `Remaining` parameter. A `P._` catch-all is provably exhaustive
212
- * even over an unresolved generic input.
217
+ * builder's `Remaining` parameter. Name every case of the input union; the
218
+ * `P._` catch-all is the escape hatch, and is provably exhaustive even over an
219
+ * unresolved generic input — one of the two cases it is irreplaceable for (see
220
+ * {@link P}).
213
221
  *
214
222
  * @category Constructors
215
223
  */
@@ -217,9 +225,18 @@ declare function match<const E>(value: E): Matcher<E, E, never>;
217
225
  /**
218
226
  * The pattern namespace (unthrown's own; the former ts-pattern `P`):
219
227
  *
220
- * - `P._` / `P.any` — the universal catch-all. Matches anything, and (because
221
- * its phantom type is `unknown`) makes the builder provably exhaustive even
222
- * when the matched input is an unresolved type parameter.
228
+ * - `P._` / `P.any` — the universal catch-all, and an **escape hatch** rather
229
+ * than the default: matching the error channel means naming its cases, so
230
+ * reach for this only where they cannot be named. Matches anything, and
231
+ * (because its phantom type is `unknown`) makes the builder provably
232
+ * exhaustive even when the matched input is an unresolved type parameter.
233
+ * Two situations are legitimate: a **helper generic in `E`**, where no arm
234
+ * list can prove exhaustiveness against an unresolved type parameter; and an
235
+ * **`E` that is a single type**, not a union of cases (a validator's issues
236
+ * array, say), where one arm _is_ the enumeration. `@unthrown/oxlint`'s
237
+ * `no-catch-all-pattern` (in its `recommended` preset) flags every other use;
238
+ * keep the deliberate ones behind a targeted `oxlint-disable` saying which of
239
+ * the two it is.
223
240
  * - `P.instanceOf(Cls)` — an `instanceof` check, narrowing to the class
224
241
  * instance type (for union members that are not tagged, e.g. a third-party
225
242
  * error class).
@@ -499,9 +516,15 @@ type ResultMethods<out T, out E> = {
499
516
  * to a `Defect` and drops it from `E`. Runs only on `Err`; `Ok` and `Defect`
500
517
  * pass through. A branch that throws also becomes a `Defect`.
501
518
  *
502
- * `.with(P._, …)` is the deliberate uniform/catch-all (it makes the match
503
- * exhaustive). Match on anything the matcher supports — `_tag`, `code`,
504
- * structural shape, guards, or grouped patterns `.with(a, b, handler)`.
519
+ * **Name every case.** Match on anything the matcher supports — `_tag`,
520
+ * `code`, structural shape, guards — and group the cases that share a handler
521
+ * with `.with(a, b, handler)`. `.with(P._, …)` is the wildcard **escape
522
+ * hatch**, not the default: it makes any match exhaustive, so it also absorbs
523
+ * every case `E` grows later. Two uses are sanctioned — a helper generic in
524
+ * `E`, where no arm list can prove exhaustiveness against an unresolved type
525
+ * parameter, and an `E` that is a single type rather than a union of cases
526
+ * (see {@link P} for both). `@unthrown/oxlint`'s `no-catch-all-pattern` (in
527
+ * its `recommended` preset) flags the rest.
505
528
  *
506
529
  * @typeParam M - the exhaustive builder the callback returns.
507
530
  * @param f - builds the match over the error (returns the un-terminated builder).
@@ -542,7 +565,8 @@ type ResultMethods<out T, out E> = {
542
565
  * @remarks
543
566
  * The callback builds a match whose branches run side effects; their return
544
567
  * values are ignored and the original `Err` flows through. Exhaustive like the
545
- * transformers (use `.with(P._, …)` for a catch-all). If a branch throws, the
568
+ * transformers, and like them it wants every case named — `.with(P._, …)`
569
+ * remains the wildcard escape hatch. If a branch throws, the
546
570
  * result is a `Defect` whose cause is an `AggregateError` of `[thrown, original
547
571
  * failure]` — observing a failure never destroys it. An **async branch is
548
572
  * rejected at compile time** ({@link NotThenable} on the builder output):
@@ -642,8 +666,9 @@ type ResultMethods<out T, out E> = {
642
666
  * exactly like the error combinators — which is why the key carries the same
643
667
  * `…Cases` suffix. Chain `.with(pattern, handler)` and **return the
644
668
  * un-terminated builder** — `match` calls `.exhaustive()` itself, so a missing
645
- * case is a compile error at the call site (no `.exhaustive()` to forget). Use
646
- * `.with(P._, …)` for a uniform catch-all. Unlike the combinators the branches
669
+ * case is a compile error at the call site (no `.exhaustive()` to forget).
670
+ * Folding at the edge names every case too — `.with(P._, …)` is the wildcard
671
+ * escape hatch, not the default. Unlike the combinators the branches
647
672
  * receive **no `defect` helper** — `match` is total elimination to a value,
648
673
  * with no `Defect` output channel; the `defect` case handles a `Result` that
649
674
  * already carries one. (A `Result` is also a discriminated union — for richer
@@ -856,7 +881,7 @@ type FailureView<E, T = never> = ErrView<E, T> | DefectView<T, E>;
856
881
  *
857
882
  * @example
858
883
  * ```ts
859
- * import { Ok, Err, P, type Result } from "unthrown";
884
+ * import { Ok, Err, type Result } from "unthrown";
860
885
  *
861
886
  * function half(n: number): Result<number, "odd"> {
862
887
  * return n % 2 === 0 ? Ok(n / 2) : Err("odd");
@@ -864,7 +889,8 @@ type FailureView<E, T = never> = ErrView<E, T> | DefectView<T, E>;
864
889
  *
865
890
  * const message = half(10).match({
866
891
  * ok: (n) => `got ${n}`,
867
- * errCases: (matcher) => matcher.with(P._, (e) => `failed: ${e}`),
892
+ * // every case of `E` named — here the one literal it holds
893
+ * errCases: (matcher) => matcher.with("odd", () => "failed: odd"),
868
894
  * defect: (cause) => `bug: ${String(cause)}`,
869
895
  * });
870
896
  * ```
@@ -1396,7 +1422,7 @@ declare class GetError<E = unknown> extends Error {
1396
1422
  *
1397
1423
  * @example
1398
1424
  * ```ts
1399
- * import { isResult, Ok } from "unthrown";
1425
+ * import { isResult, Ok, P } from "unthrown";
1400
1426
  *
1401
1427
  * isResult(Ok(1)); // => true
1402
1428
  * isResult({ tag: "Ok" }); // => false (look-alike, wrong prototype)
@@ -1404,6 +1430,9 @@ declare class GetError<E = unknown> extends Error {
1404
1430
  *
1405
1431
  * const x: unknown = Ok(1);
1406
1432
  * if (isResult(x))
1433
+ * // `E` is `unknown` here — an untyped boundary has no cases to enumerate,
1434
+ * // so the `P._` escape hatch is the only arm that can terminate the match:
1435
+ * // oxlint-disable-next-line unthrown/no-catch-all-pattern -- untyped boundary: `E` is `unknown`
1407
1436
  * x.match({ ok: () => 1, errCases: (m) => m.with(P._, () => 0), defect: () => -1 });
1408
1437
  * ```
1409
1438
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/defect.ts","../src/matcher.ts","../src/types.ts","../src/constructors.ts","../src/core.ts","../src/do.ts","../src/interop.ts","../src/facade.ts","../src/tagged.ts"],"mappings":";cAEM;;;;;;;;;;;;;;;KAgBM;YACA;WACD;;;;;;;;;;;;cCcL;cAEQ;cACA;;;;;;;;;KAUF,eAAe;YACf,iBAAiB;YACjB,WAAW;;;;;;;;;;;KAYX,mBAAmB;YACnB;;;;;;;;;KAUA,UAAU,MACpB,WAAW,qBAAqB,KAC5B,IACA,uBACK,WAAW,KAAK,UAAU,GAAG,SAChC;;;;;;;;KASI,cAAc;WACf,qFAAqF;;;;;;;;;cAUlF;;KAGT,eAAe;;;;;;;;;;;;;;KAef,aAAa,UAAU,OAAO,mBAAmB,SAAS,KAAK,WAAW;;;;;;;KAQ1E,UAAU,UAAU,MAAM,mBAAmB,SAAS,IAAI;;;;;;;;KAS1D;WACM;;;;;;;;;;;;;KAcC,QAAQ,GAAG,WAAW,GAAG,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,SAAO,MAAM,OAAO,WAAW,KAAK,KAAK,GAAG,SAAQ,MAAM;;;;;;;;;;;;;;;;;;;;;iBA2B7C,YAAY,UAAU,cACpC,SAAS,IACR,YAAU,WAAW,IAAI,KAAK,EAAE,QAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;iBA2BxC,SAAS,oBAAoB,mCAC3C,sBAAsB,MACrB,cAAY,MAAM,OAAO,WAAW,KAAK,UAAU,GAAG,SAAQ,WAAW;;;;;;;;;;;;;;;;;;;;;;iBAyC5D,iBAAiB,UAAU,mBACzC,SAAS,IACR,iBAAe,WAAW,IAAI,UAAU,EAAE,QAAO,WAAW,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cC3d1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAgCD,OAAO,GAAG,KAAK,SAAW,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA8B5B;;;;;;;;;;;;;;;;;;;;;;KAyBD,YAAY,GAAG,KAAK,cAAgB,GAAG;;;KCpI9C,QAAQ;;;;;;;;;;KAWD,oBAAoB,oBAAoB,UAAU,SAAS,QACrE,SAAS,KAAK;WAA+C,MAAM;;;;;;;;;;;;;;;;;;;;;;KAsBzD,uBAAuB;OAC5B,UAAU,YACb,YAAY,yBAER;aAAe;aAAuB;aAA0B;MACnE,oBAAoB,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8Dd,YAAY,oBAC1B,KAAK,KACL;WAAqB;IACpB,uBAAuB;;;;;;;;;;;;;;;;;;;;;iBA8DV,UAAU,oBAAoB,OAAO;EAAQ,MAAM"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/defect.ts","../src/matcher.ts","../src/types.ts","../src/constructors.ts","../src/core.ts","../src/do.ts","../src/interop.ts","../src/facade.ts","../src/tagged.ts"],"mappings":";cAEM;;;;;;;;;;;;;;;KAgBM;YACA;WACD;;;;;;;;;;;;c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uB;OAC5B,UAAU,YACb,YAAY,yBAER;aAAe;aAAuB;aAA0B;MACnE,oBAAoB,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8Dd,YAAY,oBAC1B,KAAK,KACL;WAAqB;IACpB,uBAAuB;;;;;;;;;;;;;;;;;;;;;iBA8DV,UAAU,oBAAoB,OAAO;EAAQ,MAAM"}
package/dist/index.d.mts CHANGED
@@ -127,12 +127,18 @@ type PinTooLate = {
127
127
  */
128
128
  type Matcher<E, Remaining, O, Declared = Unset> = {
129
129
  /**
130
- * The catch-all arm: `.with(P._, handler)` / `.with(P.any, handler)`. A
131
- * **state transition**, not a computation — it returns `Matcher<E, never, …>`
132
- * with the remaining cases literally `never`, so the builder is provably
133
- * exhaustive even when `E` is an unresolved type parameter (a lazily-deferred
134
- * `Exclude<E, unknown>` would not resolve there). This is what lets a
135
- * boundary helper generic in `E` terminate with the catch-all (issue #145).
130
+ * The catch-all arm: `.with(P._, handler)` / `.with(P.any, handler)` — the
131
+ * wildcard **escape hatch**, not the way to handle a concrete error union
132
+ * (name those cases; `@unthrown/oxlint`'s `no-catch-all-pattern`, in its
133
+ * `recommended` preset, flags the wildcard).
134
+ *
135
+ * It is a **state transition**, not a computation — it returns
136
+ * `Matcher<E, never, …>` with the remaining cases literally `never`, so the
137
+ * builder is provably exhaustive even when `E` is an unresolved type
138
+ * parameter (a lazily-deferred `Exclude<E, unknown>` would not resolve
139
+ * there). That is what makes it irreplaceable for a helper generic in `E`:
140
+ * it can terminate a match no arm list could (issue #145) — one of the two
141
+ * sanctioned uses (see {@link P}).
136
142
  */
137
143
  with<O2>(pattern: UniversalPattern, handler: (value: Remaining) => BranchReturn<Declared, O2>): Matcher<E, never, O | O2, Declared>;
138
144
  /**
@@ -208,8 +214,10 @@ declare class NonExhaustiveError extends Error {
208
214
  * @remarks
209
215
  * This is unthrown's own matcher (the former ts-pattern re-export): the same
210
216
  * call-site shape, with exhaustiveness computed by plain `Exclude` over the
211
- * builder's `Remaining` parameter. A `P._` catch-all is provably exhaustive
212
- * even over an unresolved generic input.
217
+ * builder's `Remaining` parameter. Name every case of the input union; the
218
+ * `P._` catch-all is the escape hatch, and is provably exhaustive even over an
219
+ * unresolved generic input — one of the two cases it is irreplaceable for (see
220
+ * {@link P}).
213
221
  *
214
222
  * @category Constructors
215
223
  */
@@ -217,9 +225,18 @@ declare function match<const E>(value: E): Matcher<E, E, never>;
217
225
  /**
218
226
  * The pattern namespace (unthrown's own; the former ts-pattern `P`):
219
227
  *
220
- * - `P._` / `P.any` — the universal catch-all. Matches anything, and (because
221
- * its phantom type is `unknown`) makes the builder provably exhaustive even
222
- * when the matched input is an unresolved type parameter.
228
+ * - `P._` / `P.any` — the universal catch-all, and an **escape hatch** rather
229
+ * than the default: matching the error channel means naming its cases, so
230
+ * reach for this only where they cannot be named. Matches anything, and
231
+ * (because its phantom type is `unknown`) makes the builder provably
232
+ * exhaustive even when the matched input is an unresolved type parameter.
233
+ * Two situations are legitimate: a **helper generic in `E`**, where no arm
234
+ * list can prove exhaustiveness against an unresolved type parameter; and an
235
+ * **`E` that is a single type**, not a union of cases (a validator's issues
236
+ * array, say), where one arm _is_ the enumeration. `@unthrown/oxlint`'s
237
+ * `no-catch-all-pattern` (in its `recommended` preset) flags every other use;
238
+ * keep the deliberate ones behind a targeted `oxlint-disable` saying which of
239
+ * the two it is.
223
240
  * - `P.instanceOf(Cls)` — an `instanceof` check, narrowing to the class
224
241
  * instance type (for union members that are not tagged, e.g. a third-party
225
242
  * error class).
@@ -499,9 +516,15 @@ type ResultMethods<out T, out E> = {
499
516
  * to a `Defect` and drops it from `E`. Runs only on `Err`; `Ok` and `Defect`
500
517
  * pass through. A branch that throws also becomes a `Defect`.
501
518
  *
502
- * `.with(P._, …)` is the deliberate uniform/catch-all (it makes the match
503
- * exhaustive). Match on anything the matcher supports — `_tag`, `code`,
504
- * structural shape, guards, or grouped patterns `.with(a, b, handler)`.
519
+ * **Name every case.** Match on anything the matcher supports — `_tag`,
520
+ * `code`, structural shape, guards — and group the cases that share a handler
521
+ * with `.with(a, b, handler)`. `.with(P._, …)` is the wildcard **escape
522
+ * hatch**, not the default: it makes any match exhaustive, so it also absorbs
523
+ * every case `E` grows later. Two uses are sanctioned — a helper generic in
524
+ * `E`, where no arm list can prove exhaustiveness against an unresolved type
525
+ * parameter, and an `E` that is a single type rather than a union of cases
526
+ * (see {@link P} for both). `@unthrown/oxlint`'s `no-catch-all-pattern` (in
527
+ * its `recommended` preset) flags the rest.
505
528
  *
506
529
  * @typeParam M - the exhaustive builder the callback returns.
507
530
  * @param f - builds the match over the error (returns the un-terminated builder).
@@ -542,7 +565,8 @@ type ResultMethods<out T, out E> = {
542
565
  * @remarks
543
566
  * The callback builds a match whose branches run side effects; their return
544
567
  * values are ignored and the original `Err` flows through. Exhaustive like the
545
- * transformers (use `.with(P._, …)` for a catch-all). If a branch throws, the
568
+ * transformers, and like them it wants every case named — `.with(P._, …)`
569
+ * remains the wildcard escape hatch. If a branch throws, the
546
570
  * result is a `Defect` whose cause is an `AggregateError` of `[thrown, original
547
571
  * failure]` — observing a failure never destroys it. An **async branch is
548
572
  * rejected at compile time** ({@link NotThenable} on the builder output):
@@ -642,8 +666,9 @@ type ResultMethods<out T, out E> = {
642
666
  * exactly like the error combinators — which is why the key carries the same
643
667
  * `…Cases` suffix. Chain `.with(pattern, handler)` and **return the
644
668
  * un-terminated builder** — `match` calls `.exhaustive()` itself, so a missing
645
- * case is a compile error at the call site (no `.exhaustive()` to forget). Use
646
- * `.with(P._, …)` for a uniform catch-all. Unlike the combinators the branches
669
+ * case is a compile error at the call site (no `.exhaustive()` to forget).
670
+ * Folding at the edge names every case too — `.with(P._, …)` is the wildcard
671
+ * escape hatch, not the default. Unlike the combinators the branches
647
672
  * receive **no `defect` helper** — `match` is total elimination to a value,
648
673
  * with no `Defect` output channel; the `defect` case handles a `Result` that
649
674
  * already carries one. (A `Result` is also a discriminated union — for richer
@@ -856,7 +881,7 @@ type FailureView<E, T = never> = ErrView<E, T> | DefectView<T, E>;
856
881
  *
857
882
  * @example
858
883
  * ```ts
859
- * import { Ok, Err, P, type Result } from "unthrown";
884
+ * import { Ok, Err, type Result } from "unthrown";
860
885
  *
861
886
  * function half(n: number): Result<number, "odd"> {
862
887
  * return n % 2 === 0 ? Ok(n / 2) : Err("odd");
@@ -864,7 +889,8 @@ type FailureView<E, T = never> = ErrView<E, T> | DefectView<T, E>;
864
889
  *
865
890
  * const message = half(10).match({
866
891
  * ok: (n) => `got ${n}`,
867
- * errCases: (matcher) => matcher.with(P._, (e) => `failed: ${e}`),
892
+ * // every case of `E` named — here the one literal it holds
893
+ * errCases: (matcher) => matcher.with("odd", () => "failed: odd"),
868
894
  * defect: (cause) => `bug: ${String(cause)}`,
869
895
  * });
870
896
  * ```
@@ -1396,7 +1422,7 @@ declare class GetError<E = unknown> extends Error {
1396
1422
  *
1397
1423
  * @example
1398
1424
  * ```ts
1399
- * import { isResult, Ok } from "unthrown";
1425
+ * import { isResult, Ok, P } from "unthrown";
1400
1426
  *
1401
1427
  * isResult(Ok(1)); // => true
1402
1428
  * isResult({ tag: "Ok" }); // => false (look-alike, wrong prototype)
@@ -1404,6 +1430,9 @@ declare class GetError<E = unknown> extends Error {
1404
1430
  *
1405
1431
  * const x: unknown = Ok(1);
1406
1432
  * if (isResult(x))
1433
+ * // `E` is `unknown` here — an untyped boundary has no cases to enumerate,
1434
+ * // so the `P._` escape hatch is the only arm that can terminate the match:
1435
+ * // oxlint-disable-next-line unthrown/no-catch-all-pattern -- untyped boundary: `E` is `unknown`
1407
1436
  * x.match({ ok: () => 1, errCases: (m) => m.with(P._, () => 0), defect: () => -1 });
1408
1437
  * ```
1409
1438
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/defect.ts","../src/matcher.ts","../src/types.ts","../src/constructors.ts","../src/core.ts","../src/do.ts","../src/interop.ts","../src/facade.ts","../src/tagged.ts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;;;;;;;;;;;;;;KAsBzD,uBAAuB;OAC5B,UAAU,YACb,YAAY,yBAER;aAAe;aAAuB;aAA0B;MACnE,oBAAoB,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8Dd,YAAY,oBAC1B,KAAK,KACL;WAAqB;IACpB,uBAAuB;;;;;;;;;;;;;;;;;;;;;iBA8DV,UAAU,oBAAoB,OAAO;EAAQ,MAAM"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/defect.ts","../src/matcher.ts","../src/types.ts","../src/constructors.ts","../src/core.ts","../src/do.ts","../src/interop.ts","../src/facade.ts","../src/tagged.ts"],"mappings":";cAEM;;;;;;;;;;;;;;;KAgBM;YACA;WACD;;;;;;;;;;;;cCcL;cAEQ;cACA;;;;;;;;;KAUF,eAAe;YACf,iBAAiB;YACjB,WAAW;;;;;;;;;;;KAYX,mBAAmB;YACnB;;;;;;;;;KAUA,UAAU,MACpB,WAAW,qBAAqB,KAC5B,IACA,uBACK,WAAW,KAAK,UAAU,GAAG,SAChC;;;;;;;;KASI,cAAc;WACf,qFAAqF;;;;;;;;;cAUlF;;KAGT,eAAe;;;;;;;;;;;;;;KAef,aAAa,UAAU,OAAO,mBAAmB,SAAS,KAAK,WAAW;;;;;;;KAQ1E,UAAU,UAAU,MAAM,mBAAmB,SAAS,IAAI;;;;;;;;KAS1D;WACM;;;;;;;;;;;;;KAcC,QAAQ,GAAG,WAAW,GAAG,WAAW;;;;;;;;;;;;;;;EAe9C,KAAK,IACH,SAAS,kBACT,UAAU,OAAO,cAAc,aAAa,UAAU,MACrD,QAAQ,UAAU,IAAI,IAAI;;;;;;;;EAQ7B,WAAW,8CAA8C,OACpD,UACE,UAAU,KACb,UAAU,OAAO,QAAQ,WAAW,UAAU,kBAAkB,aAAa,UAAU,OAExF,QAAQ,GAAG,QAAQ,WAAW,UAAU,eAAe,IAAI,IAAI;;;;;;;;;;;;;;;;;;;;;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AK,UAAU,GAAG,SAAQ,WAAW;;;;;;;;;;;;;;;;;;;;;;iBAyC5D,iBAAiB,UAAU,mBACzC,SAAS,IACR,iBAAe,WAAW,IAAI,UAAU,EAAE,QAAO,WAAW,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cC3d1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAgCD,OAAO,GAAG,KAAK,SAAW,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA8B5B;;;;;;;;;;;;;;;;;;;;;;KAyBD,YAAY,GAAG,KAAK,cAAgB,GAAG;;;KCpI9C,QAAQ;;;;;;;;;;KAWD,oBAAoB,oBAAoB,UAAU,SAAS,QACrE,SAAS,KAAK;WAA+C,MAAM;;;;;;;;;;;;;;;;;;;;;;KAsBzD,uBAAuB;OAC5B,UAAU,YACb,YAAY,yBAER;aAAe;aAAuB;aAA0B;MACnE,oBAAoB,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8Dd,YAAY,oBAC1B,KAAK,KACL;WAAqB;IACpB,uBAAuB;;;;;;;;;;;;;;;;;;;;;iBA8DV,UAAU,oBAAoB,OAAO;EAAQ,MAAM"}
package/dist/index.mjs CHANGED
@@ -116,8 +116,10 @@ Object.freeze(MatcherImpl.prototype);
116
116
  * @remarks
117
117
  * This is unthrown's own matcher (the former ts-pattern re-export): the same
118
118
  * call-site shape, with exhaustiveness computed by plain `Exclude` over the
119
- * builder's `Remaining` parameter. A `P._` catch-all is provably exhaustive
120
- * even over an unresolved generic input.
119
+ * builder's `Remaining` parameter. Name every case of the input union; the
120
+ * `P._` catch-all is the escape hatch, and is provably exhaustive even over an
121
+ * unresolved generic input — one of the two cases it is irreplaceable for (see
122
+ * {@link P}).
121
123
  *
122
124
  * @category Constructors
123
125
  */
@@ -132,9 +134,18 @@ const universal = pattern(() => true);
132
134
  /**
133
135
  * The pattern namespace (unthrown's own; the former ts-pattern `P`):
134
136
  *
135
- * - `P._` / `P.any` — the universal catch-all. Matches anything, and (because
136
- * its phantom type is `unknown`) makes the builder provably exhaustive even
137
- * when the matched input is an unresolved type parameter.
137
+ * - `P._` / `P.any` — the universal catch-all, and an **escape hatch** rather
138
+ * than the default: matching the error channel means naming its cases, so
139
+ * reach for this only where they cannot be named. Matches anything, and
140
+ * (because its phantom type is `unknown`) makes the builder provably
141
+ * exhaustive even when the matched input is an unresolved type parameter.
142
+ * Two situations are legitimate: a **helper generic in `E`**, where no arm
143
+ * list can prove exhaustiveness against an unresolved type parameter; and an
144
+ * **`E` that is a single type**, not a union of cases (a validator's issues
145
+ * array, say), where one arm _is_ the enumeration. `@unthrown/oxlint`'s
146
+ * `no-catch-all-pattern` (in its `recommended` preset) flags every other use;
147
+ * keep the deliberate ones behind a targeted `oxlint-disable` saying which of
148
+ * the two it is.
138
149
  * - `P.instanceOf(Cls)` — an `instanceof` check, narrowing to the class
139
150
  * instance type (for union members that are not tagged, e.g. a third-party
140
151
  * error class).
@@ -506,7 +517,7 @@ function defectRes(cause) {
506
517
  *
507
518
  * @example
508
519
  * ```ts
509
- * import { isResult, Ok } from "unthrown";
520
+ * import { isResult, Ok, P } from "unthrown";
510
521
  *
511
522
  * isResult(Ok(1)); // => true
512
523
  * isResult({ tag: "Ok" }); // => false (look-alike, wrong prototype)
@@ -514,6 +525,9 @@ function defectRes(cause) {
514
525
  *
515
526
  * const x: unknown = Ok(1);
516
527
  * if (isResult(x))
528
+ * // `E` is `unknown` here — an untyped boundary has no cases to enumerate,
529
+ * // so the `P._` escape hatch is the only arm that can terminate the match:
530
+ * // oxlint-disable-next-line unthrown/no-catch-all-pattern -- untyped boundary: `E` is `unknown`
517
531
  * x.match({ ok: () => 1, errCases: (m) => m.with(P._, () => 0), defect: () => -1 });
518
532
  * ```
519
533
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["#value","#matched","#result","#promise"],"sources":["../src/matcher.ts","../src/defect.ts","../src/core.ts","../src/constructors.ts","../src/do.ts","../src/interop.ts","../src/facade.ts","../src/tagged.ts"],"sourcesContent":["// unthrown — the built-in error matcher.\n//\n// A purpose-built, shallow pattern matcher for the error channel (it replaced\n// the former ts-pattern peer dependency, keeping its call-site shape:\n// `matcher.with(pattern, …patterns, handler)`, with the combinator running\n// `.exhaustive()` via `.run()`). Owning the type machinery means:\n//\n// - Exhaustiveness is computed with plain `Exclude` over the tracked\n// `Remaining` parameter — shallow, fast, and stable (no third-party minor\n// release can change what \"exhaustive\" means).\n// - The universal pattern (`P._` / `P.any`) carries phantom type `unknown`,\n// and `Exclude<Remaining, unknown>` reduces to `never` even when the input\n// is an UNRESOLVED generic — so a catch-all-terminated builder is provably\n// exhaustive inside code generic in `E` (fixes #145 by construction).\n// - A non-exhaustive builder's `exhaustive` is a branded object naming the\n// unhandled cases — a readable diagnostic instead of a deep conditional.\n//\n// Supported patterns (the vocabulary the error channel actually uses):\n// primitive literals, shallow(-ly nested) object literals (`{ _tag: \"X\" }`,\n// `{ code: \"X\" }` — `tag(t)` produces the former), and the `P.*` matchers\n// (`_`/`any`, `instanceOf`, `when`, `union`, `string`, `number`). Deliberately\n// NOT supported: deep structural inversion, selections, array/variadic\n// patterns — that is the complexity (and instability) being left behind.\n\nimport type { Defect } from \"./defect.js\";\n\n/**\n * Cross-copy brand for `P.*` pattern objects: `Symbol.for` yields the same\n * symbol in every copy of the library (dual CJS/ESM, duplicated install,\n * another realm), so a pattern built by one copy is recognised by another —\n * the same rationale as `isResult`'s prototype brand.\n *\n * @internal\n */\nconst PATTERN_BRAND = Symbol.for(\"unthrown.matcher.pattern\");\n\ndeclare const MATCHES: unique symbol;\ndeclare const UNIVERSAL: unique symbol;\n\n/**\n * A `P.*` pattern: a runtime predicate plus the phantom type `M` it matches.\n * The phantom is declaration-only (never present at runtime); it drives the\n * type-level narrowing (`Extract`) and exhaustiveness (`Exclude`).\n *\n * @typeParam M - the type this pattern matches.\n * @category Types\n */\nexport type PatternMatcher<M> = {\n readonly [PATTERN_BRAND]: (value: unknown) => boolean;\n readonly [MATCHES]?: M;\n};\n\n/**\n * The statically-known universal pattern — the type of `P._` / `P.any` only.\n * The phantom `UNIVERSAL` marker is *required*, so no other\n * `PatternMatcher<unknown>` (e.g. a `P.when` guard that happens to be\n * universal) is assignable: the catch-all `.with` overload must only fire for\n * a pattern the type system KNOWS covers everything.\n *\n * @category Types\n */\nexport type UniversalPattern = PatternMatcher<unknown> & {\n readonly [UNIVERSAL]: true;\n};\n\n/**\n * The type a single pattern matches: a `P.*` matcher's phantom, an object\n * literal mapped key-by-key (so `{ _tag: \"A\" }` matches the `\"A\"`-tagged\n * variant), or the primitive literal itself.\n *\n * @internal\n */\nexport type MatchedOf<Pt> =\n Pt extends PatternMatcher<infer M>\n ? M\n : Pt extends object\n ? { [K in keyof Pt]: MatchedOf<Pt[K]> }\n : Pt;\n\n/**\n * The diagnostic type of `.exhaustive` on a builder that has NOT covered every\n * case: not callable (so it fails the `ExhaustiveMatch` constraint at the call\n * site), and it names the remaining cases so the error reads as a to-do list.\n *\n * @internal\n */\nexport type NonExhaustive<Remaining> = {\n readonly \"unthrown: this match is not exhaustive — add a `.with(…)` for the remaining cases\": Remaining;\n};\n\n/**\n * The \"no output type declared\" sentinel for a builder's `Declared` parameter.\n * A `unique symbol` so no user type can collide with it. Declaration-only —\n * `tsc` emits it into the `.d.ts` without it needing to be exported.\n *\n * @internal\n */\ndeclare const UNSET: unique symbol;\n\n/** @internal */\ntype Unset = typeof UNSET;\n\n/**\n * A branch handler's return position: free inference (`O2`) while the builder\n * is unpinned — today's behaviour, unchanged — or the declared type once\n * `.returnType<R>()` has pinned it.\n *\n * `Defect` stays legal under a pin: the injected `defect` helper is the\n * sanctioned deliberate `Err`→`Defect` form (Thesis #5), and `Defect` is not a\n * nameable public type, so `returnType<R | Defect>()` cannot be spelled. The\n * marker is subtracted from the output by {@link PinnedOut} — the same net\n * result as the unpinned `Exclude<O, Defect>`, decided up front.\n *\n * @internal\n */\ntype BranchReturn<Declared, O2> = [Declared] extends [Unset] ? O2 : Declared | Defect;\n\n/**\n * The builder's output: the accumulated union of branch returns while\n * unpinned, or the declared type once pinned.\n *\n * @internal\n */\ntype PinnedOut<Declared, O> = [Declared] extends [Unset] ? O : Declared;\n\n/**\n * The diagnostic type of `.returnType` on a builder that already has an output\n * to contradict — an arm has contributed a return type, or it is already\n * pinned: not callable, so the mistake is caught where it is written.\n *\n * @internal\n */\ntype PinTooLate = {\n readonly \"unthrown: `.returnType<R>()` must come before any arm produces an output, and only once\": true;\n};\n\n/**\n * The match builder over an input union `E`. `Remaining` tracks the cases not\n * yet covered by a `.with(…)` arm; `O` accumulates the branch output union.\n * `.exhaustive` is callable only once `Remaining` is `never` — which is what\n * the `ExhaustiveMatch` constraint requires — and `.run()` executes it.\n *\n * @typeParam E - the full input union being matched.\n * @typeParam Remaining - the cases not yet covered.\n * @typeParam O - the union of branch return types so far.\n * @category Types\n */\nexport type Matcher<E, Remaining, O, Declared = Unset> = {\n /**\n * The catch-all arm: `.with(P._, handler)` / `.with(P.any, handler)`. A\n * **state transition**, not a computation — it returns `Matcher<E, never, …>`\n * with the remaining cases literally `never`, so the builder is provably\n * exhaustive even when `E` is an unresolved type parameter (a lazily-deferred\n * `Exclude<E, unknown>` would not resolve there). This is what lets a\n * boundary helper generic in `E` terminate with the catch-all (issue #145).\n */\n with<O2>(\n pattern: UniversalPattern,\n handler: (value: Remaining) => BranchReturn<Declared, O2>,\n ): Matcher<E, never, O | O2, Declared>;\n /**\n * Add an arm: one or more patterns sharing a single handler (grouped\n * patterns — `matcher.with(tag(\"A\"), tag(\"B\"), handler)`). The handler\n * receives the input narrowed to what the patterns match (computed against\n * `Remaining`, so cases already handled by earlier arms are excluded); the\n * matched cases are subtracted from `Remaining`.\n */\n with<const Pts extends readonly [unknown, ...unknown[]], O2>(\n ...args: [\n ...patterns: Pts,\n handler: (value: Extract<Remaining, MatchedOf<Pts[number]>>) => BranchReturn<Declared, O2>,\n ]\n ): Matcher<E, Exclude<Remaining, MatchedOf<Pts[number]>>, O | O2, Declared>;\n\n /**\n * Declare the match's output type up front: every subsequent branch handler\n * is checked against `R`, and the match evaluates to `R` instead of the\n * union of whatever the branches happened to return.\n *\n * @remarks\n * Reach for it when the output is **decided by a signature rather than by\n * the branches** — most sharply in code generic in `E`, where the fold's type\n * has to be declared. It also stops a drifting branch from silently widening\n * the outgoing type, reports the mismatch **on the offending branch**, and\n * gives branch returns a contextual type (so object literals need no\n * annotation).\n *\n * A branch may still return the injected `defect` helper's marker; the defect\n * channel is not part of the declared output.\n *\n * Callable **before any arm has produced an output**, and only once\n * (mirroring ts-pattern's up-front pin): once there is an inferred output for\n * the pin to contradict — or the builder is already pinned — this is typed as\n * a non-callable diagnostic. In practice that means calling it directly after\n * `match(…)`; the gate is about output rather than position, so an earlier arm\n * whose handler returns `never` (it always throws) contributes nothing and\n * does not close it — sound, since a `never` branch can contradict no declared\n * type. A no-op at runtime.\n *\n * @typeParam R - the declared output type of every branch.\n */\n returnType: [O] extends [never]\n ? [Declared] extends [Unset]\n ? <R>() => Matcher<E, Remaining, never, R>\n : PinTooLate\n : PinTooLate;\n\n /**\n * Terminate the match. Typed callable only when every case is covered\n * (`Remaining` is `never`); otherwise it is a branded diagnostic object\n * naming the remaining cases, and the builder fails the `ExhaustiveMatch`\n * constraint at the combinator call site.\n */\n exhaustive: [Remaining] extends [never] ? () => PinnedOut<Declared, O> : NonExhaustive<Remaining>;\n\n /**\n * Execute the match (the combinators call this; it runs `.exhaustive()`).\n * A value with no matching arm throws {@link NonExhaustiveError} —\n * unreachable for well-typed callers.\n */\n run(): PinnedOut<Declared, O>;\n};\n\n/**\n * Thrown by `.run()` / `.exhaustive()` when no arm matched the value. For\n * well-typed callers the match is exhaustive by construction, so this is only\n * reachable by a value that slipped past the types (a widened cast, a raw-JS\n * caller); inside the error combinators the throw-to-defect net converts it to\n * a `Defect`, and at the `match` edge it surfaces (a genuinely unmodeled value\n * is a bug).\n *\n * @category Errors\n */\nexport class NonExhaustiveError extends Error {\n /** The value no arm matched. */\n readonly input: unknown;\n constructor(input: unknown) {\n let printed: string;\n try {\n printed = JSON.stringify(input);\n } catch {\n printed = String(input);\n }\n super(`unthrown: no pattern matched the value ${printed}`);\n this.name = \"NonExhaustiveError\";\n this.input = input;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * Is `x` a *plain* object (prototype `Object.prototype` or `null`) — an object\n * literal, the only object shape that acts as a structural pattern?\n *\n * @internal\n */\nfunction isPlainObject(x: object): x is Record<string, unknown> {\n const proto: unknown = Object.getPrototypeOf(x);\n return proto === Object.prototype || proto === null;\n}\n\n/**\n * Runtime test: does `pattern` match `value`? A branded `P.*` pattern applies\n * its predicate; a **plain-object** pattern (an object literal, e.g. the\n * `{ _tag }` produced by `tag()`) matches when every key matches recursively\n * (extra keys on the value are ignored — matching is structural); anything\n * else — primitives, but also class instances, arrays, and foreign pattern\n * objects (e.g. a real ts-pattern matcher, whose keys are symbols) — is\n * compared with `Object.is`. Restricting structural matching to plain objects\n * is load-bearing: a keyless non-plain object (`new Date()`, `new Error()`, a\n * symbol-keyed foreign pattern) would otherwise vacuously match *every* object\n * via an empty `Object.entries`.\n *\n * @internal\n */\nfunction matches(pattern: unknown, value: unknown): boolean {\n if (typeof pattern === \"object\" && pattern !== null) {\n const predicate = (pattern as PatternMatcher<unknown>)[PATTERN_BRAND];\n if (typeof predicate === \"function\") return predicate(value);\n // A symbol-keyed plain object is a *foreign* pattern protocol (e.g. a raw\n // ts-pattern matcher object) — it would look empty to `Object.entries` and\n // vacuously match everything. Fail closed: identity only.\n if (!isPlainObject(pattern) || Object.getOwnPropertySymbols(pattern).length > 0) {\n return Object.is(pattern, value);\n }\n if (typeof value !== \"object\" || value === null) return false;\n return Object.entries(pattern).every(([key, sub]) =>\n matches(sub, (value as Record<string, unknown>)[key]),\n );\n }\n return Object.is(pattern, value);\n}\n\n/**\n * The runtime builder: first matching arm wins; later arms are skipped once a\n * result is captured. `exhaustive` is a *method* at runtime (the conditional\n * type gates its callability per instantiation).\n *\n * @internal\n */\nclass MatcherImpl {\n readonly #value: unknown;\n #matched = false;\n #result: unknown;\n\n constructor(value: unknown) {\n this.#value = value;\n }\n\n with(...args: readonly unknown[]): this {\n if (this.#matched) return this;\n const handler = args[args.length - 1] as (value: unknown) => unknown;\n for (let i = 0; i < args.length - 1; i++) {\n if (matches(args[i], this.#value)) {\n this.#matched = true;\n this.#result = handler(this.#value);\n return this;\n }\n }\n return this;\n }\n\n /**\n * Type-level only — pinning the output type has no runtime meaning, so the\n * builder is returned unchanged (as ts-pattern does).\n */\n returnType(): this {\n return this;\n }\n\n exhaustive(): unknown {\n if (this.#matched) return this.#result;\n throw new NonExhaustiveError(this.#value);\n }\n\n run(): unknown {\n return this.exhaustive();\n }\n}\nObject.freeze(MatcherImpl.prototype);\n\n/**\n * Begin a match over `value`. Chain `.with(pattern, …patterns, handler)` arms;\n * terminate with `.exhaustive()` — or return the un-terminated builder to an\n * unthrown error combinator / `match({ errCases })`, which runs it for you.\n *\n * @remarks\n * This is unthrown's own matcher (the former ts-pattern re-export): the same\n * call-site shape, with exhaustiveness computed by plain `Exclude` over the\n * builder's `Remaining` parameter. A `P._` catch-all is provably exhaustive\n * even over an unresolved generic input.\n *\n * @category Constructors\n */\nexport function match<const E>(value: E): Matcher<E, E, never> {\n return new MatcherImpl(value) as unknown as Matcher<E, E, never>;\n}\n\n/** @internal */\nfunction pattern<M>(predicate: (value: unknown) => boolean): PatternMatcher<M> {\n return Object.freeze({ [PATTERN_BRAND]: predicate }) as PatternMatcher<M>;\n}\n\n// The `UNIVERSAL` marker is phantom (declaration-only): the cast brands the\n// runtime object with the statically-known-universal type so the catch-all\n// `.with` overload fires for `P._` / `P.any` and for nothing else.\nconst universal = pattern<unknown>(() => true) as UniversalPattern;\n\n/**\n * The pattern namespace (unthrown's own; the former ts-pattern `P`):\n *\n * - `P._` / `P.any` — the universal catch-all. Matches anything, and (because\n * its phantom type is `unknown`) makes the builder provably exhaustive even\n * when the matched input is an unresolved type parameter.\n * - `P.instanceOf(Cls)` — an `instanceof` check, narrowing to the class\n * instance type (for union members that are not tagged, e.g. a third-party\n * error class).\n * - `P.when(guard)` — an arbitrary type-guard predicate.\n * - `P.union(…patterns)` — matches when any sub-pattern matches.\n * - `P.string` / `P.number` — primitive-type wildcards.\n *\n * @category Constructors\n */\nexport const P = Object.freeze({\n _: universal,\n any: universal,\n instanceOf: <C extends abstract new (...args: never[]) => unknown>(\n cls: C,\n ): PatternMatcher<InstanceType<C>> => pattern((value) => value instanceof cls),\n when: <G>(guard: (value: unknown) => value is G): PatternMatcher<G> => pattern(guard),\n union: <const Pts extends readonly [unknown, ...unknown[]]>(\n ...patterns: Pts\n ): PatternMatcher<MatchedOf<Pts[number]>> =>\n pattern((value) => patterns.some((sub) => matches(sub, value))),\n string: pattern<string>((value) => typeof value === \"string\"),\n number: pattern<number>((value) => typeof value === \"number\"),\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 // Frozen like Result instances: the marker is an opaque triage token, and a\n // mutated one must not be able to smuggle a different cause past a boundary.\n return Object.freeze({ [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","// 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 Defect, defect, isDefectMarker } from \"./defect.js\";\nimport { match } from \"./matcher.js\";\nimport type {\n AsyncResult,\n Bound,\n DefectView,\n ErrMatcher,\n ErrOf,\n ErrView,\n ExhaustiveMatch,\n FailureView,\n MatchErrOut,\n MatchOut,\n NotThenable,\n OkOf,\n OkView,\n Result,\n} from \"./types.js\";\n\n/**\n * Thrown by a {@link Result}'s `get` / `getErr` when the assertion is\n * wrong on a *modeled* result — `get()` on an `Err`, or `getErr()` on an\n * `Ok`.\n *\n * @remarks\n * The offending value is exposed two ways: the typed {@link GetError.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 a `GetError`: its original cause is\n * re-thrown (with its original stack) instead.\n *\n * `get()` and `getErr()` are type-gated (`this: Result<T, never>` /\n * `Result<never, E>`), so the wrong-variant branch that throws this is\n * unreachable through well-typed code — it remains only as a defensive guard\n * against unsound runtime misuse (e.g. an `as` cast past the gate).\n *\n * @typeParam E - the type of the {@link GetError.error} it carries.\n *\n * @category Errors\n */\nexport class GetError<E = unknown> extends Error {\n /**\n * The offending value: the `Err` error for `get()`, or the `Ok` value for\n * `getErr()`.\n */\n readonly error: E;\n constructor(error: E) {\n super(\"unthrown: get() / getErr() called on a non-matching Result variant\", { cause: error });\n this.name = \"GetError\";\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 & NotThenable<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 const r = f(this.value);\n return isResult(r) ? r : nonResultCallbackDefect();\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n tap<R>(this: Result<T, E>, f: (value: T) => R & NotThenable<R>): 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 if (!isResult(r)) return nonResultCallbackDefect();\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 (!isResult(r)) return nonResultCallbackDefect();\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 & NotThenable<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 discard(this: Result<T, E>): Result<void, E> {\n if (this.tag !== \"Ok\") return passThrough(this);\n // explicit <void, E>: inference from the argument would land on undefined, not void\n return okRes<void, E>(undefined);\n }\n\n // The type-guard/boolean overload pair lives on the public surface\n // (`ResultMethods`); this single implementation signature covers both.\n ensure<E2>(\n this: Result<T, E>,\n predicate: (value: T) => boolean,\n onFail: (value: T) => E2,\n ): Result<T, E | E2> {\n if (this.tag !== \"Ok\") return passThrough(this);\n try {\n // A passing value flows through as the SAME Ok (the passThrough\n // philosophy: nothing changed, so nothing is reallocated).\n return predicate(this.value) ? this : errRes(onFail(this.value));\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n mapErrCases<M extends ExhaustiveMatch<unknown>>(\n this: Result<T, E>,\n f: (matcher: ErrMatcher<E>, defect: (cause: unknown) => Defect) => M,\n ): Result<T, MatchErrOut<M>> {\n if (this.tag !== \"Err\") return passThrough(this);\n try {\n const out = runMatch(f, this.error);\n if (isDefectMarker(out)) return defectRes(out.cause);\n return errRes(out as MatchErrOut<M>);\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n flatMapErrCases<M extends ExhaustiveMatch<Result<unknown, unknown> | Defect>>(\n this: Result<T, E>,\n f: (matcher: ErrMatcher<E>, defect: (cause: unknown) => Defect) => M,\n ): Result<T | OkOf<MatchOut<M>>, ErrOf<MatchOut<M>>> {\n if (this.tag !== \"Err\") return passThrough(this);\n try {\n const out = runMatch(f, this.error);\n if (isDefectMarker(out)) return defectRes(out.cause);\n if (!isResult(out)) return nonResultCallbackDefect();\n return out as Result<OkOf<MatchOut<M>>, ErrOf<MatchOut<M>>>;\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n recoverErrCases<M extends ExhaustiveMatch<unknown>>(\n this: Result<T, E>,\n f: (matcher: ErrMatcher<E>, defect: (cause: unknown) => Defect) => M,\n ): Result<T | MatchErrOut<M>, never> {\n if (this.tag !== \"Err\") return passThrough(this);\n try {\n const out = runMatch(f, this.error);\n if (isDefectMarker(out)) return defectRes(out.cause);\n return okRes(out as MatchErrOut<M>);\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n tapErrCases(\n this: Result<T, E>,\n f: (matcher: ErrMatcher<E>, defect: (cause: unknown) => Defect) => ExhaustiveMatch<unknown>,\n ): Result<T, E> {\n if (this.tag !== \"Err\") return this;\n try {\n const out = runMatch(f, this.error);\n // Branch *values* are discarded here — but the injected `defect(cause)`\n // marker is not a value, it is the lint-clean, expression-position form of\n // a `throw` (Thesis #5). So it takes the same route a `throw` in this\n // branch would: the observed error survives alongside the caller's cause.\n if (isDefectMarker(out)) return observerThrowToDefect(out.cause, this.error);\n return this;\n } catch (cause) {\n return observerThrowToDefect(cause, this.error);\n }\n }\n\n flatTapErrCases<M extends ExhaustiveMatch<Result<unknown, unknown>>>(\n this: Result<T, E>,\n f: (matcher: ErrMatcher<E>, defect: (cause: unknown) => Defect) => M,\n ): Result<T, E | ErrOf<MatchOut<M>>> {\n if (this.tag !== \"Err\") return this;\n try {\n const r = runMatch(f, this.error);\n // A deliberate `defect(cause)` branch is the expression-position form of a\n // `throw` (Thesis #5), so it is treated like one: this is a failure\n // *observer*, and the observed error survives alongside the caller's cause.\n // (Contrast a branch returning a Defect-state `Result` below — an effect\n // that blew up on its own, which short-circuits and replaces the error.)\n if (isDefectMarker(r)) return observerThrowToDefect(r.cause, this.error);\n if (!isResult(r)) return nonResultCallbackDefect();\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 observerThrowToDefect(cause, this.error);\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 const r = f(this.cause);\n return isResult(r) ? r : nonResultCallbackDefect();\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n tapDefect<R>(this: Result<T, E>, f: (cause: unknown) => R & NotThenable<R>): Result<T, E> {\n if (this.tag !== \"Defect\") return this;\n try {\n f(this.cause);\n return this;\n } catch (cause) {\n return observerThrowToDefect(cause, this.cause);\n }\n }\n\n tapFailure<R>(\n this: Result<T, E>,\n f: (failure: FailureView<E, T>) => R & NotThenable<R>,\n ): Result<T, E> {\n if (this.tag === \"Ok\") return this;\n try {\n f(this);\n return this;\n } catch (cause) {\n return observerThrowToDefect(cause, this.tag === \"Err\" ? this.error : this.cause);\n }\n }\n\n match<ROk, RDefect, M extends ExhaustiveMatch<unknown>>(\n this: Result<T, E>,\n cases: {\n ok: (value: T) => ROk;\n errCases: (matcher: ErrMatcher<E>) => M;\n defect: (cause: unknown) => RDefect;\n },\n ): ROk | RDefect | MatchOut<M> {\n switch (this.tag) {\n case \"Ok\":\n return cases.ok(this.value);\n case \"Err\":\n // The `errCases` handler returns the un-terminated builder; `.run()`\n // executes `.exhaustive()`. Type-forced exhaustive for well-typed\n // callers; a value slipping past the types (widened cast, JS caller) with\n // no matching case throws the matcher's `NonExhaustiveError` — `match` is\n // an edge eliminator, so it surfaces rather than being caught into a Defect.\n return cases.errCases(match(this.error) as ErrMatcher<E>).run() as MatchOut<M>;\n case \"Defect\":\n return cases.defect(this.cause);\n }\n }\n\n get(this: Result<T, E>): T {\n switch (this.tag) {\n case \"Ok\":\n return this.value;\n case \"Err\":\n throw new GetError(this.error);\n case \"Defect\":\n throw this.cause; // rethrow original cause, original stack\n }\n }\n\n getErr(this: Result<T, E>): E {\n switch (this.tag) {\n case \"Err\":\n return this.error;\n case \"Ok\":\n throw new GetError(this.value);\n case \"Defect\":\n throw this.cause;\n }\n }\n\n getOr<U>(this: Result<T, E>, fallback: U): T | U {\n if (this.tag === \"Ok\") return this.value;\n if (this.tag === \"Defect\") throw this.cause;\n return fallback;\n }\n\n getOrElse<U>(this: Result<T, E>, f: (error: E) => U): T | U {\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 getOrThrow(this: Result<T, E>): T {\n if (this.tag === \"Ok\") return this.value;\n if (this.tag === \"Defect\") throw this.cause;\n throw this.error;\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\n/**\n * Cross-copy brand: `Symbol.for` yields the same symbol in every copy of the\n * library (the dual CJS/ESM build, a duplicated install, another realm), so\n * {@link isResult} can recognise a `Result` built by another copy whose `Res`\n * class fails the `instanceof` check. Defined non-enumerably on the prototype,\n * before it is frozen.\n *\n * @internal\n */\nconst RESULT_BRAND = Symbol.for(\"unthrown.Result\");\n\nconst RESULT_PROTO = Res.prototype;\nObject.defineProperty(RESULT_PROTO, RESULT_BRAND, { value: true });\n// Frozen prototype: the shared combinators cannot be swapped out from under\n// every instance (the instances themselves are frozen by the builders below).\nObject.freeze(RESULT_PROTO);\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 // Frozen so the `readonly` surface is real at runtime: a variant cannot be\n // forged by mutating `tag`/payload after construction.\n return Object.freeze(\n Object.assign(Object.create(RESULT_PROTO), {\n tag: \"Ok\" as const,\n value,\n }),\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.freeze(\n Object.assign(Object.create(RESULT_PROTO), {\n tag: \"Err\" as const,\n error,\n }),\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.freeze(\n Object.assign(Object.create(RESULT_PROTO), {\n tag: \"Defect\" as const,\n cause,\n }),\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\n * (`instanceof` first, falling back to the `Symbol.for(\"unthrown.Result\")`\n * brand the prototype carries — so a `Result` built by **another copy** of\n * unthrown, e.g. the CJS and ESM builds loaded side by side, is still\n * recognised). A look-alike plain object (`{ tag: \"Ok\" }`) carries neither and\n * is **not** matched. An `AsyncResult` is not a `Result` and returns `false`.\n *\n * @returns `true` when `x` is a `Result` produced by this library.\n *\n * @example\n * ```ts\n * import { isResult, Ok } from \"unthrown\";\n *\n * isResult(Ok(1)); // => true\n * isResult({ tag: \"Ok\" }); // => false (look-alike, wrong prototype)\n * isResult(Ok(1).toAsync()); // => false (an AsyncResult is not a Result)\n *\n * const x: unknown = Ok(1);\n * if (isResult(x))\n * x.match({ ok: () => 1, errCases: (m) => m.with(P._, () => 0), defect: () => -1 });\n * ```\n *\n * @category Guards\n */\nexport function isResult(x: unknown): x is Result<unknown, unknown> {\n if (x instanceof Res) return true;\n // Dual-copy / cross-realm fallback: another copy of unthrown has its own\n // `Res`, so `instanceof` fails — but its prototype carries the shared\n // `Symbol.for` brand. Reading the brand off the prototype chain keeps the\n // guarantee that a structural look-alike (no unthrown prototype) still fails.\n // Fail-closed: this guard exists for untyped boundaries, so a hostile input\n // (a Proxy `get` trap or a throwing getter at the brand key) is `false`,\n // never a throw.\n try {\n return (\n (typeof x === \"object\" || typeof x === \"function\") &&\n x !== null &&\n Reflect.get(x, RESULT_BRAND) === true\n );\n } catch {\n return false;\n }\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 * The Defect minted when a callback constrained to return a `Result` returns\n * something else — reachable only from untyped/cast callers (in typed code the\n * constraint is a compile error). The combinator-side sibling of the\n * aggregates' non-`Result`-element guard: surface the out-of-contract value as\n * a `Defect` here rather than letting a poison value throw a raw `TypeError`\n * further down the pipeline.\n *\n * @internal\n */\nfunction nonResultCallbackDefect<T, E>(): Result<T, E> {\n return defectRes(new TypeError(\"unthrown: a combinator callback returned a non-Result value\"));\n}\n\n/**\n * Drive an error-combinator callback: build `match(error)`, hand it (plus the\n * injected `defect`) to the callback, and `.run()` the returned exhaustive\n * builder to its output. `.run()` executes `.exhaustive()` — type-forced\n * exhaustive, so it always matches for well-typed callers; a value that slips\n * through the types (a widened cast, a JS caller) throws `NonExhaustiveError`,\n * which the caller's `try/catch` turns into a `Defect` — an unmodeled failure.\n *\n * @internal\n */\nfunction runMatch<E>(\n f: (matcher: ErrMatcher<E>, defect: (cause: unknown) => Defect) => { run: () => unknown },\n error: E,\n): unknown {\n return f(match(error) as ErrMatcher<E>, defect).run();\n}\n\n/**\n * A throw inside a *failure observer* (`tapErrCases` / `tapDefect` /\n * `tapFailure` / `flatTapErrCases`) must not destroy the failure being observed\n * — that is the exact place (e.g. a failing error-logger) where losing the\n * underlying failure hurts most. The resulting Defect aggregates both:\n * `errors[0]` is the observer's own failure, `errors[1]` the original failure.\n *\n * An observer branch returning the injected `defect(cause)` marker\n * (`tapErrCases` / `flatTapErrCases`) takes the same route: it is the\n * lint-clean, expression-position form of a `throw` (Thesis #5), so it must not\n * behave differently from one.\n *\n * @internal\n */\nfunction observerThrowToDefect<T, E>(thrown: unknown, original: unknown): Result<T, E> {\n return defectRes(\n new AggregateError(\n [thrown, original],\n \"unthrown: a failure-observer callback failed; errors[0] is the callback's failure (a throw, or a deliberate defect), errors[1] the original failure\",\n ),\n );\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 || Array.isArray(value)) {\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 // A native #private field: invisible to property access and untouchable even\n // via Object.defineProperty, so the wrapped promise cannot be tampered with.\n readonly #promise: Promise<Result<T, E>>;\n\n constructor(promise: Promise<Result<T, E>>) {\n this.#promise = promise;\n }\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 & NotThenable<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 const inner = await f(r.value);\n return isResult(inner) ? inner : nonResultCallbackDefect<U, E | E2>();\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n tap<R>(f: (value: T) => R & NotThenable<R>): 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 if (!isResult(inner)) return nonResultCallbackDefect();\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 (!isResult(inner)) return nonResultCallbackDefect();\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>(\n name: K,\n f: (scope: T) => U & NotThenable<U>,\n ): 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 discard(): AsyncResult<void, E> {\n return new AsyncRes<void, E>(\n this.#promise.then((r) => (r.tag === \"Ok\" ? okRes<void, E>(undefined) : passThrough(r))),\n );\n }\n\n // Like the matcher methods below, `ensure` is typed loosely here (`never`\n // channels) because TypeScript cannot relate this single implementation\n // signature to the public type-guard/boolean overload pair across the\n // class/`implements` boundary; `AsyncResultMethods` re-imposes the precision.\n ensure(\n predicate: (value: T) => boolean,\n onFail: (value: T) => unknown,\n ): AsyncResult<never, never> {\n return new AsyncRes<never, never>(\n this.#promise.then((r) => {\n if (r.tag !== \"Ok\") return passThrough(r);\n try {\n // A passing value flows through as the same Ok (see the sync `ensure`).\n return (predicate(r.value) ? r : errRes(onFail(r.value))) as Result<never, never>;\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n // The precise generic-M matcher signatures live on the public surface\n // (`AsyncResultMethods`); TypeScript cannot unify them across the\n // class/`implements` boundary (relating the two generic signatures fails to\n // equate `MatchErrOut<M>` on each side), so these implementations are typed\n // loosely — `never` error channels keep the returns bivariantly compatible —\n // and the interface re-imposes the precision, mirroring how `get`'s `this`\n // gate is re-imposed in `types.ts`.\n mapErrCases(\n f: (matcher: ErrMatcher<E>, defect: (cause: unknown) => Defect) => ExhaustiveMatch<unknown>,\n ): AsyncResult<T, never> {\n return new AsyncRes<T, never>(\n this.#promise.then((r) => {\n if (r.tag !== \"Err\") return passThrough(r);\n try {\n const out = runMatch(f, r.error);\n if (isDefectMarker(out)) return defectRes<T, never>(out.cause);\n return errRes<T, never>(out as never);\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n flatMapErrCases(\n f: (\n matcher: ErrMatcher<E>,\n defect: (cause: unknown) => Defect,\n ) => ExhaustiveMatch<Result<unknown, unknown> | AsyncResult<unknown, unknown> | Defect>,\n ): AsyncResult<T, never> {\n return new AsyncRes<T, never>(\n this.#promise.then(async (r) => {\n if (r.tag !== \"Err\") return passThrough(r);\n try {\n const out = runMatch(f, r.error);\n if (isDefectMarker(out)) return defectRes<T, never>(out.cause);\n const inner = await (out as Result<unknown, unknown> | AsyncResult<unknown, unknown>);\n if (!isResult(inner)) return nonResultCallbackDefect<T, never>();\n return inner as Result<T, never>;\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n recoverErrCases(\n f: (matcher: ErrMatcher<E>, defect: (cause: unknown) => Defect) => ExhaustiveMatch<unknown>,\n ): AsyncResult<T, never> {\n return new AsyncRes<T, never>(\n this.#promise.then((r) => {\n if (r.tag !== \"Err\") return passThrough(r);\n try {\n const out = runMatch(f, r.error);\n if (isDefectMarker(out)) return defectRes<T, never>(out.cause);\n return okRes<T, never>(out as T);\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n tapErrCases(\n f: (matcher: ErrMatcher<E>, defect: (cause: unknown) => Defect) => ExhaustiveMatch<unknown>,\n ): AsyncResult<T, E> {\n return new AsyncRes<T, E>(\n this.#promise.then((r) => {\n if (r.tag !== \"Err\") return r;\n try {\n const out = runMatch(f, r.error);\n // Same observer treatment as the sync surface — a deliberate\n // `defect(…)` is the expression-position form of a `throw`, not a\n // discarded branch value.\n if (isDefectMarker(out)) return observerThrowToDefect<T, E>(out.cause, r.error);\n return r;\n } catch (cause) {\n return observerThrowToDefect<T, E>(cause, r.error);\n }\n }),\n );\n }\n\n flatTapErrCases(\n f: (\n matcher: ErrMatcher<E>,\n defect: (cause: unknown) => Defect,\n ) => ExhaustiveMatch<Result<unknown, unknown> | AsyncResult<unknown, unknown>>,\n ): AsyncResult<T, E> {\n return new AsyncRes<T, E>(\n this.#promise.then(async (r) => {\n if (r.tag !== \"Err\") return passThrough(r);\n try {\n const out = runMatch(f, r.error);\n // Checked BEFORE the await, mirroring the async `flatMapErrCases`: the\n // marker is never thenable, so awaiting it would be a no-op microtask.\n // Same observer treatment as the sync surface — the observed error\n // survives alongside the caller's cause.\n if (isDefectMarker(out)) return observerThrowToDefect(out.cause, r.error);\n const inner = await (out as Result<unknown, unknown> | AsyncResult<unknown, unknown>);\n if (!isResult(inner)) return nonResultCallbackDefect();\n // Keep the original error on success; an Err/Defect from the effect wins.\n return inner.tag === \"Ok\" ? passThrough(r) : passThrough(inner);\n } catch (cause) {\n return observerThrowToDefect(cause, r.error);\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 const inner = await f(r.cause);\n return isResult(inner) ? inner : nonResultCallbackDefect<T | U, E | E2>();\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n tapDefect<R>(f: (cause: unknown) => R & NotThenable<R>): 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 observerThrowToDefect<T, E>(cause, r.cause);\n }\n }),\n );\n }\n\n tapFailure<R>(f: (failure: FailureView<E, T>) => R & NotThenable<R>): 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);\n return r;\n } catch (cause) {\n return observerThrowToDefect<T, E>(cause, r.tag === \"Err\" ? r.error : r.cause);\n }\n }),\n );\n }\n\n match<ROk, RDefect, M extends ExhaustiveMatch<unknown>>(cases: {\n ok: (value: T) => ROk;\n errCases: (matcher: ErrMatcher<E>) => M;\n defect: (cause: unknown) => RDefect;\n }): Promise<ROk | RDefect | MatchOut<M>> {\n return this.#promise.then((r) => r.match(cases));\n }\n\n get(): Promise<T> {\n return this.#promise.then((r) => (r as Result<T, never>).get());\n }\n getErr(): Promise<E> {\n return this.#promise.then((r) => (r as Result<never, E>).getErr());\n }\n getOr<U>(fallback: U): Promise<T | U> {\n return this.#promise.then((r) => r.getOr(fallback));\n }\n getOrElse<U>(f: (error: E) => U): Promise<T | U> {\n return this.#promise.then((r) => r.getOrElse(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 getOrThrow(): Promise<T> {\n // The cast sidesteps `getOrThrow`'s `this` gate (non-empty error channel),\n // re-imposed on the public `AsyncResultMethods` signature — mirroring `get`.\n return this.#promise.then((r) => (r as Result<T, unknown>).getOrThrow());\n }\n}\n\n// Same hardening as `Res.prototype` above: the shared async combinators cannot\n// be swapped out from under every instance. (The wrapped promise is already a\n// native #private field, unreachable from outside.)\nObject.freeze(AsyncRes.prototype);\n","// Result constructors and the standalone narrowing guards.\n\nimport { errRes, okRes } from \"./core.js\";\nimport type { AsyncResult, DefectView, ErrView, OkView, Result } from \"./types.js\";\n\n/**\n * Construct a successful `void` {@link Result} — `Result<void, never>` —\n * sparing you `Ok(undefined)` and typing the success channel `void`, not\n * `undefined`.\n *\n * @example\n * ```ts\n * import { Ok } from \"unthrown\";\n *\n * Ok(); // => a void success: Result<void, never>\n * ```\n *\n * @category Constructors\n */\nexport function Ok(): Result<void, never>;\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 *\n * Ok(2).map((n) => n + 1); // => Ok(3)\n * Ok(42).get(); // => 42\n * ```\n *\n * @category Constructors\n */\nexport function Ok<T>(value: T): Result<T, never>;\nexport function Ok<T>(value?: T): Result<T, never> {\n // The only way in with no argument is the no-arg overload, which fixes the\n // result type to void — exactly what the omitted undefined inhabits.\n // Invisible to callers.\n return okRes(value as T);\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 *\n * Err(\"not_found\").map((n) => n + 1); // => Err(\"not_found\") (map skipped)\n * Err(\"not_found\").getErr(); // => \"not_found\"\n * ```\n *\n * @category Constructors\n */\nexport function Err<E>(error: E): Result<never, E> {\n return errRes(error);\n}\n\n/**\n * Construct a successful `void` {@link AsyncResult} — `AsyncResult<void, never>`\n * — the pre-lifted form of the no-arg {@link Ok}, sparing you\n * `Ok(undefined).toAsync()`.\n *\n * @example\n * ```ts\n * import { OkAsync } from \"unthrown\";\n *\n * OkAsync(); // => a void success: AsyncResult<void, never>\n * ```\n *\n * @category Constructors\n */\nexport function OkAsync(): AsyncResult<void, never>;\n/**\n * Construct a successful {@link AsyncResult} from a pure value — the pre-lifted\n * form of {@link Ok}, sparing you `Ok(value).toAsync()`.\n *\n * @remarks\n * Reach for this on the synchronous/early branch of an `AsyncResult`-returning\n * function, so both branches share one return type without a trailing\n * `.toAsync()`. Named with the `Async` suffix the async free functions carry\n * (`allAsync`, `allFromDictAsync`); the {@link AsyncResult} companion aliases it\n * as `AsyncResult.Ok` (the namespace already says \"async\", so the suffix drops).\n *\n * @typeParam T - the success value type.\n * @param value - the success value to wrap.\n *\n * @example\n * ```ts\n * import { OkAsync, type AsyncResult } from \"unthrown\";\n *\n * function loadItems(ids: string[]): AsyncResult<Item[], never> {\n * if (ids.length === 0) return OkAsync([]); // no more Ok([]).toAsync()\n * return itemRepository.load(ids);\n * }\n * ```\n *\n * @category Constructors\n */\nexport function OkAsync<T>(value: T): AsyncResult<T, never>;\nexport function OkAsync<T>(value?: T): AsyncResult<T, never> {\n // Same deliberate cast as `Ok` above: argument-less means the no-arg\n // overload already fixed the type to `void`.\n return Ok(value as T).toAsync();\n}\n\n/**\n * Construct a failed {@link AsyncResult} carrying a **modeled** error — the\n * pre-lifted form of {@link Err}, sparing you `Err(error).toAsync()`.\n *\n * @remarks\n * The error-channel mirror of {@link OkAsync}; see it for the naming and the\n * `AsyncResult.Err` companion alias.\n *\n * @typeParam E - the modeled error type.\n * @param error - the domain error to wrap.\n *\n * @example\n * ```ts\n * import { ErrAsync } from \"unthrown\";\n *\n * ErrAsync(\"not_found\"); // AsyncResult<never, string>\n * ```\n *\n * @category Constructors\n */\nexport function ErrAsync<E>(error: E): AsyncResult<never, E> {\n return Err(error).toAsync();\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, Ok, Err, type Result } from \"unthrown\";\n *\n * isOk(Ok(1)); // => true\n * isOk(Err(\"boom\")); // => false\n *\n * declare const r: Result<number, string>;\n * if (isOk(r)) r.value; // number, narrowed\n * ```\n *\n * @category Guards\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 *\n * @example\n * ```ts\n * import { isErr, Ok, Err, type Result } from \"unthrown\";\n *\n * isErr(Err(\"boom\")); // => true\n * isErr(Ok(1)); // => false\n *\n * declare const r: Result<number, string>;\n * if (isErr(r)) r.error; // string, narrowed\n * ```\n *\n * @category Guards\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 * @remarks\n * A `Defect` has no public constructor — it only arises at a boundary (e.g. a\n * callback throwing inside a combinator). This guard is how you detect one.\n *\n * @returns `true` when `r` is a `Defect`.\n *\n * @example\n * ```ts\n * import { isDefect, Ok } from \"unthrown\";\n *\n * // A throw inside a combinator is captured as a Defect:\n * const r = Ok(1).map(() => {\n * throw new Error(\"boom\");\n * });\n * isDefect(r); // => true\n * isDefect(Ok(1)); // => false\n *\n * if (isDefect(r)) r.cause; // unknown, narrowed\n * ```\n *\n * @category Guards\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 { AsyncResult, 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 *\n * @example\n * ```ts\n * import { Do, Ok, Err } from \"unthrown\";\n *\n * // Ok path — the scope accumulates:\n * Do()\n * .bind(\"a\", () => Ok(2))\n * .let(\"b\", ({ a }) => a * 10)\n * .map(({ a, b }) => a + b); // => Ok(22)\n *\n * // Err path — the first Err short-circuits the rest:\n * Do()\n * .bind(\"a\", () => Err(\"boom\"))\n * .let(\"b\", ({ a }) => a); // => Err(\"boom\")\n * ```\n *\n * @category Do-notation\n */\nexport function Do(): Result<{}, never> {\n return Ok({});\n}\n\n/**\n * Start an **asynchronous** do-notation chain with an empty object scope — the\n * pre-lifted form of {@link Do}, sparing you `Do().toAsync()`.\n *\n * @remarks\n * From here a `bind` may return a `Result` **or** an `AsyncResult`; the scope\n * accumulates exactly as in a sync {@link Do} chain, and a throw in any step\n * becomes a `Defect`. Named with the `Async` suffix the async free functions\n * carry (`OkAsync`, `allAsync`); the {@link AsyncResult} companion aliases it as\n * `AsyncResult.Do` (the namespace already says \"async\", so the suffix drops).\n *\n * @example\n * ```ts\n * import { DoAsync, Ok } from \"unthrown\";\n *\n * const result = await DoAsync()\n * .bind(\"user\", () => findUser(id)) // AsyncResult<User, NotFound>\n * .bind(\"plan\", ({ user }) => Ok(user.plan)) // a sync Result is accepted too\n * .let(\"label\", ({ user, plan }) => `${user.name} on ${plan}`);\n * // Result<{ user: User; plan: Plan; label: string }, NotFound>\n * ```\n *\n * @category Do-notation\n */\nexport function DoAsync(): AsyncResult<{}, never> {\n return Do().toAsync();\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 { Err, Ok } from \"./constructors.js\";\nimport { AsyncRes, defectRes, errRes, isResult, okRes } from \"./core.js\";\nimport { type Defect, defect, isDefectMarker } from \"./defect.js\";\nimport type {\n AsyncErrOf,\n AsyncOkOf,\n AsyncResult,\n ErrOf,\n NotThenable,\n OkOf,\n Result,\n} 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 * @category Interop\n *\n * @example\n * ```ts\n * import { fromNullable } from \"unthrown\";\n *\n * const map = new Map([[\"a\", 1]]);\n * fromNullable(map.get(\"a\"), () => \"absent\").getOr(0); // => 1\n * fromNullable(map.get(\"z\"), () => \"absent\"); // => Err(\"absent\")\n * fromNullable(0, () => \"absent\").getOr(-1); // => 0 (falsy but present)\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`. `qualify` is **synchronous**: an `async` qualify is rejected at\n * compile time ({@link NotThenable}) — its `Promise` would land in `E` un-triaged\n * — and a thenable slipped past the types at runtime becomes a `Defect` (never\n * an `Err(Promise)`), its orphaned rejection silenced.\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 fromSafeThrowable} when every throw 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 * @category Interop\n *\n * @example\n * ```ts\n * import { fromThrowable } from \"unthrown\";\n *\n * // Model the parse failure as an `Err`, everything unexpected as a `Defect`.\n * const parse = fromThrowable(\n * (text: string) => JSON.parse(text) as unknown,\n * (cause, defect) =>\n * cause instanceof SyntaxError ? (\"invalid_json\" as const) : defect(cause),\n * );\n *\n * parse('{\"ok\":true}').getOr(null); // => { ok: true }\n * parse(\"nope\"); // => Err(\"invalid_json\")\n * ```\n */\nexport function fromThrowable<A extends unknown[], T, R>(\n fn: (...args: A) => T,\n qualify: (cause: unknown, defect: (cause: unknown) => Defect) => R & NotThenable<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 throwing synchronous function asserted **not** to fail in any modeled\n * way: any throw becomes a `Defect`.\n *\n * @remarks\n * The synchronous counterpart of {@link fromSafePromise}. Use it only when a\n * throw genuinely indicates a bug rather than an anticipated outcome — the\n * error channel is `never`, so there is nothing to triage; there is no\n * `qualify`. When some throws *are* anticipated, reach for\n * {@link fromThrowable} and triage them.\n *\n * @typeParam A - the wrapped function's argument tuple.\n * @typeParam T - the wrapped function's return type.\n * @param fn - the throwing function to wrap.\n * @returns a function with the same arguments returning `Result<T, never>`.\n *\n * @category Interop\n *\n * @example\n * ```ts\n * import { fromSafeThrowable } from \"unthrown\";\n *\n * // A decode failure here is a bug (the row came from our own schema), so\n * // every throw is a defect — no throwaway `(cause, defect) => defect(cause)`.\n * const decode = fromSafeThrowable((row: Row) => userSchema.parse(row));\n *\n * decode(row); // => Result<User, never> — a throw becomes a Defect\n * ```\n */\nexport function fromSafeThrowable<A extends unknown[], T>(\n fn: (...args: A) => T,\n): (...args: A) => Result<T, never> {\n return (...args: A): Result<T, never> => {\n try {\n return Ok(fn(...args));\n } catch (cause) {\n return defectRes<T, never>(cause);\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`. `qualify` is\n * **synchronous**: an `async` qualify is rejected at compile time\n * ({@link NotThenable}), and a thenable slipped past the types at runtime\n * becomes a `Defect` (never an `Err(Promise)`), its orphaned rejection silenced.\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 * @param _guard - compile-time only; never pass it. The phantom rest-tuple that\n * enforces \"qualify is synchronous\": an `async` qualify makes this demand an\n * impossible extra argument (whose type spells out the error), while a\n * synchronous one leaves it empty. Encoded here — not on `qualify`'s return\n * type — so `T`'s inference from `promise` is undisturbed.\n *\n * @category Interop\n *\n * @example\n * ```ts\n * import { fromPromise } from \"unthrown\";\n *\n * // A rejection with a NotFoundError becomes a modeled `Err`; anything else a Defect.\n * const user = await fromPromise(fetchUser(id), (cause, defect) =>\n * cause instanceof NotFoundError ? (\"not_found\" as const) : defect(cause),\n * );\n *\n * if (user.isOk()) user.value; // => the fetched user\n * // when fetchUser rejects with NotFoundError: user is Err(\"not_found\")\n * ```\n */\nexport function fromPromise<T, R>(\n promise: Promise<T> | (() => Promise<T>),\n qualify: (cause: unknown, defect: (cause: unknown) => Defect) => R,\n // Phantom rest-tuple guard — the async-qualify ban, encoded OFF the callback's\n // return type: `R & NotThenable<R>` there made TS defer qualify's inference,\n // which collapsed `T` to `unknown` for an inline `.then(…)` chain argument.\n // With the conditional here instead, an async qualify demands an impossible\n // third argument (compile error carrying the message) while `T`/`R` infer\n // normally. Nothing is ever passed at runtime.\n //\n // `Extract` (not `[R] extends [PromiseLike<…>]`) so the ban also fires when\n // only SOME arms of a union return are thenable (`E | Promise<X>` — a\n // sometimes-async qualify is still an unqualified rejection path), and it\n // vacuously admits the always-throwing qualify (`R = never` extracts to\n // `never`) with no special case. The runtime thenable→Defect net in\n // `qualifyToResult` stays as the last resort for untyped callers.\n ..._guard: [Extract<R, PromiseLike<unknown>>] extends [never]\n ? []\n : [\"unthrown: qualify must be synchronous — its Promise would land in E un-triaged\"]\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 // Promise.resolve() also absorbs a non-thenable passed from untyped code, so\n // this boundary never throws synchronously — it exists to prevent throws.\n const p =\n typeof promise === \"function\" ? Promise.resolve().then(promise) : Promise.resolve(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.) The\n * synchronous counterpart is {@link fromSafeThrowable}.\n *\n * @typeParam T - the resolved value type.\n * @param promise - the promise, or a thunk returning one.\n *\n * @category Interop\n *\n * @example\n * ```ts\n * import { fromSafePromise } from \"unthrown\";\n *\n * (await fromSafePromise(Promise.resolve(3))).get(); // => 3\n * // a rejection becomes a Defect (never a modeled Err):\n * await fromSafePromise(Promise.reject(new Error(\"boom\"))); // => Defect(Error(\"boom\"))\n * ```\n */\nexport function fromSafePromise<T>(\n promise: Promise<T> | (() => Promise<T>),\n): AsyncResult<T, never> {\n // Promise.resolve() also absorbs a non-thenable passed from untyped code, so\n // this boundary never throws synchronously — it exists to prevent throws.\n const p =\n typeof promise === \"function\" ? Promise.resolve().then(promise) : Promise.resolve(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 if (isDefectMarker(q)) return defectRes<T, E>(q.cause);\n if (isThenable(q)) {\n // An async `qualify` slipped past the compile-time NotThenable ban\n // (untyped/JS caller). Its Promise must never become the modeled error —\n // the boundary would be un-triaged — so surface a Defect instead. Also\n // adopt-and-silence the orphaned thenable: if the async qualify later\n // rejects, that rejection must not float as an unhandled rejection.\n void Promise.resolve(q).then(undefined, () => undefined);\n return defectRes<T, E>(\n new TypeError(\n \"unthrown: qualify must be synchronous — it returned a thenable; triage the cause without awaiting\",\n ),\n );\n }\n return 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 * Runtime thenable probe for the belt-and-braces guard above. Called inside the\n * caller's `try`, so even a hostile `.then` getter lands on the Defect path.\n *\n * @internal\n */\nfunction isThenable(x: unknown): boolean {\n return (\n (typeof x === \"object\" || typeof x === \"function\") &&\n x !== null &&\n typeof (x as { then?: unknown }).then === \"function\"\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 */\n/** The Defect minted for an out-of-contract non-`Result` element in an aggregate. */\nfunction nonResultDefect(): Result<unknown, unknown> {\n return defectRes(new TypeError(\"unthrown: aggregate received a non-Result element\"));\n}\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 (!isResult(r)) {\n // Out-of-contract element (a hole/undefined/non-Result, reachable only via\n // untyped or cast input). Surface it as a Defect — an unexpected failure —\n // rather than throwing on `.tag` (sync) or rejecting the internal promise\n // (async). A Defect dominates, so break.\n firstDefect ??= nonResultDefect();\n break;\n }\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 (!isResult(r)) {\n firstDefect ??= nonResultDefect(); // out-of-contract element → Defect (see foldArray)\n break;\n }\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\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 * @category Aggregate\n *\n * @example\n * ```ts\n * import { all, Ok, Err } from \"unthrown\";\n *\n * all([Ok(1), Ok(\"a\"), Ok(true)]).get(); // => [1, \"a\", true] (typed [number, string, boolean])\n * all([Ok(1), Err(\"e\"), Ok(3)]); // => Err(\"e\") (short-circuits on the first Err)\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 * @category Aggregate\n *\n * @example\n * ```ts\n * import { allFromDict, Ok, Err } from \"unthrown\";\n *\n * allFromDict({ id: Ok(1), name: Ok(\"ada\") }).get(); // => { id: 1, name: \"ada\" }\n * allFromDict({ id: Ok(1), name: Err(\"missing\") }); // => Err(\"missing\")\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 * @category Aggregate\n *\n * @example\n * ```ts\n * import { allAsync, fromSafePromise } from \"unthrown\";\n *\n * const both = allAsync([fromSafePromise(Promise.resolve(1)), fromSafePromise(Promise.resolve(2))]);\n * (await both).get(); // => [1, 2]\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 library AsyncResult is a never-rejecting thenable, so Promise.all\n // adopts them; `foldArray` then applies the all() rules. Adopt every input\n // defensively — a cast/untyped rejecting thenable becomes a `Defect` rather\n // than rejecting the internal promise (the \"internal promise never rejects\"\n // invariant holds even for out-of-contract input).\n const settled = Promise.all(\n results.map((r) =>\n Promise.resolve(r).then(\n (x) => x,\n (cause) => defectRes(cause),\n ),\n ),\n ).then((resolved) => foldArray(resolved as readonly Result<unknown, unknown>[]));\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 * @category Aggregate\n *\n * @example\n * ```ts\n * import { allFromDictAsync, fromSafePromise } from \"unthrown\";\n *\n * const both = allFromDictAsync({\n * a: fromSafePromise(Promise.resolve(1)),\n * b: fromSafePromise(Promise.resolve(\"x\")),\n * });\n * (await both).get(); // => { a: 1, b: \"x\" }\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(\n // Adopt each input defensively (see `allAsync`): a rejecting thenable\n // becomes a `Defect`, so the internal promise never rejects.\n entries.map(([, ar]) =>\n Promise.resolve(ar).then(\n (x) => x,\n (cause) => defectRes(cause),\n ),\n ),\n ).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, ErrAsync, isDefect, isErr, isOk, Ok, OkAsync } from \"./constructors.js\";\nimport { isResult } from \"./core.js\";\nimport { Do, DoAsync } from \"./do.js\";\nimport {\n all,\n allAsync,\n allFromDict,\n allFromDictAsync,\n fromNullable,\n fromPromise,\n fromSafePromise,\n fromSafeThrowable,\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.fromSafeThrowable}, {@link Result.all},\n * {@link Result.allFromDict}, {@link Result.isOk}, {@link Result.isErr},\n * {@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 * @category Facade\n *\n * @example\n * ```ts\n * import { Result } from \"unthrown\";\n * Result.Ok(1).flatMap((n) => Result.Ok(n + 1)).get(); // => 2\n * ```\n */\nexport const Result = {\n Ok,\n Err,\n Do,\n fromNullable,\n fromThrowable,\n fromSafeThrowable,\n all,\n allFromDict,\n isOk,\n isErr,\n isDefect,\n isResult,\n} as const;\n\n/**\n * `Result<T, E>` — the core discriminated union. Shares its name with the\n * {@link Result | companion object} above (the value and type are one name); this\n * is the type half.\n *\n * @remarks\n * A `Result` is a discriminated union, so TypeDoc can't list its methods on this\n * alias. Its fluent combinators (`map`, `flatMap`, `match`, `get`, …) are\n * documented one per entry on {@link ResultMethods} — the shared method surface\n * every variant carries. For \"which one do I reach for?\", see the\n * [Choosing a combinator](/reference/combinators) guide.\n *\n * @category Facade\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.Ok}, {@link AsyncResult.Err},\n * {@link AsyncResult.Do}, {@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 the pre-lifted constructors, `fromPromise`/`fromSafePromise`,\n * and the async aggregates sit here rather than on {@link Result}; the namespace\n * already conveys \"async\", so the members drop the `Async` suffix their free\n * functions carry (`AsyncResult.Ok` is `OkAsync`; `AsyncResult.Err` is\n * `ErrAsync`; `AsyncResult.Do` is `DoAsync`; `AsyncResult.all` is `allAsync`;\n * `AsyncResult.allFromDict` is\n * `allFromDictAsync`). Like {@link Result}, the free functions remain the\n * primary, tree-shakeable API; the value `AsyncResult` and the type\n * {@link AsyncResult} share one name.\n *\n * @category Facade\n *\n * @example\n * ```ts\n * import { AsyncResult } from \"unthrown\";\n * const user = await AsyncResult.fromPromise(fetchUser(id), (c, defect) => defect(c));\n * user.get(); // => the fetched user (on success)\n * ```\n */\nexport const AsyncResult = {\n Ok: OkAsync,\n Err: ErrAsync,\n Do: DoAsync,\n fromPromise,\n fromSafePromise,\n all: allAsync,\n allFromDict: allFromDictAsync,\n} as const;\n\n/**\n * `AsyncResult<T, E>` — the async counterpart of {@link Result}. Shares its name\n * with the {@link AsyncResult | companion object} above (value and type are one\n * name); this is the type half.\n *\n * @remarks\n * `AsyncResult` carries the async fluent surface; its combinators (`map`,\n * `flatMap`, `match`, `get`, …) are documented one per entry — with their\n * async signatures — on {@link AsyncResultMethods}. For \"which one do I reach\n * for?\", see the [Choosing a combinator](/reference/combinators) guide.\n *\n * @category Facade\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 the\n// `tag(t)` matcher pattern for matching a tagged error union.\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 *\n * @category Types\n */\nexport type TaggedErrorInstance<Tag extends string, A extends Props> = Error &\n Readonly<Omit<A, \"name\" | \"message\" | \"stack\">> & { 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. The\n * `name`, `message`, and `stack` keys are all **rejected** (`?: never`) because\n * all three are reserved: `name` is the display label, `message` is the human\n * string owned by `Error`, and `stack` is `Error`'s trace. Set the message the\n * standard way — `override message = \"…\"` (or a constructor override) on the\n * subclass — never as a free-form per-call payload field. The reservations are\n * enforced at the call site, mirroring how {@link TaggedErrorInstance} excludes\n * all three. (`cause` is deliberately **not** reserved: `Error.cause` is\n * `unknown`, so a typed payload `cause` is a legitimate structured field.)\n *\n * @typeParam Tag - the string literal discriminant.\n *\n * @category Types\n */\nexport type TaggedErrorConstructor<Tag extends string> = {\n new <A extends Props = {}>(\n args: keyof A extends never\n ? void\n : A & { readonly name?: never; readonly message?: never; readonly stack?: never },\n ): 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. The `message`\n * is **not** a payload field — it is the human string owned by `Error`, not\n * structured data, so it is reserved. Define it once per subclass the standard\n * way, `override message = \"…\"` (it may interpolate the payload via `this`,\n * which the base populates before the subclass field initialiser runs); a\n * payload `message` is rejected at compile time, so contextual detail lives in\n * typed fields, never baked into per-call prose. The `_tag` always reflects\n * `tag` and cannot be overridden by the payload. `name` is likewise reserved —\n * it is the display label (set it with `options.name`); a payload `name` is\n * rejected at compile time (and excluded from the instance type), so it can't\n * shadow `Error.name`. `stack` is reserved the same way — it is `Error`'s\n * trace, and even an untyped payload `stack` cannot clobber the real one.\n * `cause` is deliberately **not** reserved: `Error.cause` is typed `unknown`,\n * so a payload `cause` (e.g. a wrapped driver error) is a legitimate,\n * *narrowing* structured field.\n *\n * `_tag` is the discriminant matched by {@link tag} in the error combinators\n * (`result.mapErrCases((matcher) => matcher.with(tag(\"NotFound\"), …))`) and in\n * `match`; `Error.name` is the human-facing label in stack traces and logs. By\n * 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 * }) {\n * override message = \"operation failed; safe to retry\";\n * }\n *\n * const e = new RetryableError();\n * e._tag; // \"@my-lib/RetryableError\" — namespaced discriminant\n * e.name; // \"RetryableError\" — clean display name\n * e.message; // \"operation failed; safe to retry\" — the standard Error.message\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 * @category Tagged errors\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();\n if (props) {\n // `stack` is reserved like `name`/`message`: it is `Error`'s trace, not\n // payload data. Capture the genuine trace as a string (V8 exposes\n // `stack` as a lazy accessor whose setter would happily store a payload\n // value), let the payload land, then re-assert the real trace as a\n // plain data property — an untyped caller cannot clobber it. (`cause`\n // is deliberately allowed through: `Error.cause` is `unknown`, so a\n // typed payload `cause` is a legitimate structured field.)\n const stack = this.stack;\n Object.assign(this, props);\n delete (this as { stack?: unknown }).stack;\n if (stack !== undefined) {\n Object.defineProperty(this, \"stack\", {\n value: stack,\n writable: true,\n enumerable: false,\n configurable: true,\n });\n }\n }\n // `_tag`, `name`, and `message` are authoritative — an untyped caller\n // can't set them via the payload. `_tag`/`name` are re-assigned to their\n // canonical values; `message` is `Error`'s channel (set per subclass via\n // `override message = …`, whose field initialiser runs after this\n // constructor returns), so any payload-supplied `message` is dropped here.\n (this as { _tag: Tag })._tag = tag;\n this.name = displayName;\n delete (this as { message?: unknown }).message;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n }\n\n return TaggedErrorBase as unknown as TaggedErrorConstructor<Tag>;\n}\n\n/**\n * A matcher pattern matching any value whose `_tag` equals `value` — a\n * {@link TaggedError}, or any discriminated member. Equivalent to the object\n * pattern `{ _tag: value }`, but reads better inside an error-matching\n * combinator and narrows to the matching variant, payload included.\n *\n * @typeParam Tag - the string literal tag to match.\n * @param value - the `_tag` to match.\n *\n * @category Tagged errors\n *\n * @example\n * ```ts\n * result.mapErrCases((matcher) =>\n * matcher\n * .with(tag(\"NotFound\"), () => new NotFoundException())\n * .with(tag(\"Conflict\"), (e) => new ConflictException(e.key)),\n * );\n * ```\n */\nexport function tag<const Tag extends string>(value: Tag): { _tag: Tag } {\n return { _tag: value };\n}\n"],"mappings":";;;;;;;;;AAkCA,MAAM,gBAAgB,OAAO,IAAI,0BAA0B;;;;;;;;;;;AAuM3D,IAAa,qBAAb,cAAwC,MAAM;;CAE5C;CACA,YAAY,OAAgB;EAC1B,IAAI;EACJ,IAAI;GACF,UAAU,KAAK,UAAU,KAAK;EAChC,QAAQ;GACN,UAAU,OAAO,KAAK;EACxB;EACA,MAAM,0CAA0C,SAAS;EACzD,KAAK,OAAO;EACZ,KAAK,QAAQ;EACb,OAAO,eAAe,MAAM,IAAI,OAAO,SAAS;CAClD;AACF;;;;;;;AAQA,SAAS,cAAc,GAAyC;CAC9D,MAAM,QAAiB,OAAO,eAAe,CAAC;CAC9C,OAAO,UAAU,OAAO,aAAa,UAAU;AACjD;;;;;;;;;;;;;;;AAgBA,SAAS,QAAQ,SAAkB,OAA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;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,MAAa,cAAc;CACzB,IAAI;CACJ,KAAK;CACL,IAAI;CACJ;CACA;CACA,KAAK;CACL,aAAa;AACf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACdA,SAAgB,YACd,KACA,SAC6B;CAC7B,MAAM,cAAc,SAAS,QAAQ;CACrC,MAAM,wBAAwB,MAAM;EAClC;EAEA,YAAY,OAAe;GACzB,MAAM;GACN,IAAI,OAAO;IAQT,MAAM,QAAQ,KAAK;IACnB,OAAO,OAAO,MAAM,KAAK;IACzB,OAAQ,KAA6B;IACrC,IAAI,UAAU,KAAA,GACZ,OAAO,eAAe,MAAM,SAAS;KACnC,OAAO;KACP,UAAU;KACV,YAAY;KACZ,cAAc;IAChB,CAAC;GAEL;GAMA,KAAwB,OAAO;GAC/B,KAAK,OAAO;GACZ,OAAQ,KAA+B;GACvC,OAAO,eAAe,MAAM,IAAI,OAAO,SAAS;EAClD;CACF;CAEA,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,IAA8B,OAA2B;CACvE,OAAO,EAAE,MAAM,MAAM;AACvB"}
1
+ {"version":3,"file":"index.mjs","names":["#value","#matched","#result","#promise"],"sources":["../src/matcher.ts","../src/defect.ts","../src/core.ts","../src/constructors.ts","../src/do.ts","../src/interop.ts","../src/facade.ts","../src/tagged.ts"],"sourcesContent":["// unthrown — the built-in error matcher.\n//\n// A purpose-built, shallow pattern matcher for the error channel (it replaced\n// the former ts-pattern peer dependency, keeping its call-site shape:\n// `matcher.with(pattern, …patterns, handler)`, with the combinator running\n// `.exhaustive()` via `.run()`). Owning the type machinery means:\n//\n// - Exhaustiveness is computed with plain `Exclude` over the tracked\n// `Remaining` parameter — shallow, fast, and stable (no third-party minor\n// release can change what \"exhaustive\" means).\n// - The universal pattern (`P._` / `P.any`) carries phantom type `unknown`,\n// and `Exclude<Remaining, unknown>` reduces to `never` even when the input\n// is an UNRESOLVED generic — so a catch-all-terminated builder is provably\n// exhaustive inside code generic in `E` (fixes #145 by construction).\n// - A non-exhaustive builder's `exhaustive` is a branded object naming the\n// unhandled cases — a readable diagnostic instead of a deep conditional.\n//\n// Supported patterns (the vocabulary the error channel actually uses):\n// primitive literals, shallow(-ly nested) object literals (`{ _tag: \"X\" }`,\n// `{ code: \"X\" }` — `tag(t)` produces the former), and the `P.*` matchers\n// (`_`/`any`, `instanceOf`, `when`, `union`, `string`, `number`). Deliberately\n// NOT supported: deep structural inversion, selections, array/variadic\n// patterns — that is the complexity (and instability) being left behind.\n\nimport type { Defect } from \"./defect.js\";\n\n/**\n * Cross-copy brand for `P.*` pattern objects: `Symbol.for` yields the same\n * symbol in every copy of the library (dual CJS/ESM, duplicated install,\n * another realm), so a pattern built by one copy is recognised by another —\n * the same rationale as `isResult`'s prototype brand.\n *\n * @internal\n */\nconst PATTERN_BRAND = Symbol.for(\"unthrown.matcher.pattern\");\n\ndeclare const MATCHES: unique symbol;\ndeclare const UNIVERSAL: unique symbol;\n\n/**\n * A `P.*` pattern: a runtime predicate plus the phantom type `M` it matches.\n * The phantom is declaration-only (never present at runtime); it drives the\n * type-level narrowing (`Extract`) and exhaustiveness (`Exclude`).\n *\n * @typeParam M - the type this pattern matches.\n * @category Types\n */\nexport type PatternMatcher<M> = {\n readonly [PATTERN_BRAND]: (value: unknown) => boolean;\n readonly [MATCHES]?: M;\n};\n\n/**\n * The statically-known universal pattern — the type of `P._` / `P.any` only.\n * The phantom `UNIVERSAL` marker is *required*, so no other\n * `PatternMatcher<unknown>` (e.g. a `P.when` guard that happens to be\n * universal) is assignable: the catch-all `.with` overload must only fire for\n * a pattern the type system KNOWS covers everything.\n *\n * @category Types\n */\nexport type UniversalPattern = PatternMatcher<unknown> & {\n readonly [UNIVERSAL]: true;\n};\n\n/**\n * The type a single pattern matches: a `P.*` matcher's phantom, an object\n * literal mapped key-by-key (so `{ _tag: \"A\" }` matches the `\"A\"`-tagged\n * variant), or the primitive literal itself.\n *\n * @internal\n */\nexport type MatchedOf<Pt> =\n Pt extends PatternMatcher<infer M>\n ? M\n : Pt extends object\n ? { [K in keyof Pt]: MatchedOf<Pt[K]> }\n : Pt;\n\n/**\n * The diagnostic type of `.exhaustive` on a builder that has NOT covered every\n * case: not callable (so it fails the `ExhaustiveMatch` constraint at the call\n * site), and it names the remaining cases so the error reads as a to-do list.\n *\n * @internal\n */\nexport type NonExhaustive<Remaining> = {\n readonly \"unthrown: this match is not exhaustive — add a `.with(…)` for the remaining cases\": Remaining;\n};\n\n/**\n * The \"no output type declared\" sentinel for a builder's `Declared` parameter.\n * A `unique symbol` so no user type can collide with it. Declaration-only —\n * `tsc` emits it into the `.d.ts` without it needing to be exported.\n *\n * @internal\n */\ndeclare const UNSET: unique symbol;\n\n/** @internal */\ntype Unset = typeof UNSET;\n\n/**\n * A branch handler's return position: free inference (`O2`) while the builder\n * is unpinned — today's behaviour, unchanged — or the declared type once\n * `.returnType<R>()` has pinned it.\n *\n * `Defect` stays legal under a pin: the injected `defect` helper is the\n * sanctioned deliberate `Err`→`Defect` form (Thesis #5), and `Defect` is not a\n * nameable public type, so `returnType<R | Defect>()` cannot be spelled. The\n * marker is subtracted from the output by {@link PinnedOut} — the same net\n * result as the unpinned `Exclude<O, Defect>`, decided up front.\n *\n * @internal\n */\ntype BranchReturn<Declared, O2> = [Declared] extends [Unset] ? O2 : Declared | Defect;\n\n/**\n * The builder's output: the accumulated union of branch returns while\n * unpinned, or the declared type once pinned.\n *\n * @internal\n */\ntype PinnedOut<Declared, O> = [Declared] extends [Unset] ? O : Declared;\n\n/**\n * The diagnostic type of `.returnType` on a builder that already has an output\n * to contradict — an arm has contributed a return type, or it is already\n * pinned: not callable, so the mistake is caught where it is written.\n *\n * @internal\n */\ntype PinTooLate = {\n readonly \"unthrown: `.returnType<R>()` must come before any arm produces an output, and only once\": true;\n};\n\n/**\n * The match builder over an input union `E`. `Remaining` tracks the cases not\n * yet covered by a `.with(…)` arm; `O` accumulates the branch output union.\n * `.exhaustive` is callable only once `Remaining` is `never` — which is what\n * the `ExhaustiveMatch` constraint requires — and `.run()` executes it.\n *\n * @typeParam E - the full input union being matched.\n * @typeParam Remaining - the cases not yet covered.\n * @typeParam O - the union of branch return types so far.\n * @category Types\n */\nexport type Matcher<E, Remaining, O, Declared = Unset> = {\n /**\n * The catch-all arm: `.with(P._, handler)` / `.with(P.any, handler)` — the\n * wildcard **escape hatch**, not the way to handle a concrete error union\n * (name those cases; `@unthrown/oxlint`'s `no-catch-all-pattern`, in its\n * `recommended` preset, flags the wildcard).\n *\n * It is a **state transition**, not a computation — it returns\n * `Matcher<E, never, …>` with the remaining cases literally `never`, so the\n * builder is provably exhaustive even when `E` is an unresolved type\n * parameter (a lazily-deferred `Exclude<E, unknown>` would not resolve\n * there). That is what makes it irreplaceable for a helper generic in `E`:\n * it can terminate a match no arm list could (issue #145) — one of the two\n * sanctioned uses (see {@link P}).\n */\n with<O2>(\n pattern: UniversalPattern,\n handler: (value: Remaining) => BranchReturn<Declared, O2>,\n ): Matcher<E, never, O | O2, Declared>;\n /**\n * Add an arm: one or more patterns sharing a single handler (grouped\n * patterns — `matcher.with(tag(\"A\"), tag(\"B\"), handler)`). The handler\n * receives the input narrowed to what the patterns match (computed against\n * `Remaining`, so cases already handled by earlier arms are excluded); the\n * matched cases are subtracted from `Remaining`.\n */\n with<const Pts extends readonly [unknown, ...unknown[]], O2>(\n ...args: [\n ...patterns: Pts,\n handler: (value: Extract<Remaining, MatchedOf<Pts[number]>>) => BranchReturn<Declared, O2>,\n ]\n ): Matcher<E, Exclude<Remaining, MatchedOf<Pts[number]>>, O | O2, Declared>;\n\n /**\n * Declare the match's output type up front: every subsequent branch handler\n * is checked against `R`, and the match evaluates to `R` instead of the\n * union of whatever the branches happened to return.\n *\n * @remarks\n * Reach for it when the output is **decided by a signature rather than by\n * the branches** — most sharply in code generic in `E`, where the fold's type\n * has to be declared. It also stops a drifting branch from silently widening\n * the outgoing type, reports the mismatch **on the offending branch**, and\n * gives branch returns a contextual type (so object literals need no\n * annotation).\n *\n * A branch may still return the injected `defect` helper's marker; the defect\n * channel is not part of the declared output.\n *\n * Callable **before any arm has produced an output**, and only once\n * (mirroring ts-pattern's up-front pin): once there is an inferred output for\n * the pin to contradict — or the builder is already pinned — this is typed as\n * a non-callable diagnostic. In practice that means calling it directly after\n * `match(…)`; the gate is about output rather than position, so an earlier arm\n * whose handler returns `never` (it always throws) contributes nothing and\n * does not close it — sound, since a `never` branch can contradict no declared\n * type. A no-op at runtime.\n *\n * @typeParam R - the declared output type of every branch.\n */\n returnType: [O] extends [never]\n ? [Declared] extends [Unset]\n ? <R>() => Matcher<E, Remaining, never, R>\n : PinTooLate\n : PinTooLate;\n\n /**\n * Terminate the match. Typed callable only when every case is covered\n * (`Remaining` is `never`); otherwise it is a branded diagnostic object\n * naming the remaining cases, and the builder fails the `ExhaustiveMatch`\n * constraint at the combinator call site.\n */\n exhaustive: [Remaining] extends [never] ? () => PinnedOut<Declared, O> : NonExhaustive<Remaining>;\n\n /**\n * Execute the match (the combinators call this; it runs `.exhaustive()`).\n * A value with no matching arm throws {@link NonExhaustiveError} —\n * unreachable for well-typed callers.\n */\n run(): PinnedOut<Declared, O>;\n};\n\n/**\n * Thrown by `.run()` / `.exhaustive()` when no arm matched the value. For\n * well-typed callers the match is exhaustive by construction, so this is only\n * reachable by a value that slipped past the types (a widened cast, a raw-JS\n * caller); inside the error combinators the throw-to-defect net converts it to\n * a `Defect`, and at the `match` edge it surfaces (a genuinely unmodeled value\n * is a bug).\n *\n * @category Errors\n */\nexport class NonExhaustiveError extends Error {\n /** The value no arm matched. */\n readonly input: unknown;\n constructor(input: unknown) {\n let printed: string;\n try {\n printed = JSON.stringify(input);\n } catch {\n printed = String(input);\n }\n super(`unthrown: no pattern matched the value ${printed}`);\n this.name = \"NonExhaustiveError\";\n this.input = input;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * Is `x` a *plain* object (prototype `Object.prototype` or `null`) — an object\n * literal, the only object shape that acts as a structural pattern?\n *\n * @internal\n */\nfunction isPlainObject(x: object): x is Record<string, unknown> {\n const proto: unknown = Object.getPrototypeOf(x);\n return proto === Object.prototype || proto === null;\n}\n\n/**\n * Runtime test: does `pattern` match `value`? A branded `P.*` pattern applies\n * its predicate; a **plain-object** pattern (an object literal, e.g. the\n * `{ _tag }` produced by `tag()`) matches when every key matches recursively\n * (extra keys on the value are ignored — matching is structural); anything\n * else — primitives, but also class instances, arrays, and foreign pattern\n * objects (e.g. a real ts-pattern matcher, whose keys are symbols) — is\n * compared with `Object.is`. Restricting structural matching to plain objects\n * is load-bearing: a keyless non-plain object (`new Date()`, `new Error()`, a\n * symbol-keyed foreign pattern) would otherwise vacuously match *every* object\n * via an empty `Object.entries`.\n *\n * @internal\n */\nfunction matches(pattern: unknown, value: unknown): boolean {\n if (typeof pattern === \"object\" && pattern !== null) {\n const predicate = (pattern as PatternMatcher<unknown>)[PATTERN_BRAND];\n if (typeof predicate === \"function\") return predicate(value);\n // A symbol-keyed plain object is a *foreign* pattern protocol (e.g. a raw\n // ts-pattern matcher object) — it would look empty to `Object.entries` and\n // vacuously match everything. Fail closed: identity only.\n if (!isPlainObject(pattern) || Object.getOwnPropertySymbols(pattern).length > 0) {\n return Object.is(pattern, value);\n }\n if (typeof value !== \"object\" || value === null) return false;\n return Object.entries(pattern).every(([key, sub]) =>\n matches(sub, (value as Record<string, unknown>)[key]),\n );\n }\n return Object.is(pattern, value);\n}\n\n/**\n * The runtime builder: first matching arm wins; later arms are skipped once a\n * result is captured. `exhaustive` is a *method* at runtime (the conditional\n * type gates its callability per instantiation).\n *\n * @internal\n */\nclass MatcherImpl {\n readonly #value: unknown;\n #matched = false;\n #result: unknown;\n\n constructor(value: unknown) {\n this.#value = value;\n }\n\n with(...args: readonly unknown[]): this {\n if (this.#matched) return this;\n const handler = args[args.length - 1] as (value: unknown) => unknown;\n for (let i = 0; i < args.length - 1; i++) {\n if (matches(args[i], this.#value)) {\n this.#matched = true;\n this.#result = handler(this.#value);\n return this;\n }\n }\n return this;\n }\n\n /**\n * Type-level only — pinning the output type has no runtime meaning, so the\n * builder is returned unchanged (as ts-pattern does).\n */\n returnType(): this {\n return this;\n }\n\n exhaustive(): unknown {\n if (this.#matched) return this.#result;\n throw new NonExhaustiveError(this.#value);\n }\n\n run(): unknown {\n return this.exhaustive();\n }\n}\nObject.freeze(MatcherImpl.prototype);\n\n/**\n * Begin a match over `value`. Chain `.with(pattern, …patterns, handler)` arms;\n * terminate with `.exhaustive()` — or return the un-terminated builder to an\n * unthrown error combinator / `match({ errCases })`, which runs it for you.\n *\n * @remarks\n * This is unthrown's own matcher (the former ts-pattern re-export): the same\n * call-site shape, with exhaustiveness computed by plain `Exclude` over the\n * builder's `Remaining` parameter. Name every case of the input union; the\n * `P._` catch-all is the escape hatch, and is provably exhaustive even over an\n * unresolved generic input — one of the two cases it is irreplaceable for (see\n * {@link P}).\n *\n * @category Constructors\n */\nexport function match<const E>(value: E): Matcher<E, E, never> {\n return new MatcherImpl(value) as unknown as Matcher<E, E, never>;\n}\n\n/** @internal */\nfunction pattern<M>(predicate: (value: unknown) => boolean): PatternMatcher<M> {\n return Object.freeze({ [PATTERN_BRAND]: predicate }) as PatternMatcher<M>;\n}\n\n// The `UNIVERSAL` marker is phantom (declaration-only): the cast brands the\n// runtime object with the statically-known-universal type so the catch-all\n// `.with` overload fires for `P._` / `P.any` and for nothing else.\nconst universal = pattern<unknown>(() => true) as UniversalPattern;\n\n/**\n * The pattern namespace (unthrown's own; the former ts-pattern `P`):\n *\n * - `P._` / `P.any` — the universal catch-all, and an **escape hatch** rather\n * than the default: matching the error channel means naming its cases, so\n * reach for this only where they cannot be named. Matches anything, and\n * (because its phantom type is `unknown`) makes the builder provably\n * exhaustive even when the matched input is an unresolved type parameter.\n * Two situations are legitimate: a **helper generic in `E`**, where no arm\n * list can prove exhaustiveness against an unresolved type parameter; and an\n * **`E` that is a single type**, not a union of cases (a validator's issues\n * array, say), where one arm _is_ the enumeration. `@unthrown/oxlint`'s\n * `no-catch-all-pattern` (in its `recommended` preset) flags every other use;\n * keep the deliberate ones behind a targeted `oxlint-disable` saying which of\n * the two it is.\n * - `P.instanceOf(Cls)` — an `instanceof` check, narrowing to the class\n * instance type (for union members that are not tagged, e.g. a third-party\n * error class).\n * - `P.when(guard)` — an arbitrary type-guard predicate.\n * - `P.union(…patterns)` — matches when any sub-pattern matches.\n * - `P.string` / `P.number` — primitive-type wildcards.\n *\n * @category Constructors\n */\nexport const P = Object.freeze({\n _: universal,\n any: universal,\n instanceOf: <C extends abstract new (...args: never[]) => unknown>(\n cls: C,\n ): PatternMatcher<InstanceType<C>> => pattern((value) => value instanceof cls),\n when: <G>(guard: (value: unknown) => value is G): PatternMatcher<G> => pattern(guard),\n union: <const Pts extends readonly [unknown, ...unknown[]]>(\n ...patterns: Pts\n ): PatternMatcher<MatchedOf<Pts[number]>> =>\n pattern((value) => patterns.some((sub) => matches(sub, value))),\n string: pattern<string>((value) => typeof value === \"string\"),\n number: pattern<number>((value) => typeof value === \"number\"),\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 // Frozen like Result instances: the marker is an opaque triage token, and a\n // mutated one must not be able to smuggle a different cause past a boundary.\n return Object.freeze({ [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","// 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 Defect, defect, isDefectMarker } from \"./defect.js\";\nimport { match } from \"./matcher.js\";\nimport type {\n AsyncResult,\n Bound,\n DefectView,\n ErrMatcher,\n ErrOf,\n ErrView,\n ExhaustiveMatch,\n FailureView,\n MatchErrOut,\n MatchOut,\n NotThenable,\n OkOf,\n OkView,\n Result,\n} from \"./types.js\";\n\n/**\n * Thrown by a {@link Result}'s `get` / `getErr` when the assertion is\n * wrong on a *modeled* result — `get()` on an `Err`, or `getErr()` on an\n * `Ok`.\n *\n * @remarks\n * The offending value is exposed two ways: the typed {@link GetError.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 a `GetError`: its original cause is\n * re-thrown (with its original stack) instead.\n *\n * `get()` and `getErr()` are type-gated (`this: Result<T, never>` /\n * `Result<never, E>`), so the wrong-variant branch that throws this is\n * unreachable through well-typed code — it remains only as a defensive guard\n * against unsound runtime misuse (e.g. an `as` cast past the gate).\n *\n * @typeParam E - the type of the {@link GetError.error} it carries.\n *\n * @category Errors\n */\nexport class GetError<E = unknown> extends Error {\n /**\n * The offending value: the `Err` error for `get()`, or the `Ok` value for\n * `getErr()`.\n */\n readonly error: E;\n constructor(error: E) {\n super(\"unthrown: get() / getErr() called on a non-matching Result variant\", { cause: error });\n this.name = \"GetError\";\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 & NotThenable<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 const r = f(this.value);\n return isResult(r) ? r : nonResultCallbackDefect();\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n tap<R>(this: Result<T, E>, f: (value: T) => R & NotThenable<R>): 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 if (!isResult(r)) return nonResultCallbackDefect();\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 (!isResult(r)) return nonResultCallbackDefect();\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 & NotThenable<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 discard(this: Result<T, E>): Result<void, E> {\n if (this.tag !== \"Ok\") return passThrough(this);\n // explicit <void, E>: inference from the argument would land on undefined, not void\n return okRes<void, E>(undefined);\n }\n\n // The type-guard/boolean overload pair lives on the public surface\n // (`ResultMethods`); this single implementation signature covers both.\n ensure<E2>(\n this: Result<T, E>,\n predicate: (value: T) => boolean,\n onFail: (value: T) => E2,\n ): Result<T, E | E2> {\n if (this.tag !== \"Ok\") return passThrough(this);\n try {\n // A passing value flows through as the SAME Ok (the passThrough\n // philosophy: nothing changed, so nothing is reallocated).\n return predicate(this.value) ? this : errRes(onFail(this.value));\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n mapErrCases<M extends ExhaustiveMatch<unknown>>(\n this: Result<T, E>,\n f: (matcher: ErrMatcher<E>, defect: (cause: unknown) => Defect) => M,\n ): Result<T, MatchErrOut<M>> {\n if (this.tag !== \"Err\") return passThrough(this);\n try {\n const out = runMatch(f, this.error);\n if (isDefectMarker(out)) return defectRes(out.cause);\n return errRes(out as MatchErrOut<M>);\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n flatMapErrCases<M extends ExhaustiveMatch<Result<unknown, unknown> | Defect>>(\n this: Result<T, E>,\n f: (matcher: ErrMatcher<E>, defect: (cause: unknown) => Defect) => M,\n ): Result<T | OkOf<MatchOut<M>>, ErrOf<MatchOut<M>>> {\n if (this.tag !== \"Err\") return passThrough(this);\n try {\n const out = runMatch(f, this.error);\n if (isDefectMarker(out)) return defectRes(out.cause);\n if (!isResult(out)) return nonResultCallbackDefect();\n return out as Result<OkOf<MatchOut<M>>, ErrOf<MatchOut<M>>>;\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n recoverErrCases<M extends ExhaustiveMatch<unknown>>(\n this: Result<T, E>,\n f: (matcher: ErrMatcher<E>, defect: (cause: unknown) => Defect) => M,\n ): Result<T | MatchErrOut<M>, never> {\n if (this.tag !== \"Err\") return passThrough(this);\n try {\n const out = runMatch(f, this.error);\n if (isDefectMarker(out)) return defectRes(out.cause);\n return okRes(out as MatchErrOut<M>);\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n tapErrCases(\n this: Result<T, E>,\n f: (matcher: ErrMatcher<E>, defect: (cause: unknown) => Defect) => ExhaustiveMatch<unknown>,\n ): Result<T, E> {\n if (this.tag !== \"Err\") return this;\n try {\n const out = runMatch(f, this.error);\n // Branch *values* are discarded here — but the injected `defect(cause)`\n // marker is not a value, it is the lint-clean, expression-position form of\n // a `throw` (Thesis #5). So it takes the same route a `throw` in this\n // branch would: the observed error survives alongside the caller's cause.\n if (isDefectMarker(out)) return observerThrowToDefect(out.cause, this.error);\n return this;\n } catch (cause) {\n return observerThrowToDefect(cause, this.error);\n }\n }\n\n flatTapErrCases<M extends ExhaustiveMatch<Result<unknown, unknown>>>(\n this: Result<T, E>,\n f: (matcher: ErrMatcher<E>, defect: (cause: unknown) => Defect) => M,\n ): Result<T, E | ErrOf<MatchOut<M>>> {\n if (this.tag !== \"Err\") return this;\n try {\n const r = runMatch(f, this.error);\n // A deliberate `defect(cause)` branch is the expression-position form of a\n // `throw` (Thesis #5), so it is treated like one: this is a failure\n // *observer*, and the observed error survives alongside the caller's cause.\n // (Contrast a branch returning a Defect-state `Result` below — an effect\n // that blew up on its own, which short-circuits and replaces the error.)\n if (isDefectMarker(r)) return observerThrowToDefect(r.cause, this.error);\n if (!isResult(r)) return nonResultCallbackDefect();\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 observerThrowToDefect(cause, this.error);\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 const r = f(this.cause);\n return isResult(r) ? r : nonResultCallbackDefect();\n } catch (cause) {\n return defectRes(cause);\n }\n }\n\n tapDefect<R>(this: Result<T, E>, f: (cause: unknown) => R & NotThenable<R>): Result<T, E> {\n if (this.tag !== \"Defect\") return this;\n try {\n f(this.cause);\n return this;\n } catch (cause) {\n return observerThrowToDefect(cause, this.cause);\n }\n }\n\n tapFailure<R>(\n this: Result<T, E>,\n f: (failure: FailureView<E, T>) => R & NotThenable<R>,\n ): Result<T, E> {\n if (this.tag === \"Ok\") return this;\n try {\n f(this);\n return this;\n } catch (cause) {\n return observerThrowToDefect(cause, this.tag === \"Err\" ? this.error : this.cause);\n }\n }\n\n match<ROk, RDefect, M extends ExhaustiveMatch<unknown>>(\n this: Result<T, E>,\n cases: {\n ok: (value: T) => ROk;\n errCases: (matcher: ErrMatcher<E>) => M;\n defect: (cause: unknown) => RDefect;\n },\n ): ROk | RDefect | MatchOut<M> {\n switch (this.tag) {\n case \"Ok\":\n return cases.ok(this.value);\n case \"Err\":\n // The `errCases` handler returns the un-terminated builder; `.run()`\n // executes `.exhaustive()`. Type-forced exhaustive for well-typed\n // callers; a value slipping past the types (widened cast, JS caller) with\n // no matching case throws the matcher's `NonExhaustiveError` — `match` is\n // an edge eliminator, so it surfaces rather than being caught into a Defect.\n return cases.errCases(match(this.error) as ErrMatcher<E>).run() as MatchOut<M>;\n case \"Defect\":\n return cases.defect(this.cause);\n }\n }\n\n get(this: Result<T, E>): T {\n switch (this.tag) {\n case \"Ok\":\n return this.value;\n case \"Err\":\n throw new GetError(this.error);\n case \"Defect\":\n throw this.cause; // rethrow original cause, original stack\n }\n }\n\n getErr(this: Result<T, E>): E {\n switch (this.tag) {\n case \"Err\":\n return this.error;\n case \"Ok\":\n throw new GetError(this.value);\n case \"Defect\":\n throw this.cause;\n }\n }\n\n getOr<U>(this: Result<T, E>, fallback: U): T | U {\n if (this.tag === \"Ok\") return this.value;\n if (this.tag === \"Defect\") throw this.cause;\n return fallback;\n }\n\n getOrElse<U>(this: Result<T, E>, f: (error: E) => U): T | U {\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 getOrThrow(this: Result<T, E>): T {\n if (this.tag === \"Ok\") return this.value;\n if (this.tag === \"Defect\") throw this.cause;\n throw this.error;\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\n/**\n * Cross-copy brand: `Symbol.for` yields the same symbol in every copy of the\n * library (the dual CJS/ESM build, a duplicated install, another realm), so\n * {@link isResult} can recognise a `Result` built by another copy whose `Res`\n * class fails the `instanceof` check. Defined non-enumerably on the prototype,\n * before it is frozen.\n *\n * @internal\n */\nconst RESULT_BRAND = Symbol.for(\"unthrown.Result\");\n\nconst RESULT_PROTO = Res.prototype;\nObject.defineProperty(RESULT_PROTO, RESULT_BRAND, { value: true });\n// Frozen prototype: the shared combinators cannot be swapped out from under\n// every instance (the instances themselves are frozen by the builders below).\nObject.freeze(RESULT_PROTO);\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 // Frozen so the `readonly` surface is real at runtime: a variant cannot be\n // forged by mutating `tag`/payload after construction.\n return Object.freeze(\n Object.assign(Object.create(RESULT_PROTO), {\n tag: \"Ok\" as const,\n value,\n }),\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.freeze(\n Object.assign(Object.create(RESULT_PROTO), {\n tag: \"Err\" as const,\n error,\n }),\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.freeze(\n Object.assign(Object.create(RESULT_PROTO), {\n tag: \"Defect\" as const,\n cause,\n }),\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\n * (`instanceof` first, falling back to the `Symbol.for(\"unthrown.Result\")`\n * brand the prototype carries — so a `Result` built by **another copy** of\n * unthrown, e.g. the CJS and ESM builds loaded side by side, is still\n * recognised). A look-alike plain object (`{ tag: \"Ok\" }`) carries neither and\n * is **not** matched. An `AsyncResult` is not a `Result` and returns `false`.\n *\n * @returns `true` when `x` is a `Result` produced by this library.\n *\n * @example\n * ```ts\n * import { isResult, Ok, P } from \"unthrown\";\n *\n * isResult(Ok(1)); // => true\n * isResult({ tag: \"Ok\" }); // => false (look-alike, wrong prototype)\n * isResult(Ok(1).toAsync()); // => false (an AsyncResult is not a Result)\n *\n * const x: unknown = Ok(1);\n * if (isResult(x))\n * // `E` is `unknown` here — an untyped boundary has no cases to enumerate,\n * // so the `P._` escape hatch is the only arm that can terminate the match:\n * // oxlint-disable-next-line unthrown/no-catch-all-pattern -- untyped boundary: `E` is `unknown`\n * x.match({ ok: () => 1, errCases: (m) => m.with(P._, () => 0), defect: () => -1 });\n * ```\n *\n * @category Guards\n */\nexport function isResult(x: unknown): x is Result<unknown, unknown> {\n if (x instanceof Res) return true;\n // Dual-copy / cross-realm fallback: another copy of unthrown has its own\n // `Res`, so `instanceof` fails — but its prototype carries the shared\n // `Symbol.for` brand. Reading the brand off the prototype chain keeps the\n // guarantee that a structural look-alike (no unthrown prototype) still fails.\n // Fail-closed: this guard exists for untyped boundaries, so a hostile input\n // (a Proxy `get` trap or a throwing getter at the brand key) is `false`,\n // never a throw.\n try {\n return (\n (typeof x === \"object\" || typeof x === \"function\") &&\n x !== null &&\n Reflect.get(x, RESULT_BRAND) === true\n );\n } catch {\n return false;\n }\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 * The Defect minted when a callback constrained to return a `Result` returns\n * something else — reachable only from untyped/cast callers (in typed code the\n * constraint is a compile error). The combinator-side sibling of the\n * aggregates' non-`Result`-element guard: surface the out-of-contract value as\n * a `Defect` here rather than letting a poison value throw a raw `TypeError`\n * further down the pipeline.\n *\n * @internal\n */\nfunction nonResultCallbackDefect<T, E>(): Result<T, E> {\n return defectRes(new TypeError(\"unthrown: a combinator callback returned a non-Result value\"));\n}\n\n/**\n * Drive an error-combinator callback: build `match(error)`, hand it (plus the\n * injected `defect`) to the callback, and `.run()` the returned exhaustive\n * builder to its output. `.run()` executes `.exhaustive()` — type-forced\n * exhaustive, so it always matches for well-typed callers; a value that slips\n * through the types (a widened cast, a JS caller) throws `NonExhaustiveError`,\n * which the caller's `try/catch` turns into a `Defect` — an unmodeled failure.\n *\n * @internal\n */\nfunction runMatch<E>(\n f: (matcher: ErrMatcher<E>, defect: (cause: unknown) => Defect) => { run: () => unknown },\n error: E,\n): unknown {\n return f(match(error) as ErrMatcher<E>, defect).run();\n}\n\n/**\n * A throw inside a *failure observer* (`tapErrCases` / `tapDefect` /\n * `tapFailure` / `flatTapErrCases`) must not destroy the failure being observed\n * — that is the exact place (e.g. a failing error-logger) where losing the\n * underlying failure hurts most. The resulting Defect aggregates both:\n * `errors[0]` is the observer's own failure, `errors[1]` the original failure.\n *\n * An observer branch returning the injected `defect(cause)` marker\n * (`tapErrCases` / `flatTapErrCases`) takes the same route: it is the\n * lint-clean, expression-position form of a `throw` (Thesis #5), so it must not\n * behave differently from one.\n *\n * @internal\n */\nfunction observerThrowToDefect<T, E>(thrown: unknown, original: unknown): Result<T, E> {\n return defectRes(\n new AggregateError(\n [thrown, original],\n \"unthrown: a failure-observer callback failed; errors[0] is the callback's failure (a throw, or a deliberate defect), errors[1] the original failure\",\n ),\n );\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 || Array.isArray(value)) {\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 // A native #private field: invisible to property access and untouchable even\n // via Object.defineProperty, so the wrapped promise cannot be tampered with.\n readonly #promise: Promise<Result<T, E>>;\n\n constructor(promise: Promise<Result<T, E>>) {\n this.#promise = promise;\n }\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 & NotThenable<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 const inner = await f(r.value);\n return isResult(inner) ? inner : nonResultCallbackDefect<U, E | E2>();\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n tap<R>(f: (value: T) => R & NotThenable<R>): 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 if (!isResult(inner)) return nonResultCallbackDefect();\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 (!isResult(inner)) return nonResultCallbackDefect();\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>(\n name: K,\n f: (scope: T) => U & NotThenable<U>,\n ): 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 discard(): AsyncResult<void, E> {\n return new AsyncRes<void, E>(\n this.#promise.then((r) => (r.tag === \"Ok\" ? okRes<void, E>(undefined) : passThrough(r))),\n );\n }\n\n // Like the matcher methods below, `ensure` is typed loosely here (`never`\n // channels) because TypeScript cannot relate this single implementation\n // signature to the public type-guard/boolean overload pair across the\n // class/`implements` boundary; `AsyncResultMethods` re-imposes the precision.\n ensure(\n predicate: (value: T) => boolean,\n onFail: (value: T) => unknown,\n ): AsyncResult<never, never> {\n return new AsyncRes<never, never>(\n this.#promise.then((r) => {\n if (r.tag !== \"Ok\") return passThrough(r);\n try {\n // A passing value flows through as the same Ok (see the sync `ensure`).\n return (predicate(r.value) ? r : errRes(onFail(r.value))) as Result<never, never>;\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n // The precise generic-M matcher signatures live on the public surface\n // (`AsyncResultMethods`); TypeScript cannot unify them across the\n // class/`implements` boundary (relating the two generic signatures fails to\n // equate `MatchErrOut<M>` on each side), so these implementations are typed\n // loosely — `never` error channels keep the returns bivariantly compatible —\n // and the interface re-imposes the precision, mirroring how `get`'s `this`\n // gate is re-imposed in `types.ts`.\n mapErrCases(\n f: (matcher: ErrMatcher<E>, defect: (cause: unknown) => Defect) => ExhaustiveMatch<unknown>,\n ): AsyncResult<T, never> {\n return new AsyncRes<T, never>(\n this.#promise.then((r) => {\n if (r.tag !== \"Err\") return passThrough(r);\n try {\n const out = runMatch(f, r.error);\n if (isDefectMarker(out)) return defectRes<T, never>(out.cause);\n return errRes<T, never>(out as never);\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n flatMapErrCases(\n f: (\n matcher: ErrMatcher<E>,\n defect: (cause: unknown) => Defect,\n ) => ExhaustiveMatch<Result<unknown, unknown> | AsyncResult<unknown, unknown> | Defect>,\n ): AsyncResult<T, never> {\n return new AsyncRes<T, never>(\n this.#promise.then(async (r) => {\n if (r.tag !== \"Err\") return passThrough(r);\n try {\n const out = runMatch(f, r.error);\n if (isDefectMarker(out)) return defectRes<T, never>(out.cause);\n const inner = await (out as Result<unknown, unknown> | AsyncResult<unknown, unknown>);\n if (!isResult(inner)) return nonResultCallbackDefect<T, never>();\n return inner as Result<T, never>;\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n recoverErrCases(\n f: (matcher: ErrMatcher<E>, defect: (cause: unknown) => Defect) => ExhaustiveMatch<unknown>,\n ): AsyncResult<T, never> {\n return new AsyncRes<T, never>(\n this.#promise.then((r) => {\n if (r.tag !== \"Err\") return passThrough(r);\n try {\n const out = runMatch(f, r.error);\n if (isDefectMarker(out)) return defectRes<T, never>(out.cause);\n return okRes<T, never>(out as T);\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n tapErrCases(\n f: (matcher: ErrMatcher<E>, defect: (cause: unknown) => Defect) => ExhaustiveMatch<unknown>,\n ): AsyncResult<T, E> {\n return new AsyncRes<T, E>(\n this.#promise.then((r) => {\n if (r.tag !== \"Err\") return r;\n try {\n const out = runMatch(f, r.error);\n // Same observer treatment as the sync surface — a deliberate\n // `defect(…)` is the expression-position form of a `throw`, not a\n // discarded branch value.\n if (isDefectMarker(out)) return observerThrowToDefect<T, E>(out.cause, r.error);\n return r;\n } catch (cause) {\n return observerThrowToDefect<T, E>(cause, r.error);\n }\n }),\n );\n }\n\n flatTapErrCases(\n f: (\n matcher: ErrMatcher<E>,\n defect: (cause: unknown) => Defect,\n ) => ExhaustiveMatch<Result<unknown, unknown> | AsyncResult<unknown, unknown>>,\n ): AsyncResult<T, E> {\n return new AsyncRes<T, E>(\n this.#promise.then(async (r) => {\n if (r.tag !== \"Err\") return passThrough(r);\n try {\n const out = runMatch(f, r.error);\n // Checked BEFORE the await, mirroring the async `flatMapErrCases`: the\n // marker is never thenable, so awaiting it would be a no-op microtask.\n // Same observer treatment as the sync surface — the observed error\n // survives alongside the caller's cause.\n if (isDefectMarker(out)) return observerThrowToDefect(out.cause, r.error);\n const inner = await (out as Result<unknown, unknown> | AsyncResult<unknown, unknown>);\n if (!isResult(inner)) return nonResultCallbackDefect();\n // Keep the original error on success; an Err/Defect from the effect wins.\n return inner.tag === \"Ok\" ? passThrough(r) : passThrough(inner);\n } catch (cause) {\n return observerThrowToDefect(cause, r.error);\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 const inner = await f(r.cause);\n return isResult(inner) ? inner : nonResultCallbackDefect<T | U, E | E2>();\n } catch (cause) {\n return defectRes(cause);\n }\n }),\n );\n }\n\n tapDefect<R>(f: (cause: unknown) => R & NotThenable<R>): 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 observerThrowToDefect<T, E>(cause, r.cause);\n }\n }),\n );\n }\n\n tapFailure<R>(f: (failure: FailureView<E, T>) => R & NotThenable<R>): 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);\n return r;\n } catch (cause) {\n return observerThrowToDefect<T, E>(cause, r.tag === \"Err\" ? r.error : r.cause);\n }\n }),\n );\n }\n\n match<ROk, RDefect, M extends ExhaustiveMatch<unknown>>(cases: {\n ok: (value: T) => ROk;\n errCases: (matcher: ErrMatcher<E>) => M;\n defect: (cause: unknown) => RDefect;\n }): Promise<ROk | RDefect | MatchOut<M>> {\n return this.#promise.then((r) => r.match(cases));\n }\n\n get(): Promise<T> {\n return this.#promise.then((r) => (r as Result<T, never>).get());\n }\n getErr(): Promise<E> {\n return this.#promise.then((r) => (r as Result<never, E>).getErr());\n }\n getOr<U>(fallback: U): Promise<T | U> {\n return this.#promise.then((r) => r.getOr(fallback));\n }\n getOrElse<U>(f: (error: E) => U): Promise<T | U> {\n return this.#promise.then((r) => r.getOrElse(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 getOrThrow(): Promise<T> {\n // The cast sidesteps `getOrThrow`'s `this` gate (non-empty error channel),\n // re-imposed on the public `AsyncResultMethods` signature — mirroring `get`.\n return this.#promise.then((r) => (r as Result<T, unknown>).getOrThrow());\n }\n}\n\n// Same hardening as `Res.prototype` above: the shared async combinators cannot\n// be swapped out from under every instance. (The wrapped promise is already a\n// native #private field, unreachable from outside.)\nObject.freeze(AsyncRes.prototype);\n","// Result constructors and the standalone narrowing guards.\n\nimport { errRes, okRes } from \"./core.js\";\nimport type { AsyncResult, DefectView, ErrView, OkView, Result } from \"./types.js\";\n\n/**\n * Construct a successful `void` {@link Result} — `Result<void, never>` —\n * sparing you `Ok(undefined)` and typing the success channel `void`, not\n * `undefined`.\n *\n * @example\n * ```ts\n * import { Ok } from \"unthrown\";\n *\n * Ok(); // => a void success: Result<void, never>\n * ```\n *\n * @category Constructors\n */\nexport function Ok(): Result<void, never>;\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 *\n * Ok(2).map((n) => n + 1); // => Ok(3)\n * Ok(42).get(); // => 42\n * ```\n *\n * @category Constructors\n */\nexport function Ok<T>(value: T): Result<T, never>;\nexport function Ok<T>(value?: T): Result<T, never> {\n // The only way in with no argument is the no-arg overload, which fixes the\n // result type to void — exactly what the omitted undefined inhabits.\n // Invisible to callers.\n return okRes(value as T);\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 *\n * Err(\"not_found\").map((n) => n + 1); // => Err(\"not_found\") (map skipped)\n * Err(\"not_found\").getErr(); // => \"not_found\"\n * ```\n *\n * @category Constructors\n */\nexport function Err<E>(error: E): Result<never, E> {\n return errRes(error);\n}\n\n/**\n * Construct a successful `void` {@link AsyncResult} — `AsyncResult<void, never>`\n * — the pre-lifted form of the no-arg {@link Ok}, sparing you\n * `Ok(undefined).toAsync()`.\n *\n * @example\n * ```ts\n * import { OkAsync } from \"unthrown\";\n *\n * OkAsync(); // => a void success: AsyncResult<void, never>\n * ```\n *\n * @category Constructors\n */\nexport function OkAsync(): AsyncResult<void, never>;\n/**\n * Construct a successful {@link AsyncResult} from a pure value — the pre-lifted\n * form of {@link Ok}, sparing you `Ok(value).toAsync()`.\n *\n * @remarks\n * Reach for this on the synchronous/early branch of an `AsyncResult`-returning\n * function, so both branches share one return type without a trailing\n * `.toAsync()`. Named with the `Async` suffix the async free functions carry\n * (`allAsync`, `allFromDictAsync`); the {@link AsyncResult} companion aliases it\n * as `AsyncResult.Ok` (the namespace already says \"async\", so the suffix drops).\n *\n * @typeParam T - the success value type.\n * @param value - the success value to wrap.\n *\n * @example\n * ```ts\n * import { OkAsync, type AsyncResult } from \"unthrown\";\n *\n * function loadItems(ids: string[]): AsyncResult<Item[], never> {\n * if (ids.length === 0) return OkAsync([]); // no more Ok([]).toAsync()\n * return itemRepository.load(ids);\n * }\n * ```\n *\n * @category Constructors\n */\nexport function OkAsync<T>(value: T): AsyncResult<T, never>;\nexport function OkAsync<T>(value?: T): AsyncResult<T, never> {\n // Same deliberate cast as `Ok` above: argument-less means the no-arg\n // overload already fixed the type to `void`.\n return Ok(value as T).toAsync();\n}\n\n/**\n * Construct a failed {@link AsyncResult} carrying a **modeled** error — the\n * pre-lifted form of {@link Err}, sparing you `Err(error).toAsync()`.\n *\n * @remarks\n * The error-channel mirror of {@link OkAsync}; see it for the naming and the\n * `AsyncResult.Err` companion alias.\n *\n * @typeParam E - the modeled error type.\n * @param error - the domain error to wrap.\n *\n * @example\n * ```ts\n * import { ErrAsync } from \"unthrown\";\n *\n * ErrAsync(\"not_found\"); // AsyncResult<never, string>\n * ```\n *\n * @category Constructors\n */\nexport function ErrAsync<E>(error: E): AsyncResult<never, E> {\n return Err(error).toAsync();\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, Ok, Err, type Result } from \"unthrown\";\n *\n * isOk(Ok(1)); // => true\n * isOk(Err(\"boom\")); // => false\n *\n * declare const r: Result<number, string>;\n * if (isOk(r)) r.value; // number, narrowed\n * ```\n *\n * @category Guards\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 *\n * @example\n * ```ts\n * import { isErr, Ok, Err, type Result } from \"unthrown\";\n *\n * isErr(Err(\"boom\")); // => true\n * isErr(Ok(1)); // => false\n *\n * declare const r: Result<number, string>;\n * if (isErr(r)) r.error; // string, narrowed\n * ```\n *\n * @category Guards\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 * @remarks\n * A `Defect` has no public constructor — it only arises at a boundary (e.g. a\n * callback throwing inside a combinator). This guard is how you detect one.\n *\n * @returns `true` when `r` is a `Defect`.\n *\n * @example\n * ```ts\n * import { isDefect, Ok } from \"unthrown\";\n *\n * // A throw inside a combinator is captured as a Defect:\n * const r = Ok(1).map(() => {\n * throw new Error(\"boom\");\n * });\n * isDefect(r); // => true\n * isDefect(Ok(1)); // => false\n *\n * if (isDefect(r)) r.cause; // unknown, narrowed\n * ```\n *\n * @category Guards\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 { AsyncResult, 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 *\n * @example\n * ```ts\n * import { Do, Ok, Err } from \"unthrown\";\n *\n * // Ok path — the scope accumulates:\n * Do()\n * .bind(\"a\", () => Ok(2))\n * .let(\"b\", ({ a }) => a * 10)\n * .map(({ a, b }) => a + b); // => Ok(22)\n *\n * // Err path — the first Err short-circuits the rest:\n * Do()\n * .bind(\"a\", () => Err(\"boom\"))\n * .let(\"b\", ({ a }) => a); // => Err(\"boom\")\n * ```\n *\n * @category Do-notation\n */\nexport function Do(): Result<{}, never> {\n return Ok({});\n}\n\n/**\n * Start an **asynchronous** do-notation chain with an empty object scope — the\n * pre-lifted form of {@link Do}, sparing you `Do().toAsync()`.\n *\n * @remarks\n * From here a `bind` may return a `Result` **or** an `AsyncResult`; the scope\n * accumulates exactly as in a sync {@link Do} chain, and a throw in any step\n * becomes a `Defect`. Named with the `Async` suffix the async free functions\n * carry (`OkAsync`, `allAsync`); the {@link AsyncResult} companion aliases it as\n * `AsyncResult.Do` (the namespace already says \"async\", so the suffix drops).\n *\n * @example\n * ```ts\n * import { DoAsync, Ok } from \"unthrown\";\n *\n * const result = await DoAsync()\n * .bind(\"user\", () => findUser(id)) // AsyncResult<User, NotFound>\n * .bind(\"plan\", ({ user }) => Ok(user.plan)) // a sync Result is accepted too\n * .let(\"label\", ({ user, plan }) => `${user.name} on ${plan}`);\n * // Result<{ user: User; plan: Plan; label: string }, NotFound>\n * ```\n *\n * @category Do-notation\n */\nexport function DoAsync(): AsyncResult<{}, never> {\n return Do().toAsync();\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 { Err, Ok } from \"./constructors.js\";\nimport { AsyncRes, defectRes, errRes, isResult, okRes } from \"./core.js\";\nimport { type Defect, defect, isDefectMarker } from \"./defect.js\";\nimport type {\n AsyncErrOf,\n AsyncOkOf,\n AsyncResult,\n ErrOf,\n NotThenable,\n OkOf,\n Result,\n} 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 * @category Interop\n *\n * @example\n * ```ts\n * import { fromNullable } from \"unthrown\";\n *\n * const map = new Map([[\"a\", 1]]);\n * fromNullable(map.get(\"a\"), () => \"absent\").getOr(0); // => 1\n * fromNullable(map.get(\"z\"), () => \"absent\"); // => Err(\"absent\")\n * fromNullable(0, () => \"absent\").getOr(-1); // => 0 (falsy but present)\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`. `qualify` is **synchronous**: an `async` qualify is rejected at\n * compile time ({@link NotThenable}) — its `Promise` would land in `E` un-triaged\n * — and a thenable slipped past the types at runtime becomes a `Defect` (never\n * an `Err(Promise)`), its orphaned rejection silenced.\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 fromSafeThrowable} when every throw 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 * @category Interop\n *\n * @example\n * ```ts\n * import { fromThrowable } from \"unthrown\";\n *\n * // Model the parse failure as an `Err`, everything unexpected as a `Defect`.\n * const parse = fromThrowable(\n * (text: string) => JSON.parse(text) as unknown,\n * (cause, defect) =>\n * cause instanceof SyntaxError ? (\"invalid_json\" as const) : defect(cause),\n * );\n *\n * parse('{\"ok\":true}').getOr(null); // => { ok: true }\n * parse(\"nope\"); // => Err(\"invalid_json\")\n * ```\n */\nexport function fromThrowable<A extends unknown[], T, R>(\n fn: (...args: A) => T,\n qualify: (cause: unknown, defect: (cause: unknown) => Defect) => R & NotThenable<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 throwing synchronous function asserted **not** to fail in any modeled\n * way: any throw becomes a `Defect`.\n *\n * @remarks\n * The synchronous counterpart of {@link fromSafePromise}. Use it only when a\n * throw genuinely indicates a bug rather than an anticipated outcome — the\n * error channel is `never`, so there is nothing to triage; there is no\n * `qualify`. When some throws *are* anticipated, reach for\n * {@link fromThrowable} and triage them.\n *\n * @typeParam A - the wrapped function's argument tuple.\n * @typeParam T - the wrapped function's return type.\n * @param fn - the throwing function to wrap.\n * @returns a function with the same arguments returning `Result<T, never>`.\n *\n * @category Interop\n *\n * @example\n * ```ts\n * import { fromSafeThrowable } from \"unthrown\";\n *\n * // A decode failure here is a bug (the row came from our own schema), so\n * // every throw is a defect — no throwaway `(cause, defect) => defect(cause)`.\n * const decode = fromSafeThrowable((row: Row) => userSchema.parse(row));\n *\n * decode(row); // => Result<User, never> — a throw becomes a Defect\n * ```\n */\nexport function fromSafeThrowable<A extends unknown[], T>(\n fn: (...args: A) => T,\n): (...args: A) => Result<T, never> {\n return (...args: A): Result<T, never> => {\n try {\n return Ok(fn(...args));\n } catch (cause) {\n return defectRes<T, never>(cause);\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`. `qualify` is\n * **synchronous**: an `async` qualify is rejected at compile time\n * ({@link NotThenable}), and a thenable slipped past the types at runtime\n * becomes a `Defect` (never an `Err(Promise)`), its orphaned rejection silenced.\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 * @param _guard - compile-time only; never pass it. The phantom rest-tuple that\n * enforces \"qualify is synchronous\": an `async` qualify makes this demand an\n * impossible extra argument (whose type spells out the error), while a\n * synchronous one leaves it empty. Encoded here — not on `qualify`'s return\n * type — so `T`'s inference from `promise` is undisturbed.\n *\n * @category Interop\n *\n * @example\n * ```ts\n * import { fromPromise } from \"unthrown\";\n *\n * // A rejection with a NotFoundError becomes a modeled `Err`; anything else a Defect.\n * const user = await fromPromise(fetchUser(id), (cause, defect) =>\n * cause instanceof NotFoundError ? (\"not_found\" as const) : defect(cause),\n * );\n *\n * if (user.isOk()) user.value; // => the fetched user\n * // when fetchUser rejects with NotFoundError: user is Err(\"not_found\")\n * ```\n */\nexport function fromPromise<T, R>(\n promise: Promise<T> | (() => Promise<T>),\n qualify: (cause: unknown, defect: (cause: unknown) => Defect) => R,\n // Phantom rest-tuple guard — the async-qualify ban, encoded OFF the callback's\n // return type: `R & NotThenable<R>` there made TS defer qualify's inference,\n // which collapsed `T` to `unknown` for an inline `.then(…)` chain argument.\n // With the conditional here instead, an async qualify demands an impossible\n // third argument (compile error carrying the message) while `T`/`R` infer\n // normally. Nothing is ever passed at runtime.\n //\n // `Extract` (not `[R] extends [PromiseLike<…>]`) so the ban also fires when\n // only SOME arms of a union return are thenable (`E | Promise<X>` — a\n // sometimes-async qualify is still an unqualified rejection path), and it\n // vacuously admits the always-throwing qualify (`R = never` extracts to\n // `never`) with no special case. The runtime thenable→Defect net in\n // `qualifyToResult` stays as the last resort for untyped callers.\n ..._guard: [Extract<R, PromiseLike<unknown>>] extends [never]\n ? []\n : [\"unthrown: qualify must be synchronous — its Promise would land in E un-triaged\"]\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 // Promise.resolve() also absorbs a non-thenable passed from untyped code, so\n // this boundary never throws synchronously — it exists to prevent throws.\n const p =\n typeof promise === \"function\" ? Promise.resolve().then(promise) : Promise.resolve(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.) The\n * synchronous counterpart is {@link fromSafeThrowable}.\n *\n * @typeParam T - the resolved value type.\n * @param promise - the promise, or a thunk returning one.\n *\n * @category Interop\n *\n * @example\n * ```ts\n * import { fromSafePromise } from \"unthrown\";\n *\n * (await fromSafePromise(Promise.resolve(3))).get(); // => 3\n * // a rejection becomes a Defect (never a modeled Err):\n * await fromSafePromise(Promise.reject(new Error(\"boom\"))); // => Defect(Error(\"boom\"))\n * ```\n */\nexport function fromSafePromise<T>(\n promise: Promise<T> | (() => Promise<T>),\n): AsyncResult<T, never> {\n // Promise.resolve() also absorbs a non-thenable passed from untyped code, so\n // this boundary never throws synchronously — it exists to prevent throws.\n const p =\n typeof promise === \"function\" ? Promise.resolve().then(promise) : Promise.resolve(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 if (isDefectMarker(q)) return defectRes<T, E>(q.cause);\n if (isThenable(q)) {\n // An async `qualify` slipped past the compile-time NotThenable ban\n // (untyped/JS caller). Its Promise must never become the modeled error —\n // the boundary would be un-triaged — so surface a Defect instead. Also\n // adopt-and-silence the orphaned thenable: if the async qualify later\n // rejects, that rejection must not float as an unhandled rejection.\n void Promise.resolve(q).then(undefined, () => undefined);\n return defectRes<T, E>(\n new TypeError(\n \"unthrown: qualify must be synchronous — it returned a thenable; triage the cause without awaiting\",\n ),\n );\n }\n return 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 * Runtime thenable probe for the belt-and-braces guard above. Called inside the\n * caller's `try`, so even a hostile `.then` getter lands on the Defect path.\n *\n * @internal\n */\nfunction isThenable(x: unknown): boolean {\n return (\n (typeof x === \"object\" || typeof x === \"function\") &&\n x !== null &&\n typeof (x as { then?: unknown }).then === \"function\"\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 */\n/** The Defect minted for an out-of-contract non-`Result` element in an aggregate. */\nfunction nonResultDefect(): Result<unknown, unknown> {\n return defectRes(new TypeError(\"unthrown: aggregate received a non-Result element\"));\n}\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 (!isResult(r)) {\n // Out-of-contract element (a hole/undefined/non-Result, reachable only via\n // untyped or cast input). Surface it as a Defect — an unexpected failure —\n // rather than throwing on `.tag` (sync) or rejecting the internal promise\n // (async). A Defect dominates, so break.\n firstDefect ??= nonResultDefect();\n break;\n }\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 (!isResult(r)) {\n firstDefect ??= nonResultDefect(); // out-of-contract element → Defect (see foldArray)\n break;\n }\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\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 * @category Aggregate\n *\n * @example\n * ```ts\n * import { all, Ok, Err } from \"unthrown\";\n *\n * all([Ok(1), Ok(\"a\"), Ok(true)]).get(); // => [1, \"a\", true] (typed [number, string, boolean])\n * all([Ok(1), Err(\"e\"), Ok(3)]); // => Err(\"e\") (short-circuits on the first Err)\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 * @category Aggregate\n *\n * @example\n * ```ts\n * import { allFromDict, Ok, Err } from \"unthrown\";\n *\n * allFromDict({ id: Ok(1), name: Ok(\"ada\") }).get(); // => { id: 1, name: \"ada\" }\n * allFromDict({ id: Ok(1), name: Err(\"missing\") }); // => Err(\"missing\")\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 * @category Aggregate\n *\n * @example\n * ```ts\n * import { allAsync, fromSafePromise } from \"unthrown\";\n *\n * const both = allAsync([fromSafePromise(Promise.resolve(1)), fromSafePromise(Promise.resolve(2))]);\n * (await both).get(); // => [1, 2]\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 library AsyncResult is a never-rejecting thenable, so Promise.all\n // adopts them; `foldArray` then applies the all() rules. Adopt every input\n // defensively — a cast/untyped rejecting thenable becomes a `Defect` rather\n // than rejecting the internal promise (the \"internal promise never rejects\"\n // invariant holds even for out-of-contract input).\n const settled = Promise.all(\n results.map((r) =>\n Promise.resolve(r).then(\n (x) => x,\n (cause) => defectRes(cause),\n ),\n ),\n ).then((resolved) => foldArray(resolved as readonly Result<unknown, unknown>[]));\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 * @category Aggregate\n *\n * @example\n * ```ts\n * import { allFromDictAsync, fromSafePromise } from \"unthrown\";\n *\n * const both = allFromDictAsync({\n * a: fromSafePromise(Promise.resolve(1)),\n * b: fromSafePromise(Promise.resolve(\"x\")),\n * });\n * (await both).get(); // => { a: 1, b: \"x\" }\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(\n // Adopt each input defensively (see `allAsync`): a rejecting thenable\n // becomes a `Defect`, so the internal promise never rejects.\n entries.map(([, ar]) =>\n Promise.resolve(ar).then(\n (x) => x,\n (cause) => defectRes(cause),\n ),\n ),\n ).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, ErrAsync, isDefect, isErr, isOk, Ok, OkAsync } from \"./constructors.js\";\nimport { isResult } from \"./core.js\";\nimport { Do, DoAsync } from \"./do.js\";\nimport {\n all,\n allAsync,\n allFromDict,\n allFromDictAsync,\n fromNullable,\n fromPromise,\n fromSafePromise,\n fromSafeThrowable,\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.fromSafeThrowable}, {@link Result.all},\n * {@link Result.allFromDict}, {@link Result.isOk}, {@link Result.isErr},\n * {@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 * @category Facade\n *\n * @example\n * ```ts\n * import { Result } from \"unthrown\";\n * Result.Ok(1).flatMap((n) => Result.Ok(n + 1)).get(); // => 2\n * ```\n */\nexport const Result = {\n Ok,\n Err,\n Do,\n fromNullable,\n fromThrowable,\n fromSafeThrowable,\n all,\n allFromDict,\n isOk,\n isErr,\n isDefect,\n isResult,\n} as const;\n\n/**\n * `Result<T, E>` — the core discriminated union. Shares its name with the\n * {@link Result | companion object} above (the value and type are one name); this\n * is the type half.\n *\n * @remarks\n * A `Result` is a discriminated union, so TypeDoc can't list its methods on this\n * alias. Its fluent combinators (`map`, `flatMap`, `match`, `get`, …) are\n * documented one per entry on {@link ResultMethods} — the shared method surface\n * every variant carries. For \"which one do I reach for?\", see the\n * [Choosing a combinator](/reference/combinators) guide.\n *\n * @category Facade\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.Ok}, {@link AsyncResult.Err},\n * {@link AsyncResult.Do}, {@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 the pre-lifted constructors, `fromPromise`/`fromSafePromise`,\n * and the async aggregates sit here rather than on {@link Result}; the namespace\n * already conveys \"async\", so the members drop the `Async` suffix their free\n * functions carry (`AsyncResult.Ok` is `OkAsync`; `AsyncResult.Err` is\n * `ErrAsync`; `AsyncResult.Do` is `DoAsync`; `AsyncResult.all` is `allAsync`;\n * `AsyncResult.allFromDict` is\n * `allFromDictAsync`). Like {@link Result}, the free functions remain the\n * primary, tree-shakeable API; the value `AsyncResult` and the type\n * {@link AsyncResult} share one name.\n *\n * @category Facade\n *\n * @example\n * ```ts\n * import { AsyncResult } from \"unthrown\";\n * const user = await AsyncResult.fromPromise(fetchUser(id), (c, defect) => defect(c));\n * user.get(); // => the fetched user (on success)\n * ```\n */\nexport const AsyncResult = {\n Ok: OkAsync,\n Err: ErrAsync,\n Do: DoAsync,\n fromPromise,\n fromSafePromise,\n all: allAsync,\n allFromDict: allFromDictAsync,\n} as const;\n\n/**\n * `AsyncResult<T, E>` — the async counterpart of {@link Result}. Shares its name\n * with the {@link AsyncResult | companion object} above (value and type are one\n * name); this is the type half.\n *\n * @remarks\n * `AsyncResult` carries the async fluent surface; its combinators (`map`,\n * `flatMap`, `match`, `get`, …) are documented one per entry — with their\n * async signatures — on {@link AsyncResultMethods}. For \"which one do I reach\n * for?\", see the [Choosing a combinator](/reference/combinators) guide.\n *\n * @category Facade\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 the\n// `tag(t)` matcher pattern for matching a tagged error union.\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 *\n * @category Types\n */\nexport type TaggedErrorInstance<Tag extends string, A extends Props> = Error &\n Readonly<Omit<A, \"name\" | \"message\" | \"stack\">> & { 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. The\n * `name`, `message`, and `stack` keys are all **rejected** (`?: never`) because\n * all three are reserved: `name` is the display label, `message` is the human\n * string owned by `Error`, and `stack` is `Error`'s trace. Set the message the\n * standard way — `override message = \"…\"` (or a constructor override) on the\n * subclass — never as a free-form per-call payload field. The reservations are\n * enforced at the call site, mirroring how {@link TaggedErrorInstance} excludes\n * all three. (`cause` is deliberately **not** reserved: `Error.cause` is\n * `unknown`, so a typed payload `cause` is a legitimate structured field.)\n *\n * @typeParam Tag - the string literal discriminant.\n *\n * @category Types\n */\nexport type TaggedErrorConstructor<Tag extends string> = {\n new <A extends Props = {}>(\n args: keyof A extends never\n ? void\n : A & { readonly name?: never; readonly message?: never; readonly stack?: never },\n ): 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. The `message`\n * is **not** a payload field — it is the human string owned by `Error`, not\n * structured data, so it is reserved. Define it once per subclass the standard\n * way, `override message = \"…\"` (it may interpolate the payload via `this`,\n * which the base populates before the subclass field initialiser runs); a\n * payload `message` is rejected at compile time, so contextual detail lives in\n * typed fields, never baked into per-call prose. The `_tag` always reflects\n * `tag` and cannot be overridden by the payload. `name` is likewise reserved —\n * it is the display label (set it with `options.name`); a payload `name` is\n * rejected at compile time (and excluded from the instance type), so it can't\n * shadow `Error.name`. `stack` is reserved the same way — it is `Error`'s\n * trace, and even an untyped payload `stack` cannot clobber the real one.\n * `cause` is deliberately **not** reserved: `Error.cause` is typed `unknown`,\n * so a payload `cause` (e.g. a wrapped driver error) is a legitimate,\n * *narrowing* structured field.\n *\n * `_tag` is the discriminant matched by {@link tag} in the error combinators\n * (`result.mapErrCases((matcher) => matcher.with(tag(\"NotFound\"), …))`) and in\n * `match`; `Error.name` is the human-facing label in stack traces and logs. By\n * 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 * }) {\n * override message = \"operation failed; safe to retry\";\n * }\n *\n * const e = new RetryableError();\n * e._tag; // \"@my-lib/RetryableError\" — namespaced discriminant\n * e.name; // \"RetryableError\" — clean display name\n * e.message; // \"operation failed; safe to retry\" — the standard Error.message\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 * @category Tagged errors\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();\n if (props) {\n // `stack` is reserved like `name`/`message`: it is `Error`'s trace, not\n // payload data. Capture the genuine trace as a string (V8 exposes\n // `stack` as a lazy accessor whose setter would happily store a payload\n // value), let the payload land, then re-assert the real trace as a\n // plain data property — an untyped caller cannot clobber it. (`cause`\n // is deliberately allowed through: `Error.cause` is `unknown`, so a\n // typed payload `cause` is a legitimate structured field.)\n const stack = this.stack;\n Object.assign(this, props);\n delete (this as { stack?: unknown }).stack;\n if (stack !== undefined) {\n Object.defineProperty(this, \"stack\", {\n value: stack,\n writable: true,\n enumerable: false,\n configurable: true,\n });\n }\n }\n // `_tag`, `name`, and `message` are authoritative — an untyped caller\n // can't set them via the payload. `_tag`/`name` are re-assigned to their\n // canonical values; `message` is `Error`'s channel (set per subclass via\n // `override message = …`, whose field initialiser runs after this\n // constructor returns), so any payload-supplied `message` is dropped here.\n (this as { _tag: Tag })._tag = tag;\n this.name = displayName;\n delete (this as { message?: unknown }).message;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n }\n\n return TaggedErrorBase as unknown as TaggedErrorConstructor<Tag>;\n}\n\n/**\n * A matcher pattern matching any value whose `_tag` equals `value` — a\n * {@link TaggedError}, or any discriminated member. Equivalent to the object\n * pattern `{ _tag: value }`, but reads better inside an error-matching\n * combinator and narrows to the matching variant, payload included.\n *\n * @typeParam Tag - the string literal tag to match.\n * @param value - the `_tag` to match.\n *\n * @category Tagged errors\n *\n * @example\n * ```ts\n * result.mapErrCases((matcher) =>\n * matcher\n * .with(tag(\"NotFound\"), () => new NotFoundException())\n * .with(tag(\"Conflict\"), (e) => new ConflictException(e.key)),\n * );\n * ```\n */\nexport function tag<const Tag extends string>(value: Tag): { _tag: Tag } {\n return { _tag: value };\n}\n"],"mappings":";;;;;;;;;AAkCA,MAAM,gBAAgB,OAAO,IAAI,0BAA0B;;;;;;;;;;;AA6M3D,IAAa,qBAAb,cAAwC,MAAM;;CAE5C;CACA,YAAY,OAAgB;EAC1B,IAAI;EACJ,IAAI;GACF,UAAU,KAAK,UAAU,KAAK;EAChC,QAAQ;GACN,UAAU,OAAO,KAAK;EACxB;EACA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U,UAAU,KAAK,CAC5B,CACF,CACF,CAAC,CAAC,MAAM,aAAa;EAEnB,MAAM,QAAsB,OAAO,OAAO,IAAI;EAC9C,QAAQ,SAAS,CAAC,MAAM,MAAM;GAC5B,MAAM,OAAO,SAAS;EACxB,CAAC;EACD,OAAO,WAAW,KAAK;CACzB,CAC0B,CAAC;AAI7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AClfA,MAAa,SAAS;CACpB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,MAAa,cAAc;CACzB,IAAI;CACJ,KAAK;CACL,IAAI;CACJ;CACA;CACA,KAAK;CACL,aAAa;AACf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACdA,SAAgB,YACd,KACA,SAC6B;CAC7B,MAAM,cAAc,SAAS,QAAQ;CACrC,MAAM,wBAAwB,MAAM;EAClC;EAEA,YAAY,OAAe;GACzB,MAAM;GACN,IAAI,OAAO;IAQT,MAAM,QAAQ,KAAK;IACnB,OAAO,OAAO,MAAM,KAAK;IACzB,OAAQ,KAA6B;IACrC,IAAI,UAAU,KAAA,GACZ,OAAO,eAAe,MAAM,SAAS;KACnC,OAAO;KACP,UAAU;KACV,YAAY;KACZ,cAAc;IAChB,CAAC;GAEL;GAMA,KAAwB,OAAO;GAC/B,KAAK,OAAO;GACZ,OAAQ,KAA+B;GACvC,OAAO,eAAe,MAAM,IAAI,OAAO,SAAS;EAClD;CACF;CAEA,OAAO;AACT;;;;;;;;;;;;;;;;;;;;;AAsBA,SAAgB,IAA8B,OAA2B;CACvE,OAAO,EAAE,MAAM,MAAM;AACvB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unthrown",
3
- "version": "5.0.0-beta.7",
3
+ "version": "5.0.0-beta.8",
4
4
  "description": "Explicit errors as values, with a separate defect (panic) channel",
5
5
  "keywords": [
6
6
  "defect",