retuple 0.0.1 → 1.0.0-next.1
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/LICENSE +19 -0
- package/README.md +1 -0
- package/dist/index.cjs +531 -0
- package/dist/index.d.cts +286 -0
- package/dist/index.d.ts +286 -0
- package/dist/index.js +518 -0
- package/package.json +44 -6
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
export type Ok<T> = OkTuple<T> & Retuple<T, never>;
|
|
2
|
+
export type Err<E> = ErrTuple<E> & Retuple<never, E>;
|
|
3
|
+
export type Result<T, E> = (OkTuple<T> | ErrTuple<E>) & Retuple<T, E>;
|
|
4
|
+
export { type ResultAsync };
|
|
5
|
+
export declare class RetupleUnwrapFailed<E = unknown> extends Error {
|
|
6
|
+
value: E;
|
|
7
|
+
constructor(value: E, msg?: string);
|
|
8
|
+
}
|
|
9
|
+
export declare class RetupleUnwrapErrFailed<T = unknown> extends Error {
|
|
10
|
+
value: T;
|
|
11
|
+
constructor(value: T, msg?: string);
|
|
12
|
+
}
|
|
13
|
+
export declare class RetupleExpectFailed<E = unknown> extends Error {
|
|
14
|
+
value: E;
|
|
15
|
+
constructor(value: E);
|
|
16
|
+
}
|
|
17
|
+
export declare class RetupleThrownValueError extends Error {
|
|
18
|
+
value: unknown;
|
|
19
|
+
constructor(value: unknown);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* ## Result
|
|
23
|
+
*
|
|
24
|
+
* @TODO
|
|
25
|
+
*/
|
|
26
|
+
export declare const Result: {
|
|
27
|
+
Ok: typeof Ok;
|
|
28
|
+
Err: typeof Err;
|
|
29
|
+
from: typeof from;
|
|
30
|
+
safe: typeof safe;
|
|
31
|
+
safeAsync: typeof safeAsync;
|
|
32
|
+
safePromise: typeof safePromise;
|
|
33
|
+
};
|
|
34
|
+
export default Result;
|
|
35
|
+
/**
|
|
36
|
+
* ## Ok
|
|
37
|
+
*
|
|
38
|
+
* @TODO
|
|
39
|
+
*/
|
|
40
|
+
export declare function Ok(): Ok<void>;
|
|
41
|
+
export declare function Ok<T>(val: T): Ok<T>;
|
|
42
|
+
/**
|
|
43
|
+
* ## Err
|
|
44
|
+
*
|
|
45
|
+
* @TODO
|
|
46
|
+
*/
|
|
47
|
+
export declare function Err(): Err<void>;
|
|
48
|
+
export declare function Err<E>(err: E): Err<E>;
|
|
49
|
+
/**
|
|
50
|
+
* Construct a {@link Result} from a value. If the value is truthy, the result
|
|
51
|
+
* is `Ok`.
|
|
52
|
+
*/
|
|
53
|
+
export declare function from<T>(value: T): Result<Truthy<T>, true>;
|
|
54
|
+
export declare function from<T, E>(value: T, error: () => E): Result<Truthy<T>, E>;
|
|
55
|
+
/**
|
|
56
|
+
* Construct a {@link Result} from a synchronous function call. If the function
|
|
57
|
+
* returns without throwing, the result is `Ok`.
|
|
58
|
+
*/
|
|
59
|
+
export declare function safe<T>(f: () => Awaited<T>): Result<T, Error>;
|
|
60
|
+
export declare function safe<T, E>(f: () => Awaited<T>, mapError: (err: unknown) => E): Result<T, E>;
|
|
61
|
+
/**
|
|
62
|
+
* Construct a {@link ResultAsync} from a function call. If the function returns
|
|
63
|
+
* without throwing, and any promise returned resolves, the result is `Ok`.
|
|
64
|
+
*/
|
|
65
|
+
export declare function safeAsync<T>(f: () => T | PromiseLike<T>): ResultAsync<T, Error>;
|
|
66
|
+
export declare function safeAsync<T, E>(f: () => T | PromiseLike<T>, mapError: (err: unknown) => E): ResultAsync<T, E>;
|
|
67
|
+
/**
|
|
68
|
+
* Construct a {@link Result} from a promise. If the promise resolves, the
|
|
69
|
+
* result is `Ok`.
|
|
70
|
+
*/
|
|
71
|
+
export declare function safePromise<T>(promise: PromiseLike<T>): ResultAsync<T, Error>;
|
|
72
|
+
export declare function safePromise<T, E>(promise: PromiseLike<T>, mapError: (err: unknown) => E): ResultAsync<T, E>;
|
|
73
|
+
/**
|
|
74
|
+
* ## ResultAsync
|
|
75
|
+
*
|
|
76
|
+
* @TODO
|
|
77
|
+
*/
|
|
78
|
+
declare class ResultAsync<T, E> {
|
|
79
|
+
#private;
|
|
80
|
+
constructor(inner: PromiseLike<Result<T, E>>);
|
|
81
|
+
then<TResult1 = Result<T, E>, TResult2 = never>(onfulfilled?: ((result: Result<T, E>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>): PromiseLike<TResult1 | TResult2>;
|
|
82
|
+
/**
|
|
83
|
+
* @TODO
|
|
84
|
+
*/
|
|
85
|
+
$value(this: ResultAsync<T, E>): Promise<T | E>;
|
|
86
|
+
/**
|
|
87
|
+
* @TODO
|
|
88
|
+
*/
|
|
89
|
+
$expect(this: ResultAsync<T, Error>): Promise<T>;
|
|
90
|
+
/**
|
|
91
|
+
* @TODO
|
|
92
|
+
*/
|
|
93
|
+
$unwrap(this: ResultAsync<T, E>, msg?: string): Promise<T>;
|
|
94
|
+
/**
|
|
95
|
+
* @TODO
|
|
96
|
+
*/
|
|
97
|
+
$unwrapErr(this: ResultAsync<T, E>, msg?: string): Promise<E>;
|
|
98
|
+
/**
|
|
99
|
+
* @TODO
|
|
100
|
+
*/
|
|
101
|
+
$unwrapOr<U>(this: ResultAsync<T, E>, def: U): Promise<T | U>;
|
|
102
|
+
/**
|
|
103
|
+
* @TODO
|
|
104
|
+
*/
|
|
105
|
+
$unwrapOrElse<U = T>(this: ResultAsync<T, E>, f: () => U): Promise<T | U>;
|
|
106
|
+
/**
|
|
107
|
+
* @TODO
|
|
108
|
+
*/
|
|
109
|
+
$map<U>(this: ResultAsync<T, E>, f: (val: T) => U): ResultAsync<U, E>;
|
|
110
|
+
/**
|
|
111
|
+
* @TODO
|
|
112
|
+
*/
|
|
113
|
+
$mapErr<F>(this: ResultAsync<T, E>, f: (err: E) => F): ResultAsync<T, F>;
|
|
114
|
+
/**
|
|
115
|
+
* @TODO
|
|
116
|
+
*/
|
|
117
|
+
$mapOr<U>(this: ResultAsync<T, E>, def: U, f: (val: T) => U): ResultAsync<U, E>;
|
|
118
|
+
/**
|
|
119
|
+
* @TODO
|
|
120
|
+
*/
|
|
121
|
+
$mapOrElse<U>(this: ResultAsync<T, E>, def: (err: E) => U, f: (val: T) => U): ResultAsync<U, E>;
|
|
122
|
+
/**
|
|
123
|
+
* @TODO
|
|
124
|
+
*/
|
|
125
|
+
$or<U = T, F = E>(this: ResultAsync<T, E>, or: Result<U, F> | PromiseLike<Result<U, F>>): ResultAsync<T | U, E | F>;
|
|
126
|
+
/**
|
|
127
|
+
* @TODO
|
|
128
|
+
*/
|
|
129
|
+
$orElse<U = T, F = E>(this: ResultAsync<T, E>, f: (err: E) => Result<U, F> | PromiseLike<Result<U, F>>): ResultAsync<T | U, E | F>;
|
|
130
|
+
/**
|
|
131
|
+
* @TODO
|
|
132
|
+
*/
|
|
133
|
+
$orSafe<U = T, F = Error>(this: ResultAsync<T, E>, f: (err: E) => U | PromiseLike<U>, mapError?: (err: unknown) => F): ResultAsync<T | U, E | F>;
|
|
134
|
+
/**
|
|
135
|
+
* @TODO
|
|
136
|
+
*/
|
|
137
|
+
$and<U = T, F = E>(this: ResultAsync<T, E>, and: Result<U, F> | PromiseLike<Result<U, F>>): ResultAsync<U, E | F>;
|
|
138
|
+
/**
|
|
139
|
+
* @TODO
|
|
140
|
+
*/
|
|
141
|
+
$andThen<U = T, F = E>(this: ResultAsync<T, E>, f: (val: T) => Result<U, F> | PromiseLike<Result<U, F>>): ResultAsync<U, E | F>;
|
|
142
|
+
/**
|
|
143
|
+
* @TODO
|
|
144
|
+
*/
|
|
145
|
+
$andThrough<F = E>(this: ResultAsync<T, E>, f: (val: T) => Result<any, F> | PromiseLike<Result<any, F>>): ResultAsync<T, E | F>;
|
|
146
|
+
/**
|
|
147
|
+
* @TODO
|
|
148
|
+
*/
|
|
149
|
+
$andSafe<U = T, F = Error>(this: ResultAsync<T, E>, f: (val: T) => U | PromiseLike<U>, mapError?: (err: unknown) => F): ResultAsync<U, E | F>;
|
|
150
|
+
/**
|
|
151
|
+
* @TODO
|
|
152
|
+
*/
|
|
153
|
+
$peek(this: ResultAsync<T, E>, f: (res: Result<T, E>) => any): ResultAsync<T, E>;
|
|
154
|
+
/**
|
|
155
|
+
* @TODO
|
|
156
|
+
*/
|
|
157
|
+
$tap(this: ResultAsync<T, E>, f: (val: T) => any): ResultAsync<T, E>;
|
|
158
|
+
/**
|
|
159
|
+
* @TODO
|
|
160
|
+
*/
|
|
161
|
+
$tapErr(this: ResultAsync<T, E>, f: (err: E) => any): ResultAsync<T, E>;
|
|
162
|
+
/**
|
|
163
|
+
* @TODO
|
|
164
|
+
*/
|
|
165
|
+
$promise(this: ResultAsync<T, E>): Promise<Result<T, E>>;
|
|
166
|
+
}
|
|
167
|
+
type OkTuple<T> = [err: undefined, value: T];
|
|
168
|
+
type ErrTuple<E> = [err: E, value: undefined];
|
|
169
|
+
/**
|
|
170
|
+
* @TODO - Result.all / Result.any
|
|
171
|
+
*/
|
|
172
|
+
interface Retuple<T, E> {
|
|
173
|
+
/**
|
|
174
|
+
* @TODO
|
|
175
|
+
*/
|
|
176
|
+
$isOk(this: Result<T, E>): this is Ok<T>;
|
|
177
|
+
/**
|
|
178
|
+
* @TODO
|
|
179
|
+
*/
|
|
180
|
+
$isOkAnd<U extends T = T>(this: Result<T, E>, f: ((val: T) => val is U) | ((val: T) => boolean)): this is Ok<U>;
|
|
181
|
+
/**
|
|
182
|
+
* @TODO
|
|
183
|
+
*/
|
|
184
|
+
$isErr(this: Result<T, E>): this is Err<E>;
|
|
185
|
+
/**
|
|
186
|
+
* @TODO
|
|
187
|
+
*/
|
|
188
|
+
$isErrAnd<F extends E = E>(this: Result<T, E>, f: ((err: E) => err is F) | ((err: E) => boolean)): this is Err<F>;
|
|
189
|
+
/**
|
|
190
|
+
* @TODO
|
|
191
|
+
*/
|
|
192
|
+
$value(this: Result<T, E>): T | E;
|
|
193
|
+
/**
|
|
194
|
+
* @TODO
|
|
195
|
+
*/
|
|
196
|
+
$expect(this: Result<T, Error>): T;
|
|
197
|
+
/**
|
|
198
|
+
* @TODO
|
|
199
|
+
*/
|
|
200
|
+
$unwrap(this: Result<T, E>, msg?: string): T;
|
|
201
|
+
/**
|
|
202
|
+
* @TODO
|
|
203
|
+
*/
|
|
204
|
+
$unwrapErr(this: Result<T, E>, msg?: string): E;
|
|
205
|
+
/**
|
|
206
|
+
* @TODO
|
|
207
|
+
*/
|
|
208
|
+
$unwrapOr<U = T>(this: Result<T, E>, def: U): T | U;
|
|
209
|
+
/**
|
|
210
|
+
* @TODO
|
|
211
|
+
*/
|
|
212
|
+
$unwrapOrElse<U = T>(this: Result<T, E>, f: () => U): T | U;
|
|
213
|
+
/**
|
|
214
|
+
* @TODO
|
|
215
|
+
*/
|
|
216
|
+
$map<U>(this: Result<T, E>, f: (value: T) => U): Result<U, E>;
|
|
217
|
+
/**
|
|
218
|
+
* @TODO
|
|
219
|
+
*/
|
|
220
|
+
$mapErr<F>(this: Result<T, E>, f: (err: E) => F): Result<T, F>;
|
|
221
|
+
/**
|
|
222
|
+
* @TODO
|
|
223
|
+
*/
|
|
224
|
+
$mapOr<U>(this: Result<T, E>, def: U, f: (val: T) => U): Result<U, E>;
|
|
225
|
+
/**
|
|
226
|
+
* @TODO
|
|
227
|
+
*/
|
|
228
|
+
$mapOrElse<U>(this: Result<T, E>, def: (err: E) => U, f: (val: T) => U): Result<U, E>;
|
|
229
|
+
/**
|
|
230
|
+
* @TODO
|
|
231
|
+
*/
|
|
232
|
+
$or<U = T, F = E>(this: Result<T, E>, or: Result<U, F>): Result<T | U, E | F>;
|
|
233
|
+
/**
|
|
234
|
+
* @TODO
|
|
235
|
+
*/
|
|
236
|
+
$orElse<U = never, F = never>(this: Result<T, E>, f: (err: E) => Result<U, F>): Result<T | U, E | F>;
|
|
237
|
+
/**
|
|
238
|
+
* @TODO
|
|
239
|
+
*/
|
|
240
|
+
$orSafe<U = T>(this: Result<T, E>, f: (err: E) => U): Result<T | U, E | Error>;
|
|
241
|
+
$orSafe<U = T, F = E>(this: Result<T, E>, f: (err: E) => U, mapError: (err: unknown) => F): Result<T | U, E | F>;
|
|
242
|
+
$orSafe<U = T, F = Error>(this: Result<T, E>, f: (err: E) => U, mapError: (err: unknown) => F): Result<T | U, E | F>;
|
|
243
|
+
/**
|
|
244
|
+
* @TODO
|
|
245
|
+
*/
|
|
246
|
+
$and<U = T, F = E>(this: Result<T, E>, and: Result<U, F>): Result<U, E | F>;
|
|
247
|
+
/**
|
|
248
|
+
* @TODO
|
|
249
|
+
*/
|
|
250
|
+
$andThen<U = never, F = never>(this: Result<T, E>, f: (val: T) => Result<U, F>): Result<U, E | F>;
|
|
251
|
+
/**
|
|
252
|
+
* @TODO
|
|
253
|
+
*/
|
|
254
|
+
$andThrough<F = never>(this: Result<T, E>, f: (val: T) => Result<any, F>): Result<T, E | F>;
|
|
255
|
+
/**
|
|
256
|
+
* @TODO
|
|
257
|
+
*/
|
|
258
|
+
$andSafe<U = T>(this: Result<T, E>, f: (val: T) => U): Result<T | U, E | Error>;
|
|
259
|
+
$andSafe<U = T, F = E>(this: Result<T, E>, f: (val: T) => U, mapError: (err: unknown) => F): Result<T | U, E | F>;
|
|
260
|
+
$andSafe<U, F = Error>(this: Result<T, E>, f: (val: T) => U, mapError: (err: unknown) => F): Result<T | U, E | F>;
|
|
261
|
+
/**
|
|
262
|
+
* @TODO
|
|
263
|
+
*/
|
|
264
|
+
$peek(this: Result<T, E>, f: (res: Result<T, E>) => void): Result<T, E>;
|
|
265
|
+
/**
|
|
266
|
+
* @TODO
|
|
267
|
+
*/
|
|
268
|
+
$tap(this: Result<T, E>, f: (val: T) => any): Result<T, E>;
|
|
269
|
+
/**
|
|
270
|
+
* @TODO
|
|
271
|
+
*/
|
|
272
|
+
$tapErr(this: Result<T, E>, f: (err: E) => void): Result<T, E>;
|
|
273
|
+
/**
|
|
274
|
+
* @TODO
|
|
275
|
+
*/
|
|
276
|
+
$flatten<U, F>(this: Result<Result<U, F>, E>): Result<U, E | F>;
|
|
277
|
+
/**
|
|
278
|
+
* @TODO
|
|
279
|
+
*/
|
|
280
|
+
$async(this: Result<T, E>): ResultAsync<T, E>;
|
|
281
|
+
/**
|
|
282
|
+
* @TODO
|
|
283
|
+
*/
|
|
284
|
+
$promise(this: Result<T, E>): Promise<Result<T, E>>;
|
|
285
|
+
}
|
|
286
|
+
type Truthy<T> = Exclude<T, false | null | undefined | 0 | 0n | "">;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
export type Ok<T> = OkTuple<T> & Retuple<T, never>;
|
|
2
|
+
export type Err<E> = ErrTuple<E> & Retuple<never, E>;
|
|
3
|
+
export type Result<T, E> = (OkTuple<T> | ErrTuple<E>) & Retuple<T, E>;
|
|
4
|
+
export { type ResultAsync };
|
|
5
|
+
export declare class RetupleUnwrapFailed<E = unknown> extends Error {
|
|
6
|
+
value: E;
|
|
7
|
+
constructor(value: E, msg?: string);
|
|
8
|
+
}
|
|
9
|
+
export declare class RetupleUnwrapErrFailed<T = unknown> extends Error {
|
|
10
|
+
value: T;
|
|
11
|
+
constructor(value: T, msg?: string);
|
|
12
|
+
}
|
|
13
|
+
export declare class RetupleExpectFailed<E = unknown> extends Error {
|
|
14
|
+
value: E;
|
|
15
|
+
constructor(value: E);
|
|
16
|
+
}
|
|
17
|
+
export declare class RetupleThrownValueError extends Error {
|
|
18
|
+
value: unknown;
|
|
19
|
+
constructor(value: unknown);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* ## Result
|
|
23
|
+
*
|
|
24
|
+
* @TODO
|
|
25
|
+
*/
|
|
26
|
+
export declare const Result: {
|
|
27
|
+
Ok: typeof Ok;
|
|
28
|
+
Err: typeof Err;
|
|
29
|
+
from: typeof from;
|
|
30
|
+
safe: typeof safe;
|
|
31
|
+
safeAsync: typeof safeAsync;
|
|
32
|
+
safePromise: typeof safePromise;
|
|
33
|
+
};
|
|
34
|
+
export default Result;
|
|
35
|
+
/**
|
|
36
|
+
* ## Ok
|
|
37
|
+
*
|
|
38
|
+
* @TODO
|
|
39
|
+
*/
|
|
40
|
+
export declare function Ok(): Ok<void>;
|
|
41
|
+
export declare function Ok<T>(val: T): Ok<T>;
|
|
42
|
+
/**
|
|
43
|
+
* ## Err
|
|
44
|
+
*
|
|
45
|
+
* @TODO
|
|
46
|
+
*/
|
|
47
|
+
export declare function Err(): Err<void>;
|
|
48
|
+
export declare function Err<E>(err: E): Err<E>;
|
|
49
|
+
/**
|
|
50
|
+
* Construct a {@link Result} from a value. If the value is truthy, the result
|
|
51
|
+
* is `Ok`.
|
|
52
|
+
*/
|
|
53
|
+
export declare function from<T>(value: T): Result<Truthy<T>, true>;
|
|
54
|
+
export declare function from<T, E>(value: T, error: () => E): Result<Truthy<T>, E>;
|
|
55
|
+
/**
|
|
56
|
+
* Construct a {@link Result} from a synchronous function call. If the function
|
|
57
|
+
* returns without throwing, the result is `Ok`.
|
|
58
|
+
*/
|
|
59
|
+
export declare function safe<T>(f: () => Awaited<T>): Result<T, Error>;
|
|
60
|
+
export declare function safe<T, E>(f: () => Awaited<T>, mapError: (err: unknown) => E): Result<T, E>;
|
|
61
|
+
/**
|
|
62
|
+
* Construct a {@link ResultAsync} from a function call. If the function returns
|
|
63
|
+
* without throwing, and any promise returned resolves, the result is `Ok`.
|
|
64
|
+
*/
|
|
65
|
+
export declare function safeAsync<T>(f: () => T | PromiseLike<T>): ResultAsync<T, Error>;
|
|
66
|
+
export declare function safeAsync<T, E>(f: () => T | PromiseLike<T>, mapError: (err: unknown) => E): ResultAsync<T, E>;
|
|
67
|
+
/**
|
|
68
|
+
* Construct a {@link Result} from a promise. If the promise resolves, the
|
|
69
|
+
* result is `Ok`.
|
|
70
|
+
*/
|
|
71
|
+
export declare function safePromise<T>(promise: PromiseLike<T>): ResultAsync<T, Error>;
|
|
72
|
+
export declare function safePromise<T, E>(promise: PromiseLike<T>, mapError: (err: unknown) => E): ResultAsync<T, E>;
|
|
73
|
+
/**
|
|
74
|
+
* ## ResultAsync
|
|
75
|
+
*
|
|
76
|
+
* @TODO
|
|
77
|
+
*/
|
|
78
|
+
declare class ResultAsync<T, E> {
|
|
79
|
+
#private;
|
|
80
|
+
constructor(inner: PromiseLike<Result<T, E>>);
|
|
81
|
+
then<TResult1 = Result<T, E>, TResult2 = never>(onfulfilled?: ((result: Result<T, E>) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2>): PromiseLike<TResult1 | TResult2>;
|
|
82
|
+
/**
|
|
83
|
+
* @TODO
|
|
84
|
+
*/
|
|
85
|
+
$value(this: ResultAsync<T, E>): Promise<T | E>;
|
|
86
|
+
/**
|
|
87
|
+
* @TODO
|
|
88
|
+
*/
|
|
89
|
+
$expect(this: ResultAsync<T, Error>): Promise<T>;
|
|
90
|
+
/**
|
|
91
|
+
* @TODO
|
|
92
|
+
*/
|
|
93
|
+
$unwrap(this: ResultAsync<T, E>, msg?: string): Promise<T>;
|
|
94
|
+
/**
|
|
95
|
+
* @TODO
|
|
96
|
+
*/
|
|
97
|
+
$unwrapErr(this: ResultAsync<T, E>, msg?: string): Promise<E>;
|
|
98
|
+
/**
|
|
99
|
+
* @TODO
|
|
100
|
+
*/
|
|
101
|
+
$unwrapOr<U>(this: ResultAsync<T, E>, def: U): Promise<T | U>;
|
|
102
|
+
/**
|
|
103
|
+
* @TODO
|
|
104
|
+
*/
|
|
105
|
+
$unwrapOrElse<U = T>(this: ResultAsync<T, E>, f: () => U): Promise<T | U>;
|
|
106
|
+
/**
|
|
107
|
+
* @TODO
|
|
108
|
+
*/
|
|
109
|
+
$map<U>(this: ResultAsync<T, E>, f: (val: T) => U): ResultAsync<U, E>;
|
|
110
|
+
/**
|
|
111
|
+
* @TODO
|
|
112
|
+
*/
|
|
113
|
+
$mapErr<F>(this: ResultAsync<T, E>, f: (err: E) => F): ResultAsync<T, F>;
|
|
114
|
+
/**
|
|
115
|
+
* @TODO
|
|
116
|
+
*/
|
|
117
|
+
$mapOr<U>(this: ResultAsync<T, E>, def: U, f: (val: T) => U): ResultAsync<U, E>;
|
|
118
|
+
/**
|
|
119
|
+
* @TODO
|
|
120
|
+
*/
|
|
121
|
+
$mapOrElse<U>(this: ResultAsync<T, E>, def: (err: E) => U, f: (val: T) => U): ResultAsync<U, E>;
|
|
122
|
+
/**
|
|
123
|
+
* @TODO
|
|
124
|
+
*/
|
|
125
|
+
$or<U = T, F = E>(this: ResultAsync<T, E>, or: Result<U, F> | PromiseLike<Result<U, F>>): ResultAsync<T | U, E | F>;
|
|
126
|
+
/**
|
|
127
|
+
* @TODO
|
|
128
|
+
*/
|
|
129
|
+
$orElse<U = T, F = E>(this: ResultAsync<T, E>, f: (err: E) => Result<U, F> | PromiseLike<Result<U, F>>): ResultAsync<T | U, E | F>;
|
|
130
|
+
/**
|
|
131
|
+
* @TODO
|
|
132
|
+
*/
|
|
133
|
+
$orSafe<U = T, F = Error>(this: ResultAsync<T, E>, f: (err: E) => U | PromiseLike<U>, mapError?: (err: unknown) => F): ResultAsync<T | U, E | F>;
|
|
134
|
+
/**
|
|
135
|
+
* @TODO
|
|
136
|
+
*/
|
|
137
|
+
$and<U = T, F = E>(this: ResultAsync<T, E>, and: Result<U, F> | PromiseLike<Result<U, F>>): ResultAsync<U, E | F>;
|
|
138
|
+
/**
|
|
139
|
+
* @TODO
|
|
140
|
+
*/
|
|
141
|
+
$andThen<U = T, F = E>(this: ResultAsync<T, E>, f: (val: T) => Result<U, F> | PromiseLike<Result<U, F>>): ResultAsync<U, E | F>;
|
|
142
|
+
/**
|
|
143
|
+
* @TODO
|
|
144
|
+
*/
|
|
145
|
+
$andThrough<F = E>(this: ResultAsync<T, E>, f: (val: T) => Result<any, F> | PromiseLike<Result<any, F>>): ResultAsync<T, E | F>;
|
|
146
|
+
/**
|
|
147
|
+
* @TODO
|
|
148
|
+
*/
|
|
149
|
+
$andSafe<U = T, F = Error>(this: ResultAsync<T, E>, f: (val: T) => U | PromiseLike<U>, mapError?: (err: unknown) => F): ResultAsync<U, E | F>;
|
|
150
|
+
/**
|
|
151
|
+
* @TODO
|
|
152
|
+
*/
|
|
153
|
+
$peek(this: ResultAsync<T, E>, f: (res: Result<T, E>) => any): ResultAsync<T, E>;
|
|
154
|
+
/**
|
|
155
|
+
* @TODO
|
|
156
|
+
*/
|
|
157
|
+
$tap(this: ResultAsync<T, E>, f: (val: T) => any): ResultAsync<T, E>;
|
|
158
|
+
/**
|
|
159
|
+
* @TODO
|
|
160
|
+
*/
|
|
161
|
+
$tapErr(this: ResultAsync<T, E>, f: (err: E) => any): ResultAsync<T, E>;
|
|
162
|
+
/**
|
|
163
|
+
* @TODO
|
|
164
|
+
*/
|
|
165
|
+
$promise(this: ResultAsync<T, E>): Promise<Result<T, E>>;
|
|
166
|
+
}
|
|
167
|
+
type OkTuple<T> = [err: undefined, value: T];
|
|
168
|
+
type ErrTuple<E> = [err: E, value: undefined];
|
|
169
|
+
/**
|
|
170
|
+
* @TODO - Result.all / Result.any
|
|
171
|
+
*/
|
|
172
|
+
interface Retuple<T, E> {
|
|
173
|
+
/**
|
|
174
|
+
* @TODO
|
|
175
|
+
*/
|
|
176
|
+
$isOk(this: Result<T, E>): this is Ok<T>;
|
|
177
|
+
/**
|
|
178
|
+
* @TODO
|
|
179
|
+
*/
|
|
180
|
+
$isOkAnd<U extends T = T>(this: Result<T, E>, f: ((val: T) => val is U) | ((val: T) => boolean)): this is Ok<U>;
|
|
181
|
+
/**
|
|
182
|
+
* @TODO
|
|
183
|
+
*/
|
|
184
|
+
$isErr(this: Result<T, E>): this is Err<E>;
|
|
185
|
+
/**
|
|
186
|
+
* @TODO
|
|
187
|
+
*/
|
|
188
|
+
$isErrAnd<F extends E = E>(this: Result<T, E>, f: ((err: E) => err is F) | ((err: E) => boolean)): this is Err<F>;
|
|
189
|
+
/**
|
|
190
|
+
* @TODO
|
|
191
|
+
*/
|
|
192
|
+
$value(this: Result<T, E>): T | E;
|
|
193
|
+
/**
|
|
194
|
+
* @TODO
|
|
195
|
+
*/
|
|
196
|
+
$expect(this: Result<T, Error>): T;
|
|
197
|
+
/**
|
|
198
|
+
* @TODO
|
|
199
|
+
*/
|
|
200
|
+
$unwrap(this: Result<T, E>, msg?: string): T;
|
|
201
|
+
/**
|
|
202
|
+
* @TODO
|
|
203
|
+
*/
|
|
204
|
+
$unwrapErr(this: Result<T, E>, msg?: string): E;
|
|
205
|
+
/**
|
|
206
|
+
* @TODO
|
|
207
|
+
*/
|
|
208
|
+
$unwrapOr<U = T>(this: Result<T, E>, def: U): T | U;
|
|
209
|
+
/**
|
|
210
|
+
* @TODO
|
|
211
|
+
*/
|
|
212
|
+
$unwrapOrElse<U = T>(this: Result<T, E>, f: () => U): T | U;
|
|
213
|
+
/**
|
|
214
|
+
* @TODO
|
|
215
|
+
*/
|
|
216
|
+
$map<U>(this: Result<T, E>, f: (value: T) => U): Result<U, E>;
|
|
217
|
+
/**
|
|
218
|
+
* @TODO
|
|
219
|
+
*/
|
|
220
|
+
$mapErr<F>(this: Result<T, E>, f: (err: E) => F): Result<T, F>;
|
|
221
|
+
/**
|
|
222
|
+
* @TODO
|
|
223
|
+
*/
|
|
224
|
+
$mapOr<U>(this: Result<T, E>, def: U, f: (val: T) => U): Result<U, E>;
|
|
225
|
+
/**
|
|
226
|
+
* @TODO
|
|
227
|
+
*/
|
|
228
|
+
$mapOrElse<U>(this: Result<T, E>, def: (err: E) => U, f: (val: T) => U): Result<U, E>;
|
|
229
|
+
/**
|
|
230
|
+
* @TODO
|
|
231
|
+
*/
|
|
232
|
+
$or<U = T, F = E>(this: Result<T, E>, or: Result<U, F>): Result<T | U, E | F>;
|
|
233
|
+
/**
|
|
234
|
+
* @TODO
|
|
235
|
+
*/
|
|
236
|
+
$orElse<U = never, F = never>(this: Result<T, E>, f: (err: E) => Result<U, F>): Result<T | U, E | F>;
|
|
237
|
+
/**
|
|
238
|
+
* @TODO
|
|
239
|
+
*/
|
|
240
|
+
$orSafe<U = T>(this: Result<T, E>, f: (err: E) => U): Result<T | U, E | Error>;
|
|
241
|
+
$orSafe<U = T, F = E>(this: Result<T, E>, f: (err: E) => U, mapError: (err: unknown) => F): Result<T | U, E | F>;
|
|
242
|
+
$orSafe<U = T, F = Error>(this: Result<T, E>, f: (err: E) => U, mapError: (err: unknown) => F): Result<T | U, E | F>;
|
|
243
|
+
/**
|
|
244
|
+
* @TODO
|
|
245
|
+
*/
|
|
246
|
+
$and<U = T, F = E>(this: Result<T, E>, and: Result<U, F>): Result<U, E | F>;
|
|
247
|
+
/**
|
|
248
|
+
* @TODO
|
|
249
|
+
*/
|
|
250
|
+
$andThen<U = never, F = never>(this: Result<T, E>, f: (val: T) => Result<U, F>): Result<U, E | F>;
|
|
251
|
+
/**
|
|
252
|
+
* @TODO
|
|
253
|
+
*/
|
|
254
|
+
$andThrough<F = never>(this: Result<T, E>, f: (val: T) => Result<any, F>): Result<T, E | F>;
|
|
255
|
+
/**
|
|
256
|
+
* @TODO
|
|
257
|
+
*/
|
|
258
|
+
$andSafe<U = T>(this: Result<T, E>, f: (val: T) => U): Result<T | U, E | Error>;
|
|
259
|
+
$andSafe<U = T, F = E>(this: Result<T, E>, f: (val: T) => U, mapError: (err: unknown) => F): Result<T | U, E | F>;
|
|
260
|
+
$andSafe<U, F = Error>(this: Result<T, E>, f: (val: T) => U, mapError: (err: unknown) => F): Result<T | U, E | F>;
|
|
261
|
+
/**
|
|
262
|
+
* @TODO
|
|
263
|
+
*/
|
|
264
|
+
$peek(this: Result<T, E>, f: (res: Result<T, E>) => void): Result<T, E>;
|
|
265
|
+
/**
|
|
266
|
+
* @TODO
|
|
267
|
+
*/
|
|
268
|
+
$tap(this: Result<T, E>, f: (val: T) => any): Result<T, E>;
|
|
269
|
+
/**
|
|
270
|
+
* @TODO
|
|
271
|
+
*/
|
|
272
|
+
$tapErr(this: Result<T, E>, f: (err: E) => void): Result<T, E>;
|
|
273
|
+
/**
|
|
274
|
+
* @TODO
|
|
275
|
+
*/
|
|
276
|
+
$flatten<U, F>(this: Result<Result<U, F>, E>): Result<U, E | F>;
|
|
277
|
+
/**
|
|
278
|
+
* @TODO
|
|
279
|
+
*/
|
|
280
|
+
$async(this: Result<T, E>): ResultAsync<T, E>;
|
|
281
|
+
/**
|
|
282
|
+
* @TODO
|
|
283
|
+
*/
|
|
284
|
+
$promise(this: Result<T, E>): Promise<Result<T, E>>;
|
|
285
|
+
}
|
|
286
|
+
type Truthy<T> = Exclude<T, false | null | undefined | 0 | 0n | "">;
|