@shirudo/result 0.0.4 → 0.0.5
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 +108 -108
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +113 -113
- package/dist/index.d.mts +113 -113
- package/dist/index.mjs +108 -108
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -50,11 +50,11 @@ declare abstract class Pipeable {
|
|
|
50
50
|
type Ctor<T> = abstract new (...args: any[]) => T;
|
|
51
51
|
type TypeGuard<E, A extends E> = (error: E) => error is A;
|
|
52
52
|
/**
|
|
53
|
-
* Matcher
|
|
53
|
+
* Matcher for Err values (returns an arbitrary return type, e.g. string messages).
|
|
54
54
|
*
|
|
55
|
-
* - `.when(Ctor, handler)`
|
|
56
|
-
* - `.whenGuard(guard, handler)`
|
|
57
|
-
* - `.run()`
|
|
55
|
+
* - `.when(Ctor, handler)` matches via `instanceof`
|
|
56
|
+
* - `.whenGuard(guard, handler)` matches via Type-Guard
|
|
57
|
+
* - `.run()` is only allowed if all error cases have been handled (`E` has been reduced to `never`)
|
|
58
58
|
*/
|
|
59
59
|
declare class ErrorMatchBuilder<E, R$1> {
|
|
60
60
|
#private;
|
|
@@ -68,11 +68,11 @@ type OkOfReturn$1<R$1> = R$1 extends Result<infer T, any> ? T : never;
|
|
|
68
68
|
type ErrOfReturn$1<R$1> = R$1 extends Result<any, infer E> ? E : R$1;
|
|
69
69
|
type ErrFactory = <E>(error: E) => Result<never, E>;
|
|
70
70
|
/**
|
|
71
|
-
* Matcher
|
|
71
|
+
* Matcher for `Result` Errors, which returns a `Result` again.
|
|
72
72
|
*
|
|
73
|
-
*
|
|
74
|
-
* -
|
|
75
|
-
* -
|
|
73
|
+
* Handlers may:
|
|
74
|
+
* - return a `Result` (is returned directly)
|
|
75
|
+
* - return an Error value (is automatically wrapped into `Err(error)`)
|
|
76
76
|
*/
|
|
77
77
|
declare class ErrMatchBuilder<T, E, OutT, OutE> {
|
|
78
78
|
#private;
|
|
@@ -86,55 +86,55 @@ declare class ErrMatchBuilder<T, E, OutT, OutE> {
|
|
|
86
86
|
//#endregion
|
|
87
87
|
//#region src/core/map.d.ts
|
|
88
88
|
/**
|
|
89
|
-
*
|
|
90
|
-
*
|
|
89
|
+
* Transforms the value (Ok case).
|
|
90
|
+
* Corresponds to Rust `map`.
|
|
91
91
|
*/
|
|
92
92
|
declare function map<T, E, U>(project: (value: T) => U): (source: Result<T, E>) => Result<U, E>;
|
|
93
93
|
//#endregion
|
|
94
94
|
//#region src/core/mapErr.d.ts
|
|
95
95
|
/**
|
|
96
|
-
*
|
|
97
|
-
*
|
|
96
|
+
* Transforms the error (Err case).
|
|
97
|
+
* Corresponds to Rust `map_err`.
|
|
98
98
|
*/
|
|
99
99
|
declare function mapErr<T, E, F>(project: (error: E) => F): (source: Result<T, E>) => Result<T, F>;
|
|
100
100
|
//#endregion
|
|
101
101
|
//#region src/core/mapBoth.d.ts
|
|
102
102
|
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
103
|
+
* Transforms both the Ok value and the Err error.
|
|
104
|
+
* Corresponds to FP `bimap` / `mapBoth`.
|
|
105
105
|
*/
|
|
106
106
|
declare function mapBoth<T, E, U, F>(mapOk: (value: T) => U, mapErr: (error: E) => F): (source: Result<T, E>) => Result<U, F>;
|
|
107
107
|
/**
|
|
108
|
-
* Alias
|
|
108
|
+
* Alias for `mapBoth`.
|
|
109
109
|
*/
|
|
110
110
|
declare const bimap: typeof mapBoth;
|
|
111
111
|
//#endregion
|
|
112
112
|
//#region src/core/flatMap.d.ts
|
|
113
113
|
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
114
|
+
* Chains another operation that returns a Result.
|
|
115
|
+
* Corresponds to Rust `and_then` or JS `flatMap`.
|
|
116
116
|
*/
|
|
117
117
|
declare function flatMap<T, E, U>(project: (value: T) => Result<U, E>): (source: Result<T, E>) => Result<U, E>;
|
|
118
118
|
//#endregion
|
|
119
119
|
//#region src/core/zip.d.ts
|
|
120
120
|
/**
|
|
121
|
-
*
|
|
122
|
-
* Short-circuits
|
|
121
|
+
* Combines two Results into a Result of a tuple.
|
|
122
|
+
* Short-circuits on the first Err (left before right).
|
|
123
123
|
*/
|
|
124
124
|
declare function zip<A, AE, B, BE>(left: Result<A, AE>, right: Result<B, BE>): Result<[A, B], AE | BE>;
|
|
125
125
|
declare function zip<A, AE, B, BE>(right: Result<B, BE>): (left: Result<A, AE>) => Result<[A, B], AE | BE>;
|
|
126
126
|
/**
|
|
127
|
-
*
|
|
128
|
-
* - Ok
|
|
129
|
-
* - Err([errors])
|
|
127
|
+
* Combines two Results and collects errors.
|
|
128
|
+
* - Ok only if both are Ok
|
|
129
|
+
* - Err([errors]) if at least one is Err (left before right)
|
|
130
130
|
*/
|
|
131
131
|
declare function combine<A, AE, B, BE>(left: Result<A, AE>, right: Result<B, BE>): Result<[A, B], Array<AE | BE>>;
|
|
132
132
|
declare function combine<A, AE, B, BE>(right: Result<B, BE>): (left: Result<A, AE>) => Result<[A, B], Array<AE | BE>>;
|
|
133
133
|
//#endregion
|
|
134
134
|
//#region src/core/tap.d.ts
|
|
135
135
|
/**
|
|
136
|
-
*
|
|
137
|
-
*
|
|
136
|
+
* Executes a side effect (logging, debugging) without changing the Result.
|
|
137
|
+
* Corresponds to Rust `inspect` / `inspect_err`.
|
|
138
138
|
*/
|
|
139
139
|
declare function tap<T, E>(observer: {
|
|
140
140
|
ok?: (val: T) => void;
|
|
@@ -143,15 +143,15 @@ declare function tap<T, E>(observer: {
|
|
|
143
143
|
//#endregion
|
|
144
144
|
//#region src/core/filter.d.ts
|
|
145
145
|
/**
|
|
146
|
-
*
|
|
147
|
-
*
|
|
146
|
+
* Checks a condition. If false, the Result becomes Err.
|
|
147
|
+
* Corresponds to Rust `filter` (partially).
|
|
148
148
|
*/
|
|
149
149
|
declare function filter<T, E>(predicate: (val: T) => boolean, errorFn: () => E): (source: Result<T, E>) => Result<T, E>;
|
|
150
150
|
//#endregion
|
|
151
151
|
//#region src/core/match.d.ts
|
|
152
152
|
/**
|
|
153
|
-
*
|
|
154
|
-
*
|
|
153
|
+
* Resolves the Result. The end of the pipe.
|
|
154
|
+
* Corresponds to Rust `match`.
|
|
155
155
|
*/
|
|
156
156
|
declare function match<T, E, R$1>(handlers: {
|
|
157
157
|
ok: (val: T) => R$1;
|
|
@@ -160,33 +160,33 @@ declare function match<T, E, R$1>(handlers: {
|
|
|
160
160
|
//#endregion
|
|
161
161
|
//#region src/core/recover.d.ts
|
|
162
162
|
/**
|
|
163
|
-
* Recover:
|
|
164
|
-
*
|
|
163
|
+
* Recover: converts Err to Ok(defaultValue).
|
|
164
|
+
* Result is guaranteed to be Ok → Error type becomes `never`.
|
|
165
165
|
*/
|
|
166
166
|
declare function recover<T, E, F>(defaultValue: F): (source: Result<T, E>) => Result<T | F, never>;
|
|
167
167
|
/**
|
|
168
|
-
*
|
|
168
|
+
* Like `recover`, but calculates the default value based on the error.
|
|
169
169
|
*/
|
|
170
170
|
declare function recoverWith<T, E, F>(fn: (error: E) => F): (source: Result<T, E>) => Result<T | F, never>;
|
|
171
171
|
//#endregion
|
|
172
172
|
//#region src/core/swap.d.ts
|
|
173
173
|
/**
|
|
174
|
-
*
|
|
174
|
+
* Swaps Ok and Err.
|
|
175
175
|
* Result<T, E> → Result<E, T>
|
|
176
176
|
*/
|
|
177
177
|
declare function swap<T, E>(result: Result<T, E>): Result<E, T>;
|
|
178
178
|
//#endregion
|
|
179
179
|
//#region src/core/tryCatch.d.ts
|
|
180
180
|
/**
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
181
|
+
* Executes a function and catches exceptions.
|
|
182
|
+
* Converts exceptions into Result<E>.
|
|
183
|
+
* Corresponds to Rust `Result::from` for fallible operations.
|
|
184
184
|
*/
|
|
185
185
|
declare function tryCatch<T, E = unknown>(fn: () => T, errorMapper?: (error: unknown) => E): (source: Result<any, any>) => Result<T, E>;
|
|
186
186
|
//#endregion
|
|
187
187
|
//#region src/core/tryMap.d.ts
|
|
188
188
|
/**
|
|
189
|
-
*
|
|
189
|
+
* Like `map`, but catches exceptions and converts them to Err.
|
|
190
190
|
*/
|
|
191
191
|
declare function tryMap<T, E, U, F = unknown>(project: (value: T) => U, errorMapper?: (error: unknown) => F): (source: Result<T, E>) => Result<U, E | F>;
|
|
192
192
|
//#endregion
|
|
@@ -202,25 +202,25 @@ declare function collectFirstOk<const Results extends readonly Result<any, any>[
|
|
|
202
202
|
//#endregion
|
|
203
203
|
//#region src/core/mapAsync.d.ts
|
|
204
204
|
/**
|
|
205
|
-
* Async
|
|
205
|
+
* Async version of map.
|
|
206
206
|
*/
|
|
207
207
|
declare function mapAsync<T, E, U>(project: (value: T) => Promise<U>): (source: Result<T, E>) => Promise<Result<U, E>>;
|
|
208
208
|
//#endregion
|
|
209
209
|
//#region src/core/mapErrAsync.d.ts
|
|
210
210
|
/**
|
|
211
|
-
* Async
|
|
211
|
+
* Async version of mapErr.
|
|
212
212
|
*/
|
|
213
213
|
declare function mapErrAsync<T, E, F>(project: (error: E) => Promise<F>): (source: Result<T, E>) => Promise<Result<T, F>>;
|
|
214
214
|
//#endregion
|
|
215
215
|
//#region src/core/flatMapAsync.d.ts
|
|
216
216
|
/**
|
|
217
|
-
* Async
|
|
217
|
+
* Async version of flatMap.
|
|
218
218
|
*/
|
|
219
219
|
declare function flatMapAsync<T, E, U>(project: (value: T) => Promise<Result<U, E>>): (source: Result<T, E>) => Promise<Result<U, E>>;
|
|
220
220
|
//#endregion
|
|
221
221
|
//#region src/core/tapAsync.d.ts
|
|
222
222
|
/**
|
|
223
|
-
* Async
|
|
223
|
+
* Async version of tap.
|
|
224
224
|
*/
|
|
225
225
|
declare function tapAsync<T, E>(observer: {
|
|
226
226
|
ok?: (val: T) => Promise<void>;
|
|
@@ -229,13 +229,13 @@ declare function tapAsync<T, E>(observer: {
|
|
|
229
229
|
//#endregion
|
|
230
230
|
//#region src/core/filterAsync.d.ts
|
|
231
231
|
/**
|
|
232
|
-
* Async
|
|
232
|
+
* Async version of filter.
|
|
233
233
|
*/
|
|
234
234
|
declare function filterAsync<T, E>(predicate: (val: T) => Promise<boolean>, errorFn: () => Promise<E>): (source: Result<T, E>) => Promise<Result<T, E>>;
|
|
235
235
|
//#endregion
|
|
236
236
|
//#region src/core/matchAsync.d.ts
|
|
237
237
|
/**
|
|
238
|
-
* Async
|
|
238
|
+
* Async version of match.
|
|
239
239
|
*/
|
|
240
240
|
declare function matchAsync<T, E, R$1>(handlers: {
|
|
241
241
|
ok: (val: T) => Promise<R$1>;
|
|
@@ -244,13 +244,13 @@ declare function matchAsync<T, E, R$1>(handlers: {
|
|
|
244
244
|
//#endregion
|
|
245
245
|
//#region src/core/tryCatchAsync.d.ts
|
|
246
246
|
/**
|
|
247
|
-
* Async
|
|
247
|
+
* Async version of tryCatch.
|
|
248
248
|
*/
|
|
249
249
|
declare function tryCatchAsync<T, E = unknown>(fn: () => Promise<T>, errorMapper?: (error: unknown) => E): (source: Result<any, any>) => Promise<Result<T, E>>;
|
|
250
250
|
//#endregion
|
|
251
251
|
//#region src/core/tryMapAsync.d.ts
|
|
252
252
|
/**
|
|
253
|
-
* Async
|
|
253
|
+
* Async version of tryMap.
|
|
254
254
|
*/
|
|
255
255
|
declare function tryMapAsync<T, E, U, F = unknown>(project: (value: T) => Promise<U>, errorMapper?: (error: unknown) => F): (source: Result<T, E>) => Promise<Result<U, E | F>>;
|
|
256
256
|
//#endregion
|
|
@@ -289,21 +289,21 @@ declare abstract class ResultBase extends Pipeable {
|
|
|
289
289
|
*/
|
|
290
290
|
[Symbol.iterator](): Generator<unknown, OkValue<this>, unknown>;
|
|
291
291
|
/**
|
|
292
|
-
*
|
|
292
|
+
* Matches on the Err value via `.when(...)` chain.
|
|
293
293
|
*
|
|
294
|
-
*
|
|
295
|
-
*
|
|
294
|
+
* Note: for type safety reasons, `.match()` can only be called on a Result already narrowed to `Err`,
|
|
295
|
+
* e.g. inside `if (result.isErr()) { ... }`.
|
|
296
296
|
*/
|
|
297
297
|
match<T, E>(this: Result<T, E>): ErrorMatchBuilder<E, never>;
|
|
298
298
|
/**
|
|
299
|
-
*
|
|
300
|
-
* -
|
|
301
|
-
* -
|
|
299
|
+
* Matches on the Err value, but normalizes every branch to a `Result`:
|
|
300
|
+
* - Handlers may return a `Result` (is returned directly)
|
|
301
|
+
* - or an Error value (is wrapped into `Err(error)`)
|
|
302
302
|
*/
|
|
303
303
|
matchErr<T, E>(this: Result<T, E>): ErrMatchBuilder<T, E, never, never>;
|
|
304
304
|
/**
|
|
305
|
-
*
|
|
306
|
-
*
|
|
305
|
+
* Serializes the Result into a simple object format.
|
|
306
|
+
* Preserves the original types.
|
|
307
307
|
*/
|
|
308
308
|
serialize<T, E>(this: Result<T, E>): {
|
|
309
309
|
isSuccess: boolean;
|
|
@@ -311,8 +311,8 @@ declare abstract class ResultBase extends Pipeable {
|
|
|
311
311
|
error?: E;
|
|
312
312
|
};
|
|
313
313
|
/**
|
|
314
|
-
*
|
|
315
|
-
*
|
|
314
|
+
* Serializes the Result into a user-friendly format.
|
|
315
|
+
* Converts Errors to readable strings.
|
|
316
316
|
*/
|
|
317
317
|
toUserFriendly<T, E>(this: Result<T, E>): {
|
|
318
318
|
isSuccess: boolean;
|
|
@@ -444,104 +444,104 @@ declare function foldAsync<T, E, R$1>(handlers: {
|
|
|
444
444
|
//#endregion
|
|
445
445
|
//#region src/core/unwrap.d.ts
|
|
446
446
|
/**
|
|
447
|
-
*
|
|
448
|
-
*
|
|
447
|
+
* Returns the value or throws an Error.
|
|
448
|
+
* Corresponds to Rust `unwrap`.
|
|
449
449
|
*/
|
|
450
450
|
declare function unwrap<T, E>(result: Result<T, E>): T;
|
|
451
451
|
//#endregion
|
|
452
452
|
//#region src/core/unwrapOr.d.ts
|
|
453
453
|
/**
|
|
454
|
-
*
|
|
455
|
-
* Pure function
|
|
454
|
+
* Returns the value or a default value.
|
|
455
|
+
* Pure function alternative to the instance method.
|
|
456
456
|
*/
|
|
457
457
|
declare function unwrapOr<T, E>(result: Result<T, E>, defaultValue: T): T;
|
|
458
458
|
//#endregion
|
|
459
459
|
//#region src/core/unwrapOrElse.d.ts
|
|
460
460
|
/**
|
|
461
|
-
*
|
|
462
|
-
*
|
|
461
|
+
* Returns the value or calculates a default value using a function.
|
|
462
|
+
* Corresponds to Rust `unwrap_or_else`.
|
|
463
463
|
*/
|
|
464
464
|
declare function unwrapOrElse<T, E>(result: Result<T, E>, fn: (error: E) => T): T;
|
|
465
465
|
//#endregion
|
|
466
466
|
//#region src/core/unwrapOrDefault.d.ts
|
|
467
467
|
/**
|
|
468
|
-
* Alias
|
|
469
|
-
*
|
|
468
|
+
* Alias for `unwrapOr`.
|
|
469
|
+
* Corresponds to Rust `unwrap_or_default` (with explicit default value).
|
|
470
470
|
*/
|
|
471
471
|
declare function unwrapOrDefault<T, E>(result: Result<T, E>, defaultValue: T): T;
|
|
472
472
|
//#endregion
|
|
473
473
|
//#region src/core/unwrapOrThrow.d.ts
|
|
474
474
|
/**
|
|
475
|
-
*
|
|
476
|
-
*
|
|
475
|
+
* Returns the value or throws the original Err value (not wrapped).
|
|
476
|
+
* Useful to preserve `Error` instances including stack traces.
|
|
477
477
|
*/
|
|
478
478
|
declare function unwrapOrThrow<T, E>(result: Result<T, E>): T;
|
|
479
479
|
//#endregion
|
|
480
480
|
//#region src/core/unwrapErr.d.ts
|
|
481
481
|
/**
|
|
482
|
-
*
|
|
483
|
-
*
|
|
482
|
+
* Returns the error or throws an Error.
|
|
483
|
+
* Corresponds to Rust `unwrap_err`.
|
|
484
484
|
*/
|
|
485
485
|
declare function unwrapErr<T, E>(result: Result<T, E>): E;
|
|
486
486
|
//#endregion
|
|
487
487
|
//#region src/core/expectResult.d.ts
|
|
488
488
|
/**
|
|
489
|
-
*
|
|
490
|
-
*
|
|
489
|
+
* Returns the value or throws an Error with a custom message.
|
|
490
|
+
* Corresponds to Rust `expect`.
|
|
491
491
|
*/
|
|
492
492
|
declare function expectResult<T, E>(result: Result<T, E>, message: string): T;
|
|
493
493
|
//#endregion
|
|
494
494
|
//#region src/core/expectErr.d.ts
|
|
495
495
|
/**
|
|
496
|
-
*
|
|
497
|
-
*
|
|
496
|
+
* Returns the error or throws an Error with a custom message.
|
|
497
|
+
* Corresponds to Rust `expect_err`.
|
|
498
498
|
*/
|
|
499
499
|
declare function expectErr<T, E>(result: Result<T, E>, message: string): E;
|
|
500
500
|
//#endregion
|
|
501
501
|
//#region src/core/and.d.ts
|
|
502
502
|
/**
|
|
503
|
-
*
|
|
504
|
-
*
|
|
503
|
+
* Combines two Results. Returns the second one only if the first is Ok.
|
|
504
|
+
* Corresponds to Rust `and`.
|
|
505
505
|
*/
|
|
506
506
|
declare function and<T, E, U>(result: Result<T, E>, other: Result<U, E>): Result<U, E>;
|
|
507
507
|
//#endregion
|
|
508
508
|
//#region src/core/or.d.ts
|
|
509
509
|
/**
|
|
510
|
-
* Fallback
|
|
511
|
-
*
|
|
510
|
+
* Fallback to another Result if the first is Err.
|
|
511
|
+
* Corresponds to Rust `or`.
|
|
512
512
|
*/
|
|
513
513
|
declare function or<T, E, F>(result: Result<T, E>, other: Result<T, F>): Result<T, F>;
|
|
514
514
|
//#endregion
|
|
515
515
|
//#region src/core/orElse.d.ts
|
|
516
516
|
/**
|
|
517
|
-
* Fallback
|
|
518
|
-
*
|
|
517
|
+
* Fallback with a function that returns a Result.
|
|
518
|
+
* Corresponds to Rust `or_else`.
|
|
519
519
|
*/
|
|
520
520
|
declare function orElse<T, E, F>(result: Result<T, E>, fn: (error: E) => Result<T, F>): Result<T, F>;
|
|
521
521
|
//#endregion
|
|
522
522
|
//#region src/core/mapOr.d.ts
|
|
523
523
|
/**
|
|
524
|
-
*
|
|
525
|
-
*
|
|
524
|
+
* Transforms the value or returns a default value.
|
|
525
|
+
* Corresponds to Rust `map_or`.
|
|
526
526
|
*/
|
|
527
527
|
declare function mapOr<T, E, U>(result: Result<T, E>, defaultValue: U, fn: (value: T) => U): U;
|
|
528
528
|
//#endregion
|
|
529
529
|
//#region src/core/mapOrElse.d.ts
|
|
530
530
|
/**
|
|
531
|
-
*
|
|
532
|
-
*
|
|
531
|
+
* Transforms the value or calculates a default value using a function.
|
|
532
|
+
* Corresponds to Rust `map_or_else`.
|
|
533
533
|
*/
|
|
534
534
|
declare function mapOrElse<T, E, U>(result: Result<T, E>, defaultFn: (error: E) => U, fn: (value: T) => U): U;
|
|
535
535
|
//#endregion
|
|
536
536
|
//#region src/core/sequence.d.ts
|
|
537
537
|
/**
|
|
538
|
-
*
|
|
539
|
-
* Short-circuits
|
|
540
|
-
*
|
|
538
|
+
* Combines a list of Results into a single Result of a list.
|
|
539
|
+
* Short-circuits on the first Err.
|
|
540
|
+
* Analogous to Rust `collect::<Result<Vec<_>, _>>()`.
|
|
541
541
|
*/
|
|
542
542
|
declare function sequence<T, E>(results: readonly Result<T, E>[]): Result<T[], E>;
|
|
543
543
|
/**
|
|
544
|
-
* Alias
|
|
544
|
+
* Alias for `sequence`.
|
|
545
545
|
*/
|
|
546
546
|
declare function all<T, E>(results: readonly Result<T, E>[]): Result<T[], E>;
|
|
547
547
|
//#endregion
|
|
@@ -549,8 +549,8 @@ declare function all<T, E>(results: readonly Result<T, E>[]): Result<T[], E>;
|
|
|
549
549
|
type OkValueOf$1<R$1> = R$1 extends Result<infer T, any> ? T : never;
|
|
550
550
|
type ErrValueOf$1<R$1> = R$1 extends Result<any, infer E> ? E : never;
|
|
551
551
|
/**
|
|
552
|
-
*
|
|
553
|
-
* Short-circuits
|
|
552
|
+
* Like `sequence`, but for Records/Objects.
|
|
553
|
+
* Short-circuits on the first Err.
|
|
554
554
|
*/
|
|
555
555
|
declare function sequenceRecord<const R$1 extends Record<string, Result<any, any>>>(record: R$1): Result<{ [K in keyof R$1]: OkValueOf$1<R$1[K]> }, ErrValueOf$1<R$1[keyof R$1]>>;
|
|
556
556
|
//#endregion
|
|
@@ -560,11 +560,11 @@ type ResolvedResult$1<I> = I extends (() => infer R) ? Awaited<R> : I extends Pr
|
|
|
560
560
|
type OkValueOfInput$1<I> = ResolvedResult$1<I> extends Result<infer T, any> ? T : never;
|
|
561
561
|
type ErrValueOfInput$1<I> = ResolvedResult$1<I> extends Result<any, infer E> ? E : never;
|
|
562
562
|
/**
|
|
563
|
-
* Async
|
|
563
|
+
* Async version of collectFirstOk.
|
|
564
564
|
*
|
|
565
|
-
* -
|
|
566
|
-
* -
|
|
567
|
-
* -
|
|
565
|
+
* - Takes either already started Promises or "Thunks" (`() => Awaitable<Result<...>>`).
|
|
566
|
+
* - Processes inputs strictly sequentially (like `for ... of` + `await`).
|
|
567
|
+
* - Returns the first `Ok` and collects all errors if no `Ok` is found.
|
|
568
568
|
*/
|
|
569
569
|
declare function collectFirstOkAsync<const Inputs extends readonly CollectFirstOkAsyncInput$1[]>(inputs: Inputs): Promise<Result<OkValueOfInput$1<Inputs[number]>, ErrValueOfInput$1<Inputs[number]>[]>>;
|
|
570
570
|
//#endregion
|
|
@@ -574,22 +574,22 @@ type ResolvedResult<I> = I extends (() => infer R) ? Awaited<R> : I extends Prom
|
|
|
574
574
|
type OkValueOfInput<I> = ResolvedResult<I> extends Result<infer T, any> ? T : never;
|
|
575
575
|
type ErrValueOfInput<I> = ResolvedResult<I> extends Result<any, infer E> ? E : never;
|
|
576
576
|
/**
|
|
577
|
-
* Parallel
|
|
577
|
+
* Parallel version of `collectFirstOkAsync`.
|
|
578
578
|
*
|
|
579
|
-
* -
|
|
580
|
-
* -
|
|
581
|
-
* -
|
|
582
|
-
* - Rejections
|
|
583
|
-
* -
|
|
584
|
-
*
|
|
585
|
-
* -
|
|
579
|
+
* - Starts all inputs immediately (Promises or Thunks).
|
|
580
|
+
* - Returns the first `Ok` as soon as it is available.
|
|
581
|
+
* - If no `Ok` is found, returns an `Err` with all error values (in input order).
|
|
582
|
+
* - Rejections are treated as `ErrValue` (`caught as ErrValue`).
|
|
583
|
+
* - If multiple inputs provide an `Ok`, the one that completes first wins.
|
|
584
|
+
* In case of simultaneous completion, the first observed result wins.
|
|
585
|
+
* - If no `Ok` arrives and at least one input never settles, the Promise remains pending.
|
|
586
586
|
*/
|
|
587
587
|
declare function collectFirstOkParallelAsync<const Inputs extends readonly CollectFirstOkAsyncInput[]>(inputs: Inputs): Promise<Result<OkValueOfInput<Inputs[number]>, ErrValueOfInput<Inputs[number]>[]>>;
|
|
588
588
|
//#endregion
|
|
589
589
|
//#region src/core/collectAllErrors.d.ts
|
|
590
590
|
/**
|
|
591
|
-
*
|
|
592
|
-
*
|
|
591
|
+
* Combines a list of Results.
|
|
592
|
+
* Return Ok(values) only if all are Ok, otherwise Err([errors]).
|
|
593
593
|
*/
|
|
594
594
|
declare function collectAllErrors<T, E>(results: readonly Result<T, E>[]): Result<T[], E[]>;
|
|
595
595
|
//#endregion
|
|
@@ -597,57 +597,57 @@ declare function collectAllErrors<T, E>(results: readonly Result<T, E>[]): Resul
|
|
|
597
597
|
type OkValueOf<R$1> = R$1 extends Result<infer T, any> ? T : never;
|
|
598
598
|
type ErrValueOf<R$1> = R$1 extends Result<any, infer E> ? E : never;
|
|
599
599
|
/**
|
|
600
|
-
*
|
|
600
|
+
* Partitions Results into Ok values and Err errors.
|
|
601
601
|
*/
|
|
602
602
|
declare function partition<const Results extends readonly Result<any, any>[]>(results: Results): [oks: Array<OkValueOf<Results[number]>>, errs: Array<ErrValueOf<Results[number]>>];
|
|
603
603
|
//#endregion
|
|
604
604
|
//#region src/core/flatten.d.ts
|
|
605
605
|
/**
|
|
606
|
-
*
|
|
606
|
+
* Flattens a nested Result.
|
|
607
607
|
* Result<Result<T, E>, E> → Result<T, E>
|
|
608
|
-
*
|
|
608
|
+
* Corresponds to Rust `flatten`.
|
|
609
609
|
*/
|
|
610
610
|
declare function flatten<T, E>(result: Result<Result<T, E>, E>): Result<T, E>;
|
|
611
611
|
//#endregion
|
|
612
612
|
//#region src/core/toPromise.d.ts
|
|
613
613
|
/**
|
|
614
|
-
*
|
|
614
|
+
* Converts a Result to a Promise.
|
|
615
615
|
* Ok → resolve(value), Err → reject(error)
|
|
616
616
|
*/
|
|
617
617
|
declare function toPromise<T, E>(result: Result<T, E>): Promise<T>;
|
|
618
618
|
//#endregion
|
|
619
619
|
//#region src/core/toNullable.d.ts
|
|
620
620
|
/**
|
|
621
|
-
*
|
|
621
|
+
* Converts a Result to `T | null`.
|
|
622
622
|
* Ok → value, Err → null
|
|
623
623
|
*/
|
|
624
624
|
declare function toNullable<T, E>(result: Result<T, E>): T | null;
|
|
625
625
|
//#endregion
|
|
626
626
|
//#region src/core/isOk.d.ts
|
|
627
627
|
/**
|
|
628
|
-
*
|
|
629
|
-
* Pure function
|
|
628
|
+
* Checks if a Result is Ok.
|
|
629
|
+
* Pure function alternative to the instance method.
|
|
630
630
|
*/
|
|
631
631
|
declare function isOk<T, E>(result: Result<T, E>): result is Ok<T, E>;
|
|
632
632
|
//#endregion
|
|
633
633
|
//#region src/core/isErr.d.ts
|
|
634
634
|
/**
|
|
635
|
-
*
|
|
636
|
-
* Pure function
|
|
635
|
+
* Checks if a Result is Err.
|
|
636
|
+
* Pure function alternative to the instance method.
|
|
637
637
|
*/
|
|
638
638
|
declare function isErr<T, E>(result: Result<T, E>): result is Err<T, E>;
|
|
639
639
|
//#endregion
|
|
640
640
|
//#region src/core/contains.d.ts
|
|
641
641
|
/**
|
|
642
|
-
*
|
|
643
|
-
*
|
|
642
|
+
* Checks if the Result contains a specific value.
|
|
643
|
+
* Corresponds to Rust `contains`.
|
|
644
644
|
*/
|
|
645
645
|
declare function contains<T, E>(result: Result<T, E>, value: T): boolean;
|
|
646
646
|
//#endregion
|
|
647
647
|
//#region src/core/containsErr.d.ts
|
|
648
648
|
/**
|
|
649
|
-
*
|
|
650
|
-
*
|
|
649
|
+
* Checks if the Result contains a specific error.
|
|
650
|
+
* Analogous to `contains` for the Err case.
|
|
651
651
|
*/
|
|
652
652
|
declare function containsErr<T, E>(result: Result<T, E>, error: E): boolean;
|
|
653
653
|
//#endregion
|