unthrown 0.3.0 → 1.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/README.md +2 -2
- package/dist/index.cjs +172 -56
- package/dist/index.d.cts +128 -45
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +128 -45
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +169 -54
- package/dist/index.mjs.map +1 -1
- package/docs/index.md +161 -119
- package/package.json +3 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
//#region src/types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Flatten an intersection into a single object literal so accumulated `bind` /
|
|
4
|
+
* `let` scopes display cleanly (`{ a; b }` rather than `{ a } & { b }`).
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
type Prettify<T> = { [K in keyof T]: T[K] } & {};
|
|
9
|
+
/**
|
|
10
|
+
* The scope produced by a `bind` / `let` step: `T` with `K` added (as a readonly
|
|
11
|
+
* property of type `U`). `Omit<T, K>` first drops any existing `K`, so re-binding
|
|
12
|
+
* a name **overwrites** it — matching the runtime spread — rather than producing
|
|
13
|
+
* an unsound `T[K] & U` intersection.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
type Bound<T, K extends string, U> = Prettify<Omit<T, K> & { readonly [P in K]: U }>;
|
|
2
18
|
/**
|
|
3
19
|
* The method surface every {@link Result} variant carries. Factored out so the
|
|
4
20
|
* three variants ({@link OkView}, {@link ErrView}, {@link DefectView}) can each
|
|
@@ -56,6 +72,41 @@ type ResultMethods<T, E> = {
|
|
|
56
72
|
* @param f - the failable side effect; its `Ok` value is ignored.
|
|
57
73
|
*/
|
|
58
74
|
flatTap<E2>(f: (value: T) => Result$1<unknown, E2>): Result$1<T, E | E2>;
|
|
75
|
+
/**
|
|
76
|
+
* Do-notation: run `f` for a `Result` and **bind its value** under `name` in
|
|
77
|
+
* an accumulating object scope.
|
|
78
|
+
*
|
|
79
|
+
* @remarks
|
|
80
|
+
* Begin a chain with {@link Do} (an empty object scope) and grow it step by
|
|
81
|
+
* step. `f` receives the scope accumulated so far and returns a `Result`; on
|
|
82
|
+
* `Ok` the value is added as `{ ...scope, [name]: value }`, on `Err`/`Defect`
|
|
83
|
+
* the chain short-circuits. Errors union (`E | E2`). A throw becomes a
|
|
84
|
+
* `Defect` — as does calling `bind` on a non-object scope (e.g. `Ok(5).bind`),
|
|
85
|
+
* which is misuse: the scope is always an object inside a real `Do()` chain.
|
|
86
|
+
* (`let` is the pure-value counterpart.)
|
|
87
|
+
*
|
|
88
|
+
* @typeParam K - the key the bound value is stored under.
|
|
89
|
+
* @typeParam U - the bound value type.
|
|
90
|
+
* @typeParam E2 - the error type `f` may introduce.
|
|
91
|
+
* @param name - the scope key.
|
|
92
|
+
* @param f - produces a `Result` from the accumulated scope.
|
|
93
|
+
*/
|
|
94
|
+
bind<K extends string, U, E2>(name: K, f: (scope: T) => Result$1<U, E2>): Result$1<Bound<T, K, U>, E | E2>;
|
|
95
|
+
/**
|
|
96
|
+
* Do-notation: run `f` for a **plain value** and bind it under `name` in the
|
|
97
|
+
* accumulating object scope. The pure-value counterpart of {@link ResultMethods.bind | bind}.
|
|
98
|
+
*
|
|
99
|
+
* @remarks
|
|
100
|
+
* `f` receives the scope and returns a value (not a `Result`); it is added as
|
|
101
|
+
* `{ ...scope, [name]: value }`. Runs only on `Ok`; `Err`/`Defect` pass
|
|
102
|
+
* through. A throw becomes a `Defect`.
|
|
103
|
+
*
|
|
104
|
+
* @typeParam K - the key the value is stored under.
|
|
105
|
+
* @typeParam U - the value type.
|
|
106
|
+
* @param name - the scope key.
|
|
107
|
+
* @param f - computes a value from the accumulated scope.
|
|
108
|
+
*/
|
|
109
|
+
let<K extends string, U>(name: K, f: (scope: T) => U): Result$1<Bound<T, K, U>, E>;
|
|
59
110
|
/**
|
|
60
111
|
* Replace the success value with a constant `value`.
|
|
61
112
|
*
|
|
@@ -113,12 +164,12 @@ type ResultMethods<T, E> = {
|
|
|
113
164
|
* @remarks
|
|
114
165
|
* Runs `f` only when a `Defect` is present, re-entering the modeled world by
|
|
115
166
|
* returning a `Result` (an `Ok` or a fresh `Err`). `Ok` and `Err` pass
|
|
116
|
-
* through. Recovering a
|
|
167
|
+
* through. Recovering a Defect should be rare: usually you let it bubble to
|
|
117
168
|
* the edge. If `f` throws, the throw becomes a new `Defect`.
|
|
118
169
|
*
|
|
119
170
|
* @typeParam U - a success type the recovery may produce.
|
|
120
171
|
* @typeParam E2 - an error type the recovery may produce.
|
|
121
|
-
* @param f - maps the
|
|
172
|
+
* @param f - maps the Defect's unknown cause to a recovering `Result`.
|
|
122
173
|
*/
|
|
123
174
|
recoverDefect<U, E2>(f: (cause: unknown) => Result$1<U, E2>): Result$1<T | U, E | E2>;
|
|
124
175
|
/**
|
|
@@ -132,9 +183,9 @@ type ResultMethods<T, E> = {
|
|
|
132
183
|
* Exhaustively fold all three runtime states into a single value of type `R`.
|
|
133
184
|
*
|
|
134
185
|
* @remarks
|
|
135
|
-
* Exactly one handler runs. Together with the throw-to-
|
|
186
|
+
* Exactly one handler runs. Together with the throw-to-Defect guarantee, this
|
|
136
187
|
* is typically the single place a pipeline is handled at the edge — mapping
|
|
137
|
-
* `
|
|
188
|
+
* `Ok`/`Err`/`Defect` to (for example) 2xx / 4xx / 5xx with no `try`/`catch`.
|
|
138
189
|
* (For richer matching, a `Result` is also a discriminated union — branch on
|
|
139
190
|
* its `tag` property, e.g. with `ts-pattern`.)
|
|
140
191
|
*
|
|
@@ -152,7 +203,7 @@ type ResultMethods<T, E> = {
|
|
|
152
203
|
* @returns the `Ok` value.
|
|
153
204
|
* @throws On `Err`, an {@link UnwrapError} carrying the error. On a `Defect`,
|
|
154
205
|
* re-throws the **original cause** with its original stack, so an unhandled
|
|
155
|
-
*
|
|
206
|
+
* Defect surfaces at the global handler as the real failure.
|
|
156
207
|
*/
|
|
157
208
|
unwrap(): T;
|
|
158
209
|
/**
|
|
@@ -167,7 +218,7 @@ type ResultMethods<T, E> = {
|
|
|
167
218
|
* The success value, or `fallback` on `Err`.
|
|
168
219
|
*
|
|
169
220
|
* @param fallback - returned when the result is an `Err`.
|
|
170
|
-
* @throws Re-throws on a `Defect` — a
|
|
221
|
+
* @throws Re-throws on a `Defect` — a Defect is a bug, not an absent value, so
|
|
171
222
|
* it is never silently replaced.
|
|
172
223
|
*/
|
|
173
224
|
unwrapOr(fallback: T): T;
|
|
@@ -220,7 +271,7 @@ type DefectView<T = never, E = never> = ResultMethods<T, E> & {
|
|
|
220
271
|
*
|
|
221
272
|
* - **`Ok`** — a success carrying a `value: T`.
|
|
222
273
|
* - **`Err`** — a modeled, anticipated failure carrying an `error: E`.
|
|
223
|
-
* - **`Defect`** — an *unmodeled* failure carrying an unknown `cause`. A
|
|
274
|
+
* - **`Defect`** — an *unmodeled* failure carrying an unknown `cause`. A Defect
|
|
224
275
|
* never appears in `E`; it is the library's third, out-of-band channel.
|
|
225
276
|
*
|
|
226
277
|
* Because it is a real union, you can match it natively (a `switch` on `tag`, or
|
|
@@ -234,10 +285,10 @@ type DefectView<T = never, E = never> = ResultMethods<T, E> & {
|
|
|
234
285
|
*
|
|
235
286
|
* @example
|
|
236
287
|
* ```ts
|
|
237
|
-
* import {
|
|
288
|
+
* import { Ok, Err, type Result } from "unthrown";
|
|
238
289
|
*
|
|
239
290
|
* function half(n: number): Result<number, "odd"> {
|
|
240
|
-
* return n % 2 === 0 ?
|
|
291
|
+
* return n % 2 === 0 ? Ok(n / 2) : Err("odd");
|
|
241
292
|
* }
|
|
242
293
|
*
|
|
243
294
|
* const message = half(10).match({
|
|
@@ -296,7 +347,13 @@ type AsyncResult<T, E> = Awaitable<Result$1<T, E>> & {
|
|
|
296
347
|
* may return a `Result` **or** an `AsyncResult`; its `Ok` value is discarded,
|
|
297
348
|
* an `Err`/`Defect` short-circuits, and a throw becomes a `Defect`.
|
|
298
349
|
*/
|
|
299
|
-
flatTap<E2>(f: (value: T) => Result$1<unknown, E2> | AsyncResult<unknown, E2>): AsyncResult<T, E | E2>;
|
|
350
|
+
flatTap<E2>(f: (value: T) => Result$1<unknown, E2> | AsyncResult<unknown, E2>): AsyncResult<T, E | E2>;
|
|
351
|
+
/**
|
|
352
|
+
* Asynchronous `bind` (do-notation). `f` may return a `Result` **or** an
|
|
353
|
+
* `AsyncResult`; its value is bound under `name` in the accumulating scope.
|
|
354
|
+
*/
|
|
355
|
+
bind<K extends string, U, E2>(name: K, f: (scope: T) => Result$1<U, E2> | AsyncResult<U, E2>): AsyncResult<Bound<T, K, U>, E | E2>; /** Asynchronous `let` (do-notation). `f` returns a plain value, bound under `name`. */
|
|
356
|
+
let<K extends string, U>(name: K, f: (scope: T) => U): AsyncResult<Bound<T, K, U>, E>; /** Asynchronous `as`. */
|
|
300
357
|
as<U>(value: U): AsyncResult<U, E>; /** Asynchronous `mapErr`. `f` is synchronous; a throw becomes a `Defect`. */
|
|
301
358
|
mapErr<E2>(f: (error: E) => E2): AsyncResult<T, E2>; /** Asynchronous `orElse`. `f` may return a `Result` or an `AsyncResult`. */
|
|
302
359
|
orElse<U, E2>(f: (error: E) => Result$1<U, E2> | AsyncResult<U, E2>): AsyncResult<T | U, E2>; /** Asynchronous `recover`. `f` is synchronous; a throw becomes a `Defect`. */
|
|
@@ -356,11 +413,11 @@ type AsyncErrOf<R> = R extends AsyncResult<unknown, infer E> ? E : never;
|
|
|
356
413
|
*
|
|
357
414
|
* @example
|
|
358
415
|
* ```ts
|
|
359
|
-
* import {
|
|
360
|
-
*
|
|
416
|
+
* import { Ok } from "unthrown";
|
|
417
|
+
* Ok(42).unwrap(); // 42
|
|
361
418
|
* ```
|
|
362
419
|
*/
|
|
363
|
-
declare function
|
|
420
|
+
declare function Ok<T>(value: T): Result$1<T, never>;
|
|
364
421
|
/**
|
|
365
422
|
* Construct a failed {@link Result} carrying a **modeled** error.
|
|
366
423
|
*
|
|
@@ -369,11 +426,11 @@ declare function ok<T>(value: T): Result$1<T, never>;
|
|
|
369
426
|
*
|
|
370
427
|
* @example
|
|
371
428
|
* ```ts
|
|
372
|
-
* import {
|
|
373
|
-
*
|
|
429
|
+
* import { Err } from "unthrown";
|
|
430
|
+
* Err("not_found").unwrapErr(); // "not_found"
|
|
374
431
|
* ```
|
|
375
432
|
*/
|
|
376
|
-
declare function
|
|
433
|
+
declare function Err<E>(error: E): Result$1<never, E>;
|
|
377
434
|
/**
|
|
378
435
|
* Type guard: narrow a {@link Result} to its `Ok` variant, exposing `.value`.
|
|
379
436
|
*
|
|
@@ -429,7 +486,7 @@ declare const DEFECT: unique symbol;
|
|
|
429
486
|
* @remarks
|
|
430
487
|
* `qualify` (passed to {@link fromPromise} / {@link fromThrowable}) returns
|
|
431
488
|
* `E | Defect`: either a modeled domain error, or a `Defect` produced by
|
|
432
|
-
* {@link
|
|
489
|
+
* {@link Defect} to say "this failure is not modeled". A `Defect` is opaque —
|
|
433
490
|
* it carries the original cause for the boundary to convert into the third
|
|
434
491
|
* runtime state of a `Result`.
|
|
435
492
|
*/
|
|
@@ -442,18 +499,43 @@ type Defect = {
|
|
|
442
499
|
* function when a failure is **not** a modeled domain error.
|
|
443
500
|
*
|
|
444
501
|
* @param cause - the original thrown/rejected value.
|
|
445
|
-
* @returns an opaque
|
|
502
|
+
* @returns an opaque Defect marker carrying `cause`.
|
|
446
503
|
*
|
|
447
504
|
* @example
|
|
448
505
|
* ```ts
|
|
449
|
-
* import { fromPromise,
|
|
506
|
+
* import { fromPromise, Defect } from "unthrown";
|
|
450
507
|
*
|
|
451
508
|
* const user = fromPromise(fetchUser(id), (cause) =>
|
|
452
|
-
* cause instanceof NotFoundError ? cause :
|
|
509
|
+
* cause instanceof NotFoundError ? cause : Defect(cause),
|
|
453
510
|
* );
|
|
454
511
|
* ```
|
|
455
512
|
*/
|
|
456
|
-
declare function
|
|
513
|
+
declare function Defect(cause: unknown): Defect;
|
|
514
|
+
//#endregion
|
|
515
|
+
//#region src/do.d.ts
|
|
516
|
+
/**
|
|
517
|
+
* Start a do-notation chain with an empty object scope, grown step by step with
|
|
518
|
+
* `bind` (for `Result`-returning steps) and `let` (for pure values).
|
|
519
|
+
*
|
|
520
|
+
* @remarks
|
|
521
|
+
* Capitalised because `do` is a reserved word. Each step receives the scope
|
|
522
|
+
* accumulated so far; the error types union across `bind`s, and a throw in any
|
|
523
|
+
* step becomes a `Defect`. To go asynchronous, lift the chain with `toAsync()`
|
|
524
|
+
* (then a `bind` may return an `AsyncResult`).
|
|
525
|
+
*
|
|
526
|
+
* @example
|
|
527
|
+
* ```ts
|
|
528
|
+
* import { Do, Ok } from "unthrown";
|
|
529
|
+
*
|
|
530
|
+
* const result = Do()
|
|
531
|
+
* .bind("user", () => findUser(id)) // Result<User, NotFound>
|
|
532
|
+
* .bind("org", ({ user }) => findOrg(user.orgId)) // Result<Org, NotFound>
|
|
533
|
+
* .let("label", ({ user, org }) => `${user.name} @ ${org.name}`)
|
|
534
|
+
* .map(({ user, org, label }) => render(user, org, label));
|
|
535
|
+
* // Result<View, NotFound>
|
|
536
|
+
* ```
|
|
537
|
+
*/
|
|
538
|
+
declare function Do(): Result$1<{}, never>;
|
|
457
539
|
//#endregion
|
|
458
540
|
//#region src/interop.d.ts
|
|
459
541
|
/**
|
|
@@ -461,7 +543,7 @@ declare function defect(cause: unknown): Defect;
|
|
|
461
543
|
* `Err`. The sanctioned alternative to an `Option` type.
|
|
462
544
|
*
|
|
463
545
|
* @remarks
|
|
464
|
-
* `null` and `undefined` map to `
|
|
546
|
+
* `null` and `undefined` map to `Err(onAbsent())`; any other value (including
|
|
465
547
|
* falsy ones like `0`, `""`, `false`) maps to `Ok`.
|
|
466
548
|
*
|
|
467
549
|
* @typeParam T - the (nullable) value type.
|
|
@@ -482,14 +564,14 @@ declare function fromNullable<T, E>(value: T | null | undefined, onAbsent: () =>
|
|
|
482
564
|
*
|
|
483
565
|
* @remarks
|
|
484
566
|
* `qualify` **must** triage every thrown cause into a modeled error `E` or a
|
|
485
|
-
* {@link Defect} (via {@link
|
|
567
|
+
* {@link Defect} (via {@link Defect}) — there is no path that leaves `unknown`
|
|
486
568
|
* in `E`. A throw inside `qualify` itself is treated as a `Defect`.
|
|
487
569
|
*
|
|
488
570
|
* The modeled error type is `Exclude<R, Defect>` — the `Defect` arm of
|
|
489
571
|
* `qualify`'s return is **subtracted** from `E`, never inferred into it. So a
|
|
490
|
-
* `qualify` that returns *only* `
|
|
572
|
+
* `qualify` that returns *only* `Defect(cause)` yields `E = never` (a Defect is
|
|
491
573
|
* out-of-band and must not pollute the error channel); reach for
|
|
492
|
-
* {@link fromSafePromise} when every failure is a
|
|
574
|
+
* {@link fromSafePromise} when every failure is a Defect.
|
|
493
575
|
*
|
|
494
576
|
* @typeParam A - the wrapped function's argument tuple.
|
|
495
577
|
* @typeParam T - the wrapped function's return type.
|
|
@@ -501,8 +583,8 @@ declare function fromNullable<T, E>(value: T | null | undefined, onAbsent: () =>
|
|
|
501
583
|
*
|
|
502
584
|
* @example
|
|
503
585
|
* ```ts
|
|
504
|
-
* import { fromThrowable,
|
|
505
|
-
* const parse = fromThrowable(JSON.parse, (cause) =>
|
|
586
|
+
* import { fromThrowable, Defect } from "unthrown";
|
|
587
|
+
* const parse = fromThrowable(JSON.parse, (cause) => Defect(cause));
|
|
506
588
|
* parse("{}").unwrap();
|
|
507
589
|
* ```
|
|
508
590
|
*/
|
|
@@ -519,8 +601,8 @@ declare function fromThrowable<A extends unknown[], T, R>(fn: (...args: A) => T,
|
|
|
519
601
|
*
|
|
520
602
|
* The modeled error type is `Exclude<R, Defect>` — the `Defect` arm of
|
|
521
603
|
* `qualify`'s return is **subtracted** from `E`, never inferred into it. So a
|
|
522
|
-
* `qualify` that returns *only* `
|
|
523
|
-
* rejection is a
|
|
604
|
+
* `qualify` that returns *only* `Defect(cause)` yields `E = never`; when every
|
|
605
|
+
* rejection is a Defect, prefer {@link fromSafePromise}.
|
|
524
606
|
*
|
|
525
607
|
* @typeParam T - the resolved value type.
|
|
526
608
|
* @typeParam R - `qualify`'s return type; the modeled error `E` is
|
|
@@ -530,9 +612,9 @@ declare function fromThrowable<A extends unknown[], T, R>(fn: (...args: A) => T,
|
|
|
530
612
|
*
|
|
531
613
|
* @example
|
|
532
614
|
* ```ts
|
|
533
|
-
* import { fromPromise,
|
|
615
|
+
* import { fromPromise, Defect } from "unthrown";
|
|
534
616
|
* const user = await fromPromise(fetchUser(id), (cause) =>
|
|
535
|
-
* cause instanceof NotFoundError ? ("not_found" as const) :
|
|
617
|
+
* cause instanceof NotFoundError ? ("not_found" as const) : Defect(cause),
|
|
536
618
|
* );
|
|
537
619
|
* ```
|
|
538
620
|
*/
|
|
@@ -579,16 +661,16 @@ type AsyncResultRecord = Record<string, AsyncResult<unknown, unknown>>;
|
|
|
579
661
|
* @remarks
|
|
580
662
|
* Short-circuits on the **first** `Err` (later entries are not inspected for
|
|
581
663
|
* their error); any `Defect` present **dominates**, winning even over an earlier
|
|
582
|
-
* `Err`. A **fixed tuple** keeps its positional types — `all([
|
|
664
|
+
* `Err`. A **fixed tuple** keeps its positional types — `all([Ok(1), Ok("a")])`
|
|
583
665
|
* is `Result<[number, string], …>` — while a **dynamic array** `Result<T, E>[]`
|
|
584
666
|
* collapses to `Result<T[], E>` with no cast. For a **record** keyed by name,
|
|
585
667
|
* use {@link allFromDict}.
|
|
586
668
|
*
|
|
587
669
|
* @example
|
|
588
670
|
* ```ts
|
|
589
|
-
* import { all,
|
|
590
|
-
* all([
|
|
591
|
-
* all([
|
|
671
|
+
* import { all, Ok } from "unthrown";
|
|
672
|
+
* all([Ok(1), Ok("a"), Ok(true)]).unwrap(); // [1, "a", true] (typed [number, string, boolean])
|
|
673
|
+
* all([Ok(1), Ok(2)] as Result<number, never>[]).unwrap(); // number[]
|
|
592
674
|
* ```
|
|
593
675
|
*/
|
|
594
676
|
declare function all<Rs extends readonly Result$1<unknown, unknown>[]>(results: readonly [...Rs]): Result$1<AllOk<Rs, { [K in keyof Rs]: OkOf<Rs[K]> }>, ErrOf<Rs[number]>>;
|
|
@@ -604,8 +686,8 @@ declare function all<Rs extends readonly Result$1<unknown, unknown>[]>(results:
|
|
|
604
686
|
*
|
|
605
687
|
* @example
|
|
606
688
|
* ```ts
|
|
607
|
-
* import { allFromDict,
|
|
608
|
-
* allFromDict({ id:
|
|
689
|
+
* import { allFromDict, Ok } from "unthrown";
|
|
690
|
+
* allFromDict({ id: Ok(1), name: Ok("ada") }).unwrap(); // { id: 1, name: "ada" }
|
|
609
691
|
* ```
|
|
610
692
|
*/
|
|
611
693
|
declare function allFromDict<R extends ResultRecord>(results: R): Result$1<{ [K in keyof R]: OkOf<R[K]> }, ErrOf<R[keyof R]>>;
|
|
@@ -645,8 +727,8 @@ declare function allFromDictAsync<R extends AsyncResultRecord>(results: R): Asyn
|
|
|
645
727
|
//#region src/facade.d.ts
|
|
646
728
|
/**
|
|
647
729
|
* Companion object grouping the standalone entry points under a single,
|
|
648
|
-
* discoverable namespace: {@link Result.
|
|
649
|
-
* {@link Result.
|
|
730
|
+
* discoverable namespace: {@link Result.Ok}, {@link Result.Err},
|
|
731
|
+
* {@link Result.Defect}, {@link Result.fromNullable}, {@link Result.fromThrowable},
|
|
650
732
|
* {@link Result.fromPromise}, {@link Result.fromSafePromise}, {@link Result.all},
|
|
651
733
|
* {@link Result.allAsync}, {@link Result.allFromDict},
|
|
652
734
|
* {@link Result.allFromDictAsync}, {@link Result.isOk}, {@link Result.isErr},
|
|
@@ -655,19 +737,20 @@ declare function allFromDictAsync<R extends AsyncResultRecord>(results: R): Asyn
|
|
|
655
737
|
* @remarks
|
|
656
738
|
* Purely additive sugar — each member **is** the corresponding free function.
|
|
657
739
|
* The free functions remain the primary, tree-shakeable API; importing only
|
|
658
|
-
* `{
|
|
740
|
+
* `{ Ok }` never pulls this object in. The value `Result` and the type
|
|
659
741
|
* {@link Result} share one name (the companion-object pattern).
|
|
660
742
|
*
|
|
661
743
|
* @example
|
|
662
744
|
* ```ts
|
|
663
745
|
* import { Result } from "unthrown";
|
|
664
|
-
* Result.
|
|
746
|
+
* Result.Ok(1).flatMap((n) => Result.Ok(n + 1)).unwrap(); // 2
|
|
665
747
|
* ```
|
|
666
748
|
*/
|
|
667
749
|
declare const Result: {
|
|
668
|
-
readonly
|
|
669
|
-
readonly
|
|
670
|
-
readonly
|
|
750
|
+
readonly Ok: typeof Ok;
|
|
751
|
+
readonly Err: typeof Err;
|
|
752
|
+
readonly Defect: typeof Defect;
|
|
753
|
+
readonly Do: typeof Do;
|
|
671
754
|
readonly fromNullable: typeof fromNullable;
|
|
672
755
|
readonly fromThrowable: typeof fromThrowable;
|
|
673
756
|
readonly fromPromise: typeof fromPromise;
|
|
@@ -804,5 +887,5 @@ declare function matchTags<T, E extends {
|
|
|
804
887
|
_tag: string;
|
|
805
888
|
}, R>(result: AsyncResult<T, E>, handlers: TagHandlers<T, E, R>): Promise<R>;
|
|
806
889
|
//#endregion
|
|
807
|
-
export { type AsyncErrOf, type AsyncOkOf, type AsyncResult, type Awaitable,
|
|
890
|
+
export { type AsyncErrOf, type AsyncOkOf, type AsyncResult, type Awaitable, Defect, type DefectView, Do, Err, type ErrOf, type ErrView, Ok, type OkOf, type OkView, Result, type TagHandlers, TaggedError, type TaggedErrorConstructor, type TaggedErrorInstance, UnwrapError, all, allAsync, allFromDict, allFromDictAsync, fromNullable, fromPromise, fromSafePromise, fromThrowable, isDefect, isErr, isOk, matchTags };
|
|
808
891
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/constructors.ts","../src/core.ts","../src/defect.ts","../src/interop.ts","../src/facade.ts","../src/tagged.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/constructors.ts","../src/core.ts","../src/defect.ts","../src/do.ts","../src/interop.ts","../src/facade.ts","../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