unthrown 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +117 -27
- package/dist/index.d.cts +77 -20
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +77 -20
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +116 -28
- package/dist/index.mjs.map +1 -1
- package/docs/index.md +190 -100
- package/package.json +1 -1
package/docs/index.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
### UnwrapError
|
|
10
10
|
|
|
11
|
-
Defined in: [packages/core/src/core.ts:29](https://github.com/btravstack/unthrown/blob/
|
|
11
|
+
Defined in: [packages/core/src/core.ts:29](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/core.ts#L29)
|
|
12
12
|
|
|
13
13
|
Thrown by a [Result](#result)'s `unwrap` / `unwrapErr` when the assertion is
|
|
14
14
|
wrong on a *modeled* result — `unwrap()` on an `Err`, or `unwrapErr()` on an
|
|
@@ -37,7 +37,7 @@ re-thrown (with its original stack) instead.
|
|
|
37
37
|
new UnwrapError<E>(error): UnwrapError<E>;
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
Defined in: [packages/core/src/core.ts:35](https://github.com/btravstack/unthrown/blob/
|
|
40
|
+
Defined in: [packages/core/src/core.ts:35](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/core.ts#L35)
|
|
41
41
|
|
|
42
42
|
###### Parameters
|
|
43
43
|
|
|
@@ -60,7 +60,7 @@ Error.constructor
|
|
|
60
60
|
| Property | Modifier | Type | Description | Inherited from | Defined in |
|
|
61
61
|
| ------ | ------ | ------ | ------ | ------ | ------ |
|
|
62
62
|
| <a id="cause"></a> `cause?` | `public` | `unknown` | - | `Error.cause` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es2022.error.d.ts:24 |
|
|
63
|
-
| <a id="error"></a> `error` | `readonly` | `E` | The offending value: the `Err` error for `unwrap()`, or the `Ok` value for `unwrapErr()`. | - | [packages/core/src/core.ts:34](https://github.com/btravstack/unthrown/blob/
|
|
63
|
+
| <a id="error"></a> `error` | `readonly` | `E` | The offending value: the `Err` error for `unwrap()`, or the `Ok` value for `unwrapErr()`. | - | [packages/core/src/core.ts:34](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/core.ts#L34) |
|
|
64
64
|
| <a id="message"></a> `message` | `public` | `string` | - | `Error.message` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1075 |
|
|
65
65
|
| <a id="name"></a> `name` | `public` | `string` | - | `Error.name` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1074 |
|
|
66
66
|
| <a id="stack"></a> `stack?` | `public` | `string` | - | `Error.stack` | node\_modules/.pnpm/typescript@6.0.3/node\_modules/typescript/lib/lib.es5.d.ts:1076 |
|
|
@@ -174,7 +174,7 @@ Error.prepareStackTrace
|
|
|
174
174
|
type AsyncErrOf<R> = R extends AsyncResult<unknown, infer E> ? E : never;
|
|
175
175
|
```
|
|
176
176
|
|
|
177
|
-
Defined in: [packages/core/src/types.ts:
|
|
177
|
+
Defined in: [packages/core/src/types.ts:376](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L376)
|
|
178
178
|
|
|
179
179
|
Extract the error type `E` from an [AsyncResult](#asyncresult).
|
|
180
180
|
|
|
@@ -192,7 +192,7 @@ Extract the error type `E` from an [AsyncResult](#asyncresult).
|
|
|
192
192
|
type AsyncOkOf<R> = R extends AsyncResult<infer T, unknown> ? T : never;
|
|
193
193
|
```
|
|
194
194
|
|
|
195
|
-
Defined in: [packages/core/src/types.ts:
|
|
195
|
+
Defined in: [packages/core/src/types.ts:370](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L370)
|
|
196
196
|
|
|
197
197
|
Extract the success type `T` from an [AsyncResult](#asyncresult).
|
|
198
198
|
|
|
@@ -210,7 +210,7 @@ Extract the success type `T` from an [AsyncResult](#asyncresult).
|
|
|
210
210
|
type AsyncResult<T, E> = Awaitable<Result<T, E>> & object;
|
|
211
211
|
```
|
|
212
212
|
|
|
213
|
-
Defined in: [packages/core/src/types.ts:
|
|
213
|
+
Defined in: [packages/core/src/types.ts:296](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L296)
|
|
214
214
|
|
|
215
215
|
The asynchronous counterpart of [Result](#result): an awaitable wrapper with the
|
|
216
216
|
same method surface, collapsing to a `Result<T, E>` when `await`-ed.
|
|
@@ -219,23 +219,24 @@ same method surface, collapsing to a `Result<T, E>` when `await`-ed.
|
|
|
219
219
|
|
|
220
220
|
| Name | Type | Description | Defined in |
|
|
221
221
|
| ------ | ------ | ------ | ------ |
|
|
222
|
-
| `as()` | (`value`) => [`AsyncResult`](#asyncresult)<`U`, `E`> | Asynchronous `as`. | [packages/core/src/types.ts:
|
|
223
|
-
| `flatMap()` | (`f`) => [`AsyncResult`](#asyncresult)<`U`, `E` \| `E2`> | Asynchronous `flatMap`. `f` may return a `Result` **or** an `AsyncResult` (never a raw `Promise`); a throw becomes a `Defect`. | [packages/core/src/types.ts:
|
|
224
|
-
| `
|
|
225
|
-
| `
|
|
226
|
-
| `
|
|
227
|
-
| `
|
|
228
|
-
| `
|
|
229
|
-
| `
|
|
230
|
-
| `
|
|
231
|
-
| `
|
|
232
|
-
| `
|
|
233
|
-
| `
|
|
234
|
-
| `
|
|
235
|
-
| `
|
|
236
|
-
| `
|
|
237
|
-
| `
|
|
238
|
-
| `
|
|
222
|
+
| `as()` | (`value`) => [`AsyncResult`](#asyncresult)<`U`, `E`> | Asynchronous `as`. | [packages/core/src/types.ts:315](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L315) |
|
|
223
|
+
| `flatMap()` | (`f`) => [`AsyncResult`](#asyncresult)<`U`, `E` \| `E2`> | Asynchronous `flatMap`. `f` may return a `Result` **or** an `AsyncResult` (never a raw `Promise`); a throw becomes a `Defect`. | [packages/core/src/types.ts:303](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L303) |
|
|
224
|
+
| `flatTap()` | (`f`) => [`AsyncResult`](#asyncresult)<`T`, `E` \| `E2`> | Asynchronous `flatTap` — a failable tap that keeps the original value. `f` may return a `Result` **or** an `AsyncResult`; its `Ok` value is discarded, an `Err`/`Defect` short-circuits, and a throw becomes a `Defect`. | [packages/core/src/types.ts:311](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L311) |
|
|
225
|
+
| `getOrNull()` | () => `Promise`<`T` \| `null`> | Asynchronous `getOrNull`. | [packages/core/src/types.ts:348](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L348) |
|
|
226
|
+
| `getOrUndefined()` | () => `Promise`<`T` \| `undefined`> | Asynchronous `getOrUndefined`. | [packages/core/src/types.ts:350](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L350) |
|
|
227
|
+
| `map()` | (`f`) => [`AsyncResult`](#asyncresult)<`U`, `E`> | Asynchronous `map`. `f` is synchronous; a throw becomes a `Defect`. | [packages/core/src/types.ts:298](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L298) |
|
|
228
|
+
| `mapErr()` | (`f`) => [`AsyncResult`](#asyncresult)<`T`, `E2`> | Asynchronous `mapErr`. `f` is synchronous; a throw becomes a `Defect`. | [packages/core/src/types.ts:318](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L318) |
|
|
229
|
+
| `match()` | (`cases`) => `Promise`<`R`> | Asynchronous `match`. Handlers are synchronous; resolves to `R`. | [packages/core/src/types.ts:334](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L334) |
|
|
230
|
+
| `orElse()` | (`f`) => [`AsyncResult`](#asyncresult)<`T` \| `U`, `E2`> | Asynchronous `orElse`. `f` may return a `Result` or an `AsyncResult`. | [packages/core/src/types.ts:320](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L320) |
|
|
231
|
+
| `recover()` | (`f`) => [`AsyncResult`](#asyncresult)<`T` \| `U`, `never`> | Asynchronous `recover`. `f` is synchronous; a throw becomes a `Defect`. | [packages/core/src/types.ts:322](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L322) |
|
|
232
|
+
| `recoverDefect()` | (`f`) => [`AsyncResult`](#asyncresult)<`T` \| `U`, `E` \| `E2`> | Asynchronous `recoverDefect`. `f` may return a `Result` or an `AsyncResult`. | [packages/core/src/types.ts:327](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L327) |
|
|
233
|
+
| `tap()` | (`f`) => [`AsyncResult`](#asyncresult)<`T`, `E`> | Asynchronous `tap`. `f` is synchronous; a throw becomes a `Defect`. | [packages/core/src/types.ts:305](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L305) |
|
|
234
|
+
| `tapDefect()` | (`f`) => [`AsyncResult`](#asyncresult)<`T`, `E`> | Asynchronous `tapDefect`. | [packages/core/src/types.ts:331](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L331) |
|
|
235
|
+
| `tapErr()` | (`f`) => [`AsyncResult`](#asyncresult)<`T`, `E`> | Asynchronous `tapErr`. `f` is synchronous; a throw becomes a `Defect`. | [packages/core/src/types.ts:324](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L324) |
|
|
236
|
+
| `unwrap()` | () => `Promise`<`T`> | Asynchronous `unwrap`. The returned promise rejects on `Err`/`Defect`. | [packages/core/src/types.ts:340](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L340) |
|
|
237
|
+
| `unwrapErr()` | () => `Promise`<`E`> | Asynchronous `unwrapErr`. | [packages/core/src/types.ts:342](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L342) |
|
|
238
|
+
| `unwrapOr()` | (`fallback`) => `Promise`<`T`> | Asynchronous `unwrapOr`. | [packages/core/src/types.ts:344](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L344) |
|
|
239
|
+
| `unwrapOrElse()` | (`f`) => `Promise`<`T`> | Asynchronous `unwrapOrElse`. | [packages/core/src/types.ts:346](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L346) |
|
|
239
240
|
|
|
240
241
|
#### Type Parameters
|
|
241
242
|
|
|
@@ -252,7 +253,8 @@ rejection would silently become a `Defect`, skipping the triage that
|
|
|
252
253
|
[fromPromise](#frompromise) forces. To do further async work, re-enter through a
|
|
253
254
|
qualified boundary and compose it: `ar.flatMap((v) => fromPromise(work(v),
|
|
254
255
|
qualify))`. The eliminators (`unwrap`, …) return promises; the binds
|
|
255
|
-
(`flatMap`, `orElse`, `recoverDefect`) additionally accept an
|
|
256
|
+
(`flatMap`, `flatTap`, `orElse`, `recoverDefect`) additionally accept an
|
|
257
|
+
`AsyncResult`.
|
|
256
258
|
|
|
257
259
|
To pattern-match an `AsyncResult`, `await` it first: `match(await ar)`.
|
|
258
260
|
|
|
@@ -264,7 +266,7 @@ To pattern-match an `AsyncResult`, `await` it first: `match(await ar)`.
|
|
|
264
266
|
type Awaitable<T> = object;
|
|
265
267
|
```
|
|
266
268
|
|
|
267
|
-
Defined in: [packages/core/src/types.ts:
|
|
269
|
+
Defined in: [packages/core/src/types.ts:273](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L273)
|
|
268
270
|
|
|
269
271
|
A success-only thenable: awaitable, but deliberately **not** a full
|
|
270
272
|
`PromiseLike`.
|
|
@@ -291,7 +293,7 @@ being treated as a raw promise (e.g. dropped into `Promise.all`).
|
|
|
291
293
|
then<R>(onfulfilled?): PromiseLike<R>;
|
|
292
294
|
```
|
|
293
295
|
|
|
294
|
-
Defined in: [packages/core/src/types.ts:
|
|
296
|
+
Defined in: [packages/core/src/types.ts:274](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L274)
|
|
295
297
|
|
|
296
298
|
###### Type Parameters
|
|
297
299
|
|
|
@@ -317,7 +319,7 @@ Defined in: [packages/core/src/types.ts:257](https://github.com/btravstack/unthr
|
|
|
317
319
|
type Defect = object;
|
|
318
320
|
```
|
|
319
321
|
|
|
320
|
-
Defined in: [packages/core/src/defect.ts:15](https://github.com/btravstack/unthrown/blob/
|
|
322
|
+
Defined in: [packages/core/src/defect.ts:15](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/defect.ts#L15)
|
|
321
323
|
|
|
322
324
|
The marker a `qualify` function returns to triage a cause as **unexpected**.
|
|
323
325
|
|
|
@@ -333,8 +335,8 @@ runtime state of a `Result`.
|
|
|
333
335
|
|
|
334
336
|
| Property | Modifier | Type | Defined in |
|
|
335
337
|
| ------ | ------ | ------ | ------ |
|
|
336
|
-
| <a id="defect-1"></a> `[DEFECT]` | `readonly` | `true` | [packages/core/src/defect.ts:16](https://github.com/btravstack/unthrown/blob/
|
|
337
|
-
| <a id="cause-1"></a> `cause` | `readonly` | `unknown` | [packages/core/src/defect.ts:17](https://github.com/btravstack/unthrown/blob/
|
|
338
|
+
| <a id="defect-1"></a> `[DEFECT]` | `readonly` | `true` | [packages/core/src/defect.ts:16](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/defect.ts#L16) |
|
|
339
|
+
| <a id="cause-1"></a> `cause` | `readonly` | `unknown` | [packages/core/src/defect.ts:17](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/defect.ts#L17) |
|
|
338
340
|
|
|
339
341
|
***
|
|
340
342
|
|
|
@@ -344,7 +346,7 @@ runtime state of a `Result`.
|
|
|
344
346
|
type DefectView<T, E> = ResultMethods<T, E> & object;
|
|
345
347
|
```
|
|
346
348
|
|
|
347
|
-
Defined in: [packages/core/src/types.ts:
|
|
349
|
+
Defined in: [packages/core/src/types.ts:216](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L216)
|
|
348
350
|
|
|
349
351
|
The `Defect` variant of a [Result](#result): an unmodeled failure carrying a `cause`.
|
|
350
352
|
|
|
@@ -352,8 +354,8 @@ The `Defect` variant of a [Result](#result): an unmodeled failure carrying a `ca
|
|
|
352
354
|
|
|
353
355
|
| Name | Type | Defined in |
|
|
354
356
|
| ------ | ------ | ------ |
|
|
355
|
-
| `cause` | `unknown` | [packages/core/src/types.ts:
|
|
356
|
-
| `tag` | `"Defect"` | [packages/core/src/types.ts:
|
|
357
|
+
| `cause` | `unknown` | [packages/core/src/types.ts:218](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L218) |
|
|
358
|
+
| `tag` | `"Defect"` | [packages/core/src/types.ts:217](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L217) |
|
|
357
359
|
|
|
358
360
|
#### Type Parameters
|
|
359
361
|
|
|
@@ -370,7 +372,7 @@ The `Defect` variant of a [Result](#result): an unmodeled failure carrying a `ca
|
|
|
370
372
|
type ErrOf<R> = R extends object ? E : never;
|
|
371
373
|
```
|
|
372
374
|
|
|
373
|
-
Defined in: [packages/core/src/types.ts:
|
|
375
|
+
Defined in: [packages/core/src/types.ts:364](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L364)
|
|
374
376
|
|
|
375
377
|
Extract the error type `E` from a `Result`.
|
|
376
378
|
|
|
@@ -388,7 +390,7 @@ Extract the error type `E` from a `Result`.
|
|
|
388
390
|
type ErrView<E, T> = ResultMethods<T, E> & object;
|
|
389
391
|
```
|
|
390
392
|
|
|
391
|
-
Defined in: [packages/core/src/types.ts:
|
|
393
|
+
Defined in: [packages/core/src/types.ts:211](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L211)
|
|
392
394
|
|
|
393
395
|
The `Err` variant of a [Result](#result): a modeled failure carrying an `error`.
|
|
394
396
|
|
|
@@ -396,8 +398,8 @@ The `Err` variant of a [Result](#result): a modeled failure carrying an `error`.
|
|
|
396
398
|
|
|
397
399
|
| Name | Type | Defined in |
|
|
398
400
|
| ------ | ------ | ------ |
|
|
399
|
-
| `error` | `E` | [packages/core/src/types.ts:
|
|
400
|
-
| `tag` | `"Err"` | [packages/core/src/types.ts:
|
|
401
|
+
| `error` | `E` | [packages/core/src/types.ts:213](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L213) |
|
|
402
|
+
| `tag` | `"Err"` | [packages/core/src/types.ts:212](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L212) |
|
|
401
403
|
|
|
402
404
|
#### Type Parameters
|
|
403
405
|
|
|
@@ -414,7 +416,7 @@ The `Err` variant of a [Result](#result): a modeled failure carrying an `error`.
|
|
|
414
416
|
type OkOf<R> = R extends object ? T : never;
|
|
415
417
|
```
|
|
416
418
|
|
|
417
|
-
Defined in: [packages/core/src/types.ts:
|
|
419
|
+
Defined in: [packages/core/src/types.ts:358](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L358)
|
|
418
420
|
|
|
419
421
|
Extract the success type `T` from a `Result`.
|
|
420
422
|
|
|
@@ -432,7 +434,7 @@ Extract the success type `T` from a `Result`.
|
|
|
432
434
|
type OkView<T, E> = ResultMethods<T, E> & object;
|
|
433
435
|
```
|
|
434
436
|
|
|
435
|
-
Defined in: [packages/core/src/types.ts:
|
|
437
|
+
Defined in: [packages/core/src/types.ts:206](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L206)
|
|
436
438
|
|
|
437
439
|
The `Ok` variant of a [Result](#result): a success carrying a `value`.
|
|
438
440
|
|
|
@@ -440,8 +442,8 @@ The `Ok` variant of a [Result](#result): a success carrying a `value`.
|
|
|
440
442
|
|
|
441
443
|
| Name | Type | Defined in |
|
|
442
444
|
| ------ | ------ | ------ |
|
|
443
|
-
| `tag` | `"Ok"` | [packages/core/src/types.ts:
|
|
444
|
-
| `value` | `T` | [packages/core/src/types.ts:
|
|
445
|
+
| `tag` | `"Ok"` | [packages/core/src/types.ts:207](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L207) |
|
|
446
|
+
| `value` | `T` | [packages/core/src/types.ts:208](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/types.ts#L208) |
|
|
445
447
|
|
|
446
448
|
#### Type Parameters
|
|
447
449
|
|
|
@@ -458,13 +460,14 @@ The `Ok` variant of a [Result](#result): a success carrying a `value`.
|
|
|
458
460
|
type Result<T, E> = ResultType<T, E>;
|
|
459
461
|
```
|
|
460
462
|
|
|
461
|
-
Defined in: [packages/core/src/facade.ts:
|
|
463
|
+
Defined in: [packages/core/src/facade.ts:42](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/facade.ts#L42)
|
|
462
464
|
|
|
463
465
|
Companion object grouping the standalone entry points under a single,
|
|
464
466
|
discoverable namespace: [Result.ok](#property-ok), [Result.err](#property-err),
|
|
465
467
|
[Result.defect](#property-defect), [Result.fromNullable](#property-fromnullable), [Result.fromThrowable](#property-fromthrowable),
|
|
466
468
|
[Result.fromPromise](#property-frompromise), [Result.fromSafePromise](#property-fromsafepromise), [Result.all](#property-all),
|
|
467
|
-
[Result.allAsync](#property-allasync), [Result.
|
|
469
|
+
[Result.allAsync](#property-allasync), [Result.allFromDict](#property-allfromdict),
|
|
470
|
+
[Result.allFromDictAsync](#property-allfromdictasync), [Result.isOk](#property-isok), [Result.isErr](#property-iserr),
|
|
468
471
|
[Result.isDefect](#property-isdefect).
|
|
469
472
|
|
|
470
473
|
#### Type Parameters
|
|
@@ -496,7 +499,7 @@ Result.ok(1).flatMap((n) => Result.ok(n + 1)).unwrap(); // 2
|
|
|
496
499
|
type TaggedErrorConstructor<Tag> = <A>(args) => TaggedErrorInstance<Tag, A>;
|
|
497
500
|
```
|
|
498
501
|
|
|
499
|
-
Defined in: [packages/core/src/tagged.ts:28](https://github.com/btravstack/unthrown/blob/
|
|
502
|
+
Defined in: [packages/core/src/tagged.ts:28](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/tagged.ts#L28)
|
|
500
503
|
|
|
501
504
|
The class constructor returned by [TaggedError](#taggederror). Generic in its payload:
|
|
502
505
|
apply it with an instantiation expression at the `extends` site.
|
|
@@ -530,7 +533,7 @@ When the payload is empty, the constructor takes **no** arguments (the
|
|
|
530
533
|
type TaggedErrorInstance<Tag, A> = Error & Readonly<A> & object;
|
|
531
534
|
```
|
|
532
535
|
|
|
533
|
-
Defined in: [packages/core/src/tagged.ts:15](https://github.com/btravstack/unthrown/blob/
|
|
536
|
+
Defined in: [packages/core/src/tagged.ts:15](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/tagged.ts#L15)
|
|
534
537
|
|
|
535
538
|
The instance shape produced by a [TaggedError](#taggederror) class: an `Error` plus a
|
|
536
539
|
`_tag` discriminant and the (readonly) payload fields.
|
|
@@ -539,7 +542,7 @@ The instance shape produced by a [TaggedError](#taggederror) class: an `Error` p
|
|
|
539
542
|
|
|
540
543
|
| Name | Type | Defined in |
|
|
541
544
|
| ------ | ------ | ------ |
|
|
542
|
-
| `_tag` | `Tag` | [packages/core/src/tagged.ts:16](https://github.com/btravstack/unthrown/blob/
|
|
545
|
+
| `_tag` | `Tag` | [packages/core/src/tagged.ts:16](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/tagged.ts#L16) |
|
|
543
546
|
|
|
544
547
|
#### Type Parameters
|
|
545
548
|
|
|
@@ -556,7 +559,7 @@ The instance shape produced by a [TaggedError](#taggederror) class: an `Error` p
|
|
|
556
559
|
type TagHandlers<T, E, R> = object & { [K in E["_tag"]]: (error: Extract<E, { _tag: K }>) => R };
|
|
557
560
|
```
|
|
558
561
|
|
|
559
|
-
Defined in: [packages/core/src/tagged.ts:103](https://github.com/btravstack/unthrown/blob/
|
|
562
|
+
Defined in: [packages/core/src/tagged.ts:103](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/tagged.ts#L103)
|
|
560
563
|
|
|
561
564
|
The handler object [matchTags](#matchtags) requires: a branch per error tag, plus
|
|
562
565
|
`Ok` and `Defect`. Miss a tag and it will not compile — the exhaustiveness is
|
|
@@ -566,8 +569,8 @@ enforced by the type, with no `.exhaustive()` to forget.
|
|
|
566
569
|
|
|
567
570
|
| Name | Type | Defined in |
|
|
568
571
|
| ------ | ------ | ------ |
|
|
569
|
-
| `Defect()` | (`cause`) => `R` | [packages/core/src/tagged.ts:105](https://github.com/btravstack/unthrown/blob/
|
|
570
|
-
| `Ok()` | (`value`) => `R` | [packages/core/src/tagged.ts:104](https://github.com/btravstack/unthrown/blob/
|
|
572
|
+
| `Defect()` | (`cause`) => `R` | [packages/core/src/tagged.ts:105](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/tagged.ts#L105) |
|
|
573
|
+
| `Ok()` | (`value`) => `R` | [packages/core/src/tagged.ts:104](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/tagged.ts#L104) |
|
|
571
574
|
|
|
572
575
|
#### Type Parameters
|
|
573
576
|
|
|
@@ -585,31 +588,34 @@ enforced by the type, with no `.exhaustive()` to forget.
|
|
|
585
588
|
const Result: object;
|
|
586
589
|
```
|
|
587
590
|
|
|
588
|
-
Defined in: [packages/core/src/facade.ts:
|
|
591
|
+
Defined in: [packages/core/src/facade.ts:42](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/facade.ts#L42)
|
|
589
592
|
|
|
590
593
|
Companion object grouping the standalone entry points under a single,
|
|
591
594
|
discoverable namespace: [Result.ok](#property-ok), [Result.err](#property-err),
|
|
592
595
|
[Result.defect](#property-defect), [Result.fromNullable](#property-fromnullable), [Result.fromThrowable](#property-fromthrowable),
|
|
593
596
|
[Result.fromPromise](#property-frompromise), [Result.fromSafePromise](#property-fromsafepromise), [Result.all](#property-all),
|
|
594
|
-
[Result.allAsync](#property-allasync), [Result.
|
|
597
|
+
[Result.allAsync](#property-allasync), [Result.allFromDict](#property-allfromdict),
|
|
598
|
+
[Result.allFromDictAsync](#property-allfromdictasync), [Result.isOk](#property-isok), [Result.isErr](#property-iserr),
|
|
595
599
|
[Result.isDefect](#property-isdefect).
|
|
596
600
|
|
|
597
601
|
#### Type Declaration
|
|
598
602
|
|
|
599
603
|
| Name | Type | Defined in |
|
|
600
604
|
| ------ | ------ | ------ |
|
|
601
|
-
| <a id="property-all"></a> `all()` | <`Rs`>(`results`) => `Result`<`AllOk`<`Rs`, \{ \[K in string \| number \| symbol\]: OkOf\<Rs\[K\]\> \}>, [`ErrOf`](#errof)<`Rs`\[`number`\]>> | [packages/core/src/facade.ts:
|
|
602
|
-
| <a id="property-allasync"></a> `allAsync()` | <`Rs`>(`results`) => [`AsyncResult`](#asyncresult)<`AllOk`<`Rs`, \{ \[K in string \| number \| symbol\]: AsyncOkOf\<Rs\[K\]\> \}>, [`AsyncErrOf`](#asyncerrof)<`Rs`\[`number`\]>> | [packages/core/src/facade.ts:
|
|
603
|
-
| <a id="property-
|
|
604
|
-
| <a id="property-
|
|
605
|
-
| <a id="property-
|
|
606
|
-
| <a id="property-
|
|
607
|
-
| <a id="property-
|
|
608
|
-
| <a id="property-
|
|
609
|
-
| <a id="property-
|
|
610
|
-
| <a id="property-
|
|
611
|
-
| <a id="property-
|
|
612
|
-
| <a id="property-
|
|
605
|
+
| <a id="property-all"></a> `all()` | <`Rs`>(`results`) => `Result`<`AllOk`<`Rs`, \{ \[K in string \| number \| symbol\]: OkOf\<Rs\[K\]\> \}>, [`ErrOf`](#errof)<`Rs`\[`number`\]>> | [packages/core/src/facade.ts:50](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/facade.ts#L50) |
|
|
606
|
+
| <a id="property-allasync"></a> `allAsync()` | <`Rs`>(`results`) => [`AsyncResult`](#asyncresult)<`AllOk`<`Rs`, \{ \[K in string \| number \| symbol\]: AsyncOkOf\<Rs\[K\]\> \}>, [`AsyncErrOf`](#asyncerrof)<`Rs`\[`number`\]>> | [packages/core/src/facade.ts:51](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/facade.ts#L51) |
|
|
607
|
+
| <a id="property-allfromdict"></a> `allFromDict()` | <`R`>(`results`) => `Result`<\{ \[K in string \| number \| symbol\]: OkOf\<R\[K\]\> \}, [`ErrOf`](#errof)<`R`\[keyof `R`\]>> | [packages/core/src/facade.ts:52](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/facade.ts#L52) |
|
|
608
|
+
| <a id="property-allfromdictasync"></a> `allFromDictAsync()` | <`R`>(`results`) => [`AsyncResult`](#asyncresult)<\{ \[K in string \| number \| symbol\]: AsyncOkOf\<R\[K\]\> \}, [`AsyncErrOf`](#asyncerrof)<`R`\[keyof `R`\]>> | [packages/core/src/facade.ts:53](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/facade.ts#L53) |
|
|
609
|
+
| <a id="property-defect"></a> `defect()` | (`cause`) => [`Defect`](#defect) | [packages/core/src/facade.ts:45](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/facade.ts#L45) |
|
|
610
|
+
| <a id="property-err"></a> `err()` | <`E`>(`error`) => `Result`<`never`, `E`> | [packages/core/src/facade.ts:44](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/facade.ts#L44) |
|
|
611
|
+
| <a id="property-fromnullable"></a> `fromNullable()` | <`T`, `E`>(`value`, `onAbsent`) => `Result`<`NonNullable`<`T`>, `E`> | [packages/core/src/facade.ts:46](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/facade.ts#L46) |
|
|
612
|
+
| <a id="property-frompromise"></a> `fromPromise()` | <`T`, `R`>(`promise`, `qualify`) => [`AsyncResult`](#asyncresult)<`T`, `Exclude`<`R`, [`Defect`](#defect)>> | [packages/core/src/facade.ts:48](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/facade.ts#L48) |
|
|
613
|
+
| <a id="property-fromsafepromise"></a> `fromSafePromise()` | <`T`>(`promise`) => [`AsyncResult`](#asyncresult)<`T`, `never`> | [packages/core/src/facade.ts:49](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/facade.ts#L49) |
|
|
614
|
+
| <a id="property-fromthrowable"></a> `fromThrowable()` | <`A`, `T`, `R`>(`fn`, `qualify`) => (...`args`) => `Result`<`T`, `Exclude`<`R`, [`Defect`](#defect)>> | [packages/core/src/facade.ts:47](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/facade.ts#L47) |
|
|
615
|
+
| <a id="property-isdefect"></a> `isDefect()` | <`T`, `E`>(`r`) => `r is DefectView<T, E>` | [packages/core/src/facade.ts:56](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/facade.ts#L56) |
|
|
616
|
+
| <a id="property-iserr"></a> `isErr()` | <`T`, `E`>(`r`) => `r is ErrView<E, T>` | [packages/core/src/facade.ts:55](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/facade.ts#L55) |
|
|
617
|
+
| <a id="property-isok"></a> `isOk()` | <`T`, `E`>(`r`) => `r is OkView<T, E>` | [packages/core/src/facade.ts:54](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/facade.ts#L54) |
|
|
618
|
+
| <a id="property-ok"></a> `ok()` | <`T`>(`value`) => `Result`<`T`, `never`> | [packages/core/src/facade.ts:43](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/facade.ts#L43) |
|
|
613
619
|
|
|
614
620
|
#### Remarks
|
|
615
621
|
|
|
@@ -633,21 +639,22 @@ Result.ok(1).flatMap((n) => Result.ok(n + 1)).unwrap(); // 2
|
|
|
633
639
|
function all<Rs>(results): Result<AllOk<Rs, { [K in string | number | symbol]: OkOf<Rs[K]> }>, ErrOf<Rs[number]>>;
|
|
634
640
|
```
|
|
635
641
|
|
|
636
|
-
Defined in: [packages/core/src/interop.ts:
|
|
642
|
+
Defined in: [packages/core/src/interop.ts:249](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/interop.ts#L249)
|
|
637
643
|
|
|
638
|
-
Collect [Result](#result)s into a single `Result` of all their
|
|
644
|
+
Collect a tuple/array of [Result](#result)s into a single `Result` of all their
|
|
645
|
+
success values.
|
|
639
646
|
|
|
640
647
|
#### Type Parameters
|
|
641
648
|
|
|
642
|
-
| Type Parameter |
|
|
643
|
-
| ------ |
|
|
644
|
-
| `Rs` *extends* readonly `Result`<`unknown`, `unknown`>[] |
|
|
649
|
+
| Type Parameter |
|
|
650
|
+
| ------ |
|
|
651
|
+
| `Rs` *extends* readonly `Result`<`unknown`, `unknown`>[] |
|
|
645
652
|
|
|
646
653
|
#### Parameters
|
|
647
654
|
|
|
648
|
-
| Parameter | Type |
|
|
649
|
-
| ------ | ------ |
|
|
650
|
-
| `results` | readonly \[`Rs`\] |
|
|
655
|
+
| Parameter | Type |
|
|
656
|
+
| ------ | ------ |
|
|
657
|
+
| `results` | readonly \[`Rs`\] |
|
|
651
658
|
|
|
652
659
|
#### Returns
|
|
653
660
|
|
|
@@ -659,7 +666,8 @@ Short-circuits on the **first** `Err` (later entries are not inspected for
|
|
|
659
666
|
their error); any `Defect` present **dominates**, winning even over an earlier
|
|
660
667
|
`Err`. A **fixed tuple** keeps its positional types — `all([ok(1), ok("a")])`
|
|
661
668
|
is `Result<[number, string], …>` — while a **dynamic array** `Result<T, E>[]`
|
|
662
|
-
collapses to `Result<T[], E>` with no cast.
|
|
669
|
+
collapses to `Result<T[], E>` with no cast. For a **record** keyed by name,
|
|
670
|
+
use [allFromDict](#allfromdict).
|
|
663
671
|
|
|
664
672
|
#### Example
|
|
665
673
|
|
|
@@ -677,22 +685,22 @@ all([ok(1), ok(2)] as Result<number, never>[]).unwrap(); // number[]
|
|
|
677
685
|
function allAsync<Rs>(results): AsyncResult<AllOk<Rs, { [K in string | number | symbol]: AsyncOkOf<Rs[K]> }>, AsyncErrOf<Rs[number]>>;
|
|
678
686
|
```
|
|
679
687
|
|
|
680
|
-
Defined in: [packages/core/src/interop.ts:
|
|
688
|
+
Defined in: [packages/core/src/interop.ts:296](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/interop.ts#L296)
|
|
681
689
|
|
|
682
|
-
The asynchronous counterpart of [all](#all): combine
|
|
683
|
-
one `AsyncResult` of all their success values.
|
|
690
|
+
The asynchronous counterpart of [all](#all): combine a tuple/array of
|
|
691
|
+
[AsyncResult](#asyncresult)s into one `AsyncResult` of all their success values.
|
|
684
692
|
|
|
685
693
|
#### Type Parameters
|
|
686
694
|
|
|
687
|
-
| Type Parameter |
|
|
688
|
-
| ------ |
|
|
689
|
-
| `Rs` *extends* readonly [`AsyncResult`](#asyncresult)<`unknown`, `unknown`>[] |
|
|
695
|
+
| Type Parameter |
|
|
696
|
+
| ------ |
|
|
697
|
+
| `Rs` *extends* readonly [`AsyncResult`](#asyncresult)<`unknown`, `unknown`>[] |
|
|
690
698
|
|
|
691
699
|
#### Parameters
|
|
692
700
|
|
|
693
|
-
| Parameter | Type |
|
|
694
|
-
| ------ | ------ |
|
|
695
|
-
| `results` | readonly \[`Rs`\] |
|
|
701
|
+
| Parameter | Type |
|
|
702
|
+
| ------ | ------ |
|
|
703
|
+
| `results` | readonly \[`Rs`\] |
|
|
696
704
|
|
|
697
705
|
#### Returns
|
|
698
706
|
|
|
@@ -700,18 +708,100 @@ one `AsyncResult` of all their success values.
|
|
|
700
708
|
|
|
701
709
|
#### Remarks
|
|
702
710
|
|
|
703
|
-
The inputs are resolved **concurrently** (
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
positional types; a **dynamic array** `AsyncResult<T, E>[]` collapses to
|
|
708
|
-
`AsyncResult<T[], E>`.
|
|
711
|
+
The inputs are resolved **concurrently** (order preserved); the resolved
|
|
712
|
+
`Result`s are then folded with the same rules as [all](#all) — first `Err`
|
|
713
|
+
short-circuits, any `Defect` dominates. As ever, the returned `AsyncResult`'s
|
|
714
|
+
internal promise never rejects. For a **record**, use [allFromDictAsync](#allfromdictasync).
|
|
709
715
|
|
|
710
716
|
#### Example
|
|
711
717
|
|
|
712
718
|
```ts
|
|
713
719
|
import { allAsync, fromSafePromise } from "unthrown";
|
|
714
|
-
|
|
720
|
+
await allAsync([fromSafePromise(a()), fromSafePromise(b())]);
|
|
721
|
+
```
|
|
722
|
+
|
|
723
|
+
***
|
|
724
|
+
|
|
725
|
+
### allFromDict()
|
|
726
|
+
|
|
727
|
+
```ts
|
|
728
|
+
function allFromDict<R>(results): Result<{ [K in string | number | symbol]: OkOf<R[K]> }, ErrOf<R[keyof R]>>;
|
|
729
|
+
```
|
|
730
|
+
|
|
731
|
+
Defined in: [packages/core/src/interop.ts:274](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/interop.ts#L274)
|
|
732
|
+
|
|
733
|
+
Collect a **record** of [Result](#result)s into a single `Result` of a record of
|
|
734
|
+
their success values — `allFromDict({ a: Result<A, E>, b: Result<B, E> })` is
|
|
735
|
+
`Result<{ a: A; b: B }, E>`. The named counterpart of [all](#all), for
|
|
736
|
+
parallel work you'd rather not tuple.
|
|
737
|
+
|
|
738
|
+
#### Type Parameters
|
|
739
|
+
|
|
740
|
+
| Type Parameter |
|
|
741
|
+
| ------ |
|
|
742
|
+
| `R` *extends* `ResultRecord` |
|
|
743
|
+
|
|
744
|
+
#### Parameters
|
|
745
|
+
|
|
746
|
+
| Parameter | Type |
|
|
747
|
+
| ------ | ------ |
|
|
748
|
+
| `results` | `R` |
|
|
749
|
+
|
|
750
|
+
#### Returns
|
|
751
|
+
|
|
752
|
+
`Result`<\{ \[K in string \| number \| symbol\]: OkOf\<R\[K\]\> \}, [`ErrOf`](#errof)<`R`\[keyof `R`\]>>
|
|
753
|
+
|
|
754
|
+
#### Remarks
|
|
755
|
+
|
|
756
|
+
Same folding rules as [all](#all): first `Err` short-circuits, any `Defect`
|
|
757
|
+
dominates. This is **not** error accumulation.
|
|
758
|
+
|
|
759
|
+
#### Example
|
|
760
|
+
|
|
761
|
+
```ts
|
|
762
|
+
import { allFromDict, ok } from "unthrown";
|
|
763
|
+
allFromDict({ id: ok(1), name: ok("ada") }).unwrap(); // { id: 1, name: "ada" }
|
|
764
|
+
```
|
|
765
|
+
|
|
766
|
+
***
|
|
767
|
+
|
|
768
|
+
### allFromDictAsync()
|
|
769
|
+
|
|
770
|
+
```ts
|
|
771
|
+
function allFromDictAsync<R>(results): AsyncResult<{ [K in string | number | symbol]: AsyncOkOf<R[K]> }, AsyncErrOf<R[keyof R]>>;
|
|
772
|
+
```
|
|
773
|
+
|
|
774
|
+
Defined in: [packages/core/src/interop.ts:324](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/interop.ts#L324)
|
|
775
|
+
|
|
776
|
+
The asynchronous counterpart of [allFromDict](#allfromdict): combine a record of
|
|
777
|
+
[AsyncResult](#asyncresult)s into one `AsyncResult` of a record of their values.
|
|
778
|
+
|
|
779
|
+
#### Type Parameters
|
|
780
|
+
|
|
781
|
+
| Type Parameter |
|
|
782
|
+
| ------ |
|
|
783
|
+
| `R` *extends* `AsyncResultRecord` |
|
|
784
|
+
|
|
785
|
+
#### Parameters
|
|
786
|
+
|
|
787
|
+
| Parameter | Type |
|
|
788
|
+
| ------ | ------ |
|
|
789
|
+
| `results` | `R` |
|
|
790
|
+
|
|
791
|
+
#### Returns
|
|
792
|
+
|
|
793
|
+
[`AsyncResult`](#asyncresult)<\{ \[K in string \| number \| symbol\]: AsyncOkOf\<R\[K\]\> \}, [`AsyncErrOf`](#asyncerrof)<`R`\[keyof `R`\]>>
|
|
794
|
+
|
|
795
|
+
#### Remarks
|
|
796
|
+
|
|
797
|
+
Resolved concurrently (order preserved), folded with the [all](#all) rules,
|
|
798
|
+
and the internal promise never rejects.
|
|
799
|
+
|
|
800
|
+
#### Example
|
|
801
|
+
|
|
802
|
+
```ts
|
|
803
|
+
import { allFromDictAsync, fromSafePromise } from "unthrown";
|
|
804
|
+
await allFromDictAsync({ a: fromSafePromise(a()), b: fromSafePromise(b()) });
|
|
715
805
|
```
|
|
716
806
|
|
|
717
807
|
***
|
|
@@ -722,7 +812,7 @@ const both = await allAsync([fromSafePromise(a()), fromSafePromise(b())]);
|
|
|
722
812
|
function defect(cause): Defect;
|
|
723
813
|
```
|
|
724
814
|
|
|
725
|
-
Defined in: [packages/core/src/defect.ts:36](https://github.com/btravstack/unthrown/blob/
|
|
815
|
+
Defined in: [packages/core/src/defect.ts:36](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/defect.ts#L36)
|
|
726
816
|
|
|
727
817
|
Wrap a cause as a [Defect](#defect) — the value you return from a `qualify`
|
|
728
818
|
function when a failure is **not** a modeled domain error.
|
|
@@ -757,7 +847,7 @@ const user = fromPromise(fetchUser(id), (cause) =>
|
|
|
757
847
|
function err<E>(error): Result<never, E>;
|
|
758
848
|
```
|
|
759
849
|
|
|
760
|
-
Defined in: [packages/core/src/constructors.ts:34](https://github.com/btravstack/unthrown/blob/
|
|
850
|
+
Defined in: [packages/core/src/constructors.ts:34](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/constructors.ts#L34)
|
|
761
851
|
|
|
762
852
|
Construct a failed [Result](#result) carrying a **modeled** error.
|
|
763
853
|
|
|
@@ -792,7 +882,7 @@ err("not_found").unwrapErr(); // "not_found"
|
|
|
792
882
|
function fromNullable<T, E>(value, onAbsent): Result<NonNullable<T>, E>;
|
|
793
883
|
```
|
|
794
884
|
|
|
795
|
-
Defined in: [packages/core/src/interop.ts:29](https://github.com/btravstack/unthrown/blob/
|
|
885
|
+
Defined in: [packages/core/src/interop.ts:29](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/interop.ts#L29)
|
|
796
886
|
|
|
797
887
|
Bridge a nullable value into a [Result](#result): absence becomes a **modeled**
|
|
798
888
|
`Err`. The sanctioned alternative to an `Option` type.
|
|
@@ -835,7 +925,7 @@ fromNullable(map.get(key), () => "missing").unwrap();
|
|
|
835
925
|
function fromPromise<T, R>(promise, qualify): AsyncResult<T, Exclude<R, Defect>>;
|
|
836
926
|
```
|
|
837
927
|
|
|
838
|
-
Defined in: [packages/core/src/interop.ts:110](https://github.com/btravstack/unthrown/blob/
|
|
928
|
+
Defined in: [packages/core/src/interop.ts:110](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/interop.ts#L110)
|
|
839
929
|
|
|
840
930
|
Wrap a `Promise` (or a thunk producing one) as an [AsyncResult](#asyncresult), forcing
|
|
841
931
|
every rejection to be triaged.
|
|
@@ -887,7 +977,7 @@ const user = await fromPromise(fetchUser(id), (cause) =>
|
|
|
887
977
|
function fromSafePromise<T>(promise): AsyncResult<T, never>;
|
|
888
978
|
```
|
|
889
979
|
|
|
890
|
-
Defined in: [packages/core/src/interop.ts:136](https://github.com/btravstack/unthrown/blob/
|
|
980
|
+
Defined in: [packages/core/src/interop.ts:136](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/interop.ts#L136)
|
|
891
981
|
|
|
892
982
|
Wrap a `Promise` asserted **not** to fail in any modeled way: any rejection
|
|
893
983
|
becomes a `Defect`.
|
|
@@ -922,7 +1012,7 @@ triage. (`await`-ing still yields a `Result`; it never throws.)
|
|
|
922
1012
|
function fromThrowable<A, T, R>(fn, qualify): (...args) => Result<T, Exclude<R, Defect>>;
|
|
923
1013
|
```
|
|
924
1014
|
|
|
925
|
-
Defined in: [packages/core/src/interop.ts:66](https://github.com/btravstack/unthrown/blob/
|
|
1015
|
+
Defined in: [packages/core/src/interop.ts:66](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/interop.ts#L66)
|
|
926
1016
|
|
|
927
1017
|
Wrap a throwing synchronous function so it returns a [Result](#result) instead of
|
|
928
1018
|
throwing.
|
|
@@ -976,7 +1066,7 @@ parse("{}").unwrap();
|
|
|
976
1066
|
function isDefect<T, E>(r): r is DefectView<T, E>;
|
|
977
1067
|
```
|
|
978
1068
|
|
|
979
|
-
Defined in: [packages/core/src/constructors.ts:66](https://github.com/btravstack/unthrown/blob/
|
|
1069
|
+
Defined in: [packages/core/src/constructors.ts:66](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/constructors.ts#L66)
|
|
980
1070
|
|
|
981
1071
|
Type guard: narrow a [Result](#result) to its `Defect` variant, exposing `.cause`.
|
|
982
1072
|
|
|
@@ -1007,7 +1097,7 @@ Type guard: narrow a [Result](#result) to its `Defect` variant, exposing `.cause
|
|
|
1007
1097
|
function isErr<T, E>(r): r is ErrView<E, T>;
|
|
1008
1098
|
```
|
|
1009
1099
|
|
|
1010
|
-
Defined in: [packages/core/src/constructors.ts:58](https://github.com/btravstack/unthrown/blob/
|
|
1100
|
+
Defined in: [packages/core/src/constructors.ts:58](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/constructors.ts#L58)
|
|
1011
1101
|
|
|
1012
1102
|
Type guard: narrow a [Result](#result) to its `Err` variant, exposing `.error`.
|
|
1013
1103
|
|
|
@@ -1038,7 +1128,7 @@ Type guard: narrow a [Result](#result) to its `Err` variant, exposing `.error`.
|
|
|
1038
1128
|
function isOk<T, E>(r): r is OkView<T, E>;
|
|
1039
1129
|
```
|
|
1040
1130
|
|
|
1041
|
-
Defined in: [packages/core/src/constructors.ts:50](https://github.com/btravstack/unthrown/blob/
|
|
1131
|
+
Defined in: [packages/core/src/constructors.ts:50](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/constructors.ts#L50)
|
|
1042
1132
|
|
|
1043
1133
|
Type guard: narrow a [Result](#result) to its `Ok` variant, exposing `.value`.
|
|
1044
1134
|
|
|
@@ -1079,7 +1169,7 @@ if (isOk(r)) r.value; // number, narrowed
|
|
|
1079
1169
|
function matchTags<T, E, R>(result, handlers): R;
|
|
1080
1170
|
```
|
|
1081
1171
|
|
|
1082
|
-
Defined in: [packages/core/src/tagged.ts:138](https://github.com/btravstack/unthrown/blob/
|
|
1172
|
+
Defined in: [packages/core/src/tagged.ts:138](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/tagged.ts#L138)
|
|
1083
1173
|
|
|
1084
1174
|
Exhaustively fold a [Result](#result) (or [AsyncResult](#asyncresult)) whose error type is
|
|
1085
1175
|
a tagged union, dispatching each error to the handler matching its `_tag`.
|
|
@@ -1131,7 +1221,7 @@ matchTags(r, {
|
|
|
1131
1221
|
function matchTags<T, E, R>(result, handlers): Promise<R>;
|
|
1132
1222
|
```
|
|
1133
1223
|
|
|
1134
|
-
Defined in: [packages/core/src/tagged.ts:142](https://github.com/btravstack/unthrown/blob/
|
|
1224
|
+
Defined in: [packages/core/src/tagged.ts:142](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/tagged.ts#L142)
|
|
1135
1225
|
|
|
1136
1226
|
Exhaustively fold a [Result](#result) (or [AsyncResult](#asyncresult)) whose error type is
|
|
1137
1227
|
a tagged union, dispatching each error to the handler matching its `_tag`.
|
|
@@ -1185,7 +1275,7 @@ matchTags(r, {
|
|
|
1185
1275
|
function ok<T>(value): Result<T, never>;
|
|
1186
1276
|
```
|
|
1187
1277
|
|
|
1188
|
-
Defined in: [packages/core/src/constructors.ts:18](https://github.com/btravstack/unthrown/blob/
|
|
1278
|
+
Defined in: [packages/core/src/constructors.ts:18](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/constructors.ts#L18)
|
|
1189
1279
|
|
|
1190
1280
|
Construct a successful [Result](#result).
|
|
1191
1281
|
|
|
@@ -1220,7 +1310,7 @@ ok(42).unwrap(); // 42
|
|
|
1220
1310
|
function TaggedError<Tag>(tag, options?): TaggedErrorConstructor<Tag>;
|
|
1221
1311
|
```
|
|
1222
1312
|
|
|
1223
|
-
Defined in: [packages/core/src/tagged.ts:72](https://github.com/btravstack/unthrown/blob/
|
|
1313
|
+
Defined in: [packages/core/src/tagged.ts:72](https://github.com/btravstack/unthrown/blob/1e34025e0177665dde9c50faca313fd1b95e5545/packages/core/src/tagged.ts#L72)
|
|
1224
1314
|
|
|
1225
1315
|
Build a base class for a tagged error — a class extending `Error` with a
|
|
1226
1316
|
`_tag` string discriminant, in the style of Effect's `Data.TaggedError`.
|