unthrown 1.0.0 → 1.1.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 +39 -2
- package/dist/index.d.cts +41 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +41 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +39 -3
- package/dist/index.mjs.map +1 -1
- package/docs/index.md +119 -85
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -127,6 +127,15 @@ var Res = class {
|
|
|
127
127
|
return defectRes(cause);
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
|
+
flatTapErr(f) {
|
|
131
|
+
if (this.tag !== "Err") return this;
|
|
132
|
+
try {
|
|
133
|
+
const r = f(this.error);
|
|
134
|
+
return r.tag === "Ok" ? this : passThrough(r);
|
|
135
|
+
} catch (cause) {
|
|
136
|
+
return defectRes(cause);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
130
139
|
recoverDefect(f) {
|
|
131
140
|
if (this.tag !== "Defect") return this;
|
|
132
141
|
try {
|
|
@@ -232,6 +241,21 @@ function defectRes(cause) {
|
|
|
232
241
|
});
|
|
233
242
|
}
|
|
234
243
|
/**
|
|
244
|
+
* Type guard: is `x` a {@link Result} (any of `Ok` / `Err` / `Defect`)?
|
|
245
|
+
*
|
|
246
|
+
* @remarks
|
|
247
|
+
* Unlike {@link isOk} / {@link isErr} / {@link isDefect}, which narrow a value
|
|
248
|
+
* already known to be a `Result`, this narrows from `unknown` — useful at an
|
|
249
|
+
* untyped boundary. It checks the value carries the `Result` prototype, so a
|
|
250
|
+
* look-alike plain object (`{ tag: "Ok" }`) is **not** matched. An `AsyncResult`
|
|
251
|
+
* is not a `Result` and returns `false`.
|
|
252
|
+
*
|
|
253
|
+
* @returns `true` when `x` is a `Result` produced by this library.
|
|
254
|
+
*/
|
|
255
|
+
function isResult(x) {
|
|
256
|
+
return x instanceof Res;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
235
259
|
* Reuse a non-matching variant (an `Err` or `Defect`) as a differently-typed
|
|
236
260
|
* `Result`, with no runtime work. Sound because the passed-through variant
|
|
237
261
|
* carries no value of the changed success type, so retyping it is a no-op — only
|
|
@@ -395,6 +419,17 @@ var AsyncRes = class AsyncRes {
|
|
|
395
419
|
}
|
|
396
420
|
}));
|
|
397
421
|
}
|
|
422
|
+
flatTapErr(f) {
|
|
423
|
+
return new AsyncRes(this.promise.then(async (r) => {
|
|
424
|
+
if (r.tag !== "Err") return passThrough(r);
|
|
425
|
+
try {
|
|
426
|
+
const inner = await f(r.error);
|
|
427
|
+
return inner.tag === "Ok" ? passThrough(r) : passThrough(inner);
|
|
428
|
+
} catch (cause) {
|
|
429
|
+
return defectRes(cause);
|
|
430
|
+
}
|
|
431
|
+
}));
|
|
432
|
+
}
|
|
398
433
|
recoverDefect(f) {
|
|
399
434
|
return new AsyncRes(this.promise.then(async (r) => {
|
|
400
435
|
if (r.tag !== "Defect") return r;
|
|
@@ -816,7 +851,7 @@ function allFromDictAsync(results) {
|
|
|
816
851
|
* {@link Result.fromPromise}, {@link Result.fromSafePromise}, {@link Result.all},
|
|
817
852
|
* {@link Result.allAsync}, {@link Result.allFromDict},
|
|
818
853
|
* {@link Result.allFromDictAsync}, {@link Result.isOk}, {@link Result.isErr},
|
|
819
|
-
* {@link Result.isDefect}.
|
|
854
|
+
* {@link Result.isDefect}, {@link Result.isResult}.
|
|
820
855
|
*
|
|
821
856
|
* @remarks
|
|
822
857
|
* Purely additive sugar — each member **is** the corresponding free function.
|
|
@@ -845,7 +880,8 @@ const Result = {
|
|
|
845
880
|
allFromDictAsync,
|
|
846
881
|
isOk,
|
|
847
882
|
isErr,
|
|
848
|
-
isDefect
|
|
883
|
+
isDefect,
|
|
884
|
+
isResult
|
|
849
885
|
};
|
|
850
886
|
//#endregion
|
|
851
887
|
//#region src/tagged.ts
|
|
@@ -933,4 +969,5 @@ exports.fromThrowable = fromThrowable;
|
|
|
933
969
|
exports.isDefect = isDefect;
|
|
934
970
|
exports.isErr = isErr;
|
|
935
971
|
exports.isOk = isOk;
|
|
972
|
+
exports.isResult = isResult;
|
|
936
973
|
exports.matchTags = matchTags;
|
package/dist/index.d.cts
CHANGED
|
@@ -158,6 +158,23 @@ type ResultMethods<T, E> = {
|
|
|
158
158
|
* @param f - the side effect (its return value is ignored).
|
|
159
159
|
*/
|
|
160
160
|
tapErr(f: (error: E) => void): Result$1<T, E>;
|
|
161
|
+
/**
|
|
162
|
+
* Run a **failable** side effect on the error, keeping the original error but
|
|
163
|
+
* threading the effect's own error.
|
|
164
|
+
*
|
|
165
|
+
* @remarks
|
|
166
|
+
* The error-channel mirror of {@link ResultMethods.flatTap | flatTap}: `f`
|
|
167
|
+
* returns a `Result`, but its **success value is discarded** — on the effect's
|
|
168
|
+
* `Ok` the original `Err` flows through unchanged, while an `Err` (or `Defect`)
|
|
169
|
+
* from `f` short-circuits and threads its error (`Result<T, E | E2>`). Runs only
|
|
170
|
+
* on `Err`; `Ok` and `Defect` pass through. If `f` throws, the throw becomes a
|
|
171
|
+
* `Defect`. Use it for a failable effect _during_ error handling (e.g. writing
|
|
172
|
+
* the error to an audit log that may itself fail).
|
|
173
|
+
*
|
|
174
|
+
* @typeParam E2 - the error type the effect may introduce.
|
|
175
|
+
* @param f - the failable side effect; its `Ok` value is ignored.
|
|
176
|
+
*/
|
|
177
|
+
flatTapErr<E2>(f: (error: E) => Result$1<unknown, E2>): Result$1<T, E | E2>;
|
|
161
178
|
/**
|
|
162
179
|
* Recover from a `Defect` — the **only** combinator that can touch one.
|
|
163
180
|
*
|
|
@@ -358,7 +375,14 @@ type AsyncResult<T, E> = Awaitable<Result$1<T, E>> & {
|
|
|
358
375
|
mapErr<E2>(f: (error: E) => E2): AsyncResult<T, E2>; /** Asynchronous `orElse`. `f` may return a `Result` or an `AsyncResult`. */
|
|
359
376
|
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`. */
|
|
360
377
|
recover<U>(f: (error: E) => U): AsyncResult<T | U, never>; /** Asynchronous `tapErr`. `f` is synchronous; a throw becomes a `Defect`. */
|
|
361
|
-
tapErr(f: (error: E) => void): AsyncResult<T, E>;
|
|
378
|
+
tapErr(f: (error: E) => void): AsyncResult<T, E>;
|
|
379
|
+
/**
|
|
380
|
+
* Asynchronous `flatTapErr` — a failable tap on the error that keeps the
|
|
381
|
+
* original error. `f` may return a `Result` **or** an `AsyncResult`; its `Ok`
|
|
382
|
+
* value is discarded, an `Err`/`Defect` from `f` threads through, and a throw
|
|
383
|
+
* becomes a `Defect`.
|
|
384
|
+
*/
|
|
385
|
+
flatTapErr<E2>(f: (error: E) => Result$1<unknown, E2> | AsyncResult<unknown, E2>): AsyncResult<T, E | E2>; /** Asynchronous `recoverDefect`. `f` may return a `Result` or an `AsyncResult`. */
|
|
362
386
|
recoverDefect<U, E2>(f: (cause: unknown) => Result$1<U, E2> | AsyncResult<U, E2>): AsyncResult<T | U, E | E2>; /** Asynchronous `tapDefect`. */
|
|
363
387
|
tapDefect(f: (cause: unknown) => void): AsyncResult<T, E>; /** Asynchronous `match`. Handlers are synchronous; resolves to `R`. */
|
|
364
388
|
match<R>(cases: {
|
|
@@ -477,6 +501,19 @@ declare class UnwrapError<E = unknown> extends Error {
|
|
|
477
501
|
readonly error: E;
|
|
478
502
|
constructor(error: E);
|
|
479
503
|
}
|
|
504
|
+
/**
|
|
505
|
+
* Type guard: is `x` a {@link Result} (any of `Ok` / `Err` / `Defect`)?
|
|
506
|
+
*
|
|
507
|
+
* @remarks
|
|
508
|
+
* Unlike {@link isOk} / {@link isErr} / {@link isDefect}, which narrow a value
|
|
509
|
+
* already known to be a `Result`, this narrows from `unknown` — useful at an
|
|
510
|
+
* untyped boundary. It checks the value carries the `Result` prototype, so a
|
|
511
|
+
* look-alike plain object (`{ tag: "Ok" }`) is **not** matched. An `AsyncResult`
|
|
512
|
+
* is not a `Result` and returns `false`.
|
|
513
|
+
*
|
|
514
|
+
* @returns `true` when `x` is a `Result` produced by this library.
|
|
515
|
+
*/
|
|
516
|
+
declare function isResult(x: unknown): x is Result$1<unknown, unknown>;
|
|
480
517
|
//#endregion
|
|
481
518
|
//#region src/defect.d.ts
|
|
482
519
|
declare const DEFECT: unique symbol;
|
|
@@ -732,7 +769,7 @@ declare function allFromDictAsync<R extends AsyncResultRecord>(results: R): Asyn
|
|
|
732
769
|
* {@link Result.fromPromise}, {@link Result.fromSafePromise}, {@link Result.all},
|
|
733
770
|
* {@link Result.allAsync}, {@link Result.allFromDict},
|
|
734
771
|
* {@link Result.allFromDictAsync}, {@link Result.isOk}, {@link Result.isErr},
|
|
735
|
-
* {@link Result.isDefect}.
|
|
772
|
+
* {@link Result.isDefect}, {@link Result.isResult}.
|
|
736
773
|
*
|
|
737
774
|
* @remarks
|
|
738
775
|
* Purely additive sugar — each member **is** the corresponding free function.
|
|
@@ -762,6 +799,7 @@ declare const Result: {
|
|
|
762
799
|
readonly isOk: typeof isOk;
|
|
763
800
|
readonly isErr: typeof isErr;
|
|
764
801
|
readonly isDefect: typeof isDefect;
|
|
802
|
+
readonly isResult: typeof isResult;
|
|
765
803
|
};
|
|
766
804
|
type Result<T, E> = Result$1<T, E>;
|
|
767
805
|
//#endregion
|
|
@@ -887,5 +925,5 @@ declare function matchTags<T, E extends {
|
|
|
887
925
|
_tag: string;
|
|
888
926
|
}, R>(result: AsyncResult<T, E>, handlers: TagHandlers<T, E, R>): Promise<R>;
|
|
889
927
|
//#endregion
|
|
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 };
|
|
928
|
+
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, isResult, matchTags };
|
|
891
929
|
//# 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/do.ts","../src/interop.ts","../src/facade.ts","../src/tagged.ts"],"mappings":";;AAQA;;;;;KAAY,QAAA,oBAA4B,CAAA,GAAI,CAAA,CAAE,CAAA;;;;;;;AAAC;AAU/C;KAAY,KAAA,2BAAgC,QAAA,CAAS,IAAA,CAAK,CAAA,EAAG,CAAA,qBAAsB,CAAA,GAAI,CAAA;;;;;;;;;;KAW3E,aAAA;EAXgC;;;;;;;;AAA4C;EAqBtF,GAAA,IAAO,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,CAAA,GAAI,QAAA,CAAO,CAAA,EAAG,CAAA;EAVf;;;;;;;;;;EAqBvB,OAAA,QAAe,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,QAAA,CAAO,CAAA,EAAG,EAAA,IAAM,QAAA,CAAO,CAAA,EAAG,CAAA,GAAI,EAAA;EAAP;;;;;;;;EASvD,GAAA,CAAI,CAAA,GAAI,KAAA,EAAO,CAAA,YAAa,QAAA,CAAO,CAAA,EAAG,CAAA;EAiBO;;;;;;;;;;;;;;;;EAA7C,OAAA,KAAY,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,QAAA,UAAgB,EAAA,IAAM,QAAA,CAAO,CAAA,EAAG,CAAA,GAAI,EAAA;EAuB9D;;;;;;;;;;;;;;;;;;;EAHH,IAAA,0BACE,IAAA,EAAM,CAAA,EACN,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,QAAA,CAAO,CAAA,EAAG,EAAA,IAC1B,QAAA,CAAO,KAAA,CAAM,CAAA,EAAG,CAAA,EAAG,CAAA,GAAI,CAAA,GAAI,EAAA;EA6CQ;;;;;;;;;;;;;;EA9BtC,GAAA,sBAAyB,IAAA,EAAM,CAAA,EAAG,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,CAAA,GAAI,QAAA,CAAO,KAAA,CAAM,CAAA,EAAG,CAAA,EAAG,CAAA,GAAI,CAAA;EAoD/C;;;;;;;EA5C/B,EAAA,IAAM,KAAA,EAAO,CAAA,GAAI,QAAA,CAAO,CAAA,EAAG,CAAA;
|
|
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","../src/tagged.ts"],"mappings":";;AAQA;;;;;KAAY,QAAA,oBAA4B,CAAA,GAAI,CAAA,CAAE,CAAA;;;;;;;AAAC;AAU/C;KAAY,KAAA,2BAAgC,QAAA,CAAS,IAAA,CAAK,CAAA,EAAG,CAAA,qBAAsB,CAAA,GAAI,CAAA;;;;;;;;;;KAW3E,aAAA;EAXgC;;;;;;;;AAA4C;EAqBtF,GAAA,IAAO,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,CAAA,GAAI,QAAA,CAAO,CAAA,EAAG,CAAA;EAVf;;;;;;;;;;EAqBvB,OAAA,QAAe,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,QAAA,CAAO,CAAA,EAAG,EAAA,IAAM,QAAA,CAAO,CAAA,EAAG,CAAA,GAAI,EAAA;EAAP;;;;;;;;EASvD,GAAA,CAAI,CAAA,GAAI,KAAA,EAAO,CAAA,YAAa,QAAA,CAAO,CAAA,EAAG,CAAA;EAiBO;;;;;;;;;;;;;;;;EAA7C,OAAA,KAAY,CAAA,GAAI,KAAA,EAA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A,EAAM,GAAA;AAAA;;;;APPc;AAU/C;;;;;;KOSY,sBAAA;EAAA,eACK,KAAA,OAAY,IAAA,QAAY,CAAA,wBAAyB,CAAA,GAAI,mBAAA,CAAoB,GAAA,EAAK,CAAA;AAAA;;;;;;;;;;;;;;APVP;AAWxF;;;;;;;;;;;;;;;;;;;;;;;;;;iBO0CgB,WAAA,qBACd,GAAA,EAAK,GAAA,EACL,OAAA;EAAA,SAAqB,IAAA;AAAA,IACpB,sBAAA,CAAuB,GAAA;;;;;;;;;;KA4Bd,WAAA;EAA2B,IAAA;AAAA;EACrC,EAAA,GAAK,KAAA,EAAO,CAAA,KAAM,CAAA;EAClB,MAAA,GAAS,KAAA,cAAmB,CAAA;AAAA,YAClB,CAAA,YAAa,KAAA,EAAO,OAAA,CAAQ,CAAA;EAAK,IAAA,EAAM,CAAA;AAAA,OAAS,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAgC5C,SAAA;EAAyB,IAAA;AAAA,MACvC,MAAA,EAAQ,QAAA,CAAO,CAAA,EAAG,CAAA,GAClB,QAAA,EAAU,WAAA,CAAY,CAAA,EAAG,CAAA,EAAG,CAAA,IAC3B,CAAA;AAAA,iBACa,SAAA;EAAyB,IAAA;AAAA,MACvC,MAAA,EAAQ,WAAA,CAAY,CAAA,EAAG,CAAA,GACvB,QAAA,EAAU,WAAA,CAAY,CAAA,EAAG,CAAA,EAAG,CAAA,IAC3B,OAAA,CAAQ,CAAA"}
|
package/dist/index.d.mts
CHANGED
|
@@ -158,6 +158,23 @@ type ResultMethods<T, E> = {
|
|
|
158
158
|
* @param f - the side effect (its return value is ignored).
|
|
159
159
|
*/
|
|
160
160
|
tapErr(f: (error: E) => void): Result$1<T, E>;
|
|
161
|
+
/**
|
|
162
|
+
* Run a **failable** side effect on the error, keeping the original error but
|
|
163
|
+
* threading the effect's own error.
|
|
164
|
+
*
|
|
165
|
+
* @remarks
|
|
166
|
+
* The error-channel mirror of {@link ResultMethods.flatTap | flatTap}: `f`
|
|
167
|
+
* returns a `Result`, but its **success value is discarded** — on the effect's
|
|
168
|
+
* `Ok` the original `Err` flows through unchanged, while an `Err` (or `Defect`)
|
|
169
|
+
* from `f` short-circuits and threads its error (`Result<T, E | E2>`). Runs only
|
|
170
|
+
* on `Err`; `Ok` and `Defect` pass through. If `f` throws, the throw becomes a
|
|
171
|
+
* `Defect`. Use it for a failable effect _during_ error handling (e.g. writing
|
|
172
|
+
* the error to an audit log that may itself fail).
|
|
173
|
+
*
|
|
174
|
+
* @typeParam E2 - the error type the effect may introduce.
|
|
175
|
+
* @param f - the failable side effect; its `Ok` value is ignored.
|
|
176
|
+
*/
|
|
177
|
+
flatTapErr<E2>(f: (error: E) => Result$1<unknown, E2>): Result$1<T, E | E2>;
|
|
161
178
|
/**
|
|
162
179
|
* Recover from a `Defect` — the **only** combinator that can touch one.
|
|
163
180
|
*
|
|
@@ -358,7 +375,14 @@ type AsyncResult<T, E> = Awaitable<Result$1<T, E>> & {
|
|
|
358
375
|
mapErr<E2>(f: (error: E) => E2): AsyncResult<T, E2>; /** Asynchronous `orElse`. `f` may return a `Result` or an `AsyncResult`. */
|
|
359
376
|
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`. */
|
|
360
377
|
recover<U>(f: (error: E) => U): AsyncResult<T | U, never>; /** Asynchronous `tapErr`. `f` is synchronous; a throw becomes a `Defect`. */
|
|
361
|
-
tapErr(f: (error: E) => void): AsyncResult<T, E>;
|
|
378
|
+
tapErr(f: (error: E) => void): AsyncResult<T, E>;
|
|
379
|
+
/**
|
|
380
|
+
* Asynchronous `flatTapErr` — a failable tap on the error that keeps the
|
|
381
|
+
* original error. `f` may return a `Result` **or** an `AsyncResult`; its `Ok`
|
|
382
|
+
* value is discarded, an `Err`/`Defect` from `f` threads through, and a throw
|
|
383
|
+
* becomes a `Defect`.
|
|
384
|
+
*/
|
|
385
|
+
flatTapErr<E2>(f: (error: E) => Result$1<unknown, E2> | AsyncResult<unknown, E2>): AsyncResult<T, E | E2>; /** Asynchronous `recoverDefect`. `f` may return a `Result` or an `AsyncResult`. */
|
|
362
386
|
recoverDefect<U, E2>(f: (cause: unknown) => Result$1<U, E2> | AsyncResult<U, E2>): AsyncResult<T | U, E | E2>; /** Asynchronous `tapDefect`. */
|
|
363
387
|
tapDefect(f: (cause: unknown) => void): AsyncResult<T, E>; /** Asynchronous `match`. Handlers are synchronous; resolves to `R`. */
|
|
364
388
|
match<R>(cases: {
|
|
@@ -477,6 +501,19 @@ declare class UnwrapError<E = unknown> extends Error {
|
|
|
477
501
|
readonly error: E;
|
|
478
502
|
constructor(error: E);
|
|
479
503
|
}
|
|
504
|
+
/**
|
|
505
|
+
* Type guard: is `x` a {@link Result} (any of `Ok` / `Err` / `Defect`)?
|
|
506
|
+
*
|
|
507
|
+
* @remarks
|
|
508
|
+
* Unlike {@link isOk} / {@link isErr} / {@link isDefect}, which narrow a value
|
|
509
|
+
* already known to be a `Result`, this narrows from `unknown` — useful at an
|
|
510
|
+
* untyped boundary. It checks the value carries the `Result` prototype, so a
|
|
511
|
+
* look-alike plain object (`{ tag: "Ok" }`) is **not** matched. An `AsyncResult`
|
|
512
|
+
* is not a `Result` and returns `false`.
|
|
513
|
+
*
|
|
514
|
+
* @returns `true` when `x` is a `Result` produced by this library.
|
|
515
|
+
*/
|
|
516
|
+
declare function isResult(x: unknown): x is Result$1<unknown, unknown>;
|
|
480
517
|
//#endregion
|
|
481
518
|
//#region src/defect.d.ts
|
|
482
519
|
declare const DEFECT: unique symbol;
|
|
@@ -732,7 +769,7 @@ declare function allFromDictAsync<R extends AsyncResultRecord>(results: R): Asyn
|
|
|
732
769
|
* {@link Result.fromPromise}, {@link Result.fromSafePromise}, {@link Result.all},
|
|
733
770
|
* {@link Result.allAsync}, {@link Result.allFromDict},
|
|
734
771
|
* {@link Result.allFromDictAsync}, {@link Result.isOk}, {@link Result.isErr},
|
|
735
|
-
* {@link Result.isDefect}.
|
|
772
|
+
* {@link Result.isDefect}, {@link Result.isResult}.
|
|
736
773
|
*
|
|
737
774
|
* @remarks
|
|
738
775
|
* Purely additive sugar — each member **is** the corresponding free function.
|
|
@@ -762,6 +799,7 @@ declare const Result: {
|
|
|
762
799
|
readonly isOk: typeof isOk;
|
|
763
800
|
readonly isErr: typeof isErr;
|
|
764
801
|
readonly isDefect: typeof isDefect;
|
|
802
|
+
readonly isResult: typeof isResult;
|
|
765
803
|
};
|
|
766
804
|
type Result<T, E> = Result$1<T, E>;
|
|
767
805
|
//#endregion
|
|
@@ -887,5 +925,5 @@ declare function matchTags<T, E extends {
|
|
|
887
925
|
_tag: string;
|
|
888
926
|
}, R>(result: AsyncResult<T, E>, handlers: TagHandlers<T, E, R>): Promise<R>;
|
|
889
927
|
//#endregion
|
|
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 };
|
|
928
|
+
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, isResult, matchTags };
|
|
891
929
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/constructors.ts","../src/core.ts","../src/defect.ts","../src/do.ts","../src/interop.ts","../src/facade.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AAA;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/constructors.ts","../src/core.ts","../src/defect.ts","../src/do.ts","../src/interop.ts","../src/facade.ts","../src/tagged.ts"],"mappings":";;AAQA;;;;;KAAY,QAAA,oBAA4B,CAAA,GAAI,CAAA,CAAE,CAAA;;;;;;;AAAC;AAU/C;KAAY,KAAA,2BAAgC,QAAA,CAAS,IAAA,CAAK,CAAA,EAAG,CAAA,qBAAsB,CAAA,GAAI,CAAA;;;;;;;;;;KAW3E,aAAA;EAXgC;;;;;;;;AAA4C;EAqBtF,GAAA,IAAO,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,CAAA,GAAI,QAAA,CAAO,CAAA,EAAG,CAAA;EAVf;;;;;;;;;;EAqBvB,OAAA,QAAe,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,QAAA,CAAO,CAAA,EAAG,EAAA,IAAM,QAAA,CAAO,CAAA,EAAG,CAAA,GAAI,EAAA;EAAP;;;;;;;;EASvD,GAAA,CAAI,CAAA,GAAI,KAAA,EAAO,CAAA,YAAa,QAAA,CAAO,CAAA,EAAG,CAAA;EAiBO;;;;;;;;;;;;;;;;EAA7C,OAAA,KAAY,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,QAAA,UAAgB,EAAA,IAAM,QAAA,CAAO,CAAA,EAAG,CAAA,GAAI,EAAA;EAuB9D;;;;;;;;;;;;;;;;;;;EAHH,IAAA,0BACE,IAAA,EAAM,CAAA,EACN,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,QAAA,CAAO,CAAA,EAAG,EAAA,IAC1B,QAAA,CAAO,KAAA,CAAM,CAAA,EAAG,CAAA,EAAG,CAAA,GAAI,CAAA,GAAI,EAAA;EA6CQ;;;;;;;;;;;;;;EA9BtC,GAAA,sBAAyB,IAAA,EAAM,CAAA,EAAG,CAAA,GAAI,KAAA,EAAO,CAAA,KAAM,CAAA,GAAI,QAAA,CAAO,KAAA,CAAM,CAAA,E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B,CAAA,YAAa,KAAA,EAAO,OAAA,CAAQ,CAAA;EAAK,IAAA,EAAM,CAAA;AAAA,OAAS,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAgC5C,SAAA;EAAyB,IAAA;AAAA,MACvC,MAAA,EAAQ,QAAA,CAAO,CAAA,EAAG,CAAA,GAClB,QAAA,EAAU,WAAA,CAAY,CAAA,EAAG,CAAA,EAAG,CAAA,IAC3B,CAAA;AAAA,iBACa,SAAA;EAAyB,IAAA;AAAA,MACvC,MAAA,EAAQ,WAAA,CAAY,CAAA,EAAG,CAAA,GACvB,QAAA,EAAU,WAAA,CAAY,CAAA,EAAG,CAAA,EAAG,CAAA,IAC3B,OAAA,CAAQ,CAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -126,6 +126,15 @@ var Res = class {
|
|
|
126
126
|
return defectRes(cause);
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
|
+
flatTapErr(f) {
|
|
130
|
+
if (this.tag !== "Err") return this;
|
|
131
|
+
try {
|
|
132
|
+
const r = f(this.error);
|
|
133
|
+
return r.tag === "Ok" ? this : passThrough(r);
|
|
134
|
+
} catch (cause) {
|
|
135
|
+
return defectRes(cause);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
129
138
|
recoverDefect(f) {
|
|
130
139
|
if (this.tag !== "Defect") return this;
|
|
131
140
|
try {
|
|
@@ -231,6 +240,21 @@ function defectRes(cause) {
|
|
|
231
240
|
});
|
|
232
241
|
}
|
|
233
242
|
/**
|
|
243
|
+
* Type guard: is `x` a {@link Result} (any of `Ok` / `Err` / `Defect`)?
|
|
244
|
+
*
|
|
245
|
+
* @remarks
|
|
246
|
+
* Unlike {@link isOk} / {@link isErr} / {@link isDefect}, which narrow a value
|
|
247
|
+
* already known to be a `Result`, this narrows from `unknown` — useful at an
|
|
248
|
+
* untyped boundary. It checks the value carries the `Result` prototype, so a
|
|
249
|
+
* look-alike plain object (`{ tag: "Ok" }`) is **not** matched. An `AsyncResult`
|
|
250
|
+
* is not a `Result` and returns `false`.
|
|
251
|
+
*
|
|
252
|
+
* @returns `true` when `x` is a `Result` produced by this library.
|
|
253
|
+
*/
|
|
254
|
+
function isResult(x) {
|
|
255
|
+
return x instanceof Res;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
234
258
|
* Reuse a non-matching variant (an `Err` or `Defect`) as a differently-typed
|
|
235
259
|
* `Result`, with no runtime work. Sound because the passed-through variant
|
|
236
260
|
* carries no value of the changed success type, so retyping it is a no-op — only
|
|
@@ -394,6 +418,17 @@ var AsyncRes = class AsyncRes {
|
|
|
394
418
|
}
|
|
395
419
|
}));
|
|
396
420
|
}
|
|
421
|
+
flatTapErr(f) {
|
|
422
|
+
return new AsyncRes(this.promise.then(async (r) => {
|
|
423
|
+
if (r.tag !== "Err") return passThrough(r);
|
|
424
|
+
try {
|
|
425
|
+
const inner = await f(r.error);
|
|
426
|
+
return inner.tag === "Ok" ? passThrough(r) : passThrough(inner);
|
|
427
|
+
} catch (cause) {
|
|
428
|
+
return defectRes(cause);
|
|
429
|
+
}
|
|
430
|
+
}));
|
|
431
|
+
}
|
|
397
432
|
recoverDefect(f) {
|
|
398
433
|
return new AsyncRes(this.promise.then(async (r) => {
|
|
399
434
|
if (r.tag !== "Defect") return r;
|
|
@@ -815,7 +850,7 @@ function allFromDictAsync(results) {
|
|
|
815
850
|
* {@link Result.fromPromise}, {@link Result.fromSafePromise}, {@link Result.all},
|
|
816
851
|
* {@link Result.allAsync}, {@link Result.allFromDict},
|
|
817
852
|
* {@link Result.allFromDictAsync}, {@link Result.isOk}, {@link Result.isErr},
|
|
818
|
-
* {@link Result.isDefect}.
|
|
853
|
+
* {@link Result.isDefect}, {@link Result.isResult}.
|
|
819
854
|
*
|
|
820
855
|
* @remarks
|
|
821
856
|
* Purely additive sugar — each member **is** the corresponding free function.
|
|
@@ -844,7 +879,8 @@ const Result = {
|
|
|
844
879
|
allFromDictAsync,
|
|
845
880
|
isOk,
|
|
846
881
|
isErr,
|
|
847
|
-
isDefect
|
|
882
|
+
isDefect,
|
|
883
|
+
isResult
|
|
848
884
|
};
|
|
849
885
|
//#endregion
|
|
850
886
|
//#region src/tagged.ts
|
|
@@ -914,6 +950,6 @@ function matchTags(result, handlers) {
|
|
|
914
950
|
});
|
|
915
951
|
}
|
|
916
952
|
//#endregion
|
|
917
|
-
export { Defect, Do, Err, Ok, Result, TaggedError, UnwrapError, all, allAsync, allFromDict, allFromDictAsync, fromNullable, fromPromise, fromSafePromise, fromThrowable, isDefect, isErr, isOk, matchTags };
|
|
953
|
+
export { Defect, Do, Err, Ok, Result, TaggedError, UnwrapError, all, allAsync, allFromDict, allFromDictAsync, fromNullable, fromPromise, fromSafePromise, fromThrowable, isDefect, isErr, isOk, isResult, matchTags };
|
|
918
954
|
|
|
919
955
|
//# sourceMappingURL=index.mjs.map
|