@shirudo/result 1.0.1 → 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/collections.cjs +4 -3
- package/dist/collections.d.cts +2 -2
- package/dist/collections.d.mts +2 -2
- package/dist/collections.mjs +2 -2
- package/dist/errors.cjs +131 -20
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.cts +63 -2
- package/dist/errors.d.cts.map +1 -0
- package/dist/errors.d.mts +63 -2
- package/dist/errors.d.mts.map +1 -0
- package/dist/errors.mjs +109 -2
- package/dist/errors.mjs.map +1 -0
- package/dist/{flatten-Df9U40nO.cjs → flatten-B_XIkaOK.cjs} +29 -3
- package/dist/flatten-B_XIkaOK.cjs.map +1 -0
- package/dist/flatten-C7D6Kttf.d.mts +81 -0
- package/dist/flatten-C7D6Kttf.d.mts.map +1 -0
- package/dist/{flatten-C6Y9hx79.mjs → flatten-ChTL5BfA.mjs} +24 -4
- package/dist/flatten-ChTL5BfA.mjs.map +1 -0
- package/dist/flatten-D0K8UcQH.d.cts +81 -0
- package/dist/flatten-D0K8UcQH.d.cts.map +1 -0
- package/dist/index.cjs +90 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +78 -58
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +78 -58
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +58 -12
- package/dist/index.mjs.map +1 -1
- package/dist/operators.cjs +31 -30
- package/dist/operators.d.cts +2 -2
- package/dist/operators.d.mts +2 -2
- package/dist/operators.mjs +2 -2
- package/dist/{result-CY-KIivk.cjs → result-BBOGxvSH.cjs} +86 -503
- package/dist/result-BBOGxvSH.cjs.map +1 -0
- package/dist/{result-DKKaNdOx.mjs → result-q9Na2bGa.mjs} +87 -372
- package/dist/result-q9Na2bGa.mjs.map +1 -0
- package/dist/sequence-DDwePRLd.d.cts +283 -0
- package/dist/sequence-DDwePRLd.d.cts.map +1 -0
- package/dist/sequence-DDwePRLd.d.mts +283 -0
- package/dist/sequence-DDwePRLd.d.mts.map +1 -0
- package/dist/swap-BnyMBdD_.cjs +552 -0
- package/dist/swap-BnyMBdD_.cjs.map +1 -0
- package/dist/swap-CFD2g1cB.mjs +385 -0
- package/dist/swap-CFD2g1cB.mjs.map +1 -0
- package/dist/swap-CrHQZIax.d.cts +212 -0
- package/dist/swap-CrHQZIax.d.cts.map +1 -0
- package/dist/swap-DT4LdRFV.d.mts +212 -0
- package/dist/swap-DT4LdRFV.d.mts.map +1 -0
- package/package.json +9 -8
- package/dist/errors-2WOswg7r.mjs +0 -95
- package/dist/errors-2WOswg7r.mjs.map +0 -1
- package/dist/errors-BFjY06EV.d.cts +0 -55
- package/dist/errors-BFjY06EV.d.cts.map +0 -1
- package/dist/errors-C5qGMRiU.d.mts +0 -55
- package/dist/errors-C5qGMRiU.d.mts.map +0 -1
- package/dist/errors-D2EMzJQl.cjs +0 -209
- package/dist/errors-D2EMzJQl.cjs.map +0 -1
- package/dist/flatten-B8bN6fiI.d.mts +0 -71
- package/dist/flatten-B8bN6fiI.d.mts.map +0 -1
- package/dist/flatten-C6Y9hx79.mjs.map +0 -1
- package/dist/flatten-DK7eJKPx.d.cts +0 -71
- package/dist/flatten-DK7eJKPx.d.cts.map +0 -1
- package/dist/flatten-Df9U40nO.cjs.map +0 -1
- package/dist/mapOrElse-B0_4r6Jn.mjs +0 -96
- package/dist/mapOrElse-B0_4r6Jn.mjs.map +0 -1
- package/dist/mapOrElse-B5gx9x2E.d.mts +0 -64
- package/dist/mapOrElse-B5gx9x2E.d.mts.map +0 -1
- package/dist/mapOrElse-DIe7LkYV.d.cts +0 -64
- package/dist/mapOrElse-DIe7LkYV.d.cts.map +0 -1
- package/dist/mapOrElse-H-GvAUka.cjs +0 -137
- package/dist/mapOrElse-H-GvAUka.cjs.map +0 -1
- package/dist/result-CY-KIivk.cjs.map +0 -1
- package/dist/result-DKKaNdOx.mjs.map +0 -1
- package/dist/sequence-Br6tAIIu.d.cts +0 -419
- package/dist/sequence-Br6tAIIu.d.cts.map +0 -1
- package/dist/sequence-C0jlR3AY.d.mts +0 -419
- package/dist/sequence-C0jlR3AY.d.mts.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as collectFirstOkAsync, i as collectFirstOkParallelAsync, n as partition, o as
|
|
3
|
-
import {
|
|
4
|
-
import { a as
|
|
1
|
+
import { S as Awaitable, _ as tryFn, a as Ok, b as isResult, c as ResultType, d as fromPromise, f as fromThrowable, g as tryAsync, h as okIfLazy, i as Err, l as err, m as okIf, n as sequence, o as OperatorFunction, p as ok, r as AsyncOperatorFunction, s as Result, t as all, u as fromNullable, v as combine, x as matchTag, y as zip } from "./sequence-DDwePRLd.cjs";
|
|
2
|
+
import { a as collectFirstOkAsync, i as collectFirstOkParallelAsync, n as partition, o as collectFirstOk, r as collectAllErrors, s as sequenceRecord, t as flatten } from "./flatten-D0K8UcQH.cjs";
|
|
3
|
+
import { ERR_EXPECT_ERR, ERR_EXPECT_OK, ERR_INVALID_RESULT_STATE, ERR_INVALID_STATE, ERR_MATCH_ERR_HANDLER_NOT_RESULT, ERR_MATCH_ON_OK, ERR_MATCH_TAG_MISSING_HANDLER, ERR_TASK_YIELD_NOT_RESULT, ERR_UNWRAP_ERR_ON_OK, ERR_UNWRAP_ON_ERR, ExpectErrError, ExpectOkError, InvalidResultStateError, MatchErrHandlerNotResultError, MatchOnOkError, MatchTagMissingHandlerError, ResultError, ResultErrorCode, ResultTypeError, TaskYieldNotResultError, UnwrapErrOnOkError, UnwrapOnErrError } from "./errors.cjs";
|
|
4
|
+
import { C as tap, D as mapErr, E as mapBoth, O as map, S as filter, T as bimap, _ as recoverWith, a as or, b as match, c as tryCatchAsync, d as filterAsync, f as tapAsync, g as recover, h as mapAsync, i as orElse, l as matchAsync, m as mapErrAsync, n as mapOrElse, o as and, p as flatMapAsync, r as mapOr, s as tryMapAsync, t as swap, u as foldAsync, v as tryMap, w as flatMap, x as fold, y as tryCatch } from "./swap-CrHQZIax.cjs";
|
|
5
5
|
|
|
6
6
|
//#region src/gen.d.ts
|
|
7
7
|
type AnyGenerator<Y = unknown, R = unknown, N = unknown> = Generator<Y, R, N> | AsyncGenerator<Y, R, N>;
|
|
@@ -11,118 +11,138 @@ type AwaitedReturn<R> = Awaited<R>;
|
|
|
11
11
|
type OkOfReturn<R> = AwaitedReturn<R> extends Result<infer T, any> ? T : AwaitedReturn<R>;
|
|
12
12
|
type ErrOfReturn<R> = AwaitedReturn<R> extends Result<any, infer E> ? E : never;
|
|
13
13
|
/**
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
* Generator-based do-notation for `Result`.
|
|
15
|
+
*
|
|
16
|
+
* Usage:
|
|
17
|
+
* ```ts
|
|
18
|
+
* const out = await task(async function* () {
|
|
19
|
+
* const user = yield* await fromPromise(findUser(1));
|
|
20
|
+
* const email = yield* validate(user.email);
|
|
21
|
+
* return email;
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
25
|
declare function task<const Y, const R>(makeGenerator: () => AnyGenerator<Y, R, unknown>): Promise<Result<OkOfReturn<R>, ErrorOfYield<Y> | ErrOfReturn<R>>>;
|
|
26
26
|
declare function task<const Y, const R, EThrown>(makeGenerator: () => AnyGenerator<Y, R, unknown>, onThrow: OnThrow<EThrown>): Promise<Result<OkOfReturn<R>, ErrorOfYield<Y> | ErrOfReturn<R> | EThrown>>;
|
|
27
27
|
declare const gen: typeof task;
|
|
28
28
|
//#endregion
|
|
29
29
|
//#region src/core/unwrap.d.ts
|
|
30
30
|
/**
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
* Returns the value or throws an Error.
|
|
32
|
+
* Corresponds to Rust `unwrap`.
|
|
33
|
+
*/
|
|
34
34
|
declare function unwrap<T, E>(result: Result<T, E>): T;
|
|
35
35
|
//#endregion
|
|
36
36
|
//#region src/core/unwrapOr.d.ts
|
|
37
37
|
/**
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
* Returns the value or a default value.
|
|
39
|
+
* Pure function alternative to the instance method.
|
|
40
|
+
*/
|
|
41
41
|
declare function unwrapOr<T, E>(result: Result<T, E>, defaultValue: T): T;
|
|
42
42
|
//#endregion
|
|
43
43
|
//#region src/core/unwrapOrElse.d.ts
|
|
44
44
|
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
* Returns the value or calculates a default value using a function.
|
|
46
|
+
* Corresponds to Rust `unwrap_or_else`.
|
|
47
|
+
*/
|
|
48
48
|
declare function unwrapOrElse<T, E>(result: Result<T, E>, fn: (error: E) => T): T;
|
|
49
49
|
//#endregion
|
|
50
50
|
//#region src/core/unwrapOrDefault.d.ts
|
|
51
51
|
/**
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
* Alias for `unwrapOr`.
|
|
53
|
+
*
|
|
54
|
+
* @deprecated Use {@link unwrapOr} instead. The name is misleading: Rust's
|
|
55
|
+
* `unwrap_or_default` takes no argument (it uses the type's `Default`),
|
|
56
|
+
* whereas this function requires an explicit default value — which is exactly
|
|
57
|
+
* what `unwrapOr` does.
|
|
58
|
+
*/
|
|
55
59
|
declare function unwrapOrDefault<T, E>(result: Result<T, E>, defaultValue: T): T;
|
|
56
60
|
//#endregion
|
|
57
61
|
//#region src/core/unwrapOrThrow.d.ts
|
|
58
62
|
/**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
63
|
+
* Returns the value or throws the original Err value (not wrapped).
|
|
64
|
+
* Useful to preserve `Error` instances including stack traces.
|
|
65
|
+
*/
|
|
62
66
|
declare function unwrapOrThrow<T, E>(result: Result<T, E>): T;
|
|
63
67
|
//#endregion
|
|
64
68
|
//#region src/core/unwrapErr.d.ts
|
|
65
69
|
/**
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
70
|
+
* Returns the error or throws an Error.
|
|
71
|
+
* Corresponds to Rust `unwrap_err`.
|
|
72
|
+
*/
|
|
69
73
|
declare function unwrapErr<T, E>(result: Result<T, E>): E;
|
|
70
74
|
//#endregion
|
|
71
75
|
//#region src/core/expectResult.d.ts
|
|
72
76
|
/**
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
77
|
+
* Returns the value or throws an Error with a custom message.
|
|
78
|
+
* Corresponds to Rust `expect`.
|
|
79
|
+
*/
|
|
76
80
|
declare function expectResult<T, E>(result: Result<T, E>, message: string): T;
|
|
77
81
|
//#endregion
|
|
78
82
|
//#region src/core/expectErr.d.ts
|
|
79
83
|
/**
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
84
|
+
* Returns the error or throws an Error with a custom message.
|
|
85
|
+
* Corresponds to Rust `expect_err`.
|
|
86
|
+
*/
|
|
83
87
|
declare function expectErr<T, E>(result: Result<T, E>, message: string): E;
|
|
84
88
|
//#endregion
|
|
89
|
+
//#region src/core/fromSerialized.d.ts
|
|
90
|
+
/**
|
|
91
|
+
* Rebuilds a `Result` from its serialized discriminated form
|
|
92
|
+
* (`{ _tag: 'Ok', value }` / `{ _tag: 'Err', error }`), the shape produced
|
|
93
|
+
* by `Result.toSerialized()` and by `JSON.stringify` on a Result.
|
|
94
|
+
*
|
|
95
|
+
* Throws `InvalidResultStateError` for data that is not in that shape.
|
|
96
|
+
*/
|
|
97
|
+
declare function fromSerialized<T, E>(data: ResultType<T, E>): Result<T, E>;
|
|
98
|
+
//#endregion
|
|
85
99
|
//#region src/core/toPromise.d.ts
|
|
86
100
|
/**
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
101
|
+
* Converts a Result to a Promise.
|
|
102
|
+
* Ok → resolve(value), Err → reject(error)
|
|
103
|
+
*/
|
|
90
104
|
declare function toPromise<T, E>(result: Result<T, E>): Promise<T>;
|
|
91
105
|
//#endregion
|
|
92
106
|
//#region src/core/toNullable.d.ts
|
|
93
107
|
/**
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
108
|
+
* Converts a Result to `T | null`.
|
|
109
|
+
* Ok → value, Err → null
|
|
110
|
+
*/
|
|
97
111
|
declare function toNullable<T, E>(result: Result<T, E>): T | null;
|
|
98
112
|
//#endregion
|
|
99
113
|
//#region src/core/isOk.d.ts
|
|
100
114
|
/**
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
115
|
+
* Checks if a Result is Ok.
|
|
116
|
+
* Pure function alternative to the instance method.
|
|
117
|
+
*/
|
|
104
118
|
declare function isOk<T, E>(result: Result<T, E>): result is Ok<T, E>;
|
|
105
119
|
//#endregion
|
|
106
120
|
//#region src/core/isErr.d.ts
|
|
107
121
|
/**
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
122
|
+
* Checks if a Result is Err.
|
|
123
|
+
* Pure function alternative to the instance method.
|
|
124
|
+
*/
|
|
111
125
|
declare function isErr<T, E>(result: Result<T, E>): result is Err<T, E>;
|
|
112
126
|
//#endregion
|
|
113
127
|
//#region src/core/contains.d.ts
|
|
114
128
|
/**
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
129
|
+
* Checks if the Result contains a specific value.
|
|
130
|
+
* Corresponds to Rust `contains`.
|
|
131
|
+
*
|
|
132
|
+
* Comparison uses `Object.is` (SameValue): `NaN` matches `NaN`, `+0` and
|
|
133
|
+
* `-0` are distinct, and objects are compared by reference.
|
|
134
|
+
*/
|
|
118
135
|
declare function contains<T, E>(result: Result<T, E>, value: T): boolean;
|
|
119
136
|
//#endregion
|
|
120
137
|
//#region src/core/containsErr.d.ts
|
|
121
138
|
/**
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
139
|
+
* Checks if the Result contains a specific error.
|
|
140
|
+
* Analogous to `contains` for the Err case.
|
|
141
|
+
*
|
|
142
|
+
* Comparison uses `Object.is` (SameValue): `NaN` matches `NaN`, `+0` and
|
|
143
|
+
* `-0` are distinct, and objects are compared by reference.
|
|
144
|
+
*/
|
|
125
145
|
declare function containsErr<T, E>(result: Result<T, E>, error: E): boolean;
|
|
126
146
|
//#endregion
|
|
127
|
-
export { AsyncOperatorFunction, Awaitable, ERR_EXPECT_ERR, ERR_EXPECT_OK, ERR_INVALID_RESULT_STATE, ERR_INVALID_STATE, ERR_MATCH_ERR_HANDLER_NOT_RESULT, ERR_MATCH_ON_OK, ERR_TASK_YIELD_NOT_RESULT, ERR_UNWRAP_ERR_ON_OK, ERR_UNWRAP_ON_ERR, Err, ExpectErrError, ExpectOkError, InvalidResultStateError, MatchErrHandlerNotResultError, MatchOnOkError, Ok, OperatorFunction, Result, ResultError, ResultErrorCode, ResultType, ResultTypeError, TaskYieldNotResultError, UnwrapErrOnOkError, UnwrapOnErrError, all, and, bimap, collectAllErrors, collectFirstOk, collectFirstOkAsync, collectFirstOkParallelAsync, combine, contains, containsErr, err, expectErr, expectResult, filter, filterAsync, flatMap, flatMapAsync, flatten, fold, foldAsync, fromNullable, fromPromise, fromThrowable, gen, isErr, isOk, isResult, map, mapAsync, mapBoth, mapErr, mapErrAsync, mapOr, mapOrElse, match, matchAsync, matchTag, ok, okIf, okIfLazy, or, orElse, partition, recover, recoverWith, sequence, sequenceRecord, swap, tap, tapAsync, task, toNullable, toPromise, tryAsync, tryCatch, tryCatchAsync, tryFn, tryMap, tryMapAsync, unwrap, unwrapErr, unwrapOr, unwrapOrDefault, unwrapOrElse, unwrapOrThrow, zip };
|
|
147
|
+
export { AsyncOperatorFunction, type Awaitable, ERR_EXPECT_ERR, ERR_EXPECT_OK, ERR_INVALID_RESULT_STATE, ERR_INVALID_STATE, ERR_MATCH_ERR_HANDLER_NOT_RESULT, ERR_MATCH_ON_OK, ERR_MATCH_TAG_MISSING_HANDLER, ERR_TASK_YIELD_NOT_RESULT, ERR_UNWRAP_ERR_ON_OK, ERR_UNWRAP_ON_ERR, Err, ExpectErrError, ExpectOkError, InvalidResultStateError, MatchErrHandlerNotResultError, MatchOnOkError, MatchTagMissingHandlerError, Ok, OperatorFunction, Result, ResultError, ResultErrorCode, ResultType, ResultTypeError, TaskYieldNotResultError, UnwrapErrOnOkError, UnwrapOnErrError, all, and, bimap, collectAllErrors, collectFirstOk, collectFirstOkAsync, collectFirstOkParallelAsync, combine, contains, containsErr, err, expectErr, expectResult, filter, filterAsync, flatMap, flatMapAsync, flatten, fold, foldAsync, fromNullable, fromPromise, fromSerialized, fromThrowable, gen, isErr, isOk, isResult, map, mapAsync, mapBoth, mapErr, mapErrAsync, mapOr, mapOrElse, match, matchAsync, matchTag, ok, okIf, okIfLazy, or, orElse, partition, recover, recoverWith, sequence, sequenceRecord, swap, tap, tapAsync, task, toNullable, toPromise, tryAsync, tryCatch, tryCatchAsync, tryFn, tryMap, tryMapAsync, unwrap, unwrapErr, unwrapOr, unwrapOrDefault, unwrapOrElse, unwrapOrThrow, zip };
|
|
128
148
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/gen.ts","../src/core/unwrap.ts","../src/core/unwrapOr.ts","../src/core/unwrapOrElse.ts","../src/core/unwrapOrDefault.ts","../src/core/unwrapOrThrow.ts","../src/core/unwrapErr.ts","../src/core/expectResult.ts","../src/core/expectErr.ts","../src/core/toPromise.ts","../src/core/toNullable.ts","../src/core/isOk.ts","../src/core/isErr.ts","../src/core/contains.ts","../src/core/containsErr.ts"],"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/gen.ts","../src/core/unwrap.ts","../src/core/unwrapOr.ts","../src/core/unwrapOrElse.ts","../src/core/unwrapOrDefault.ts","../src/core/unwrapOrThrow.ts","../src/core/unwrapErr.ts","../src/core/expectResult.ts","../src/core/expectErr.ts","../src/core/fromSerialized.ts","../src/core/toPromise.ts","../src/core/toNullable.ts","../src/core/isOk.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
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as collectFirstOkAsync, i as collectFirstOkParallelAsync, n as partition, o as
|
|
3
|
-
import {
|
|
4
|
-
import { a as
|
|
1
|
+
import { S as Awaitable, _ as tryFn, a as Ok, b as isResult, c as ResultType, d as fromPromise, f as fromThrowable, g as tryAsync, h as okIfLazy, i as Err, l as err, m as okIf, n as sequence, o as OperatorFunction, p as ok, r as AsyncOperatorFunction, s as Result, t as all, u as fromNullable, v as combine, x as matchTag, y as zip } from "./sequence-DDwePRLd.mjs";
|
|
2
|
+
import { a as collectFirstOkAsync, i as collectFirstOkParallelAsync, n as partition, o as collectFirstOk, r as collectAllErrors, s as sequenceRecord, t as flatten } from "./flatten-C7D6Kttf.mjs";
|
|
3
|
+
import { ERR_EXPECT_ERR, ERR_EXPECT_OK, ERR_INVALID_RESULT_STATE, ERR_INVALID_STATE, ERR_MATCH_ERR_HANDLER_NOT_RESULT, ERR_MATCH_ON_OK, ERR_MATCH_TAG_MISSING_HANDLER, ERR_TASK_YIELD_NOT_RESULT, ERR_UNWRAP_ERR_ON_OK, ERR_UNWRAP_ON_ERR, ExpectErrError, ExpectOkError, InvalidResultStateError, MatchErrHandlerNotResultError, MatchOnOkError, MatchTagMissingHandlerError, ResultError, ResultErrorCode, ResultTypeError, TaskYieldNotResultError, UnwrapErrOnOkError, UnwrapOnErrError } from "./errors.mjs";
|
|
4
|
+
import { C as tap, D as mapErr, E as mapBoth, O as map, S as filter, T as bimap, _ as recoverWith, a as or, b as match, c as tryCatchAsync, d as filterAsync, f as tapAsync, g as recover, h as mapAsync, i as orElse, l as matchAsync, m as mapErrAsync, n as mapOrElse, o as and, p as flatMapAsync, r as mapOr, s as tryMapAsync, t as swap, u as foldAsync, v as tryMap, w as flatMap, x as fold, y as tryCatch } from "./swap-DT4LdRFV.mjs";
|
|
5
5
|
|
|
6
6
|
//#region src/gen.d.ts
|
|
7
7
|
type AnyGenerator<Y = unknown, R = unknown, N = unknown> = Generator<Y, R, N> | AsyncGenerator<Y, R, N>;
|
|
@@ -11,118 +11,138 @@ type AwaitedReturn<R> = Awaited<R>;
|
|
|
11
11
|
type OkOfReturn<R> = AwaitedReturn<R> extends Result<infer T, any> ? T : AwaitedReturn<R>;
|
|
12
12
|
type ErrOfReturn<R> = AwaitedReturn<R> extends Result<any, infer E> ? E : never;
|
|
13
13
|
/**
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
* Generator-based do-notation for `Result`.
|
|
15
|
+
*
|
|
16
|
+
* Usage:
|
|
17
|
+
* ```ts
|
|
18
|
+
* const out = await task(async function* () {
|
|
19
|
+
* const user = yield* await fromPromise(findUser(1));
|
|
20
|
+
* const email = yield* validate(user.email);
|
|
21
|
+
* return email;
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
25
|
declare function task<const Y, const R>(makeGenerator: () => AnyGenerator<Y, R, unknown>): Promise<Result<OkOfReturn<R>, ErrorOfYield<Y> | ErrOfReturn<R>>>;
|
|
26
26
|
declare function task<const Y, const R, EThrown>(makeGenerator: () => AnyGenerator<Y, R, unknown>, onThrow: OnThrow<EThrown>): Promise<Result<OkOfReturn<R>, ErrorOfYield<Y> | ErrOfReturn<R> | EThrown>>;
|
|
27
27
|
declare const gen: typeof task;
|
|
28
28
|
//#endregion
|
|
29
29
|
//#region src/core/unwrap.d.ts
|
|
30
30
|
/**
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
* Returns the value or throws an Error.
|
|
32
|
+
* Corresponds to Rust `unwrap`.
|
|
33
|
+
*/
|
|
34
34
|
declare function unwrap<T, E>(result: Result<T, E>): T;
|
|
35
35
|
//#endregion
|
|
36
36
|
//#region src/core/unwrapOr.d.ts
|
|
37
37
|
/**
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
* Returns the value or a default value.
|
|
39
|
+
* Pure function alternative to the instance method.
|
|
40
|
+
*/
|
|
41
41
|
declare function unwrapOr<T, E>(result: Result<T, E>, defaultValue: T): T;
|
|
42
42
|
//#endregion
|
|
43
43
|
//#region src/core/unwrapOrElse.d.ts
|
|
44
44
|
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
* Returns the value or calculates a default value using a function.
|
|
46
|
+
* Corresponds to Rust `unwrap_or_else`.
|
|
47
|
+
*/
|
|
48
48
|
declare function unwrapOrElse<T, E>(result: Result<T, E>, fn: (error: E) => T): T;
|
|
49
49
|
//#endregion
|
|
50
50
|
//#region src/core/unwrapOrDefault.d.ts
|
|
51
51
|
/**
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
* Alias for `unwrapOr`.
|
|
53
|
+
*
|
|
54
|
+
* @deprecated Use {@link unwrapOr} instead. The name is misleading: Rust's
|
|
55
|
+
* `unwrap_or_default` takes no argument (it uses the type's `Default`),
|
|
56
|
+
* whereas this function requires an explicit default value — which is exactly
|
|
57
|
+
* what `unwrapOr` does.
|
|
58
|
+
*/
|
|
55
59
|
declare function unwrapOrDefault<T, E>(result: Result<T, E>, defaultValue: T): T;
|
|
56
60
|
//#endregion
|
|
57
61
|
//#region src/core/unwrapOrThrow.d.ts
|
|
58
62
|
/**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
63
|
+
* Returns the value or throws the original Err value (not wrapped).
|
|
64
|
+
* Useful to preserve `Error` instances including stack traces.
|
|
65
|
+
*/
|
|
62
66
|
declare function unwrapOrThrow<T, E>(result: Result<T, E>): T;
|
|
63
67
|
//#endregion
|
|
64
68
|
//#region src/core/unwrapErr.d.ts
|
|
65
69
|
/**
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
70
|
+
* Returns the error or throws an Error.
|
|
71
|
+
* Corresponds to Rust `unwrap_err`.
|
|
72
|
+
*/
|
|
69
73
|
declare function unwrapErr<T, E>(result: Result<T, E>): E;
|
|
70
74
|
//#endregion
|
|
71
75
|
//#region src/core/expectResult.d.ts
|
|
72
76
|
/**
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
77
|
+
* Returns the value or throws an Error with a custom message.
|
|
78
|
+
* Corresponds to Rust `expect`.
|
|
79
|
+
*/
|
|
76
80
|
declare function expectResult<T, E>(result: Result<T, E>, message: string): T;
|
|
77
81
|
//#endregion
|
|
78
82
|
//#region src/core/expectErr.d.ts
|
|
79
83
|
/**
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
84
|
+
* Returns the error or throws an Error with a custom message.
|
|
85
|
+
* Corresponds to Rust `expect_err`.
|
|
86
|
+
*/
|
|
83
87
|
declare function expectErr<T, E>(result: Result<T, E>, message: string): E;
|
|
84
88
|
//#endregion
|
|
89
|
+
//#region src/core/fromSerialized.d.ts
|
|
90
|
+
/**
|
|
91
|
+
* Rebuilds a `Result` from its serialized discriminated form
|
|
92
|
+
* (`{ _tag: 'Ok', value }` / `{ _tag: 'Err', error }`), the shape produced
|
|
93
|
+
* by `Result.toSerialized()` and by `JSON.stringify` on a Result.
|
|
94
|
+
*
|
|
95
|
+
* Throws `InvalidResultStateError` for data that is not in that shape.
|
|
96
|
+
*/
|
|
97
|
+
declare function fromSerialized<T, E>(data: ResultType<T, E>): Result<T, E>;
|
|
98
|
+
//#endregion
|
|
85
99
|
//#region src/core/toPromise.d.ts
|
|
86
100
|
/**
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
101
|
+
* Converts a Result to a Promise.
|
|
102
|
+
* Ok → resolve(value), Err → reject(error)
|
|
103
|
+
*/
|
|
90
104
|
declare function toPromise<T, E>(result: Result<T, E>): Promise<T>;
|
|
91
105
|
//#endregion
|
|
92
106
|
//#region src/core/toNullable.d.ts
|
|
93
107
|
/**
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
108
|
+
* Converts a Result to `T | null`.
|
|
109
|
+
* Ok → value, Err → null
|
|
110
|
+
*/
|
|
97
111
|
declare function toNullable<T, E>(result: Result<T, E>): T | null;
|
|
98
112
|
//#endregion
|
|
99
113
|
//#region src/core/isOk.d.ts
|
|
100
114
|
/**
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
115
|
+
* Checks if a Result is Ok.
|
|
116
|
+
* Pure function alternative to the instance method.
|
|
117
|
+
*/
|
|
104
118
|
declare function isOk<T, E>(result: Result<T, E>): result is Ok<T, E>;
|
|
105
119
|
//#endregion
|
|
106
120
|
//#region src/core/isErr.d.ts
|
|
107
121
|
/**
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
122
|
+
* Checks if a Result is Err.
|
|
123
|
+
* Pure function alternative to the instance method.
|
|
124
|
+
*/
|
|
111
125
|
declare function isErr<T, E>(result: Result<T, E>): result is Err<T, E>;
|
|
112
126
|
//#endregion
|
|
113
127
|
//#region src/core/contains.d.ts
|
|
114
128
|
/**
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
129
|
+
* Checks if the Result contains a specific value.
|
|
130
|
+
* Corresponds to Rust `contains`.
|
|
131
|
+
*
|
|
132
|
+
* Comparison uses `Object.is` (SameValue): `NaN` matches `NaN`, `+0` and
|
|
133
|
+
* `-0` are distinct, and objects are compared by reference.
|
|
134
|
+
*/
|
|
118
135
|
declare function contains<T, E>(result: Result<T, E>, value: T): boolean;
|
|
119
136
|
//#endregion
|
|
120
137
|
//#region src/core/containsErr.d.ts
|
|
121
138
|
/**
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
139
|
+
* Checks if the Result contains a specific error.
|
|
140
|
+
* Analogous to `contains` for the Err case.
|
|
141
|
+
*
|
|
142
|
+
* Comparison uses `Object.is` (SameValue): `NaN` matches `NaN`, `+0` and
|
|
143
|
+
* `-0` are distinct, and objects are compared by reference.
|
|
144
|
+
*/
|
|
125
145
|
declare function containsErr<T, E>(result: Result<T, E>, error: E): boolean;
|
|
126
146
|
//#endregion
|
|
127
|
-
export { AsyncOperatorFunction, Awaitable, ERR_EXPECT_ERR, ERR_EXPECT_OK, ERR_INVALID_RESULT_STATE, ERR_INVALID_STATE, ERR_MATCH_ERR_HANDLER_NOT_RESULT, ERR_MATCH_ON_OK, ERR_TASK_YIELD_NOT_RESULT, ERR_UNWRAP_ERR_ON_OK, ERR_UNWRAP_ON_ERR, Err, ExpectErrError, ExpectOkError, InvalidResultStateError, MatchErrHandlerNotResultError, MatchOnOkError, Ok, OperatorFunction, Result, ResultError, ResultErrorCode, ResultType, ResultTypeError, TaskYieldNotResultError, UnwrapErrOnOkError, UnwrapOnErrError, all, and, bimap, collectAllErrors, collectFirstOk, collectFirstOkAsync, collectFirstOkParallelAsync, combine, contains, containsErr, err, expectErr, expectResult, filter, filterAsync, flatMap, flatMapAsync, flatten, fold, foldAsync, fromNullable, fromPromise, fromThrowable, gen, isErr, isOk, isResult, map, mapAsync, mapBoth, mapErr, mapErrAsync, mapOr, mapOrElse, match, matchAsync, matchTag, ok, okIf, okIfLazy, or, orElse, partition, recover, recoverWith, sequence, sequenceRecord, swap, tap, tapAsync, task, toNullable, toPromise, tryAsync, tryCatch, tryCatchAsync, tryFn, tryMap, tryMapAsync, unwrap, unwrapErr, unwrapOr, unwrapOrDefault, unwrapOrElse, unwrapOrThrow, zip };
|
|
147
|
+
export { AsyncOperatorFunction, type Awaitable, ERR_EXPECT_ERR, ERR_EXPECT_OK, ERR_INVALID_RESULT_STATE, ERR_INVALID_STATE, ERR_MATCH_ERR_HANDLER_NOT_RESULT, ERR_MATCH_ON_OK, ERR_MATCH_TAG_MISSING_HANDLER, ERR_TASK_YIELD_NOT_RESULT, ERR_UNWRAP_ERR_ON_OK, ERR_UNWRAP_ON_ERR, Err, ExpectErrError, ExpectOkError, InvalidResultStateError, MatchErrHandlerNotResultError, MatchOnOkError, MatchTagMissingHandlerError, Ok, OperatorFunction, Result, ResultError, ResultErrorCode, ResultType, ResultTypeError, TaskYieldNotResultError, UnwrapErrOnOkError, UnwrapOnErrError, all, and, bimap, collectAllErrors, collectFirstOk, collectFirstOkAsync, collectFirstOkParallelAsync, combine, contains, containsErr, err, expectErr, expectResult, filter, filterAsync, flatMap, flatMapAsync, flatten, fold, foldAsync, fromNullable, fromPromise, fromSerialized, fromThrowable, gen, isErr, isOk, isResult, map, mapAsync, mapBoth, mapErr, mapErrAsync, mapOr, mapOrElse, match, matchAsync, matchTag, ok, okIf, okIfLazy, or, orElse, partition, recover, recoverWith, sequence, sequenceRecord, swap, tap, tapAsync, task, toNullable, toPromise, tryAsync, tryCatch, tryCatchAsync, tryFn, tryMap, tryMapAsync, unwrap, unwrapErr, unwrapOr, unwrapOrDefault, unwrapOrElse, unwrapOrThrow, zip };
|
|
128
148
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/gen.ts","../src/core/unwrap.ts","../src/core/unwrapOr.ts","../src/core/unwrapOrElse.ts","../src/core/unwrapOrDefault.ts","../src/core/unwrapOrThrow.ts","../src/core/unwrapErr.ts","../src/core/expectResult.ts","../src/core/expectErr.ts","../src/core/toPromise.ts","../src/core/toNullable.ts","../src/core/isOk.ts","../src/core/isErr.ts","../src/core/contains.ts","../src/core/containsErr.ts"],"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/gen.ts","../src/core/unwrap.ts","../src/core/unwrapOr.ts","../src/core/unwrapOrElse.ts","../src/core/unwrapOrDefault.ts","../src/core/unwrapOrThrow.ts","../src/core/unwrapErr.ts","../src/core/expectResult.ts","../src/core/expectErr.ts","../src/core/fromSerialized.ts","../src/core/toPromise.ts","../src/core/toNullable.ts","../src/core/isOk.ts","../src/core/isErr.ts","../src/core/contains.ts","../src/core/containsErr.ts"],"mappings":";;;;;;KAKK,YAAA,0CAAsD,SAAA,CAAU,CAAA,EAAG,CAAA,EAAG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FirstOkAsync, i as collectFirstOkParallelAsync, n as partition, o as
|
|
1
|
+
import { _ as matchTag, a as fromNullable, c as ok, d as tryAsync, f as tryFn, g as sequence, h as all, i as err, l as okIf, m as zip, n as Ok, o as fromPromise, p as combine, r as Result, s as fromThrowable, t as Err, u as okIfLazy, v as isResult } from "./result-q9Na2bGa.mjs";
|
|
2
|
+
import { ERR_EXPECT_ERR, ERR_EXPECT_OK, ERR_INVALID_RESULT_STATE, ERR_INVALID_STATE, ERR_MATCH_ERR_HANDLER_NOT_RESULT, ERR_MATCH_ON_OK, ERR_MATCH_TAG_MISSING_HANDLER, ERR_TASK_YIELD_NOT_RESULT, ERR_UNWRAP_ERR_ON_OK, ERR_UNWRAP_ON_ERR, ExpectErrError, ExpectOkError, InvalidResultStateError, MatchErrHandlerNotResultError, MatchOnOkError, MatchTagMissingHandlerError, ResultError, ResultTypeError, TaskYieldNotResultError, UnwrapErrOnOkError, UnwrapOnErrError } from "./errors.mjs";
|
|
3
|
+
import { C as tap, D as mapErr, E as mapBoth, O as map, S as filter, T as bimap, _ as recoverWith, a as or, b as match, c as tryCatchAsync, d as filterAsync, f as tapAsync, g as recover, h as mapAsync, i as orElse, l as matchAsync, m as mapErrAsync, n as mapOrElse, o as and, p as flatMapAsync, r as mapOr, s as tryMapAsync, t as swap, u as foldAsync, v as tryMap, w as flatMap, x as fold, y as tryCatch } from "./swap-CFD2g1cB.mjs";
|
|
4
|
+
import { a as collectFirstOkAsync, i as collectFirstOkParallelAsync, n as partition, o as collectFirstOk, r as collectAllErrors, s as sequenceRecord, t as flatten } from "./flatten-ChTL5BfA.mjs";
|
|
5
5
|
|
|
6
6
|
//#region src/gen.ts
|
|
7
7
|
async function task(makeGenerator, onThrow) {
|
|
8
8
|
const iterator = makeGenerator();
|
|
9
9
|
let input = void 0;
|
|
10
|
+
const runGeneratorReturn = async () => {
|
|
11
|
+
if (typeof iterator.return !== "function") return;
|
|
12
|
+
let step = await iterator.return(void 0);
|
|
13
|
+
while (!step.done) step = await iterator.next(void 0);
|
|
14
|
+
};
|
|
10
15
|
while (true) {
|
|
11
16
|
let step;
|
|
12
17
|
try {
|
|
@@ -24,20 +29,34 @@ async function task(makeGenerator, onThrow) {
|
|
|
24
29
|
return err(onThrow(caught));
|
|
25
30
|
}
|
|
26
31
|
const yielded = step.value;
|
|
27
|
-
if (!isResult(yielded))
|
|
32
|
+
if (!isResult(yielded)) {
|
|
33
|
+
try {
|
|
34
|
+
await runGeneratorReturn();
|
|
35
|
+
} catch (caught) {
|
|
36
|
+
if (!onThrow) throw caught;
|
|
37
|
+
return err(onThrow(caught));
|
|
38
|
+
}
|
|
39
|
+
throw new TaskYieldNotResultError(yielded);
|
|
40
|
+
}
|
|
28
41
|
if (yielded.isOk()) {
|
|
29
42
|
input = yielded.value;
|
|
30
43
|
continue;
|
|
31
44
|
}
|
|
32
45
|
if (yielded.isErr()) {
|
|
33
46
|
try {
|
|
34
|
-
|
|
47
|
+
await runGeneratorReturn();
|
|
35
48
|
} catch (caught) {
|
|
36
49
|
if (!onThrow) throw caught;
|
|
37
50
|
return err(onThrow(caught));
|
|
38
51
|
}
|
|
39
52
|
return yielded;
|
|
40
53
|
}
|
|
54
|
+
try {
|
|
55
|
+
await runGeneratorReturn();
|
|
56
|
+
} catch (caught) {
|
|
57
|
+
if (!onThrow) throw caught;
|
|
58
|
+
return err(onThrow(caught));
|
|
59
|
+
}
|
|
41
60
|
throw new InvalidResultStateError("task");
|
|
42
61
|
}
|
|
43
62
|
}
|
|
@@ -83,7 +102,11 @@ function unwrapOrElse(result, fn) {
|
|
|
83
102
|
//#region src/core/unwrapOrDefault.ts
|
|
84
103
|
/**
|
|
85
104
|
* Alias for `unwrapOr`.
|
|
86
|
-
*
|
|
105
|
+
*
|
|
106
|
+
* @deprecated Use {@link unwrapOr} instead. The name is misleading: Rust's
|
|
107
|
+
* `unwrap_or_default` takes no argument (it uses the type's `Default`),
|
|
108
|
+
* whereas this function requires an explicit default value — which is exactly
|
|
109
|
+
* what `unwrapOr` does.
|
|
87
110
|
*/
|
|
88
111
|
function unwrapOrDefault(result, defaultValue) {
|
|
89
112
|
return unwrapOr(result, defaultValue);
|
|
@@ -121,7 +144,7 @@ function unwrapErr(result) {
|
|
|
121
144
|
*/
|
|
122
145
|
function expectResult(result, message) {
|
|
123
146
|
if (result.isOk()) return result.value;
|
|
124
|
-
if (result.isErr()) throw new ExpectOkError(message);
|
|
147
|
+
if (result.isErr()) throw new ExpectOkError(message, result.error);
|
|
125
148
|
throw new InvalidResultStateError("expectResult");
|
|
126
149
|
}
|
|
127
150
|
|
|
@@ -133,10 +156,27 @@ function expectResult(result, message) {
|
|
|
133
156
|
*/
|
|
134
157
|
function expectErr(result, message) {
|
|
135
158
|
if (result.isErr()) return result.error;
|
|
136
|
-
if (result.isOk()) throw new ExpectErrError(message);
|
|
159
|
+
if (result.isOk()) throw new ExpectErrError(message, result.value);
|
|
137
160
|
throw new InvalidResultStateError("expectErr");
|
|
138
161
|
}
|
|
139
162
|
|
|
163
|
+
//#endregion
|
|
164
|
+
//#region src/core/fromSerialized.ts
|
|
165
|
+
/**
|
|
166
|
+
* Rebuilds a `Result` from its serialized discriminated form
|
|
167
|
+
* (`{ _tag: 'Ok', value }` / `{ _tag: 'Err', error }`), the shape produced
|
|
168
|
+
* by `Result.toSerialized()` and by `JSON.stringify` on a Result.
|
|
169
|
+
*
|
|
170
|
+
* Throws `InvalidResultStateError` for data that is not in that shape.
|
|
171
|
+
*/
|
|
172
|
+
function fromSerialized(data) {
|
|
173
|
+
if (data !== null && typeof data === "object") {
|
|
174
|
+
if (data._tag === "Ok" && "value" in data) return ok(data.value);
|
|
175
|
+
if (data._tag === "Err" && "error" in data) return err(data.error);
|
|
176
|
+
}
|
|
177
|
+
throw new InvalidResultStateError("fromSerialized");
|
|
178
|
+
}
|
|
179
|
+
|
|
140
180
|
//#endregion
|
|
141
181
|
//#region src/core/toPromise.ts
|
|
142
182
|
/**
|
|
@@ -190,9 +230,12 @@ function isErr(result) {
|
|
|
190
230
|
/**
|
|
191
231
|
* Checks if the Result contains a specific value.
|
|
192
232
|
* Corresponds to Rust `contains`.
|
|
233
|
+
*
|
|
234
|
+
* Comparison uses `Object.is` (SameValue): `NaN` matches `NaN`, `+0` and
|
|
235
|
+
* `-0` are distinct, and objects are compared by reference.
|
|
193
236
|
*/
|
|
194
237
|
function contains(result, value) {
|
|
195
|
-
if (result.isOk()) return result.value
|
|
238
|
+
if (result.isOk()) return Object.is(result.value, value);
|
|
196
239
|
if (result.isErr()) return false;
|
|
197
240
|
throw new InvalidResultStateError("contains");
|
|
198
241
|
}
|
|
@@ -202,13 +245,16 @@ function contains(result, value) {
|
|
|
202
245
|
/**
|
|
203
246
|
* Checks if the Result contains a specific error.
|
|
204
247
|
* Analogous to `contains` for the Err case.
|
|
248
|
+
*
|
|
249
|
+
* Comparison uses `Object.is` (SameValue): `NaN` matches `NaN`, `+0` and
|
|
250
|
+
* `-0` are distinct, and objects are compared by reference.
|
|
205
251
|
*/
|
|
206
252
|
function containsErr(result, error) {
|
|
207
|
-
if (result.isErr()) return result.error
|
|
253
|
+
if (result.isErr()) return Object.is(result.error, error);
|
|
208
254
|
if (result.isOk()) return false;
|
|
209
255
|
throw new InvalidResultStateError("containsErr");
|
|
210
256
|
}
|
|
211
257
|
|
|
212
258
|
//#endregion
|
|
213
|
-
export { ERR_EXPECT_ERR, ERR_EXPECT_OK, ERR_INVALID_RESULT_STATE, ERR_INVALID_STATE, ERR_MATCH_ERR_HANDLER_NOT_RESULT, ERR_MATCH_ON_OK, ERR_TASK_YIELD_NOT_RESULT, ERR_UNWRAP_ERR_ON_OK, ERR_UNWRAP_ON_ERR, Err, ExpectErrError, ExpectOkError, InvalidResultStateError, MatchErrHandlerNotResultError, MatchOnOkError, Ok, Result, ResultError, ResultTypeError, TaskYieldNotResultError, UnwrapErrOnOkError, UnwrapOnErrError, all, and, bimap, collectAllErrors, collectFirstOk, collectFirstOkAsync, collectFirstOkParallelAsync, combine, contains, containsErr, err, expectErr, expectResult, filter, filterAsync, flatMap, flatMapAsync, flatten, fold, foldAsync, fromNullable, fromPromise, fromThrowable, gen, isErr, isOk, isResult, map, mapAsync, mapBoth, mapErr, mapErrAsync, mapOr, mapOrElse, match, matchAsync, matchTag, ok, okIf, okIfLazy, or, orElse, partition, recover, recoverWith, sequence, sequenceRecord, swap, tap, tapAsync, task, toNullable, toPromise, tryAsync, tryCatch, tryCatchAsync, tryFn, tryMap, tryMapAsync, unwrap, unwrapErr, unwrapOr, unwrapOrDefault, unwrapOrElse, unwrapOrThrow, zip };
|
|
259
|
+
export { ERR_EXPECT_ERR, ERR_EXPECT_OK, ERR_INVALID_RESULT_STATE, ERR_INVALID_STATE, ERR_MATCH_ERR_HANDLER_NOT_RESULT, ERR_MATCH_ON_OK, ERR_MATCH_TAG_MISSING_HANDLER, ERR_TASK_YIELD_NOT_RESULT, ERR_UNWRAP_ERR_ON_OK, ERR_UNWRAP_ON_ERR, Err, ExpectErrError, ExpectOkError, InvalidResultStateError, MatchErrHandlerNotResultError, MatchOnOkError, MatchTagMissingHandlerError, Ok, Result, ResultError, ResultTypeError, TaskYieldNotResultError, UnwrapErrOnOkError, UnwrapOnErrError, all, and, bimap, collectAllErrors, collectFirstOk, collectFirstOkAsync, collectFirstOkParallelAsync, combine, contains, containsErr, err, expectErr, expectResult, filter, filterAsync, flatMap, flatMapAsync, flatten, fold, foldAsync, fromNullable, fromPromise, fromSerialized, fromThrowable, gen, isErr, isOk, isResult, map, mapAsync, mapBoth, mapErr, mapErrAsync, mapOr, mapOrElse, match, matchAsync, matchTag, ok, okIf, okIfLazy, or, orElse, partition, recover, recoverWith, sequence, sequenceRecord, swap, tap, tapAsync, task, toNullable, toPromise, tryAsync, tryCatch, tryCatchAsync, tryFn, tryMap, tryMapAsync, unwrap, unwrapErr, unwrapOr, unwrapOrDefault, unwrapOrElse, unwrapOrThrow, zip };
|
|
214
260
|
//# sourceMappingURL=index.mjs.map
|