unthrown 1.1.0 → 2.0.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 +38 -11
- package/dist/index.d.cts +63 -36
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +63 -36
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +38 -12
- package/dist/index.mjs.map +1 -1
- package/docs/index.md +150 -127
- 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:30](https://github.com/btravstack/unthrown/blob/
|
|
11
|
+
Defined in: [packages/core/src/core.ts:30](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/core.ts#L30)
|
|
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:36](https://github.com/btravstack/unthrown/blob/
|
|
40
|
+
Defined in: [packages/core/src/core.ts:36](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/core.ts#L36)
|
|
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:35](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:35](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/core.ts#L35) |
|
|
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:468](https://github.com/btravstack/unthrown/blob/
|
|
177
|
+
Defined in: [packages/core/src/types.ts:468](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/types.ts#L468)
|
|
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:462](https://github.com/btravstack/unthrown/blob/
|
|
195
|
+
Defined in: [packages/core/src/types.ts:462](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/types.ts#L462)
|
|
196
196
|
|
|
197
197
|
Extract the success type `T` from an [AsyncResult](#asyncresult).
|
|
198
198
|
|
|
@@ -207,59 +207,39 @@ Extract the success type `T` from an [AsyncResult](#asyncresult).
|
|
|
207
207
|
### AsyncResult
|
|
208
208
|
|
|
209
209
|
```ts
|
|
210
|
-
type AsyncResult<T, E> =
|
|
210
|
+
type AsyncResult<T, E> = AsyncResultType<T, E>;
|
|
211
211
|
```
|
|
212
212
|
|
|
213
|
-
Defined in: [packages/core/src/
|
|
213
|
+
Defined in: [packages/core/src/facade.ts:88](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/facade.ts#L88)
|
|
214
214
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
| Name | Type | Description | Defined in |
|
|
221
|
-
| ------ | ------ | ------ | ------ |
|
|
222
|
-
| `as()` | (`value`) => [`AsyncResult`](#asyncresult)<`U`, `E`> | Asynchronous `as`. | [packages/core/src/types.ts:398](https://github.com/btravstack/unthrown/blob/8424c0f1e5d5b49a3cb6853d52fb8d5085bd4701/packages/core/src/types.ts#L398) |
|
|
223
|
-
| `bind()` | (`name`, `f`) => [`AsyncResult`](#asyncresult)<\{ \[K in string \| number \| symbol\]: (Omit\<T, K\> & \{ readonly \[P in string\]: U \})\[K\] \}, `E` \| `E2`> | Asynchronous `bind` (do-notation). `f` may return a `Result` **or** an `AsyncResult`; its value is bound under `name` in the accumulating scope. | [packages/core/src/types.ts:391](https://github.com/btravstack/unthrown/blob/8424c0f1e5d5b49a3cb6853d52fb8d5085bd4701/packages/core/src/types.ts#L391) |
|
|
224
|
-
| `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:376](https://github.com/btravstack/unthrown/blob/8424c0f1e5d5b49a3cb6853d52fb8d5085bd4701/packages/core/src/types.ts#L376) |
|
|
225
|
-
| `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:384](https://github.com/btravstack/unthrown/blob/8424c0f1e5d5b49a3cb6853d52fb8d5085bd4701/packages/core/src/types.ts#L384) |
|
|
226
|
-
| `flatTapErr()` | (`f`) => [`AsyncResult`](#asyncresult)<`T`, `E` \| `E2`> | Asynchronous `flatTapErr` — a failable tap on the error that keeps the original error. `f` may return a `Result` **or** an `AsyncResult`; its `Ok` value is discarded, an `Err`/`Defect` from `f` threads through, and a throw becomes a `Defect`. | [packages/core/src/types.ts:414](https://github.com/btravstack/unthrown/blob/8424c0f1e5d5b49a3cb6853d52fb8d5085bd4701/packages/core/src/types.ts#L414) |
|
|
227
|
-
| `getOrNull()` | () => `Promise`<`T` \| `null`> | Asynchronous `getOrNull`. | [packages/core/src/types.ts:440](https://github.com/btravstack/unthrown/blob/8424c0f1e5d5b49a3cb6853d52fb8d5085bd4701/packages/core/src/types.ts#L440) |
|
|
228
|
-
| `getOrUndefined()` | () => `Promise`<`T` \| `undefined`> | Asynchronous `getOrUndefined`. | [packages/core/src/types.ts:442](https://github.com/btravstack/unthrown/blob/8424c0f1e5d5b49a3cb6853d52fb8d5085bd4701/packages/core/src/types.ts#L442) |
|
|
229
|
-
| `let()` | (`name`, `f`) => [`AsyncResult`](#asyncresult)<\{ \[K in string \| number \| symbol\]: (Omit\<T, K\> & \{ readonly \[P in string\]: U \})\[K\] \}, `E`> | Asynchronous `let` (do-notation). `f` returns a plain value, bound under `name`. | [packages/core/src/types.ts:396](https://github.com/btravstack/unthrown/blob/8424c0f1e5d5b49a3cb6853d52fb8d5085bd4701/packages/core/src/types.ts#L396) |
|
|
230
|
-
| `map()` | (`f`) => [`AsyncResult`](#asyncresult)<`U`, `E`> | Asynchronous `map`. `f` is synchronous; a throw becomes a `Defect`. | [packages/core/src/types.ts:371](https://github.com/btravstack/unthrown/blob/8424c0f1e5d5b49a3cb6853d52fb8d5085bd4701/packages/core/src/types.ts#L371) |
|
|
231
|
-
| `mapErr()` | (`f`) => [`AsyncResult`](#asyncresult)<`T`, `E2`> | Asynchronous `mapErr`. `f` is synchronous; a throw becomes a `Defect`. | [packages/core/src/types.ts:401](https://github.com/btravstack/unthrown/blob/8424c0f1e5d5b49a3cb6853d52fb8d5085bd4701/packages/core/src/types.ts#L401) |
|
|
232
|
-
| `match()` | (`cases`) => `Promise`<`R`> | Asynchronous `match`. Handlers are synchronous; resolves to `R`. | [packages/core/src/types.ts:426](https://github.com/btravstack/unthrown/blob/8424c0f1e5d5b49a3cb6853d52fb8d5085bd4701/packages/core/src/types.ts#L426) |
|
|
233
|
-
| `orElse()` | (`f`) => [`AsyncResult`](#asyncresult)<`T` \| `U`, `E2`> | Asynchronous `orElse`. `f` may return a `Result` or an `AsyncResult`. | [packages/core/src/types.ts:403](https://github.com/btravstack/unthrown/blob/8424c0f1e5d5b49a3cb6853d52fb8d5085bd4701/packages/core/src/types.ts#L403) |
|
|
234
|
-
| `recover()` | (`f`) => [`AsyncResult`](#asyncresult)<`T` \| `U`, `never`> | Asynchronous `recover`. `f` is synchronous; a throw becomes a `Defect`. | [packages/core/src/types.ts:405](https://github.com/btravstack/unthrown/blob/8424c0f1e5d5b49a3cb6853d52fb8d5085bd4701/packages/core/src/types.ts#L405) |
|
|
235
|
-
| `recoverDefect()` | (`f`) => [`AsyncResult`](#asyncresult)<`T` \| `U`, `E` \| `E2`> | Asynchronous `recoverDefect`. `f` may return a `Result` or an `AsyncResult`. | [packages/core/src/types.ts:419](https://github.com/btravstack/unthrown/blob/8424c0f1e5d5b49a3cb6853d52fb8d5085bd4701/packages/core/src/types.ts#L419) |
|
|
236
|
-
| `tap()` | (`f`) => [`AsyncResult`](#asyncresult)<`T`, `E`> | Asynchronous `tap`. `f` is synchronous; a throw becomes a `Defect`. | [packages/core/src/types.ts:378](https://github.com/btravstack/unthrown/blob/8424c0f1e5d5b49a3cb6853d52fb8d5085bd4701/packages/core/src/types.ts#L378) |
|
|
237
|
-
| `tapDefect()` | (`f`) => [`AsyncResult`](#asyncresult)<`T`, `E`> | Asynchronous `tapDefect`. | [packages/core/src/types.ts:423](https://github.com/btravstack/unthrown/blob/8424c0f1e5d5b49a3cb6853d52fb8d5085bd4701/packages/core/src/types.ts#L423) |
|
|
238
|
-
| `tapErr()` | (`f`) => [`AsyncResult`](#asyncresult)<`T`, `E`> | Asynchronous `tapErr`. `f` is synchronous; a throw becomes a `Defect`. | [packages/core/src/types.ts:407](https://github.com/btravstack/unthrown/blob/8424c0f1e5d5b49a3cb6853d52fb8d5085bd4701/packages/core/src/types.ts#L407) |
|
|
239
|
-
| `unwrap()` | () => `Promise`<`T`> | Asynchronous `unwrap`. The returned promise rejects on `Err`/`Defect`. | [packages/core/src/types.ts:432](https://github.com/btravstack/unthrown/blob/8424c0f1e5d5b49a3cb6853d52fb8d5085bd4701/packages/core/src/types.ts#L432) |
|
|
240
|
-
| `unwrapErr()` | () => `Promise`<`E`> | Asynchronous `unwrapErr`. | [packages/core/src/types.ts:434](https://github.com/btravstack/unthrown/blob/8424c0f1e5d5b49a3cb6853d52fb8d5085bd4701/packages/core/src/types.ts#L434) |
|
|
241
|
-
| `unwrapOr()` | (`fallback`) => `Promise`<`T`> | Asynchronous `unwrapOr`. | [packages/core/src/types.ts:436](https://github.com/btravstack/unthrown/blob/8424c0f1e5d5b49a3cb6853d52fb8d5085bd4701/packages/core/src/types.ts#L436) |
|
|
242
|
-
| `unwrapOrElse()` | (`f`) => `Promise`<`T`> | Asynchronous `unwrapOrElse`. | [packages/core/src/types.ts:438](https://github.com/btravstack/unthrown/blob/8424c0f1e5d5b49a3cb6853d52fb8d5085bd4701/packages/core/src/types.ts#L438) |
|
|
215
|
+
Companion object grouping the **`AsyncResult`-producing** entry points under
|
|
216
|
+
the matching namespace: [AsyncResult.fromPromise](#property-frompromise),
|
|
217
|
+
[AsyncResult.fromSafePromise](#property-fromsafepromise), [AsyncResult.all](#property-all),
|
|
218
|
+
[AsyncResult.allFromDict](#property-allfromdict).
|
|
243
219
|
|
|
244
220
|
#### Type Parameters
|
|
245
221
|
|
|
246
|
-
| Type Parameter |
|
|
247
|
-
| ------ |
|
|
248
|
-
| `T` |
|
|
249
|
-
| `E` |
|
|
222
|
+
| Type Parameter |
|
|
223
|
+
| ------ |
|
|
224
|
+
| `T` |
|
|
225
|
+
| `E` |
|
|
250
226
|
|
|
251
227
|
#### Remarks
|
|
252
228
|
|
|
253
|
-
|
|
254
|
-
`
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
`AsyncResult`.
|
|
229
|
+
The async sibling of [Result](#result-1). Statics are grouped by what they
|
|
230
|
+
**return**, so `fromPromise`/`fromSafePromise` and the async aggregates sit
|
|
231
|
+
here rather than on [Result](#result-1); the namespace already conveys "async", so
|
|
232
|
+
the aggregates drop the `Async` suffix (`AsyncResult.all` is the free function
|
|
233
|
+
`allAsync`; `AsyncResult.allFromDict` is `allFromDictAsync`). Like
|
|
234
|
+
[Result](#result-1), the free functions remain the primary, tree-shakeable API; the
|
|
235
|
+
value `AsyncResult` and the type [AsyncResult](#asyncresult-1) share one name.
|
|
261
236
|
|
|
262
|
-
|
|
237
|
+
#### Example
|
|
238
|
+
|
|
239
|
+
```ts
|
|
240
|
+
import { AsyncResult, Defect } from "unthrown";
|
|
241
|
+
const user = await AsyncResult.fromPromise(fetchUser(id), (c) => Defect(c));
|
|
242
|
+
```
|
|
263
243
|
|
|
264
244
|
***
|
|
265
245
|
|
|
@@ -269,7 +249,7 @@ To pattern-match an `AsyncResult`, `await` it first: `match(await ar)`.
|
|
|
269
249
|
type Awaitable<T> = object;
|
|
270
250
|
```
|
|
271
251
|
|
|
272
|
-
Defined in: [packages/core/src/types.ts:346](https://github.com/btravstack/unthrown/blob/
|
|
252
|
+
Defined in: [packages/core/src/types.ts:346](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/types.ts#L346)
|
|
273
253
|
|
|
274
254
|
A success-only thenable: awaitable, but deliberately **not** a full
|
|
275
255
|
`PromiseLike`.
|
|
@@ -296,7 +276,7 @@ being treated as a raw promise (e.g. dropped into `Promise.all`).
|
|
|
296
276
|
then<R>(onfulfilled?): PromiseLike<R>;
|
|
297
277
|
```
|
|
298
278
|
|
|
299
|
-
Defined in: [packages/core/src/types.ts:347](https://github.com/btravstack/unthrown/blob/
|
|
279
|
+
Defined in: [packages/core/src/types.ts:347](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/types.ts#L347)
|
|
300
280
|
|
|
301
281
|
###### Type Parameters
|
|
302
282
|
|
|
@@ -322,7 +302,7 @@ Defined in: [packages/core/src/types.ts:347](https://github.com/btravstack/unthr
|
|
|
322
302
|
type Defect = object;
|
|
323
303
|
```
|
|
324
304
|
|
|
325
|
-
Defined in: [packages/core/src/defect.ts:36](https://github.com/btravstack/unthrown/blob/
|
|
305
|
+
Defined in: [packages/core/src/defect.ts:36](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/defect.ts#L36)
|
|
326
306
|
|
|
327
307
|
The marker a `qualify` function returns to triage a cause as **unexpected**.
|
|
328
308
|
|
|
@@ -338,8 +318,8 @@ runtime state of a `Result`.
|
|
|
338
318
|
|
|
339
319
|
| Property | Modifier | Type | Defined in |
|
|
340
320
|
| ------ | ------ | ------ | ------ |
|
|
341
|
-
| <a id="defect-1"></a> `[DEFECT]` | `readonly` | `true` | [packages/core/src/defect.ts:16](https://github.com/btravstack/unthrown/blob/
|
|
342
|
-
| <a id="cause-1"></a> `cause` | `readonly` | `unknown` | [packages/core/src/defect.ts:17](https://github.com/btravstack/unthrown/blob/
|
|
321
|
+
| <a id="defect-1"></a> `[DEFECT]` | `readonly` | `true` | [packages/core/src/defect.ts:16](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/defect.ts#L16) |
|
|
322
|
+
| <a id="cause-1"></a> `cause` | `readonly` | `unknown` | [packages/core/src/defect.ts:17](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/defect.ts#L17) |
|
|
343
323
|
|
|
344
324
|
***
|
|
345
325
|
|
|
@@ -349,7 +329,7 @@ runtime state of a `Result`.
|
|
|
349
329
|
type DefectView<T, E> = ResultMethods<T, E> & object;
|
|
350
330
|
```
|
|
351
331
|
|
|
352
|
-
Defined in: [packages/core/src/types.ts:289](https://github.com/btravstack/unthrown/blob/
|
|
332
|
+
Defined in: [packages/core/src/types.ts:289](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/types.ts#L289)
|
|
353
333
|
|
|
354
334
|
The `Defect` variant of a [Result](#result): an unmodeled failure carrying a `cause`.
|
|
355
335
|
|
|
@@ -357,8 +337,8 @@ The `Defect` variant of a [Result](#result): an unmodeled failure carrying a `ca
|
|
|
357
337
|
|
|
358
338
|
| Name | Type | Defined in |
|
|
359
339
|
| ------ | ------ | ------ |
|
|
360
|
-
| `cause` | `unknown` | [packages/core/src/types.ts:291](https://github.com/btravstack/unthrown/blob/
|
|
361
|
-
| `tag` | `"Defect"` | [packages/core/src/types.ts:290](https://github.com/btravstack/unthrown/blob/
|
|
340
|
+
| `cause` | `unknown` | [packages/core/src/types.ts:291](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/types.ts#L291) |
|
|
341
|
+
| `tag` | `"Defect"` | [packages/core/src/types.ts:290](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/types.ts#L290) |
|
|
362
342
|
|
|
363
343
|
#### Type Parameters
|
|
364
344
|
|
|
@@ -375,7 +355,7 @@ The `Defect` variant of a [Result](#result): an unmodeled failure carrying a `ca
|
|
|
375
355
|
type ErrOf<R> = R extends object ? E : never;
|
|
376
356
|
```
|
|
377
357
|
|
|
378
|
-
Defined in: [packages/core/src/types.ts:456](https://github.com/btravstack/unthrown/blob/
|
|
358
|
+
Defined in: [packages/core/src/types.ts:456](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/types.ts#L456)
|
|
379
359
|
|
|
380
360
|
Extract the error type `E` from a `Result`.
|
|
381
361
|
|
|
@@ -393,7 +373,7 @@ Extract the error type `E` from a `Result`.
|
|
|
393
373
|
type ErrView<E, T> = ResultMethods<T, E> & object;
|
|
394
374
|
```
|
|
395
375
|
|
|
396
|
-
Defined in: [packages/core/src/types.ts:284](https://github.com/btravstack/unthrown/blob/
|
|
376
|
+
Defined in: [packages/core/src/types.ts:284](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/types.ts#L284)
|
|
397
377
|
|
|
398
378
|
The `Err` variant of a [Result](#result): a modeled failure carrying an `error`.
|
|
399
379
|
|
|
@@ -401,8 +381,8 @@ The `Err` variant of a [Result](#result): a modeled failure carrying an `error`.
|
|
|
401
381
|
|
|
402
382
|
| Name | Type | Defined in |
|
|
403
383
|
| ------ | ------ | ------ |
|
|
404
|
-
| `error` | `E` | [packages/core/src/types.ts:286](https://github.com/btravstack/unthrown/blob/
|
|
405
|
-
| `tag` | `"Err"` | [packages/core/src/types.ts:285](https://github.com/btravstack/unthrown/blob/
|
|
384
|
+
| `error` | `E` | [packages/core/src/types.ts:286](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/types.ts#L286) |
|
|
385
|
+
| `tag` | `"Err"` | [packages/core/src/types.ts:285](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/types.ts#L285) |
|
|
406
386
|
|
|
407
387
|
#### Type Parameters
|
|
408
388
|
|
|
@@ -419,7 +399,7 @@ The `Err` variant of a [Result](#result): a modeled failure carrying an `error`.
|
|
|
419
399
|
type OkOf<R> = R extends object ? T : never;
|
|
420
400
|
```
|
|
421
401
|
|
|
422
|
-
Defined in: [packages/core/src/types.ts:450](https://github.com/btravstack/unthrown/blob/
|
|
402
|
+
Defined in: [packages/core/src/types.ts:450](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/types.ts#L450)
|
|
423
403
|
|
|
424
404
|
Extract the success type `T` from a `Result`.
|
|
425
405
|
|
|
@@ -437,7 +417,7 @@ Extract the success type `T` from a `Result`.
|
|
|
437
417
|
type OkView<T, E> = ResultMethods<T, E> & object;
|
|
438
418
|
```
|
|
439
419
|
|
|
440
|
-
Defined in: [packages/core/src/types.ts:279](https://github.com/btravstack/unthrown/blob/
|
|
420
|
+
Defined in: [packages/core/src/types.ts:279](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/types.ts#L279)
|
|
441
421
|
|
|
442
422
|
The `Ok` variant of a [Result](#result): a success carrying a `value`.
|
|
443
423
|
|
|
@@ -445,8 +425,8 @@ The `Ok` variant of a [Result](#result): a success carrying a `value`.
|
|
|
445
425
|
|
|
446
426
|
| Name | Type | Defined in |
|
|
447
427
|
| ------ | ------ | ------ |
|
|
448
|
-
| `tag` | `"Ok"` | [packages/core/src/types.ts:280](https://github.com/btravstack/unthrown/blob/
|
|
449
|
-
| `value` | `T` | [packages/core/src/types.ts:281](https://github.com/btravstack/unthrown/blob/
|
|
428
|
+
| `tag` | `"Ok"` | [packages/core/src/types.ts:280](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/types.ts#L280) |
|
|
429
|
+
| `value` | `T` | [packages/core/src/types.ts:281](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/types.ts#L281) |
|
|
450
430
|
|
|
451
431
|
#### Type Parameters
|
|
452
432
|
|
|
@@ -463,15 +443,14 @@ The `Ok` variant of a [Result](#result): a success carrying a `value`.
|
|
|
463
443
|
type Result<T, E> = ResultType<T, E>;
|
|
464
444
|
```
|
|
465
445
|
|
|
466
|
-
Defined in: [packages/core/src/facade.ts:
|
|
446
|
+
Defined in: [packages/core/src/facade.ts:47](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/facade.ts#L47)
|
|
467
447
|
|
|
468
|
-
Companion object grouping the
|
|
469
|
-
discoverable namespace: [Result.Ok](#property-ok), [Result.Err](#property-err),
|
|
470
|
-
[Result.Defect](#property-defect), [Result.
|
|
471
|
-
[Result.
|
|
472
|
-
[Result.
|
|
473
|
-
[Result.
|
|
474
|
-
[Result.isDefect](#property-isdefect), [Result.isResult](#property-isresult).
|
|
448
|
+
Companion object grouping the **`Result`-producing** entry points under a
|
|
449
|
+
single, discoverable namespace: [Result.Ok](#property-ok), [Result.Err](#property-err),
|
|
450
|
+
[Result.Defect](#property-defect), [Result.Do](#property-do), [Result.fromNullable](#property-fromnullable),
|
|
451
|
+
[Result.fromThrowable](#property-fromthrowable), [Result.all](#property-all-1), [Result.allFromDict](#property-allfromdict-1),
|
|
452
|
+
[Result.isOk](#property-isok), [Result.isErr](#property-iserr), [Result.isDefect](#property-isdefect),
|
|
453
|
+
[Result.isResult](#property-isresult).
|
|
475
454
|
|
|
476
455
|
#### Type Parameters
|
|
477
456
|
|
|
@@ -487,6 +466,10 @@ The free functions remain the primary, tree-shakeable API; importing only
|
|
|
487
466
|
`{ Ok }` never pulls this object in. The value `Result` and the type
|
|
488
467
|
[Result](#result-1) share one name (the companion-object pattern).
|
|
489
468
|
|
|
469
|
+
The **async** entry points live on the sibling [AsyncResult](#asyncresult-1) companion
|
|
470
|
+
(`AsyncResult.fromPromise`, `AsyncResult.all`, …), grouped by what they
|
|
471
|
+
return — a static lives in exactly one namespace.
|
|
472
|
+
|
|
490
473
|
#### Example
|
|
491
474
|
|
|
492
475
|
```ts
|
|
@@ -502,7 +485,7 @@ Result.Ok(1).flatMap((n) => Result.Ok(n + 1)).unwrap(); // 2
|
|
|
502
485
|
type TaggedErrorConstructor<Tag> = <A>(args) => TaggedErrorInstance<Tag, A>;
|
|
503
486
|
```
|
|
504
487
|
|
|
505
|
-
Defined in: [packages/core/src/tagged.ts:28](https://github.com/btravstack/unthrown/blob/
|
|
488
|
+
Defined in: [packages/core/src/tagged.ts:28](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/tagged.ts#L28)
|
|
506
489
|
|
|
507
490
|
The class constructor returned by [TaggedError](#taggederror). Generic in its payload:
|
|
508
491
|
apply it with an instantiation expression at the `extends` site.
|
|
@@ -536,7 +519,7 @@ When the payload is empty, the constructor takes **no** arguments (the
|
|
|
536
519
|
type TaggedErrorInstance<Tag, A> = Error & Readonly<A> & object;
|
|
537
520
|
```
|
|
538
521
|
|
|
539
|
-
Defined in: [packages/core/src/tagged.ts:15](https://github.com/btravstack/unthrown/blob/
|
|
522
|
+
Defined in: [packages/core/src/tagged.ts:15](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/tagged.ts#L15)
|
|
540
523
|
|
|
541
524
|
The instance shape produced by a [TaggedError](#taggederror) class: an `Error` plus a
|
|
542
525
|
`_tag` discriminant and the (readonly) payload fields.
|
|
@@ -545,7 +528,7 @@ The instance shape produced by a [TaggedError](#taggederror) class: an `Error` p
|
|
|
545
528
|
|
|
546
529
|
| Name | Type | Defined in |
|
|
547
530
|
| ------ | ------ | ------ |
|
|
548
|
-
| `_tag` | `Tag` | [packages/core/src/tagged.ts:16](https://github.com/btravstack/unthrown/blob/
|
|
531
|
+
| `_tag` | `Tag` | [packages/core/src/tagged.ts:16](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/tagged.ts#L16) |
|
|
549
532
|
|
|
550
533
|
#### Type Parameters
|
|
551
534
|
|
|
@@ -562,7 +545,7 @@ The instance shape produced by a [TaggedError](#taggederror) class: an `Error` p
|
|
|
562
545
|
type TagHandlers<T, E, R> = object & { [K in E["_tag"]]: (error: Extract<E, { _tag: K }>) => R };
|
|
563
546
|
```
|
|
564
547
|
|
|
565
|
-
Defined in: [packages/core/src/tagged.ts:103](https://github.com/btravstack/unthrown/blob/
|
|
548
|
+
Defined in: [packages/core/src/tagged.ts:103](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/tagged.ts#L103)
|
|
566
549
|
|
|
567
550
|
The handler object [matchTags](#matchtags) requires: a branch per error tag, plus
|
|
568
551
|
`Ok` and `Defect`. Miss a tag and it will not compile — the exhaustiveness is
|
|
@@ -572,8 +555,8 @@ enforced by the type, with no `.exhaustive()` to forget.
|
|
|
572
555
|
|
|
573
556
|
| Name | Type | Defined in |
|
|
574
557
|
| ------ | ------ | ------ |
|
|
575
|
-
| `Defect()` | (`cause`) => `R` | [packages/core/src/tagged.ts:105](https://github.com/btravstack/unthrown/blob/
|
|
576
|
-
| `Ok()` | (`value`) => `R` | [packages/core/src/tagged.ts:104](https://github.com/btravstack/unthrown/blob/
|
|
558
|
+
| `Defect()` | (`cause`) => `R` | [packages/core/src/tagged.ts:105](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/tagged.ts#L105) |
|
|
559
|
+
| `Ok()` | (`value`) => `R` | [packages/core/src/tagged.ts:104](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/tagged.ts#L104) |
|
|
577
560
|
|
|
578
561
|
#### Type Parameters
|
|
579
562
|
|
|
@@ -585,42 +568,78 @@ enforced by the type, with no `.exhaustive()` to forget.
|
|
|
585
568
|
|
|
586
569
|
## Variables
|
|
587
570
|
|
|
571
|
+
### AsyncResult
|
|
572
|
+
|
|
573
|
+
```ts
|
|
574
|
+
const AsyncResult: object;
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
Defined in: [packages/core/src/facade.ts:88](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/facade.ts#L88)
|
|
578
|
+
|
|
579
|
+
Companion object grouping the **`AsyncResult`-producing** entry points under
|
|
580
|
+
the matching namespace: [AsyncResult.fromPromise](#property-frompromise),
|
|
581
|
+
[AsyncResult.fromSafePromise](#property-fromsafepromise), [AsyncResult.all](#property-all),
|
|
582
|
+
[AsyncResult.allFromDict](#property-allfromdict).
|
|
583
|
+
|
|
584
|
+
#### Type Declaration
|
|
585
|
+
|
|
586
|
+
| Name | Type | Default value | Defined in |
|
|
587
|
+
| ------ | ------ | ------ | ------ |
|
|
588
|
+
| <a id="property-all"></a> `all()` | <`Rs`>(`results`) => `AsyncResult`<`AllOk`<`Rs`, \{ \[K in string \| number \| symbol\]: AsyncOkOf\<Rs\[K\]\> \}>, [`AsyncErrOf`](#asyncerrof)<`Rs`\[`number`\]>> | `allAsync` | [packages/core/src/facade.ts:91](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/facade.ts#L91) |
|
|
589
|
+
| <a id="property-allfromdict"></a> `allFromDict()` | <`R`>(`results`) => `AsyncResult`<\{ \[K in string \| number \| symbol\]: AsyncOkOf\<R\[K\]\> \}, [`AsyncErrOf`](#asyncerrof)<`R`\[keyof `R`\]>> | `allFromDictAsync` | [packages/core/src/facade.ts:92](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/facade.ts#L92) |
|
|
590
|
+
| <a id="property-frompromise"></a> `fromPromise()` | <`T`, `R`>(`promise`, `qualify`) => `AsyncResult`<`T`, `Exclude`<`R`, [`Defect`](#defect)>> | - | [packages/core/src/facade.ts:89](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/facade.ts#L89) |
|
|
591
|
+
| <a id="property-fromsafepromise"></a> `fromSafePromise()` | <`T`>(`promise`) => `AsyncResult`<`T`, `never`> | - | [packages/core/src/facade.ts:90](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/facade.ts#L90) |
|
|
592
|
+
|
|
593
|
+
#### Remarks
|
|
594
|
+
|
|
595
|
+
The async sibling of [Result](#result-1). Statics are grouped by what they
|
|
596
|
+
**return**, so `fromPromise`/`fromSafePromise` and the async aggregates sit
|
|
597
|
+
here rather than on [Result](#result-1); the namespace already conveys "async", so
|
|
598
|
+
the aggregates drop the `Async` suffix (`AsyncResult.all` is the free function
|
|
599
|
+
`allAsync`; `AsyncResult.allFromDict` is `allFromDictAsync`). Like
|
|
600
|
+
[Result](#result-1), the free functions remain the primary, tree-shakeable API; the
|
|
601
|
+
value `AsyncResult` and the type [AsyncResult](#asyncresult-1) share one name.
|
|
602
|
+
|
|
603
|
+
#### Example
|
|
604
|
+
|
|
605
|
+
```ts
|
|
606
|
+
import { AsyncResult, Defect } from "unthrown";
|
|
607
|
+
const user = await AsyncResult.fromPromise(fetchUser(id), (c) => Defect(c));
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
***
|
|
611
|
+
|
|
588
612
|
### Result
|
|
589
613
|
|
|
590
614
|
```ts
|
|
591
615
|
const Result: object;
|
|
592
616
|
```
|
|
593
617
|
|
|
594
|
-
Defined in: [packages/core/src/facade.ts:
|
|
618
|
+
Defined in: [packages/core/src/facade.ts:47](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/facade.ts#L47)
|
|
595
619
|
|
|
596
|
-
Companion object grouping the
|
|
597
|
-
discoverable namespace: [Result.Ok](#property-ok), [Result.Err](#property-err),
|
|
598
|
-
[Result.Defect](#property-defect), [Result.
|
|
599
|
-
[Result.
|
|
600
|
-
[Result.
|
|
601
|
-
[Result.
|
|
602
|
-
[Result.isDefect](#property-isdefect), [Result.isResult](#property-isresult).
|
|
620
|
+
Companion object grouping the **`Result`-producing** entry points under a
|
|
621
|
+
single, discoverable namespace: [Result.Ok](#property-ok), [Result.Err](#property-err),
|
|
622
|
+
[Result.Defect](#property-defect), [Result.Do](#property-do), [Result.fromNullable](#property-fromnullable),
|
|
623
|
+
[Result.fromThrowable](#property-fromthrowable), [Result.all](#property-all-1), [Result.allFromDict](#property-allfromdict-1),
|
|
624
|
+
[Result.isOk](#property-isok), [Result.isErr](#property-iserr), [Result.isDefect](#property-isdefect),
|
|
625
|
+
[Result.isResult](#property-isresult).
|
|
603
626
|
|
|
604
627
|
#### Type Declaration
|
|
605
628
|
|
|
606
629
|
| Name | Type | Defined in |
|
|
607
630
|
| ------ | ------ | ------ |
|
|
608
|
-
| <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:
|
|
609
|
-
| <a id="property-
|
|
610
|
-
| <a id="property-
|
|
611
|
-
| <a id="property-
|
|
612
|
-
| <a id="property-
|
|
613
|
-
| <a id="property-
|
|
614
|
-
| <a id="property-
|
|
615
|
-
| <a id="property-
|
|
616
|
-
| <a id="property-
|
|
617
|
-
| <a id="property-
|
|
618
|
-
| <a id="property-
|
|
619
|
-
| <a id="property-
|
|
620
|
-
| <a id="property-iserr"></a> `isErr()` | <`T`, `E`>(`r`) => `r is ErrView<E, T>` | [packages/core/src/facade.ts:58](https://github.com/btravstack/unthrown/blob/8424c0f1e5d5b49a3cb6853d52fb8d5085bd4701/packages/core/src/facade.ts#L58) |
|
|
621
|
-
| <a id="property-isok"></a> `isOk()` | <`T`, `E`>(`r`) => `r is OkView<T, E>` | [packages/core/src/facade.ts:57](https://github.com/btravstack/unthrown/blob/8424c0f1e5d5b49a3cb6853d52fb8d5085bd4701/packages/core/src/facade.ts#L57) |
|
|
622
|
-
| <a id="property-isresult"></a> `isResult()` | (`x`) => `x is Result<unknown, unknown>` | [packages/core/src/facade.ts:60](https://github.com/btravstack/unthrown/blob/8424c0f1e5d5b49a3cb6853d52fb8d5085bd4701/packages/core/src/facade.ts#L60) |
|
|
623
|
-
| <a id="property-ok"></a> `Ok()` | <`T`>(`value`) => `Result`<`T`, `never`> | [packages/core/src/facade.ts:45](https://github.com/btravstack/unthrown/blob/8424c0f1e5d5b49a3cb6853d52fb8d5085bd4701/packages/core/src/facade.ts#L45) |
|
|
631
|
+
| <a id="property-all-1"></a> `all()` | <`Rs`>(`results`) => `Result`<`AllOk`<`Rs`, \{ \[K in string \| number \| symbol\]: OkOf\<Rs\[K\]\> \}>, [`ErrOf`](#errof)<`Rs`\[`number`\]>> | [packages/core/src/facade.ts:54](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/facade.ts#L54) |
|
|
632
|
+
| <a id="property-allfromdict-1"></a> `allFromDict()` | <`R`>(`results`) => `Result`<\{ \[K in string \| number \| symbol\]: OkOf\<R\[K\]\> \}, [`ErrOf`](#errof)<`R`\[keyof `R`\]>> | [packages/core/src/facade.ts:55](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/facade.ts#L55) |
|
|
633
|
+
| <a id="property-defect"></a> `Defect()` | (`cause`) => [`Defect`](#defect) | [packages/core/src/facade.ts:50](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/facade.ts#L50) |
|
|
634
|
+
| <a id="property-do"></a> `Do()` | () => `Result`<\{ \}, `never`> | [packages/core/src/facade.ts:51](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/facade.ts#L51) |
|
|
635
|
+
| <a id="property-err"></a> `Err()` | <`E`>(`error`) => `Result`<`never`, `E`> | [packages/core/src/facade.ts:49](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/facade.ts#L49) |
|
|
636
|
+
| <a id="property-fromnullable"></a> `fromNullable()` | <`T`, `E`>(`value`, `onAbsent`) => `Result`<`NonNullable`<`T`>, `E`> | [packages/core/src/facade.ts:52](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/facade.ts#L52) |
|
|
637
|
+
| <a id="property-fromthrowable"></a> `fromThrowable()` | <`A`, `T`, `R`>(`fn`, `qualify`) => (...`args`) => `Result`<`T`, `Exclude`<`R`, [`Defect`](#defect)>> | [packages/core/src/facade.ts:53](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/facade.ts#L53) |
|
|
638
|
+
| <a id="property-isdefect"></a> `isDefect()` | <`T`, `E`>(`r`) => `r is DefectView<T, E>` | [packages/core/src/facade.ts:58](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/facade.ts#L58) |
|
|
639
|
+
| <a id="property-iserr"></a> `isErr()` | <`T`, `E`>(`r`) => `r is ErrView<E, T>` | [packages/core/src/facade.ts:57](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/facade.ts#L57) |
|
|
640
|
+
| <a id="property-isok"></a> `isOk()` | <`T`, `E`>(`r`) => `r is OkView<T, E>` | [packages/core/src/facade.ts:56](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/facade.ts#L56) |
|
|
641
|
+
| <a id="property-isresult"></a> `isResult()` | (`x`) => `x is Result<unknown, unknown>` | [packages/core/src/facade.ts:59](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/facade.ts#L59) |
|
|
642
|
+
| <a id="property-ok"></a> `Ok()` | <`T`>(`value`) => `Result`<`T`, `never`> | [packages/core/src/facade.ts:48](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/facade.ts#L48) |
|
|
624
643
|
|
|
625
644
|
#### Remarks
|
|
626
645
|
|
|
@@ -629,6 +648,10 @@ The free functions remain the primary, tree-shakeable API; importing only
|
|
|
629
648
|
`{ Ok }` never pulls this object in. The value `Result` and the type
|
|
630
649
|
[Result](#result-1) share one name (the companion-object pattern).
|
|
631
650
|
|
|
651
|
+
The **async** entry points live on the sibling [AsyncResult](#asyncresult-1) companion
|
|
652
|
+
(`AsyncResult.fromPromise`, `AsyncResult.all`, …), grouped by what they
|
|
653
|
+
return — a static lives in exactly one namespace.
|
|
654
|
+
|
|
632
655
|
#### Example
|
|
633
656
|
|
|
634
657
|
```ts
|
|
@@ -644,7 +667,7 @@ Result.Ok(1).flatMap((n) => Result.Ok(n + 1)).unwrap(); // 2
|
|
|
644
667
|
function all<Rs>(results): Result<AllOk<Rs, { [K in string | number | symbol]: OkOf<Rs[K]> }>, ErrOf<Rs[number]>>;
|
|
645
668
|
```
|
|
646
669
|
|
|
647
|
-
Defined in: [packages/core/src/interop.ts:249](https://github.com/btravstack/unthrown/blob/
|
|
670
|
+
Defined in: [packages/core/src/interop.ts:249](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/interop.ts#L249)
|
|
648
671
|
|
|
649
672
|
Collect a tuple/array of [Result](#result)s into a single `Result` of all their
|
|
650
673
|
success values.
|
|
@@ -690,7 +713,7 @@ all([Ok(1), Ok(2)] as Result<number, never>[]).unwrap(); // number[]
|
|
|
690
713
|
function allAsync<Rs>(results): AsyncResult<AllOk<Rs, { [K in string | number | symbol]: AsyncOkOf<Rs[K]> }>, AsyncErrOf<Rs[number]>>;
|
|
691
714
|
```
|
|
692
715
|
|
|
693
|
-
Defined in: [packages/core/src/interop.ts:299](https://github.com/btravstack/unthrown/blob/
|
|
716
|
+
Defined in: [packages/core/src/interop.ts:299](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/interop.ts#L299)
|
|
694
717
|
|
|
695
718
|
The asynchronous counterpart of [all](#all): combine a tuple/array of
|
|
696
719
|
[AsyncResult](#asyncresult)s into one `AsyncResult` of all their success values.
|
|
@@ -699,7 +722,7 @@ The asynchronous counterpart of [all](#all): combine a tuple/array of
|
|
|
699
722
|
|
|
700
723
|
| Type Parameter |
|
|
701
724
|
| ------ |
|
|
702
|
-
| `Rs` *extends* readonly
|
|
725
|
+
| `Rs` *extends* readonly `AsyncResult`<`unknown`, `unknown`>[] |
|
|
703
726
|
|
|
704
727
|
#### Parameters
|
|
705
728
|
|
|
@@ -709,7 +732,7 @@ The asynchronous counterpart of [all](#all): combine a tuple/array of
|
|
|
709
732
|
|
|
710
733
|
#### Returns
|
|
711
734
|
|
|
712
|
-
|
|
735
|
+
`AsyncResult`<`AllOk`<`Rs`, \{ \[K in string \| number \| symbol\]: AsyncOkOf\<Rs\[K\]\> \}>, [`AsyncErrOf`](#asyncerrof)<`Rs`\[`number`\]>>
|
|
713
736
|
|
|
714
737
|
#### Remarks
|
|
715
738
|
|
|
@@ -733,7 +756,7 @@ await allAsync([fromSafePromise(a()), fromSafePromise(b())]);
|
|
|
733
756
|
function allFromDict<R>(results): Result<{ [K in string | number | symbol]: OkOf<R[K]> }, ErrOf<R[keyof R]>>;
|
|
734
757
|
```
|
|
735
758
|
|
|
736
|
-
Defined in: [packages/core/src/interop.ts:274](https://github.com/btravstack/unthrown/blob/
|
|
759
|
+
Defined in: [packages/core/src/interop.ts:274](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/interop.ts#L274)
|
|
737
760
|
|
|
738
761
|
Collect a **record** of [Result](#result)s into a single `Result` of a record of
|
|
739
762
|
their success values — `allFromDict({ a: Result<A, E>, b: Result<B, E> })` is
|
|
@@ -776,7 +799,7 @@ allFromDict({ id: Ok(1), name: Ok("ada") }).unwrap(); // { id: 1, name: "ada" }
|
|
|
776
799
|
function allFromDictAsync<R>(results): AsyncResult<{ [K in string | number | symbol]: AsyncOkOf<R[K]> }, AsyncErrOf<R[keyof R]>>;
|
|
777
800
|
```
|
|
778
801
|
|
|
779
|
-
Defined in: [packages/core/src/interop.ts:327](https://github.com/btravstack/unthrown/blob/
|
|
802
|
+
Defined in: [packages/core/src/interop.ts:327](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/interop.ts#L327)
|
|
780
803
|
|
|
781
804
|
The asynchronous counterpart of [allFromDict](#allfromdict): combine a record of
|
|
782
805
|
[AsyncResult](#asyncresult)s into one `AsyncResult` of a record of their values.
|
|
@@ -795,7 +818,7 @@ The asynchronous counterpart of [allFromDict](#allfromdict): combine a record of
|
|
|
795
818
|
|
|
796
819
|
#### Returns
|
|
797
820
|
|
|
798
|
-
|
|
821
|
+
`AsyncResult`<\{ \[K in string \| number \| symbol\]: AsyncOkOf\<R\[K\]\> \}, [`AsyncErrOf`](#asyncerrof)<`R`\[keyof `R`\]>>
|
|
799
822
|
|
|
800
823
|
#### Remarks
|
|
801
824
|
|
|
@@ -817,7 +840,7 @@ await allFromDictAsync({ a: fromSafePromise(a()), b: fromSafePromise(b()) });
|
|
|
817
840
|
function Defect(cause): Defect;
|
|
818
841
|
```
|
|
819
842
|
|
|
820
|
-
Defined in: [packages/core/src/defect.ts:36](https://github.com/btravstack/unthrown/blob/
|
|
843
|
+
Defined in: [packages/core/src/defect.ts:36](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/defect.ts#L36)
|
|
821
844
|
|
|
822
845
|
Wrap a cause as a [Defect](#defect-2) — the value you return from a `qualify`
|
|
823
846
|
function when a failure is **not** a modeled domain error.
|
|
@@ -853,7 +876,7 @@ function Do(): Result<{
|
|
|
853
876
|
}, never>;
|
|
854
877
|
```
|
|
855
878
|
|
|
856
|
-
Defined in: [packages/core/src/do.ts:30](https://github.com/btravstack/unthrown/blob/
|
|
879
|
+
Defined in: [packages/core/src/do.ts:30](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/do.ts#L30)
|
|
857
880
|
|
|
858
881
|
Start a do-notation chain with an empty object scope, grown step by step with
|
|
859
882
|
`bind` (for `Result`-returning steps) and `let` (for pure values).
|
|
@@ -891,7 +914,7 @@ const result = Do()
|
|
|
891
914
|
function Err<E>(error): Result<never, E>;
|
|
892
915
|
```
|
|
893
916
|
|
|
894
|
-
Defined in: [packages/core/src/constructors.ts:34](https://github.com/btravstack/unthrown/blob/
|
|
917
|
+
Defined in: [packages/core/src/constructors.ts:34](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/constructors.ts#L34)
|
|
895
918
|
|
|
896
919
|
Construct a failed [Result](#result) carrying a **modeled** error.
|
|
897
920
|
|
|
@@ -926,7 +949,7 @@ Err("not_found").unwrapErr(); // "not_found"
|
|
|
926
949
|
function fromNullable<T, E>(value, onAbsent): Result<NonNullable<T>, E>;
|
|
927
950
|
```
|
|
928
951
|
|
|
929
|
-
Defined in: [packages/core/src/interop.ts:29](https://github.com/btravstack/unthrown/blob/
|
|
952
|
+
Defined in: [packages/core/src/interop.ts:29](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/interop.ts#L29)
|
|
930
953
|
|
|
931
954
|
Bridge a nullable value into a [Result](#result): absence becomes a **modeled**
|
|
932
955
|
`Err`. The sanctioned alternative to an `Option` type.
|
|
@@ -969,7 +992,7 @@ fromNullable(map.get(key), () => "missing").unwrap();
|
|
|
969
992
|
function fromPromise<T, R>(promise, qualify): AsyncResult<T, Exclude<R, Defect>>;
|
|
970
993
|
```
|
|
971
994
|
|
|
972
|
-
Defined in: [packages/core/src/interop.ts:110](https://github.com/btravstack/unthrown/blob/
|
|
995
|
+
Defined in: [packages/core/src/interop.ts:110](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/interop.ts#L110)
|
|
973
996
|
|
|
974
997
|
Wrap a `Promise` (or a thunk producing one) as an [AsyncResult](#asyncresult), forcing
|
|
975
998
|
every rejection to be triaged.
|
|
@@ -990,7 +1013,7 @@ every rejection to be triaged.
|
|
|
990
1013
|
|
|
991
1014
|
#### Returns
|
|
992
1015
|
|
|
993
|
-
|
|
1016
|
+
`AsyncResult`<`T`, `Exclude`<`R`, [`Defect`](#defect)>>
|
|
994
1017
|
|
|
995
1018
|
#### Remarks
|
|
996
1019
|
|
|
@@ -1021,7 +1044,7 @@ const user = await fromPromise(fetchUser(id), (cause) =>
|
|
|
1021
1044
|
function fromSafePromise<T>(promise): AsyncResult<T, never>;
|
|
1022
1045
|
```
|
|
1023
1046
|
|
|
1024
|
-
Defined in: [packages/core/src/interop.ts:136](https://github.com/btravstack/unthrown/blob/
|
|
1047
|
+
Defined in: [packages/core/src/interop.ts:136](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/interop.ts#L136)
|
|
1025
1048
|
|
|
1026
1049
|
Wrap a `Promise` asserted **not** to fail in any modeled way: any rejection
|
|
1027
1050
|
becomes a `Defect`.
|
|
@@ -1040,7 +1063,7 @@ becomes a `Defect`.
|
|
|
1040
1063
|
|
|
1041
1064
|
#### Returns
|
|
1042
1065
|
|
|
1043
|
-
|
|
1066
|
+
`AsyncResult`<`T`, `never`>
|
|
1044
1067
|
|
|
1045
1068
|
#### Remarks
|
|
1046
1069
|
|
|
@@ -1056,7 +1079,7 @@ triage. (`await`-ing still yields a `Result`; it never throws.)
|
|
|
1056
1079
|
function fromThrowable<A, T, R>(fn, qualify): (...args) => Result<T, Exclude<R, Defect>>;
|
|
1057
1080
|
```
|
|
1058
1081
|
|
|
1059
|
-
Defined in: [packages/core/src/interop.ts:66](https://github.com/btravstack/unthrown/blob/
|
|
1082
|
+
Defined in: [packages/core/src/interop.ts:66](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/interop.ts#L66)
|
|
1060
1083
|
|
|
1061
1084
|
Wrap a throwing synchronous function so it returns a [Result](#result) instead of
|
|
1062
1085
|
throwing.
|
|
@@ -1110,7 +1133,7 @@ parse("{}").unwrap();
|
|
|
1110
1133
|
function isDefect<T, E>(r): r is DefectView<T, E>;
|
|
1111
1134
|
```
|
|
1112
1135
|
|
|
1113
|
-
Defined in: [packages/core/src/constructors.ts:66](https://github.com/btravstack/unthrown/blob/
|
|
1136
|
+
Defined in: [packages/core/src/constructors.ts:66](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/constructors.ts#L66)
|
|
1114
1137
|
|
|
1115
1138
|
Type guard: narrow a [Result](#result) to its `Defect` variant, exposing `.cause`.
|
|
1116
1139
|
|
|
@@ -1141,7 +1164,7 @@ Type guard: narrow a [Result](#result) to its `Defect` variant, exposing `.cause
|
|
|
1141
1164
|
function isErr<T, E>(r): r is ErrView<E, T>;
|
|
1142
1165
|
```
|
|
1143
1166
|
|
|
1144
|
-
Defined in: [packages/core/src/constructors.ts:58](https://github.com/btravstack/unthrown/blob/
|
|
1167
|
+
Defined in: [packages/core/src/constructors.ts:58](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/constructors.ts#L58)
|
|
1145
1168
|
|
|
1146
1169
|
Type guard: narrow a [Result](#result) to its `Err` variant, exposing `.error`.
|
|
1147
1170
|
|
|
@@ -1172,7 +1195,7 @@ Type guard: narrow a [Result](#result) to its `Err` variant, exposing `.error`.
|
|
|
1172
1195
|
function isOk<T, E>(r): r is OkView<T, E>;
|
|
1173
1196
|
```
|
|
1174
1197
|
|
|
1175
|
-
Defined in: [packages/core/src/constructors.ts:50](https://github.com/btravstack/unthrown/blob/
|
|
1198
|
+
Defined in: [packages/core/src/constructors.ts:50](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/constructors.ts#L50)
|
|
1176
1199
|
|
|
1177
1200
|
Type guard: narrow a [Result](#result) to its `Ok` variant, exposing `.value`.
|
|
1178
1201
|
|
|
@@ -1211,7 +1234,7 @@ if (isOk(r)) r.value; // number, narrowed
|
|
|
1211
1234
|
function isResult(x): x is Result<unknown, unknown>;
|
|
1212
1235
|
```
|
|
1213
1236
|
|
|
1214
|
-
Defined in: [packages/core/src/core.ts:333](https://github.com/btravstack/unthrown/blob/
|
|
1237
|
+
Defined in: [packages/core/src/core.ts:333](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/core.ts#L333)
|
|
1215
1238
|
|
|
1216
1239
|
Type guard: is `x` a [Result](#result) (any of `Ok` / `Err` / `Defect`)?
|
|
1217
1240
|
|
|
@@ -1245,7 +1268,7 @@ is not a `Result` and returns `false`.
|
|
|
1245
1268
|
function matchTags<T, E, R>(result, handlers): R;
|
|
1246
1269
|
```
|
|
1247
1270
|
|
|
1248
|
-
Defined in: [packages/core/src/tagged.ts:138](https://github.com/btravstack/unthrown/blob/
|
|
1271
|
+
Defined in: [packages/core/src/tagged.ts:138](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/tagged.ts#L138)
|
|
1249
1272
|
|
|
1250
1273
|
Exhaustively fold a [Result](#result) (or [AsyncResult](#asyncresult)) whose error type is
|
|
1251
1274
|
a tagged union, dispatching each error to the handler matching its `_tag`.
|
|
@@ -1297,7 +1320,7 @@ matchTags(r, {
|
|
|
1297
1320
|
function matchTags<T, E, R>(result, handlers): Promise<R>;
|
|
1298
1321
|
```
|
|
1299
1322
|
|
|
1300
|
-
Defined in: [packages/core/src/tagged.ts:142](https://github.com/btravstack/unthrown/blob/
|
|
1323
|
+
Defined in: [packages/core/src/tagged.ts:142](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/tagged.ts#L142)
|
|
1301
1324
|
|
|
1302
1325
|
Exhaustively fold a [Result](#result) (or [AsyncResult](#asyncresult)) whose error type is
|
|
1303
1326
|
a tagged union, dispatching each error to the handler matching its `_tag`.
|
|
@@ -1314,7 +1337,7 @@ a tagged union, dispatching each error to the handler matching its `_tag`.
|
|
|
1314
1337
|
|
|
1315
1338
|
| Parameter | Type | Description |
|
|
1316
1339
|
| ------ | ------ | ------ |
|
|
1317
|
-
| `result` |
|
|
1340
|
+
| `result` | `AsyncResult`<`T`, `E`> | the result to fold. |
|
|
1318
1341
|
| `handlers` | [`TagHandlers`](#taghandlers)<`T`, `E`, `R`> | one branch per channel/tag. |
|
|
1319
1342
|
|
|
1320
1343
|
##### Returns
|
|
@@ -1351,7 +1374,7 @@ matchTags(r, {
|
|
|
1351
1374
|
function Ok<T>(value): Result<T, never>;
|
|
1352
1375
|
```
|
|
1353
1376
|
|
|
1354
|
-
Defined in: [packages/core/src/constructors.ts:18](https://github.com/btravstack/unthrown/blob/
|
|
1377
|
+
Defined in: [packages/core/src/constructors.ts:18](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/constructors.ts#L18)
|
|
1355
1378
|
|
|
1356
1379
|
Construct a successful [Result](#result).
|
|
1357
1380
|
|
|
@@ -1386,7 +1409,7 @@ Ok(42).unwrap(); // 42
|
|
|
1386
1409
|
function TaggedError<Tag>(tag, options?): TaggedErrorConstructor<Tag>;
|
|
1387
1410
|
```
|
|
1388
1411
|
|
|
1389
|
-
Defined in: [packages/core/src/tagged.ts:72](https://github.com/btravstack/unthrown/blob/
|
|
1412
|
+
Defined in: [packages/core/src/tagged.ts:72](https://github.com/btravstack/unthrown/blob/9964bddff12c79925119bbfc5de67104bbcfc533/packages/core/src/tagged.ts#L72)
|
|
1390
1413
|
|
|
1391
1414
|
Build a base class for a tagged error — a class extending `Error` with a
|
|
1392
1415
|
`_tag` string discriminant, in the style of Effect's `Data.TaggedError`.
|