@nlozgachev/pipelined 0.62.0 → 0.63.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/dist/{Duration-B8joKzro.d.cts → Duration-DeyxG6VQ.d.cts} +20 -20
- package/dist/{Duration-B8joKzro.d.ts → Duration-DeyxG6VQ.d.ts} +20 -20
- package/dist/{InternalTypes-LdhLQx3N.d.ts → InternalTypes-CCXa8Kvr.d.ts} +11 -11
- package/dist/{InternalTypes-DuK_XpTi.d.cts → InternalTypes-GFn4RTwD.d.cts} +11 -11
- package/dist/{Validation-DZLizBZ0.d.ts → Validation-C5RGZUXy.d.ts} +384 -280
- package/dist/{Validation-DC3uUizM.d.cts → Validation-KFUpea_k.d.cts} +384 -280
- package/dist/composition.cjs +216 -95
- package/dist/composition.d.cts +8 -76
- package/dist/composition.d.ts +8 -76
- package/dist/composition.mjs +216 -95
- package/dist/core.cjs +4784 -996
- package/dist/core.d.cts +269 -769
- package/dist/core.d.ts +269 -769
- package/dist/core.mjs +4784 -996
- package/dist/data.cjs +2916 -1240
- package/dist/data.d.cts +479 -1967
- package/dist/data.d.ts +479 -1967
- package/dist/data.mjs +2916 -1240
- package/dist/index.cjs +6739 -2169
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.mjs +6718 -2148
- package/dist/types.cjs +175 -31
- package/dist/types.d.cts +6 -6
- package/dist/types.d.ts +6 -6
- package/dist/types.mjs +175 -31
- package/package.json +24 -13
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { h as WithKind, o as WithValue, e as WithError, a as NonEmptyArr, T as Thenable, D as Deferred, f as WithErrors } from './InternalTypes-
|
|
2
|
-
import { D as Duration } from './Duration-
|
|
1
|
+
import { h as WithKind, o as WithValue, e as WithError, a as NonEmptyArr, T as Thenable, D as Deferred, f as WithErrors } from './InternalTypes-CCXa8Kvr.js';
|
|
2
|
+
import { D as Duration } from './Duration-DeyxG6VQ.js';
|
|
3
3
|
import { RetryPolicy } from './types.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -16,7 +16,7 @@ import { RetryPolicy } from './types.js';
|
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
18
|
type Equality<A> = (a: A, b: A) => boolean;
|
|
19
|
-
declare
|
|
19
|
+
declare const Equality: {
|
|
20
20
|
/**
|
|
21
21
|
* Equality for strings. Case-sensitive.
|
|
22
22
|
*
|
|
@@ -26,7 +26,7 @@ declare namespace Equality {
|
|
|
26
26
|
* Equality.string("hello", "Hello"); // false
|
|
27
27
|
* ```
|
|
28
28
|
*/
|
|
29
|
-
|
|
29
|
+
string: Equality<string>;
|
|
30
30
|
/**
|
|
31
31
|
* Equality for numbers. Uses strict equality.
|
|
32
32
|
*
|
|
@@ -35,7 +35,7 @@ declare namespace Equality {
|
|
|
35
35
|
* Equality.number(42, 42); // true
|
|
36
36
|
* ```
|
|
37
37
|
*/
|
|
38
|
-
|
|
38
|
+
number: Equality<number>;
|
|
39
39
|
/**
|
|
40
40
|
* Equality for booleans.
|
|
41
41
|
*
|
|
@@ -44,7 +44,7 @@ declare namespace Equality {
|
|
|
44
44
|
* Equality.boolean(true, true); // true
|
|
45
45
|
* ```
|
|
46
46
|
*/
|
|
47
|
-
|
|
47
|
+
boolean: Equality<boolean>;
|
|
48
48
|
/**
|
|
49
49
|
* Equality for `Date` values. Compares by numeric time value.
|
|
50
50
|
*
|
|
@@ -53,7 +53,7 @@ declare namespace Equality {
|
|
|
53
53
|
* Equality.date(new Date("2024-01-01"), new Date("2024-01-01")); // true
|
|
54
54
|
* ```
|
|
55
55
|
*/
|
|
56
|
-
|
|
56
|
+
date: Equality<Date>;
|
|
57
57
|
/**
|
|
58
58
|
* Lifts an element equality into an array equality. Two arrays are equal if they have the
|
|
59
59
|
* same length and every element pair is equal under `eq`.
|
|
@@ -63,7 +63,7 @@ declare namespace Equality {
|
|
|
63
63
|
* Equality.array(Equality.number)([1, 2, 3], [1, 2, 3]); // true
|
|
64
64
|
* ```
|
|
65
65
|
*/
|
|
66
|
-
|
|
66
|
+
array: <A>(eq: Equality<A>) => Equality<readonly A[]>;
|
|
67
67
|
/**
|
|
68
68
|
* Adapts an equality for type `A` into an equality for type `B` by extracting a field.
|
|
69
69
|
* Read as "equality by this field": `pipe(Equality.string, Equality.by(u => u.name))`.
|
|
@@ -75,7 +75,7 @@ declare namespace Equality {
|
|
|
75
75
|
* byId({ id: "p1", price: 9 }, { id: "p1", price: 12 }); // true
|
|
76
76
|
* ```
|
|
77
77
|
*/
|
|
78
|
-
|
|
78
|
+
by: <A, B>(f: (b: B) => A) => (eq: Equality<A>) => Equality<B>;
|
|
79
79
|
/**
|
|
80
80
|
* Combines two equalities with logical AND. Both must pass for two values to be considered equal.
|
|
81
81
|
* Data-last: the first equality is the data being piped.
|
|
@@ -86,7 +86,7 @@ declare namespace Equality {
|
|
|
86
86
|
* exact(userA, userB); // true only if name AND role match
|
|
87
87
|
* ```
|
|
88
88
|
*/
|
|
89
|
-
|
|
89
|
+
and: <A>(eq2: Equality<A>) => (eq1: Equality<A>) => Equality<A>;
|
|
90
90
|
/**
|
|
91
91
|
* Derives deep equality for a record from field-level `Equality` checkers.
|
|
92
92
|
*
|
|
@@ -98,7 +98,7 @@ declare namespace Equality {
|
|
|
98
98
|
* });
|
|
99
99
|
* ```
|
|
100
100
|
*/
|
|
101
|
-
|
|
101
|
+
struct: <R extends Record<string, unknown>>(fields: { [K in keyof R]: Equality<R[K]>; }) => Equality<R>;
|
|
102
102
|
/**
|
|
103
103
|
* Derives element-wise equality for a tuple from positional `Equality` checkers.
|
|
104
104
|
*
|
|
@@ -108,8 +108,8 @@ declare namespace Equality {
|
|
|
108
108
|
* pairEq(["a", 1], ["a", 1]); // true
|
|
109
109
|
* ```
|
|
110
110
|
*/
|
|
111
|
-
|
|
112
|
-
}
|
|
111
|
+
tuple: <T extends readonly unknown[]>(...equalities: { [K in keyof T]: Equality<T[K]>; }) => Equality<T>;
|
|
112
|
+
};
|
|
113
113
|
|
|
114
114
|
type Some<A> = WithKind<"Some"> & WithValue<A>;
|
|
115
115
|
type None = WithKind<"None">;
|
|
@@ -129,8 +129,8 @@ type None = WithKind<"None">;
|
|
|
129
129
|
* ```
|
|
130
130
|
*/
|
|
131
131
|
type Maybe<T> = Some<T> | None;
|
|
132
|
-
declare
|
|
133
|
-
|
|
132
|
+
declare const Maybe: {
|
|
133
|
+
make: {
|
|
134
134
|
/**
|
|
135
135
|
* Creates a Some containing the given value.
|
|
136
136
|
*
|
|
@@ -139,7 +139,7 @@ declare namespace Maybe {
|
|
|
139
139
|
* Maybe.make.some(42); // Some(42)
|
|
140
140
|
* ```
|
|
141
141
|
*/
|
|
142
|
-
|
|
142
|
+
some: <A>(value: A) => Some<A>;
|
|
143
143
|
/**
|
|
144
144
|
* Creates a None (empty Maybe).
|
|
145
145
|
*
|
|
@@ -148,9 +148,9 @@ declare namespace Maybe {
|
|
|
148
148
|
* Maybe.make.none(); // None
|
|
149
149
|
* ```
|
|
150
150
|
*/
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
|
|
151
|
+
none: () => None;
|
|
152
|
+
};
|
|
153
|
+
is: {
|
|
154
154
|
/**
|
|
155
155
|
* Type guard that checks if a Maybe is Some.
|
|
156
156
|
*
|
|
@@ -162,7 +162,7 @@ declare namespace Maybe {
|
|
|
162
162
|
* }
|
|
163
163
|
* ```
|
|
164
164
|
*/
|
|
165
|
-
|
|
165
|
+
some: <A>(data: Maybe<A>) => data is Some<A>;
|
|
166
166
|
/**
|
|
167
167
|
* Type guard that checks if a Maybe is None.
|
|
168
168
|
*
|
|
@@ -174,9 +174,9 @@ declare namespace Maybe {
|
|
|
174
174
|
* }
|
|
175
175
|
* ```
|
|
176
176
|
*/
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
|
|
177
|
+
none: <A>(data: Maybe<A>) => data is None;
|
|
178
|
+
};
|
|
179
|
+
to: {
|
|
180
180
|
/**
|
|
181
181
|
* Extracts the value from a Maybe, returning null if None.
|
|
182
182
|
*
|
|
@@ -186,7 +186,7 @@ declare namespace Maybe {
|
|
|
186
186
|
* Maybe.to.nullable(Maybe.make.none()); // null
|
|
187
187
|
* ```
|
|
188
188
|
*/
|
|
189
|
-
|
|
189
|
+
nullable: <A>(data: Maybe<A>) => A | null;
|
|
190
190
|
/**
|
|
191
191
|
* Extracts the value from a Maybe, returning undefined if None.
|
|
192
192
|
*
|
|
@@ -196,7 +196,7 @@ declare namespace Maybe {
|
|
|
196
196
|
* Maybe.to.undefined(Maybe.make.none()); // undefined
|
|
197
197
|
* ```
|
|
198
198
|
*/
|
|
199
|
-
|
|
199
|
+
undefined: <A>(data: Maybe<A>) => A | undefined;
|
|
200
200
|
/**
|
|
201
201
|
* Converts a Maybe to a Result.
|
|
202
202
|
* Some becomes Ok, None becomes Err with the provided error.
|
|
@@ -214,9 +214,9 @@ declare namespace Maybe {
|
|
|
214
214
|
* ); // Err("Value was missing")
|
|
215
215
|
* ```
|
|
216
216
|
*/
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
|
|
217
|
+
Result: <E>(onNone: () => E) => <A>(data: Maybe<A>) => Result<E, A>;
|
|
218
|
+
};
|
|
219
|
+
from: {
|
|
220
220
|
/**
|
|
221
221
|
* Creates a Maybe from a nullable value.
|
|
222
222
|
* Returns None if the value is null or undefined, Some otherwise.
|
|
@@ -227,7 +227,7 @@ declare namespace Maybe {
|
|
|
227
227
|
* Maybe.from.nullable(42); // Some(42)
|
|
228
228
|
* ```
|
|
229
229
|
*/
|
|
230
|
-
|
|
230
|
+
nullable: <A>(value: A | null | undefined) => Maybe<A>;
|
|
231
231
|
/**
|
|
232
232
|
* Creates a Maybe from a predicate applied to a value.
|
|
233
233
|
* Returns Some if the predicate passes, None otherwise.
|
|
@@ -241,7 +241,7 @@ declare namespace Maybe {
|
|
|
241
241
|
* pipe("", Maybe.from.Predicate((s: string) => s.length > 0)); // None
|
|
242
242
|
* ```
|
|
243
243
|
*/
|
|
244
|
-
|
|
244
|
+
Predicate: <A>(pred: (a: A) => boolean) => (a: A) => Maybe<A>;
|
|
245
245
|
/**
|
|
246
246
|
* Creates a Maybe from a Result.
|
|
247
247
|
* Ok becomes Some, Err becomes None (the error is discarded).
|
|
@@ -252,8 +252,8 @@ declare namespace Maybe {
|
|
|
252
252
|
* Maybe.from.Result(Result.make.err("oops")); // None
|
|
253
253
|
* ```
|
|
254
254
|
*/
|
|
255
|
-
|
|
256
|
-
}
|
|
255
|
+
Result: <E, A>(data: Result<E, A>) => Maybe<A>;
|
|
256
|
+
};
|
|
257
257
|
/**
|
|
258
258
|
* Transforms the value inside a Maybe if it exists.
|
|
259
259
|
*
|
|
@@ -263,7 +263,7 @@ declare namespace Maybe {
|
|
|
263
263
|
* pipe(Maybe.make.none(), Maybe.map(n => n * 2)); // None
|
|
264
264
|
* ```
|
|
265
265
|
*/
|
|
266
|
-
|
|
266
|
+
map: <A, B>(f: (a: A) => B) => (data: Maybe<A>) => Maybe<B>;
|
|
267
267
|
/**
|
|
268
268
|
* Chains Maybe computations. If the first is Some, passes the value to f.
|
|
269
269
|
* If the first is None, propagates None.
|
|
@@ -279,7 +279,7 @@ declare namespace Maybe {
|
|
|
279
279
|
* pipe(Maybe.make.some("abc"), Maybe.chain(parseNumber)); // None
|
|
280
280
|
* ```
|
|
281
281
|
*/
|
|
282
|
-
|
|
282
|
+
chain: <A, B>(f: (a: A) => Maybe<B>) => (data: Maybe<A>) => Maybe<B>;
|
|
283
283
|
/**
|
|
284
284
|
* Extracts the value from a Maybe by providing handlers for both cases.
|
|
285
285
|
*
|
|
@@ -294,7 +294,7 @@ declare namespace Maybe {
|
|
|
294
294
|
* ); // "Value: 5"
|
|
295
295
|
* ```
|
|
296
296
|
*/
|
|
297
|
-
|
|
297
|
+
fold: <A, B>(onNone: () => B, onSome: (a: A) => B) => (data: Maybe<A>) => B;
|
|
298
298
|
/**
|
|
299
299
|
* Pattern matches on a Maybe, returning the result of the matching case.
|
|
300
300
|
*
|
|
@@ -309,7 +309,7 @@ declare namespace Maybe {
|
|
|
309
309
|
* );
|
|
310
310
|
* ```
|
|
311
311
|
*/
|
|
312
|
-
|
|
312
|
+
match: <A, B>(cases: {
|
|
313
313
|
none: () => B;
|
|
314
314
|
some: (a: A) => B;
|
|
315
315
|
}) => (data: Maybe<A>) => B;
|
|
@@ -325,7 +325,7 @@ declare namespace Maybe {
|
|
|
325
325
|
* pipe(Maybe.make.none<string>(), Maybe.getOrElse(() => null)); // null — typed as string | null
|
|
326
326
|
* ```
|
|
327
327
|
*/
|
|
328
|
-
|
|
328
|
+
getOrElse: <B>(defaultValue: () => B) => <A>(data: Maybe<A>) => A | B;
|
|
329
329
|
/**
|
|
330
330
|
* Executes a side effect on the value without changing the Maybe.
|
|
331
331
|
* Useful for logging or debugging.
|
|
@@ -339,7 +339,7 @@ declare namespace Maybe {
|
|
|
339
339
|
* );
|
|
340
340
|
* ```
|
|
341
341
|
*/
|
|
342
|
-
|
|
342
|
+
tap: <A>(f: (a: A) => void) => (data: Maybe<A>) => Maybe<A>;
|
|
343
343
|
/**
|
|
344
344
|
* Filters a Maybe based on a predicate.
|
|
345
345
|
* Returns None if the predicate returns false or if the Maybe is already None.
|
|
@@ -350,7 +350,7 @@ declare namespace Maybe {
|
|
|
350
350
|
* pipe(Maybe.make.some(2), Maybe.filter(n => n > 3)); // None
|
|
351
351
|
* ```
|
|
352
352
|
*/
|
|
353
|
-
|
|
353
|
+
filter: <A>(predicate: (a: A) => boolean) => (data: Maybe<A>) => Maybe<A>;
|
|
354
354
|
/**
|
|
355
355
|
* Recovers from a None by providing a fallback Maybe.
|
|
356
356
|
* The fallback can produce a different type, widening the result to `Maybe<A | B>`.
|
|
@@ -361,7 +361,7 @@ declare namespace Maybe {
|
|
|
361
361
|
* pipe(Maybe.make.some(10), Maybe.recover(() => Maybe.make.some(42))); // Some(10)
|
|
362
362
|
* ```
|
|
363
363
|
*/
|
|
364
|
-
|
|
364
|
+
recover: <B>(fallback: () => Maybe<B>) => <A>(data: Maybe<A>) => Maybe<A | B>;
|
|
365
365
|
/**
|
|
366
366
|
* Applies a function wrapped in a Maybe to a value wrapped in a Maybe.
|
|
367
367
|
*
|
|
@@ -375,7 +375,7 @@ declare namespace Maybe {
|
|
|
375
375
|
* ); // Some(8)
|
|
376
376
|
* ```
|
|
377
377
|
*/
|
|
378
|
-
|
|
378
|
+
ap: <A>(arg: Maybe<A>) => <B>(data: Maybe<(a: A) => B>) => Maybe<B>;
|
|
379
379
|
/**
|
|
380
380
|
* Converts a Maybe value into an object containing a single property.
|
|
381
381
|
* Initiates the pipeline accumulator record.
|
|
@@ -385,7 +385,7 @@ declare namespace Maybe {
|
|
|
385
385
|
* pipe(Maybe.make.some(42), Maybe.bindTo("value")); // Some({ value: 42 })
|
|
386
386
|
* ```
|
|
387
387
|
*/
|
|
388
|
-
|
|
388
|
+
bindTo: <K extends string>(key: K) => <A>(data: Maybe<A>) => Maybe<{ [P in K]: A; }>;
|
|
389
389
|
/**
|
|
390
390
|
* Evaluates a new Maybe using the current accumulator and attaches the output to a new key.
|
|
391
391
|
*
|
|
@@ -397,7 +397,7 @@ declare namespace Maybe {
|
|
|
397
397
|
* ); // Some({ a: 1, b: 2 })
|
|
398
398
|
* ```
|
|
399
399
|
*/
|
|
400
|
-
|
|
400
|
+
bind: <K extends string, A, B>(key: K, f: (a: A) => Maybe<B>) => (data: Maybe<A>) => Maybe<A & { [P in K]: B; }>;
|
|
401
401
|
/**
|
|
402
402
|
* Combines a record of Maybes into a single Maybe of a record.
|
|
403
403
|
* Evaluates fields in key order and short-circuits on the first None.
|
|
@@ -410,7 +410,7 @@ declare namespace Maybe {
|
|
|
410
410
|
* }); // Some({ name: "Alice", age: 30 })
|
|
411
411
|
* ```
|
|
412
412
|
*/
|
|
413
|
-
|
|
413
|
+
struct: <R extends Record<string, any>>(fields: { [K in keyof R]: Maybe<R[K]>; }) => Maybe<R>;
|
|
414
414
|
/**
|
|
415
415
|
* Swaps the outer `Maybe` and inner `Result` context.
|
|
416
416
|
* `Some(Ok(a))` becomes `Ok(Some(a))`, `Some(Err(e))` becomes `Err(e)`, and `None` becomes `Ok(None)`.
|
|
@@ -422,8 +422,8 @@ declare namespace Maybe {
|
|
|
422
422
|
* Maybe.transposeResult(Maybe.make.none()); // Ok(None)
|
|
423
423
|
* ```
|
|
424
424
|
*/
|
|
425
|
-
|
|
426
|
-
}
|
|
425
|
+
transposeResult: <E, A>(data: Maybe<Result<E, A>>) => Result<E, Maybe<A>>;
|
|
426
|
+
};
|
|
427
427
|
|
|
428
428
|
/**
|
|
429
429
|
* A function that orders two values of type `A`. Returns a negative number when `a` comes before
|
|
@@ -442,7 +442,7 @@ declare namespace Maybe {
|
|
|
442
442
|
* ```
|
|
443
443
|
*/
|
|
444
444
|
type Ordering<A> = (a: A, b: A) => number;
|
|
445
|
-
declare
|
|
445
|
+
declare const Ordering: {
|
|
446
446
|
/**
|
|
447
447
|
* Alphabetical ordering for strings.
|
|
448
448
|
*
|
|
@@ -451,7 +451,7 @@ declare namespace Ordering {
|
|
|
451
451
|
* Ordering.string("apple", "banana"); // negative
|
|
452
452
|
* ```
|
|
453
453
|
*/
|
|
454
|
-
|
|
454
|
+
string: Ordering<string>;
|
|
455
455
|
/**
|
|
456
456
|
* Numeric ordering. Equivalent to `(a, b) => a - b`.
|
|
457
457
|
*
|
|
@@ -460,7 +460,7 @@ declare namespace Ordering {
|
|
|
460
460
|
* pipe([3, 1, 2], Arr.sortWith(Ordering.number)); // [1, 2, 3]
|
|
461
461
|
* ```
|
|
462
462
|
*/
|
|
463
|
-
|
|
463
|
+
number: Ordering<number>;
|
|
464
464
|
/**
|
|
465
465
|
* Ordering for `Date` values by numeric time value.
|
|
466
466
|
*
|
|
@@ -469,7 +469,7 @@ declare namespace Ordering {
|
|
|
469
469
|
* pipe(dates, Arr.sortWith(Ordering.date)); // earliest first
|
|
470
470
|
* ```
|
|
471
471
|
*/
|
|
472
|
-
|
|
472
|
+
date: Ordering<Date>;
|
|
473
473
|
/**
|
|
474
474
|
* Flips the direction of an ordering.
|
|
475
475
|
*
|
|
@@ -478,7 +478,7 @@ declare namespace Ordering {
|
|
|
478
478
|
* pipe([3, 1, 2], Arr.sortWith(Ordering.reverse(Ordering.number))); // [3, 2, 1]
|
|
479
479
|
* ```
|
|
480
480
|
*/
|
|
481
|
-
|
|
481
|
+
reverse: <A>(ord: Ordering<A>) => Ordering<A>;
|
|
482
482
|
/**
|
|
483
483
|
* Chains two orderings: the second is used only when the first returns `0`.
|
|
484
484
|
* Data-last: the first ordering is the data being piped.
|
|
@@ -488,7 +488,7 @@ declare namespace Ordering {
|
|
|
488
488
|
* const byDeptThenSalary = pipe(byDept, Ordering.thenBy(bySalary));
|
|
489
489
|
* ```
|
|
490
490
|
*/
|
|
491
|
-
|
|
491
|
+
thenBy: <A>(ord2: Ordering<A>) => (ord1: Ordering<A>) => Ordering<A>;
|
|
492
492
|
/**
|
|
493
493
|
* Adapts an ordering for type `A` into an ordering for type `B` by extracting a field.
|
|
494
494
|
* Read as "ordering by this field": `pipe(Ordering.number, Ordering.by(p => p.price))`.
|
|
@@ -500,7 +500,7 @@ declare namespace Ordering {
|
|
|
500
500
|
* pipe(products, Arr.sortWith(byPrice));
|
|
501
501
|
* ```
|
|
502
502
|
*/
|
|
503
|
-
|
|
503
|
+
by: <A, B>(f: (b: B) => A) => (ord: Ordering<A>) => Ordering<B>;
|
|
504
504
|
/**
|
|
505
505
|
* Combines a list of orderings into a single composite comparator.
|
|
506
506
|
* Evaluates each ordering in sequence until a non-zero comparison result is found.
|
|
@@ -512,7 +512,7 @@ declare namespace Ordering {
|
|
|
512
512
|
* const sortUsers = Ordering.byFields([byName, byAge]);
|
|
513
513
|
* ```
|
|
514
514
|
*/
|
|
515
|
-
|
|
515
|
+
byFields: <A>(orderings: ReadonlyArray<Ordering<A>>) => Ordering<A>;
|
|
516
516
|
/**
|
|
517
517
|
* Derives a lexicographical tuple ordering from positional `Ordering` comparators.
|
|
518
518
|
*
|
|
@@ -522,8 +522,8 @@ declare namespace Ordering {
|
|
|
522
522
|
* pairOrd(["a", 1], ["a", 2]); // negative
|
|
523
523
|
* ```
|
|
524
524
|
*/
|
|
525
|
-
|
|
526
|
-
}
|
|
525
|
+
tuple: <T extends readonly unknown[]>(...orderings: { [K in keyof T]: Ordering<T[K]>; }) => Ordering<T>;
|
|
526
|
+
};
|
|
527
527
|
|
|
528
528
|
type Ok<A> = WithKind<"Ok"> & WithValue<A>;
|
|
529
529
|
type Err<E> = WithKind<"Err"> & WithError<E>;
|
|
@@ -544,8 +544,8 @@ type Err<E> = WithKind<"Err"> & WithError<E>;
|
|
|
544
544
|
* ```
|
|
545
545
|
*/
|
|
546
546
|
type Result<E, A> = Ok<A> | Err<E>;
|
|
547
|
-
declare
|
|
548
|
-
|
|
547
|
+
declare const Result: {
|
|
548
|
+
make: {
|
|
549
549
|
/**
|
|
550
550
|
* Creates a successful Result with the given value.
|
|
551
551
|
*
|
|
@@ -554,7 +554,7 @@ declare namespace Result {
|
|
|
554
554
|
* Result.make.ok(42); // Ok(42)
|
|
555
555
|
* ```
|
|
556
556
|
*/
|
|
557
|
-
|
|
557
|
+
ok: <A>(value: A) => Ok<A>;
|
|
558
558
|
/**
|
|
559
559
|
* Creates a failed Result with the given error.
|
|
560
560
|
*
|
|
@@ -563,9 +563,9 @@ declare namespace Result {
|
|
|
563
563
|
* Result.make.err("Error message"); // Err("Error message")
|
|
564
564
|
* ```
|
|
565
565
|
*/
|
|
566
|
-
|
|
567
|
-
}
|
|
568
|
-
|
|
566
|
+
err: <E>(e: E) => Err<E>;
|
|
567
|
+
};
|
|
568
|
+
is: {
|
|
569
569
|
/**
|
|
570
570
|
* Type guard that checks if a Result is Ok.
|
|
571
571
|
*
|
|
@@ -577,7 +577,7 @@ declare namespace Result {
|
|
|
577
577
|
* }
|
|
578
578
|
* ```
|
|
579
579
|
*/
|
|
580
|
-
|
|
580
|
+
ok: <E, A>(data: Result<E, A>) => data is Ok<A>;
|
|
581
581
|
/**
|
|
582
582
|
* Type guard that checks if a Result is Err.
|
|
583
583
|
*
|
|
@@ -589,12 +589,8 @@ declare namespace Result {
|
|
|
589
589
|
* }
|
|
590
590
|
* ```
|
|
591
591
|
*/
|
|
592
|
-
|
|
593
|
-
}
|
|
594
|
-
/**
|
|
595
|
-
* Creates a Result from a function that may throw.
|
|
596
|
-
* Catches any errors and transforms them using the onError function.
|
|
597
|
-
*
|
|
592
|
+
err: <E, A>(data: Result<E, A>) => data is Err<E>;
|
|
593
|
+
};
|
|
598
594
|
/**
|
|
599
595
|
* Creates a Result from a synchronous thunk that may throw.
|
|
600
596
|
* Catches any errors and transforms them using the `onError` function.
|
|
@@ -607,7 +603,7 @@ declare namespace Result {
|
|
|
607
603
|
* );
|
|
608
604
|
* ```
|
|
609
605
|
*/
|
|
610
|
-
|
|
606
|
+
tryCatch: <E, A>(f: () => A, options: {
|
|
611
607
|
onError: (e: unknown) => E;
|
|
612
608
|
}) => Result<E, A>;
|
|
613
609
|
/**
|
|
@@ -619,7 +615,7 @@ declare namespace Result {
|
|
|
619
615
|
* pipe(Result.make.err("error"), Result.map(n => n * 2)); // Err("error")
|
|
620
616
|
* ```
|
|
621
617
|
*/
|
|
622
|
-
|
|
618
|
+
map: <E, A, B>(f: (a: A) => B) => (data: Result<E, A>) => Result<E, B>;
|
|
623
619
|
/**
|
|
624
620
|
* Transforms the error value inside a Result.
|
|
625
621
|
*
|
|
@@ -628,7 +624,7 @@ declare namespace Result {
|
|
|
628
624
|
* pipe(Result.make.err("oops"), Result.mapError(e => e.toUpperCase())); // Err("OOPS")
|
|
629
625
|
* ```
|
|
630
626
|
*/
|
|
631
|
-
|
|
627
|
+
mapError: <E, F, A>(f: (e: E) => F) => (data: Result<E, A>) => Result<F, A>;
|
|
632
628
|
/**
|
|
633
629
|
* Chains Result computations. If the first is Ok, passes the value to f.
|
|
634
630
|
* If the first is Err, propagates the error.
|
|
@@ -642,7 +638,7 @@ declare namespace Result {
|
|
|
642
638
|
* pipe(Result.make.ok(-1), Result.chain(validatePositive)); // Err("Must be positive")
|
|
643
639
|
* ```
|
|
644
640
|
*/
|
|
645
|
-
|
|
641
|
+
chain: <E2, A, B>(f: (a: A) => Result<E2, B>) => <E1 = never>(data: Result<E1, A>) => Result<E1 | E2, B>;
|
|
646
642
|
/**
|
|
647
643
|
* Extracts the value from a Result by providing handlers for both cases.
|
|
648
644
|
*
|
|
@@ -657,7 +653,7 @@ declare namespace Result {
|
|
|
657
653
|
* ); // "Value: 5"
|
|
658
654
|
* ```
|
|
659
655
|
*/
|
|
660
|
-
|
|
656
|
+
fold: <E, A, B>(onErr: (e: E) => B, onOk: (a: A) => B) => (data: Result<E, A>) => B;
|
|
661
657
|
/**
|
|
662
658
|
* Pattern matches on a Result, returning the result of the matching case.
|
|
663
659
|
*
|
|
@@ -672,7 +668,7 @@ declare namespace Result {
|
|
|
672
668
|
* );
|
|
673
669
|
* ```
|
|
674
670
|
*/
|
|
675
|
-
|
|
671
|
+
match: <E, A, B>(cases: {
|
|
676
672
|
ok: (a: A) => B;
|
|
677
673
|
err: (e: E) => B;
|
|
678
674
|
}) => (data: Result<E, A>) => B;
|
|
@@ -688,7 +684,7 @@ declare namespace Result {
|
|
|
688
684
|
* pipe(Result.make.err("error"), Result.getOrElse(() => null)); // null — typed as number | null
|
|
689
685
|
* ```
|
|
690
686
|
*/
|
|
691
|
-
|
|
687
|
+
getOrElse: <B>(defaultValue: () => B) => <E, A>(data: Result<E, A>) => A | B;
|
|
692
688
|
/**
|
|
693
689
|
* Executes a side effect on the success value without changing the Result.
|
|
694
690
|
* Useful for logging or debugging.
|
|
@@ -702,7 +698,7 @@ declare namespace Result {
|
|
|
702
698
|
* );
|
|
703
699
|
* ```
|
|
704
700
|
*/
|
|
705
|
-
|
|
701
|
+
tap: <E, A>(f: (a: A) => void) => (data: Result<E, A>) => Result<E, A>;
|
|
706
702
|
/**
|
|
707
703
|
* Executes a side effect on the error value without changing the Result.
|
|
708
704
|
* Useful for logging or reporting errors.
|
|
@@ -716,8 +712,8 @@ declare namespace Result {
|
|
|
716
712
|
* )
|
|
717
713
|
* ```
|
|
718
714
|
*/
|
|
719
|
-
|
|
720
|
-
|
|
715
|
+
tapError: <E, A>(f: (e: E) => void) => (data: Result<E, A>) => Result<E, A>;
|
|
716
|
+
from: {
|
|
721
717
|
/**
|
|
722
718
|
* Creates a Result from a predicate applied to a value.
|
|
723
719
|
* Returns Ok if the predicate passes, Err from onFalse otherwise.
|
|
@@ -729,7 +725,7 @@ declare namespace Result {
|
|
|
729
725
|
* pipe("", Result.from.Predicate(s => s.length > 0, () => "empty string")); // Err("empty string")
|
|
730
726
|
* ```
|
|
731
727
|
*/
|
|
732
|
-
|
|
728
|
+
Predicate: <E, A>(pred: (a: A) => boolean, onFalse: (a: A) => E) => (a: A) => Result<E, A>;
|
|
733
729
|
/**
|
|
734
730
|
* Creates a Result from a nullable value.
|
|
735
731
|
* Returns Ok if the value is not null or undefined, error from onNull otherwise.
|
|
@@ -740,7 +736,7 @@ declare namespace Result {
|
|
|
740
736
|
* pipe(42, Result.from.nullable(() => "is null")); // Ok(42)
|
|
741
737
|
* ```
|
|
742
738
|
*/
|
|
743
|
-
|
|
739
|
+
nullable: <E>(onNull: () => E) => <A>(value: A | null | undefined) => Result<E, A>;
|
|
744
740
|
/**
|
|
745
741
|
* Creates a Result from a Maybe.
|
|
746
742
|
* Some becomes Ok, None becomes error from onNone.
|
|
@@ -751,7 +747,7 @@ declare namespace Result {
|
|
|
751
747
|
* pipe(Maybe.make.some(42), Result.from.Maybe(() => "is none")); // Ok(42)
|
|
752
748
|
* ```
|
|
753
749
|
*/
|
|
754
|
-
|
|
750
|
+
Maybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => Result<E, A>;
|
|
755
751
|
/**
|
|
756
752
|
* Converts a `Validation` to a `Result`, combining accumulated errors using `combineErrors`.
|
|
757
753
|
* `Passed(a)` becomes `Ok(a)`; `Failed(errors)` becomes `Err(combineErrors(errors))`.
|
|
@@ -761,13 +757,13 @@ declare namespace Result {
|
|
|
761
757
|
* Result.from.Validation((errors) => errors.join(", "))(Validation.make.failed("error1")); // Err("error1")
|
|
762
758
|
* ```
|
|
763
759
|
*/
|
|
764
|
-
|
|
765
|
-
}
|
|
760
|
+
Validation: <E1, E2, A>(combineErrors: (errors: NonEmptyArr<E1>) => E2) => (val: Validation<E1, A>) => Result<E2, A>;
|
|
761
|
+
};
|
|
766
762
|
/**
|
|
767
763
|
* Recovers from an error by providing a fallback Result.
|
|
768
764
|
* The fallback can produce a different success type, widening the result to `Result<E, A | B>`.
|
|
769
765
|
*/
|
|
770
|
-
|
|
766
|
+
recover: <E, B>(fallback: (e: E) => Result<E, B>) => <A>(data: Result<E, A>) => Result<E, A | B>;
|
|
771
767
|
/**
|
|
772
768
|
* Recovers from an error unless the predicate `isBlocked` returns true for that error.
|
|
773
769
|
* The fallback can produce a different success type, widening the result to `Result<E, A | B>`.
|
|
@@ -780,8 +776,8 @@ declare namespace Result {
|
|
|
780
776
|
* ); // Ok(0)
|
|
781
777
|
* ```
|
|
782
778
|
*/
|
|
783
|
-
|
|
784
|
-
|
|
779
|
+
recoverUnless: <E, B>(isBlocked: (e: E) => boolean, fallback: () => Result<E, B>) => <A>(data: Result<E, A>) => Result<E, A | B>;
|
|
780
|
+
to: {
|
|
785
781
|
/**
|
|
786
782
|
* Converts a Result to a Maybe.
|
|
787
783
|
* Ok becomes Some, Err becomes None (the error is discarded).
|
|
@@ -792,7 +788,7 @@ declare namespace Result {
|
|
|
792
788
|
* Result.to.Maybe(Result.make.err("oops")); // None
|
|
793
789
|
* ```
|
|
794
790
|
*/
|
|
795
|
-
|
|
791
|
+
Maybe: <E, A>(data: Result<E, A>) => Maybe<A>;
|
|
796
792
|
/**
|
|
797
793
|
* Converts a `Result` to a `Validation`. `Ok(a)` becomes `Passed(a)`; `Err(e)` becomes `Failed([e])`.
|
|
798
794
|
*
|
|
@@ -802,8 +798,8 @@ declare namespace Result {
|
|
|
802
798
|
* Result.to.Validation(Result.make.err("bad")); // Failed(["bad"])
|
|
803
799
|
* ```
|
|
804
800
|
*/
|
|
805
|
-
|
|
806
|
-
}
|
|
801
|
+
Validation: <E, A>(data: Result<E, A>) => Validation<E, A>;
|
|
802
|
+
};
|
|
807
803
|
/**
|
|
808
804
|
* Swaps the outer `Result` and inner `Maybe` context.
|
|
809
805
|
* `Ok(Some(a))` becomes `Some(Ok(a))`, `Ok(None)` becomes `None`, and `Err(e)` becomes `Some(Err(e))`.
|
|
@@ -815,7 +811,7 @@ declare namespace Result {
|
|
|
815
811
|
* Result.transposeMaybe(Result.make.err("error")); // Some(Err("error"))
|
|
816
812
|
* ```
|
|
817
813
|
*/
|
|
818
|
-
|
|
814
|
+
transposeMaybe: <E, A>(data: Result<E, Maybe<A>>) => Maybe<Result<E, A>>;
|
|
819
815
|
/**
|
|
820
816
|
* Applies a function wrapped in a Result to a value wrapped in a Result.
|
|
821
817
|
*
|
|
@@ -829,7 +825,7 @@ declare namespace Result {
|
|
|
829
825
|
* ); // Ok(8)
|
|
830
826
|
* ```
|
|
831
827
|
*/
|
|
832
|
-
|
|
828
|
+
ap: <E, A>(arg: Result<E, A>) => <B>(data: Result<E, (a: A) => B>) => Result<E, B>;
|
|
833
829
|
/**
|
|
834
830
|
* Converts a Result value into an object containing a single property.
|
|
835
831
|
* Initiates the pipeline accumulator record.
|
|
@@ -839,7 +835,7 @@ declare namespace Result {
|
|
|
839
835
|
* pipe(Result.make.ok(42), Result.bindTo("value")); // Ok({ value: 42 })
|
|
840
836
|
* ```
|
|
841
837
|
*/
|
|
842
|
-
|
|
838
|
+
bindTo: <K extends string>(key: K) => <E, A>(data: Result<E, A>) => Result<E, { [P in K]: A; }>;
|
|
843
839
|
/**
|
|
844
840
|
* Evaluates a new Result using the current accumulator and attaches the output to a new key.
|
|
845
841
|
*
|
|
@@ -851,7 +847,7 @@ declare namespace Result {
|
|
|
851
847
|
* ); // Ok({ a: 1, b: 2 })
|
|
852
848
|
* ```
|
|
853
849
|
*/
|
|
854
|
-
|
|
850
|
+
bind: <K extends string, E, A, B>(key: K, f: (a: A) => Result<E, B>) => (data: Result<E, A>) => Result<E, A & { [P in K]: B; }>;
|
|
855
851
|
/**
|
|
856
852
|
* Combines a record of Results into a single Result of a record.
|
|
857
853
|
* Evaluates fields in key order and short-circuits on the first failure.
|
|
@@ -864,7 +860,7 @@ declare namespace Result {
|
|
|
864
860
|
* }); // Ok({ name: "Alice", age: 30 })
|
|
865
861
|
* ```
|
|
866
862
|
*/
|
|
867
|
-
|
|
863
|
+
struct: <E, R extends Record<string, any>>(fields: { [K in keyof R]: Result<E, R[K]>; }) => Result<E, R>;
|
|
868
864
|
/**
|
|
869
865
|
* Narrows an `Ok` value with a predicate, converting to `Err(onFail(a))` if the predicate returns false.
|
|
870
866
|
*
|
|
@@ -876,7 +872,7 @@ declare namespace Result {
|
|
|
876
872
|
* ); // Err("Age 15 is below 18")
|
|
877
873
|
* ```
|
|
878
874
|
*/
|
|
879
|
-
|
|
875
|
+
ensure: <A, E2>(predicate: (a: A) => boolean, onFail: (a: A) => E2) => <E1 = never>(data: Result<E1, A>) => Result<E1 | E2, A>;
|
|
880
876
|
/**
|
|
881
877
|
* Transforms both branches of a Result simultaneously.
|
|
882
878
|
* Applies `onErr` to `Err` values and `onOk` to `Ok` values.
|
|
@@ -892,8 +888,8 @@ declare namespace Result {
|
|
|
892
888
|
* ); // Ok(10)
|
|
893
889
|
* ```
|
|
894
890
|
*/
|
|
895
|
-
|
|
896
|
-
}
|
|
891
|
+
bimap: <E1, E2, A, B>(onErr: (e: E1) => E2, onOk: (a: A) => B) => (data: Result<E1, A>) => Result<E2, B>;
|
|
892
|
+
};
|
|
897
893
|
|
|
898
894
|
/**
|
|
899
895
|
* TaskMaybe represents a lazy, infallible async operation that resolves to a `Maybe<A>`.
|
|
@@ -910,7 +906,7 @@ declare namespace Result {
|
|
|
910
906
|
* ```
|
|
911
907
|
*/
|
|
912
908
|
type TaskMaybe<A> = Task<Maybe<A>>;
|
|
913
|
-
declare
|
|
909
|
+
declare const TaskMaybe: {
|
|
914
910
|
/**
|
|
915
911
|
* Wraps a value in a Some inside a Task.
|
|
916
912
|
*
|
|
@@ -920,7 +916,7 @@ declare namespace TaskMaybe {
|
|
|
920
916
|
* const res = await task(); // Some(42)
|
|
921
917
|
* ```
|
|
922
918
|
*/
|
|
923
|
-
|
|
919
|
+
make: {
|
|
924
920
|
/**
|
|
925
921
|
* Creates a Task.Maybe that resolves to Some(value).
|
|
926
922
|
*
|
|
@@ -930,7 +926,7 @@ declare namespace TaskMaybe {
|
|
|
930
926
|
* const res = await task(); // Some(42)
|
|
931
927
|
* ```
|
|
932
928
|
*/
|
|
933
|
-
|
|
929
|
+
some: <A>(value: A) => TaskMaybe<A>;
|
|
934
930
|
/**
|
|
935
931
|
* Creates a Task.Maybe that resolves to None.
|
|
936
932
|
*
|
|
@@ -940,11 +936,11 @@ declare namespace TaskMaybe {
|
|
|
940
936
|
* const res = await task(); // None
|
|
941
937
|
* ```
|
|
942
938
|
*/
|
|
943
|
-
|
|
944
|
-
}
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
939
|
+
none: <A = never>() => TaskMaybe<A>;
|
|
940
|
+
};
|
|
941
|
+
some: <A>(value: A) => TaskMaybe<A>;
|
|
942
|
+
none: <A = never>() => TaskMaybe<A>;
|
|
943
|
+
from: {
|
|
948
944
|
/**
|
|
949
945
|
* Lifts a Maybe into a Task.Maybe.
|
|
950
946
|
*
|
|
@@ -953,7 +949,7 @@ declare namespace TaskMaybe {
|
|
|
953
949
|
* Task.Maybe.from.Maybe(Maybe.make.some(42));
|
|
954
950
|
* ```
|
|
955
951
|
*/
|
|
956
|
-
|
|
952
|
+
Maybe: <A>(option: Maybe<A>) => TaskMaybe<A>;
|
|
957
953
|
/**
|
|
958
954
|
* Creates a Task.Maybe from a nullable value.
|
|
959
955
|
* Returns Some if the value is not null or undefined, None otherwise.
|
|
@@ -964,7 +960,7 @@ declare namespace TaskMaybe {
|
|
|
964
960
|
* Task.Maybe.from.nullable(null); // resolves to None
|
|
965
961
|
* ```
|
|
966
962
|
*/
|
|
967
|
-
|
|
963
|
+
nullable: <A>(value: A | null | undefined) => TaskMaybe<A>;
|
|
968
964
|
/**
|
|
969
965
|
* Creates a Task.Maybe from a Result.
|
|
970
966
|
* Ok becomes Some, Error becomes None (the error value is discarded).
|
|
@@ -975,7 +971,7 @@ declare namespace TaskMaybe {
|
|
|
975
971
|
* Task.Maybe.from.Result(Result.make.err("e")); // resolves to None
|
|
976
972
|
* ```
|
|
977
973
|
*/
|
|
978
|
-
|
|
974
|
+
Result: <E, A>(result: Result<E, A>) => TaskMaybe<A>;
|
|
979
975
|
/**
|
|
980
976
|
* Lifts a Task into a Task.Maybe by wrapping its result in Some.
|
|
981
977
|
*
|
|
@@ -984,8 +980,8 @@ declare namespace TaskMaybe {
|
|
|
984
980
|
* Task.Maybe.from.Task(Task.resolve(42)); // resolves to Some(42)
|
|
985
981
|
* ```
|
|
986
982
|
*/
|
|
987
|
-
|
|
988
|
-
}
|
|
983
|
+
Task: <A>(task: Task<A>) => TaskMaybe<A>;
|
|
984
|
+
};
|
|
989
985
|
/**
|
|
990
986
|
* Creates a Task.Maybe from a Promise-returning function.
|
|
991
987
|
* Returns Some if the promise resolves, None if it rejects.
|
|
@@ -998,11 +994,11 @@ declare namespace TaskMaybe {
|
|
|
998
994
|
* );
|
|
999
995
|
* ```
|
|
1000
996
|
*/
|
|
1001
|
-
|
|
997
|
+
tryCatch: <A>(f: (signal?: AbortSignal) => Thenable<A>) => TaskMaybe<A>;
|
|
1002
998
|
/**
|
|
1003
999
|
* Transforms the value inside a Task.Maybe.
|
|
1004
1000
|
*/
|
|
1005
|
-
|
|
1001
|
+
map: <A, B>(f: (a: A) => B) => (data: TaskMaybe<A>) => TaskMaybe<B>;
|
|
1006
1002
|
/**
|
|
1007
1003
|
* Chains Task.Maybe computations. If the first resolves to Some, passes the
|
|
1008
1004
|
* value to f. If the first resolves to None, propagates None.
|
|
@@ -1015,16 +1011,16 @@ declare namespace TaskMaybe {
|
|
|
1015
1011
|
* )();
|
|
1016
1012
|
* ```
|
|
1017
1013
|
*/
|
|
1018
|
-
|
|
1014
|
+
chain: <A, B>(f: (a: A) => TaskMaybe<B>) => (data: TaskMaybe<A>) => TaskMaybe<B>;
|
|
1019
1015
|
/**
|
|
1020
1016
|
* Applies a function wrapped in a Task.Maybe to a value wrapped in a Task.Maybe.
|
|
1021
1017
|
* Both Tasks run in parallel.
|
|
1022
1018
|
*/
|
|
1023
|
-
|
|
1019
|
+
ap: <A>(arg: TaskMaybe<A>) => <B>(data: TaskMaybe<(a: A) => B>) => TaskMaybe<B>;
|
|
1024
1020
|
/**
|
|
1025
1021
|
* Extracts a value from a Task.Maybe by providing handlers for both cases.
|
|
1026
1022
|
*/
|
|
1027
|
-
|
|
1023
|
+
fold: <A, B>(onNone: () => B, onSome: (a: A) => B) => (data: TaskMaybe<A>) => Task<B>;
|
|
1028
1024
|
/**
|
|
1029
1025
|
* Pattern matches on a Task.Maybe, returning a Task of the result.
|
|
1030
1026
|
*
|
|
@@ -1039,7 +1035,7 @@ declare namespace TaskMaybe {
|
|
|
1039
1035
|
* )();
|
|
1040
1036
|
* ```
|
|
1041
1037
|
*/
|
|
1042
|
-
|
|
1038
|
+
match: <A, B>(cases: {
|
|
1043
1039
|
none: () => B;
|
|
1044
1040
|
some: (a: A) => B;
|
|
1045
1041
|
}) => (data: TaskMaybe<A>) => Task<B>;
|
|
@@ -1047,17 +1043,17 @@ declare namespace TaskMaybe {
|
|
|
1047
1043
|
* Returns the value or a default if the Task.Maybe resolves to None.
|
|
1048
1044
|
* The default can be a different type, widening the result to `Task<A | B>`.
|
|
1049
1045
|
*/
|
|
1050
|
-
|
|
1046
|
+
getOrElse: <B>(defaultValue: () => B) => <A>(data: TaskMaybe<A>) => Task<A | B>;
|
|
1051
1047
|
/**
|
|
1052
1048
|
* Executes a side effect on the value without changing the Task.Maybe.
|
|
1053
1049
|
* Useful for logging or debugging.
|
|
1054
1050
|
*/
|
|
1055
|
-
|
|
1051
|
+
tap: <A>(f: (a: A) => void) => (data: TaskMaybe<A>) => TaskMaybe<A>;
|
|
1056
1052
|
/**
|
|
1057
1053
|
* Filters the value inside a Task.Maybe. Returns None if the predicate fails.
|
|
1058
1054
|
*/
|
|
1059
|
-
|
|
1060
|
-
|
|
1055
|
+
filter: <A>(predicate: (a: A) => boolean) => (data: TaskMaybe<A>) => TaskMaybe<A>;
|
|
1056
|
+
to: {
|
|
1061
1057
|
/**
|
|
1062
1058
|
* Converts a Task.Maybe to a Task.Result, using onNone to produce the error value.
|
|
1063
1059
|
*
|
|
@@ -1069,8 +1065,8 @@ declare namespace TaskMaybe {
|
|
|
1069
1065
|
* );
|
|
1070
1066
|
* ```
|
|
1071
1067
|
*/
|
|
1072
|
-
|
|
1073
|
-
}
|
|
1068
|
+
Result: <E>(onNone: () => E) => <A>(data: TaskMaybe<A>) => Task.Result<E, A>;
|
|
1069
|
+
};
|
|
1074
1070
|
/**
|
|
1075
1071
|
* Lifts a Task.Maybe value into an accumulator object.
|
|
1076
1072
|
*
|
|
@@ -1079,7 +1075,7 @@ declare namespace TaskMaybe {
|
|
|
1079
1075
|
* pipe(Task.Maybe.some(42), Task.Maybe.bindTo("value")); // Task.Maybe({ value: 42 })
|
|
1080
1076
|
* ```
|
|
1081
1077
|
*/
|
|
1082
|
-
|
|
1078
|
+
bindTo: <K extends string>(key: K) => <A>(data: TaskMaybe<A>) => TaskMaybe<{ [P in K]: A; }>;
|
|
1083
1079
|
/**
|
|
1084
1080
|
* Evaluates a new Task.Maybe using the current accumulator and attaches the output to a new key.
|
|
1085
1081
|
*
|
|
@@ -1091,7 +1087,7 @@ declare namespace TaskMaybe {
|
|
|
1091
1087
|
* ); // Task.Maybe({ a: 1, b: 2 })
|
|
1092
1088
|
* ```
|
|
1093
1089
|
*/
|
|
1094
|
-
|
|
1090
|
+
bind: <K extends string, A, B>(key: K, f: (a: A) => TaskMaybe<B>) => (data: TaskMaybe<A>) => TaskMaybe<A & { [P in K]: B; }>;
|
|
1095
1091
|
/**
|
|
1096
1092
|
* Recovers from a None state by providing a fallback Task.Maybe.
|
|
1097
1093
|
*
|
|
@@ -1103,7 +1099,7 @@ declare namespace TaskMaybe {
|
|
|
1103
1099
|
* ); // Task.Maybe(42)
|
|
1104
1100
|
* ```
|
|
1105
1101
|
*/
|
|
1106
|
-
|
|
1102
|
+
recover: <B>(fallback: () => TaskMaybe<B>) => <A>(data: TaskMaybe<A>) => TaskMaybe<A | B>;
|
|
1107
1103
|
/**
|
|
1108
1104
|
* Combines a record of Task.Maybes into a single Task.Maybe of a record.
|
|
1109
1105
|
* Evaluates fields in parallel and returns None if any task resolves to None.
|
|
@@ -1116,7 +1112,7 @@ declare namespace TaskMaybe {
|
|
|
1116
1112
|
* }); // Task.Maybe({ name: "Alice", age: 30 })
|
|
1117
1113
|
* ```
|
|
1118
1114
|
*/
|
|
1119
|
-
|
|
1115
|
+
struct: <R extends Record<string, any>>(fields: { [K in keyof R]: TaskMaybe<R[K]>; }) => TaskMaybe<R>;
|
|
1120
1116
|
/**
|
|
1121
1117
|
* Creates a memoized version of a Task.Maybe. The task is executed at most once on first call,
|
|
1122
1118
|
* and its resolved Maybe is cached for all subsequent calls.
|
|
@@ -1126,8 +1122,8 @@ declare namespace TaskMaybe {
|
|
|
1126
1122
|
* const loadUser = Task.Maybe.memoize(fetchUserMaybeTask);
|
|
1127
1123
|
* ```
|
|
1128
1124
|
*/
|
|
1129
|
-
|
|
1130
|
-
}
|
|
1125
|
+
memoize: <A>(task: TaskMaybe<A>) => TaskMaybe<A>;
|
|
1126
|
+
};
|
|
1131
1127
|
|
|
1132
1128
|
/**
|
|
1133
1129
|
* A Task that can fail with an error of type E or succeed with a value of type A.
|
|
@@ -1143,8 +1139,8 @@ declare namespace TaskMaybe {
|
|
|
1143
1139
|
* ```
|
|
1144
1140
|
*/
|
|
1145
1141
|
type TaskResult<E, A> = Task<Result<E, A>>;
|
|
1146
|
-
declare
|
|
1147
|
-
|
|
1142
|
+
declare const TaskResult: {
|
|
1143
|
+
make: {
|
|
1148
1144
|
/**
|
|
1149
1145
|
* Wraps a value in a successful Task.Result.
|
|
1150
1146
|
*
|
|
@@ -1154,7 +1150,7 @@ declare namespace TaskResult {
|
|
|
1154
1150
|
* const res = await task(); // Ok(42)
|
|
1155
1151
|
* ```
|
|
1156
1152
|
*/
|
|
1157
|
-
|
|
1153
|
+
ok: <E = never, A = unknown>(value: A) => TaskResult<E, A>;
|
|
1158
1154
|
/**
|
|
1159
1155
|
* Creates a failed Task.Result with the given error.
|
|
1160
1156
|
*
|
|
@@ -1164,11 +1160,11 @@ declare namespace TaskResult {
|
|
|
1164
1160
|
* const res = await task(); // Err("failed")
|
|
1165
1161
|
* ```
|
|
1166
1162
|
*/
|
|
1167
|
-
|
|
1168
|
-
}
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1163
|
+
err: <E, A = never>(error: E) => TaskResult<E, A>;
|
|
1164
|
+
};
|
|
1165
|
+
ok: <E = never, A = unknown>(value: A) => TaskResult<E, A>;
|
|
1166
|
+
err: <E, A = never>(error: E) => TaskResult<E, A>;
|
|
1167
|
+
from: {
|
|
1172
1168
|
/**
|
|
1173
1169
|
* Creates a Task.Result from a nullable value.
|
|
1174
1170
|
* Returns Ok if the value is not null or undefined, err from onNull otherwise.
|
|
@@ -1179,7 +1175,7 @@ declare namespace TaskResult {
|
|
|
1179
1175
|
* Task.Result.from.nullable(() => "missing")(null); // resolves to Err("missing")
|
|
1180
1176
|
* ```
|
|
1181
1177
|
*/
|
|
1182
|
-
|
|
1178
|
+
nullable: <E>(onNull: () => E) => <A>(value: A | null | undefined) => TaskResult<E, A>;
|
|
1183
1179
|
/**
|
|
1184
1180
|
* Creates a Task.Result from a Maybe.
|
|
1185
1181
|
* Some becomes Ok, None becomes err from onNone.
|
|
@@ -1190,15 +1186,7 @@ declare namespace TaskResult {
|
|
|
1190
1186
|
* Task.Result.from.Maybe(() => "empty")(Maybe.make.none()); // resolves to Err("empty")
|
|
1191
1187
|
* ```
|
|
1192
1188
|
*/
|
|
1193
|
-
|
|
1194
|
-
/**
|
|
1195
|
-
* Lifts a Result into a Task.Result.
|
|
1196
|
-
*
|
|
1197
|
-
* @example
|
|
1198
|
-
* ```ts
|
|
1199
|
-
* Task.Result.from.Result(Result.make.ok(42)); // resolves to Ok(42)
|
|
1200
|
-
* ```
|
|
1201
|
-
*/
|
|
1189
|
+
Maybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => TaskResult<E, A>;
|
|
1202
1190
|
/**
|
|
1203
1191
|
* Lifts a Result into a Task.Result.
|
|
1204
1192
|
*
|
|
@@ -1207,9 +1195,9 @@ declare namespace TaskResult {
|
|
|
1207
1195
|
* Task.Result.from.Result(Result.make.ok(42)); // resolves to Ok(42)
|
|
1208
1196
|
* ```
|
|
1209
1197
|
*/
|
|
1210
|
-
|
|
1211
|
-
}
|
|
1212
|
-
|
|
1198
|
+
Result: <E, A>(result: Result<E, A>) => TaskResult<E, A>;
|
|
1199
|
+
};
|
|
1200
|
+
to: {
|
|
1213
1201
|
/**
|
|
1214
1202
|
* Converts a Task.Result to a Task.Maybe, dropping the error value on Err.
|
|
1215
1203
|
*
|
|
@@ -1219,8 +1207,8 @@ declare namespace TaskResult {
|
|
|
1219
1207
|
* const taskMaybe = pipe(taskResult, Task.Result.to.Maybe);
|
|
1220
1208
|
* ```
|
|
1221
1209
|
*/
|
|
1222
|
-
|
|
1223
|
-
}
|
|
1210
|
+
Maybe: <E, A>(data: TaskResult<E, A>) => TaskMaybe<A>;
|
|
1211
|
+
};
|
|
1224
1212
|
/**
|
|
1225
1213
|
* Creates a Task.Result from a Promise-returning thunk that may throw or reject.
|
|
1226
1214
|
* Catches any errors and transforms them using the `onError` function into an `Err`.
|
|
@@ -1234,30 +1222,30 @@ declare namespace TaskResult {
|
|
|
1234
1222
|
* );
|
|
1235
1223
|
* ```
|
|
1236
1224
|
*/
|
|
1237
|
-
|
|
1225
|
+
tryCatch: <E, A>(f: (signal?: AbortSignal) => Thenable<A>, options: {
|
|
1238
1226
|
onError: (error: unknown) => E;
|
|
1239
1227
|
}) => TaskResult<E, A>;
|
|
1240
1228
|
/**
|
|
1241
1229
|
* Transforms the success value inside a Task.Result.
|
|
1242
1230
|
*/
|
|
1243
|
-
|
|
1231
|
+
map: <E, A, B>(f: (a: A) => B) => (data: TaskResult<E, A>) => TaskResult<E, B>;
|
|
1244
1232
|
/**
|
|
1245
1233
|
* Transforms the error value inside a Task.Result.
|
|
1246
1234
|
*/
|
|
1247
|
-
|
|
1235
|
+
mapError: <E, F, A>(f: (e: E) => F) => (data: TaskResult<E, A>) => TaskResult<F, A>;
|
|
1248
1236
|
/**
|
|
1249
1237
|
* Chains Task.Result computations. If the first succeeds, passes the value to f.
|
|
1250
1238
|
* If the first fails, propagates the error.
|
|
1251
1239
|
*/
|
|
1252
|
-
|
|
1240
|
+
chain: <E2, A, B>(f: (a: A) => TaskResult<E2, B>) => <E1 = never>(data: TaskResult<E1, A>) => TaskResult<E1 | E2, B>;
|
|
1253
1241
|
/**
|
|
1254
1242
|
* Extracts the value from a Task.Result by providing handlers for both cases.
|
|
1255
1243
|
*/
|
|
1256
|
-
|
|
1244
|
+
fold: <E, A, B>(onErr: (e: E) => B, onOk: (a: A) => B) => (data: TaskResult<E, A>) => Task<B>;
|
|
1257
1245
|
/**
|
|
1258
1246
|
* Pattern matches on a Task.Result, returning a Task of the result.
|
|
1259
1247
|
*/
|
|
1260
|
-
|
|
1248
|
+
match: <E, A, B>(cases: {
|
|
1261
1249
|
err: (e: E) => B;
|
|
1262
1250
|
ok: (a: A) => B;
|
|
1263
1251
|
}) => (data: TaskResult<E, A>) => Task<B>;
|
|
@@ -1265,7 +1253,7 @@ declare namespace TaskResult {
|
|
|
1265
1253
|
* Recovers from an error by providing a fallback Task.Result.
|
|
1266
1254
|
* The fallback can produce a different success type, widening the result to `Task.Result<E, A | B>`.
|
|
1267
1255
|
*/
|
|
1268
|
-
|
|
1256
|
+
recover: <E, B>(fallback: (e: E) => TaskResult<E, B>) => <A>(data: TaskResult<E, A>) => TaskResult<E, A | B>;
|
|
1269
1257
|
/**
|
|
1270
1258
|
* Recovers from an error unless the predicate `isBlocked` returns true for that error.
|
|
1271
1259
|
* The fallback can produce a different success type, widening the result to `Task.Result<E, A | B>`.
|
|
@@ -1281,17 +1269,17 @@ declare namespace TaskResult {
|
|
|
1281
1269
|
* );
|
|
1282
1270
|
* ```
|
|
1283
1271
|
*/
|
|
1284
|
-
|
|
1272
|
+
recoverUnless: <E, B>(isBlocked: (e: E) => boolean, fallback: (e: E) => TaskResult<E, B>) => <A>(data: TaskResult<E, A>) => TaskResult<E, A | B>;
|
|
1285
1273
|
/**
|
|
1286
1274
|
* Returns the success value or a default value if the Task.Result is an error.
|
|
1287
1275
|
* The default can be a different type, widening the result to `Task<A | B>`.
|
|
1288
1276
|
*/
|
|
1289
|
-
|
|
1277
|
+
getOrElse: <B>(defaultValue: () => B) => <E, A>(data: TaskResult<E, A>) => Task<A | B>;
|
|
1290
1278
|
/**
|
|
1291
1279
|
* Executes a side effect on the success value without changing the Task.Result.
|
|
1292
1280
|
* Useful for logging or debugging.
|
|
1293
1281
|
*/
|
|
1294
|
-
|
|
1282
|
+
tap: <E, A>(f: (a: A) => void) => (data: TaskResult<E, A>) => TaskResult<E, A>;
|
|
1295
1283
|
/**
|
|
1296
1284
|
* Executes a side effect on the error value without changing the Task.Result.
|
|
1297
1285
|
* Useful for logging or reporting async errors.
|
|
@@ -1305,12 +1293,12 @@ declare namespace TaskResult {
|
|
|
1305
1293
|
* )
|
|
1306
1294
|
* ```
|
|
1307
1295
|
*/
|
|
1308
|
-
|
|
1296
|
+
tapError: <E, A>(f: (e: E) => void) => (data: TaskResult<E, A>) => TaskResult<E, A>;
|
|
1309
1297
|
/**
|
|
1310
1298
|
* Applies a function wrapped in a Task.Result to a value wrapped in a Task.Result.
|
|
1311
1299
|
* Both Tasks run in parallel.
|
|
1312
1300
|
*/
|
|
1313
|
-
|
|
1301
|
+
ap: <E, A>(arg: TaskResult<E, A>) => <B>(data: TaskResult<E, (a: A) => B>) => TaskResult<E, B>;
|
|
1314
1302
|
/**
|
|
1315
1303
|
* Executes a `Task.Result` with an optional signal, returning `Promise<Result<E, A>>`.
|
|
1316
1304
|
* Use as a terminal step in a `pipe` chain.
|
|
@@ -1326,7 +1314,7 @@ declare namespace TaskResult {
|
|
|
1326
1314
|
* if (Result.is.ok(result)) render(result.value);
|
|
1327
1315
|
* ```
|
|
1328
1316
|
*/
|
|
1329
|
-
|
|
1317
|
+
run: (signal?: AbortSignal) => <E, A>(task: TaskResult<E, A>) => Deferred<Result<E, A>>;
|
|
1330
1318
|
/**
|
|
1331
1319
|
* Converts a Task.Result value into an object containing a single property.
|
|
1332
1320
|
* Initiates the pipeline accumulator record.
|
|
@@ -1336,7 +1324,7 @@ declare namespace TaskResult {
|
|
|
1336
1324
|
* pipe(Task.Result.ok(42), Task.Result.bindTo("value")); // Task.Result({ value: 42 })
|
|
1337
1325
|
* ```
|
|
1338
1326
|
*/
|
|
1339
|
-
|
|
1327
|
+
bindTo: <K extends string>(key: K) => <E, A>(data: TaskResult<E, A>) => TaskResult<E, { [P in K]: A; }>;
|
|
1340
1328
|
/**
|
|
1341
1329
|
* Evaluates a new Task.Result using the current accumulator and attaches the output to a new key.
|
|
1342
1330
|
*
|
|
@@ -1348,7 +1336,7 @@ declare namespace TaskResult {
|
|
|
1348
1336
|
* ); // Task.Result({ a: 1, b: 2 })
|
|
1349
1337
|
* ```
|
|
1350
1338
|
*/
|
|
1351
|
-
|
|
1339
|
+
bind: <K extends string, E, A, B>(key: K, f: (a: A) => TaskResult<E, B>) => (data: TaskResult<E, A>) => TaskResult<E, A & { [P in K]: B; }>;
|
|
1352
1340
|
/**
|
|
1353
1341
|
* Combines a record of Task.Results into a single Task.Result of a record.
|
|
1354
1342
|
* Evaluates all tasks in parallel, forwarding the AbortSignal down to each sub-task.
|
|
@@ -1362,7 +1350,7 @@ declare namespace TaskResult {
|
|
|
1362
1350
|
* }); // Task.Result({ name: "Alice", age: 30 })
|
|
1363
1351
|
* ```
|
|
1364
1352
|
*/
|
|
1365
|
-
|
|
1353
|
+
struct: <E, R extends Record<string, any>>(fields: { [K in keyof R]: TaskResult<E, R[K]>; }) => TaskResult<E, R>;
|
|
1366
1354
|
/**
|
|
1367
1355
|
* Retries a fallible Task.Result according to a RetryPolicy.
|
|
1368
1356
|
* If the task succeeds, returns Ok immediately.
|
|
@@ -1374,7 +1362,7 @@ declare namespace TaskResult {
|
|
|
1374
1362
|
* const retryableFetch = pipe(fetchData, Task.Result.retry(policy));
|
|
1375
1363
|
* ```
|
|
1376
1364
|
*/
|
|
1377
|
-
|
|
1365
|
+
retry: (policy: RetryPolicy) => <E, A>(task: TaskResult<E, A>) => TaskResult<E, A>;
|
|
1378
1366
|
/**
|
|
1379
1367
|
* Creates a memoized version of a Task.Result. The task is executed at most once on first call,
|
|
1380
1368
|
* and its resolved Result is cached for all subsequent calls.
|
|
@@ -1384,7 +1372,7 @@ declare namespace TaskResult {
|
|
|
1384
1372
|
* const loadConfig = Task.Result.memoize(fetchConfigTask);
|
|
1385
1373
|
* ```
|
|
1386
1374
|
*/
|
|
1387
|
-
|
|
1375
|
+
memoize: <E, A>(task: TaskResult<E, A>) => TaskResult<E, A>;
|
|
1388
1376
|
/**
|
|
1389
1377
|
* Times out a fallible task, resolving to `Err(onTimeout())` if the duration elapses
|
|
1390
1378
|
* before the task completes.
|
|
@@ -1397,7 +1385,7 @@ declare namespace TaskResult {
|
|
|
1397
1385
|
* );
|
|
1398
1386
|
* ```
|
|
1399
1387
|
*/
|
|
1400
|
-
|
|
1388
|
+
timeout: <E2>(options: {
|
|
1401
1389
|
duration: Duration;
|
|
1402
1390
|
onTimeout: () => E2;
|
|
1403
1391
|
}) => <E1 = never, A = unknown>(task: TaskResult<E1, A>) => TaskResult<E1 | E2, A>;
|
|
@@ -1411,8 +1399,8 @@ declare namespace TaskResult {
|
|
|
1411
1399
|
* // [Ok(val1), Err(err2), Ok(val3)]
|
|
1412
1400
|
* ```
|
|
1413
1401
|
*/
|
|
1414
|
-
|
|
1415
|
-
}
|
|
1402
|
+
allSettled: <E, A>(tasks: ReadonlyArray<TaskResult<E, A>>) => Task<ReadonlyArray<Result<E, A>>>;
|
|
1403
|
+
};
|
|
1416
1404
|
|
|
1417
1405
|
/**
|
|
1418
1406
|
* A Task that resolves to a Validation — combining async operations with
|
|
@@ -1436,8 +1424,8 @@ declare namespace TaskResult {
|
|
|
1436
1424
|
* ```
|
|
1437
1425
|
*/
|
|
1438
1426
|
type TaskValidation<E, A> = Task<Validation<E, A>>;
|
|
1439
|
-
declare
|
|
1440
|
-
|
|
1427
|
+
declare const TaskValidation: {
|
|
1428
|
+
make: {
|
|
1441
1429
|
/**
|
|
1442
1430
|
* Wraps a value in a passed Task.Validation.
|
|
1443
1431
|
*
|
|
@@ -1447,7 +1435,7 @@ declare namespace TaskValidation {
|
|
|
1447
1435
|
* const res = await task(); // Passed(42)
|
|
1448
1436
|
* ```
|
|
1449
1437
|
*/
|
|
1450
|
-
|
|
1438
|
+
passed: <E = never, A = unknown>(value: A) => TaskValidation<E, A>;
|
|
1451
1439
|
/**
|
|
1452
1440
|
* Creates a failed Task.Validation with a single error.
|
|
1453
1441
|
*
|
|
@@ -1457,7 +1445,7 @@ declare namespace TaskValidation {
|
|
|
1457
1445
|
* const res = await task(); // Failed(["invalid"])
|
|
1458
1446
|
* ```
|
|
1459
1447
|
*/
|
|
1460
|
-
|
|
1448
|
+
failed: <E, A = never>(error: E) => TaskValidation<E, A>;
|
|
1461
1449
|
/**
|
|
1462
1450
|
* Creates a failed Task.Validation from multiple errors.
|
|
1463
1451
|
*
|
|
@@ -1467,12 +1455,12 @@ declare namespace TaskValidation {
|
|
|
1467
1455
|
* const res = await task(); // Failed(["err1", "err2"])
|
|
1468
1456
|
* ```
|
|
1469
1457
|
*/
|
|
1470
|
-
|
|
1471
|
-
}
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1458
|
+
failedAll: <E, A = never>(errors: NonEmptyArr<E>) => TaskValidation<E, A>;
|
|
1459
|
+
};
|
|
1460
|
+
passed: <E = never, A = unknown>(value: A) => TaskValidation<E, A>;
|
|
1461
|
+
failed: <E, A = never>(error: E) => TaskValidation<E, A>;
|
|
1462
|
+
failedAll: <E, A = never>(errors: NonEmptyArr<E>) => TaskValidation<E, A>;
|
|
1463
|
+
from: {
|
|
1476
1464
|
/**
|
|
1477
1465
|
* Lifts a Validation into a Task.Validation.
|
|
1478
1466
|
*
|
|
@@ -1481,7 +1469,7 @@ declare namespace TaskValidation {
|
|
|
1481
1469
|
* Task.Validation.from.Validation(Validation.make.passed(42));
|
|
1482
1470
|
* ```
|
|
1483
1471
|
*/
|
|
1484
|
-
|
|
1472
|
+
Validation: <E, A>(validation: Validation<E, A>) => TaskValidation<E, A>;
|
|
1485
1473
|
/**
|
|
1486
1474
|
* Creates a Task.Validation from a nullable value.
|
|
1487
1475
|
* If the value is null or undefined, returns Failed with the error from onNull.
|
|
@@ -1493,7 +1481,7 @@ declare namespace TaskValidation {
|
|
|
1493
1481
|
* Task.Validation.from.nullable(() => "missing")(null); // resolves to Failed(["missing"])
|
|
1494
1482
|
* ```
|
|
1495
1483
|
*/
|
|
1496
|
-
|
|
1484
|
+
nullable: <E>(onNull: () => E) => <A>(value: A | null | undefined) => TaskValidation<E, A>;
|
|
1497
1485
|
/**
|
|
1498
1486
|
* Creates a Task.Validation from a Maybe.
|
|
1499
1487
|
* Some becomes Passed, None becomes Failed with the error from onNone.
|
|
@@ -1504,7 +1492,7 @@ declare namespace TaskValidation {
|
|
|
1504
1492
|
* Task.Validation.from.Maybe(() => "empty")(Maybe.make.none()); // resolves to Failed(["empty"])
|
|
1505
1493
|
* ```
|
|
1506
1494
|
*/
|
|
1507
|
-
|
|
1495
|
+
Maybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => TaskValidation<E, A>;
|
|
1508
1496
|
/**
|
|
1509
1497
|
* Creates a Task.Validation from a Result.
|
|
1510
1498
|
* Ok becomes Passed, Err(e) becomes Failed([e]).
|
|
@@ -1515,9 +1503,9 @@ declare namespace TaskValidation {
|
|
|
1515
1503
|
* Task.Validation.from.Result(Result.make.err("bad")); // resolves to Failed(["bad"])
|
|
1516
1504
|
* ```
|
|
1517
1505
|
*/
|
|
1518
|
-
|
|
1519
|
-
}
|
|
1520
|
-
|
|
1506
|
+
Result: <E, A>(result: Result<E, A>) => TaskValidation<E, A>;
|
|
1507
|
+
};
|
|
1508
|
+
to: {
|
|
1521
1509
|
/**
|
|
1522
1510
|
* Converts a `Task.Validation` to a `Task.Result`, combining accumulated errors using `combineErrors`.
|
|
1523
1511
|
* `Passed(a)` becomes `Ok(a)`; `Failed(errors)` becomes `Err(combineErrors(errors))`.
|
|
@@ -1527,7 +1515,7 @@ declare namespace TaskValidation {
|
|
|
1527
1515
|
* Task.Validation.to.Result((errors) => errors.join(", "))(validationTask);
|
|
1528
1516
|
* ```
|
|
1529
1517
|
*/
|
|
1530
|
-
|
|
1518
|
+
Result: <E1, E2, A>(combineErrors: (errors: NonEmptyArr<E1>) => E2) => (data: TaskValidation<E1, A>) => TaskResult<E2, A>;
|
|
1531
1519
|
/**
|
|
1532
1520
|
* Converts a `Task.Validation` to a `Task.Maybe`.
|
|
1533
1521
|
* `Passed(a)` becomes `Some(a)`; `Failed(errors)` becomes `None` (errors are discarded).
|
|
@@ -1537,12 +1525,8 @@ declare namespace TaskValidation {
|
|
|
1537
1525
|
* Task.Validation.to.Maybe(validationTask);
|
|
1538
1526
|
* ```
|
|
1539
1527
|
*/
|
|
1540
|
-
|
|
1541
|
-
}
|
|
1542
|
-
/**
|
|
1543
|
-
* Creates a Task.Validation from a Promise-returning function.
|
|
1544
|
-
* Catches any errors and transforms them using the onError function.
|
|
1545
|
-
* The factory optionally receives an `AbortSignal` forwarded from the call site.
|
|
1528
|
+
Maybe: <E, A>(data: TaskValidation<E, A>) => TaskMaybe<A>;
|
|
1529
|
+
};
|
|
1546
1530
|
/**
|
|
1547
1531
|
* Creates a Task.Validation from a Promise-returning thunk that may throw or reject.
|
|
1548
1532
|
* Catches any errors and transforms them using the `onError` function into a Failed validation.
|
|
@@ -1556,13 +1540,13 @@ declare namespace TaskValidation {
|
|
|
1556
1540
|
* );
|
|
1557
1541
|
* ```
|
|
1558
1542
|
*/
|
|
1559
|
-
|
|
1543
|
+
tryCatch: <E, A>(f: (signal?: AbortSignal) => Thenable<A>, options: {
|
|
1560
1544
|
onError: (error: unknown) => E;
|
|
1561
1545
|
}) => TaskValidation<E, A>;
|
|
1562
1546
|
/**
|
|
1563
1547
|
* Transforms the success value inside a Task.Validation.
|
|
1564
1548
|
*/
|
|
1565
|
-
|
|
1549
|
+
map: <E, A, B>(f: (a: A) => B) => (data: TaskValidation<E, A>) => TaskValidation<E, B>;
|
|
1566
1550
|
/**
|
|
1567
1551
|
* Applies a function wrapped in a Task.Validation to a value wrapped in a
|
|
1568
1552
|
* Task.Validation. Both Tasks run in parallel and errors from both sides
|
|
@@ -1577,11 +1561,11 @@ declare namespace TaskValidation {
|
|
|
1577
1561
|
* )();
|
|
1578
1562
|
* ```
|
|
1579
1563
|
*/
|
|
1580
|
-
|
|
1564
|
+
ap: <E, A>(arg: TaskValidation<E, A>) => <B>(data: TaskValidation<E, (a: A) => B>) => TaskValidation<E, B>;
|
|
1581
1565
|
/**
|
|
1582
1566
|
* Extracts a value from a Task.Validation by providing handlers for both cases.
|
|
1583
1567
|
*/
|
|
1584
|
-
|
|
1568
|
+
fold: <E, A, B>(onFailed: (errors: NonEmptyArr<E>) => B, onPassed: (a: A) => B) => (data: TaskValidation<E, A>) => Task<B>;
|
|
1585
1569
|
/**
|
|
1586
1570
|
* Pattern matches on a Task.Validation, returning a Task of the result.
|
|
1587
1571
|
*
|
|
@@ -1596,7 +1580,7 @@ declare namespace TaskValidation {
|
|
|
1596
1580
|
* )();
|
|
1597
1581
|
* ```
|
|
1598
1582
|
*/
|
|
1599
|
-
|
|
1583
|
+
match: <E, A, B>(cases: {
|
|
1600
1584
|
passed: (a: A) => B;
|
|
1601
1585
|
failed: (errors: NonEmptyArr<E>) => B;
|
|
1602
1586
|
}) => (data: TaskValidation<E, A>) => Task<B>;
|
|
@@ -1604,18 +1588,18 @@ declare namespace TaskValidation {
|
|
|
1604
1588
|
* Returns the success value or a default value if the Task.Validation is failed.
|
|
1605
1589
|
* The default can be a different type, widening the result to `Task<A | B>`.
|
|
1606
1590
|
*/
|
|
1607
|
-
|
|
1591
|
+
getOrElse: <B>(defaultValue: () => B) => <E, A>(data: TaskValidation<E, A>) => Task<A | B>;
|
|
1608
1592
|
/**
|
|
1609
1593
|
* Executes a side effect on the success value without changing the Task.Validation.
|
|
1610
1594
|
* Useful for logging or debugging.
|
|
1611
1595
|
*/
|
|
1612
|
-
|
|
1596
|
+
tap: <E, A>(f: (a: A) => void) => (data: TaskValidation<E, A>) => TaskValidation<E, A>;
|
|
1613
1597
|
/**
|
|
1614
1598
|
* Recovers from a Failed state by providing a fallback Task.Validation.
|
|
1615
1599
|
* The fallback receives the accumulated error list so callers can inspect which errors occurred.
|
|
1616
1600
|
* The fallback can produce a different success type, widening the result to `Task.Validation<E, A | B>`.
|
|
1617
1601
|
*/
|
|
1618
|
-
|
|
1602
|
+
recover: <E, B>(fallback: (errors: NonEmptyArr<E>) => TaskValidation<E, B>) => <A>(data: TaskValidation<E, A>) => TaskValidation<E, A | B>;
|
|
1619
1603
|
/**
|
|
1620
1604
|
* Recovers from a Failed state unless the predicate `isBlocked` returns true for the accumulated errors.
|
|
1621
1605
|
* The fallback receives the accumulated errors and can produce a different success type, widening the result to `Task.Validation<E, A | B>`.
|
|
@@ -1631,7 +1615,7 @@ declare namespace TaskValidation {
|
|
|
1631
1615
|
* );
|
|
1632
1616
|
* ```
|
|
1633
1617
|
*/
|
|
1634
|
-
|
|
1618
|
+
recoverUnless: <E, B>(isBlocked: (errors: NonEmptyArr<E>) => boolean, fallback: (errors: NonEmptyArr<E>) => TaskValidation<E, B>) => <A>(data: TaskValidation<E, A>) => TaskValidation<E, A | B>;
|
|
1635
1619
|
/**
|
|
1636
1620
|
* Runs two Task.Validations concurrently and combines their results into a tuple.
|
|
1637
1621
|
* If both are Passed, returns Passed with both values. If either fails, accumulates
|
|
@@ -1645,7 +1629,7 @@ declare namespace TaskValidation {
|
|
|
1645
1629
|
* )(); // Passed(["Alice", 30]) or Failed([...errors])
|
|
1646
1630
|
* ```
|
|
1647
1631
|
*/
|
|
1648
|
-
|
|
1632
|
+
product: <E, A, B>(first: TaskValidation<E, A>, second: TaskValidation<E, B>) => TaskValidation<E, readonly [A, B]>;
|
|
1649
1633
|
/**
|
|
1650
1634
|
* Runs all Task.Validations concurrently and collects results.
|
|
1651
1635
|
* If all are Passed, returns Passed with all values as an array.
|
|
@@ -1660,7 +1644,7 @@ declare namespace TaskValidation {
|
|
|
1660
1644
|
* ])(); // Passed([name, email, age]) or Failed([...all errors])
|
|
1661
1645
|
* ```
|
|
1662
1646
|
*/
|
|
1663
|
-
|
|
1647
|
+
productAll: <E, A>(data: NonEmptyArr<TaskValidation<E, A>>) => TaskValidation<E, readonly A[]>;
|
|
1664
1648
|
/**
|
|
1665
1649
|
* Transforms all accumulated errors inside a Task.Validation.
|
|
1666
1650
|
*
|
|
@@ -1672,7 +1656,7 @@ declare namespace TaskValidation {
|
|
|
1672
1656
|
* ); // Task.Validation(Failed(["OOPS"]))
|
|
1673
1657
|
* ```
|
|
1674
1658
|
*/
|
|
1675
|
-
|
|
1659
|
+
mapError: <E, F, A>(f: (e: E) => F) => (data: TaskValidation<E, A>) => TaskValidation<F, A>;
|
|
1676
1660
|
/**
|
|
1677
1661
|
* Executes a side effect on the accumulated errors without changing the Task.Validation.
|
|
1678
1662
|
*
|
|
@@ -1684,7 +1668,7 @@ declare namespace TaskValidation {
|
|
|
1684
1668
|
* );
|
|
1685
1669
|
* ```
|
|
1686
1670
|
*/
|
|
1687
|
-
|
|
1671
|
+
tapError: <E, A>(f: (errors: NonEmptyArr<E>) => void) => (data: TaskValidation<E, A>) => TaskValidation<E, A>;
|
|
1688
1672
|
/**
|
|
1689
1673
|
* Combines a record of Task.Validations into a single Task.Validation of a record.
|
|
1690
1674
|
* Evaluates fields in parallel and accumulates all validation errors.
|
|
@@ -1697,7 +1681,7 @@ declare namespace TaskValidation {
|
|
|
1697
1681
|
* }); // Task.Validation({ name: "Alice", age: 30 })
|
|
1698
1682
|
* ```
|
|
1699
1683
|
*/
|
|
1700
|
-
|
|
1684
|
+
struct: <E, R extends Record<string, any>>(fields: { [K in keyof R]: TaskValidation<E, R[K]>; }) => TaskValidation<E, R>;
|
|
1701
1685
|
/**
|
|
1702
1686
|
* Creates a memoized version of a Task.Validation. The task is executed at most once on first call,
|
|
1703
1687
|
* and its resolved Validation is cached for all subsequent calls.
|
|
@@ -1707,8 +1691,8 @@ declare namespace TaskValidation {
|
|
|
1707
1691
|
* const validate = Task.Validation.memoize(validateFormTask);
|
|
1708
1692
|
* ```
|
|
1709
1693
|
*/
|
|
1710
|
-
|
|
1711
|
-
}
|
|
1694
|
+
memoize: <E, A>(task: TaskValidation<E, A>) => TaskValidation<E, A>;
|
|
1695
|
+
};
|
|
1712
1696
|
|
|
1713
1697
|
/**
|
|
1714
1698
|
* A lazy async computation that always resolves.
|
|
@@ -1753,7 +1737,7 @@ declare namespace TaskValidation {
|
|
|
1753
1737
|
* ```
|
|
1754
1738
|
*/
|
|
1755
1739
|
type Task<A> = (signal?: AbortSignal) => Deferred<A>;
|
|
1756
|
-
declare
|
|
1740
|
+
declare const Task: {
|
|
1757
1741
|
/**
|
|
1758
1742
|
* Creates a Task that immediately resolves to the given value.
|
|
1759
1743
|
*
|
|
@@ -1763,8 +1747,8 @@ declare namespace Task {
|
|
|
1763
1747
|
* const value = await task(); // 42
|
|
1764
1748
|
* ```
|
|
1765
1749
|
*/
|
|
1766
|
-
|
|
1767
|
-
|
|
1750
|
+
resolve: <A>(value: A) => Task<A>;
|
|
1751
|
+
from: {
|
|
1768
1752
|
/**
|
|
1769
1753
|
* Creates a Task from a lazy synchronous thunk.
|
|
1770
1754
|
* Unlike `Task.resolve(f())`, `from.sync` does not evaluate `f` until the Task is called.
|
|
@@ -1775,8 +1759,8 @@ declare namespace Task {
|
|
|
1775
1759
|
* const ts = await t(); // called here, every time
|
|
1776
1760
|
* ```
|
|
1777
1761
|
*/
|
|
1778
|
-
|
|
1779
|
-
}
|
|
1762
|
+
sync: <A>(f: () => A) => Task<A>;
|
|
1763
|
+
};
|
|
1780
1764
|
/**
|
|
1781
1765
|
* Wraps a Promise-returning thunk that may throw or reject,
|
|
1782
1766
|
* trapping errors with a fallback function and returning a guaranteed `Task<A>`.
|
|
@@ -1789,7 +1773,7 @@ declare namespace Task {
|
|
|
1789
1773
|
* );
|
|
1790
1774
|
* ```
|
|
1791
1775
|
*/
|
|
1792
|
-
|
|
1776
|
+
tryCatch: <A>(f: (signal?: AbortSignal) => globalThis.Promise<A>, options: {
|
|
1793
1777
|
onError: (error: unknown) => A;
|
|
1794
1778
|
}) => Task<A>;
|
|
1795
1779
|
/**
|
|
@@ -1803,7 +1787,7 @@ declare namespace Task {
|
|
|
1803
1787
|
* )(); // Deferred<10>
|
|
1804
1788
|
* ```
|
|
1805
1789
|
*/
|
|
1806
|
-
|
|
1790
|
+
map: <A, B>(f: (a: A) => B) => (data: Task<A>) => Task<B>;
|
|
1807
1791
|
/**
|
|
1808
1792
|
* Chains Task computations. Passes the resolved value of the first Task to f.
|
|
1809
1793
|
*
|
|
@@ -1819,7 +1803,7 @@ declare namespace Task {
|
|
|
1819
1803
|
* )(); // Deferred<Preferences>
|
|
1820
1804
|
* ```
|
|
1821
1805
|
*/
|
|
1822
|
-
|
|
1806
|
+
chain: <A, B>(f: (a: A) => Task<B>) => (data: Task<A>) => Task<B>;
|
|
1823
1807
|
/**
|
|
1824
1808
|
* Applies a function wrapped in a Task to a value wrapped in a Task.
|
|
1825
1809
|
* Both Tasks run in parallel.
|
|
@@ -1834,7 +1818,7 @@ declare namespace Task {
|
|
|
1834
1818
|
* )(); // Deferred<8>
|
|
1835
1819
|
* ```
|
|
1836
1820
|
*/
|
|
1837
|
-
|
|
1821
|
+
ap: <A>(arg: Task<A>) => <B>(data: Task<(a: A) => B>) => Task<B>;
|
|
1838
1822
|
/**
|
|
1839
1823
|
* Executes a side effect on the value without changing the Task.
|
|
1840
1824
|
* Useful for logging or debugging.
|
|
@@ -1848,7 +1832,7 @@ declare namespace Task {
|
|
|
1848
1832
|
* );
|
|
1849
1833
|
* ```
|
|
1850
1834
|
*/
|
|
1851
|
-
|
|
1835
|
+
tap: <A>(f: (a: A) => void) => (data: Task<A>) => Task<A>;
|
|
1852
1836
|
/**
|
|
1853
1837
|
* Runs multiple Tasks in parallel and collects their results.
|
|
1854
1838
|
*
|
|
@@ -1858,7 +1842,7 @@ declare namespace Task {
|
|
|
1858
1842
|
* // Deferred<[Config, string, Theme]>
|
|
1859
1843
|
* ```
|
|
1860
1844
|
*/
|
|
1861
|
-
|
|
1845
|
+
all: <T extends readonly Task<unknown>[]>(tasks: T) => Task<{ [K in keyof T]: T[K] extends Task<infer A> ? A : never; }>;
|
|
1862
1846
|
/**
|
|
1863
1847
|
* Delays the execution of a Task by the specified duration.
|
|
1864
1848
|
* Useful for debouncing or rate limiting.
|
|
@@ -1871,7 +1855,7 @@ declare namespace Task {
|
|
|
1871
1855
|
* )(); // Resolves after 1 second
|
|
1872
1856
|
* ```
|
|
1873
1857
|
*/
|
|
1874
|
-
|
|
1858
|
+
delay: (duration: Duration) => <A>(data: Task<A>) => Task<A>;
|
|
1875
1859
|
/**
|
|
1876
1860
|
* Runs a Task a fixed number of times sequentially, collecting all results into an array.
|
|
1877
1861
|
* An optional delay duration can be inserted between runs.
|
|
@@ -1884,7 +1868,7 @@ declare namespace Task {
|
|
|
1884
1868
|
* )(); // Task<Reading[]> — 5 readings, one per second
|
|
1885
1869
|
* ```
|
|
1886
1870
|
*/
|
|
1887
|
-
|
|
1871
|
+
repeat: (options: {
|
|
1888
1872
|
times: number;
|
|
1889
1873
|
delay?: Duration;
|
|
1890
1874
|
}) => <A>(task: Task<A>) => Task<readonly A[]>;
|
|
@@ -1902,7 +1886,7 @@ declare namespace Task {
|
|
|
1902
1886
|
* )(); // polls every 500ms until status is "ready"
|
|
1903
1887
|
* ```
|
|
1904
1888
|
*/
|
|
1905
|
-
|
|
1889
|
+
repeatUntil: <A>(options: {
|
|
1906
1890
|
when: (a: A) => boolean;
|
|
1907
1891
|
delay?: Duration;
|
|
1908
1892
|
maxAttempts?: number;
|
|
@@ -1920,7 +1904,7 @@ declare namespace Task {
|
|
|
1920
1904
|
* await Task.race([fast, slow])(); // "fast"
|
|
1921
1905
|
* ```
|
|
1922
1906
|
*/
|
|
1923
|
-
|
|
1907
|
+
race: <A>(tasks: ReadonlyArray<Task<A>>) => Task<A>;
|
|
1924
1908
|
/**
|
|
1925
1909
|
* Runs an array of Tasks concurrently and collects their results in an array.
|
|
1926
1910
|
* Forward-propagates the call site's AbortSignal to all subtasks concurrently.
|
|
@@ -1931,7 +1915,7 @@ declare namespace Task {
|
|
|
1931
1915
|
* // Deferred<[Config, string, Theme]>
|
|
1932
1916
|
* ```
|
|
1933
1917
|
*/
|
|
1934
|
-
|
|
1918
|
+
sequence: <A>(tasks: ReadonlyArray<Task<A>>) => Task<ReadonlyArray<A>>;
|
|
1935
1919
|
/**
|
|
1936
1920
|
* Runs an array of Tasks one at a time in order, collecting all results.
|
|
1937
1921
|
* Each Task starts only after the previous one resolves.
|
|
@@ -1945,7 +1929,7 @@ declare namespace Task {
|
|
|
1945
1929
|
* // log = [1, 2, 3] — tasks ran in order
|
|
1946
1930
|
* ```
|
|
1947
1931
|
*/
|
|
1948
|
-
|
|
1932
|
+
sequential: <A>(tasks: ReadonlyArray<Task<A>>) => Task<ReadonlyArray<A>>;
|
|
1949
1933
|
/**
|
|
1950
1934
|
* Converts a `Task<A>` into a `Task<Result<E, A>>`, resolving to `Err` if the
|
|
1951
1935
|
* Task does not complete within the given duration. The inner Task receives an
|
|
@@ -1961,7 +1945,7 @@ declare namespace Task {
|
|
|
1961
1945
|
* );
|
|
1962
1946
|
* ```
|
|
1963
1947
|
*/
|
|
1964
|
-
|
|
1948
|
+
timeout: <E>(options: {
|
|
1965
1949
|
duration: Duration;
|
|
1966
1950
|
onTimeout: () => E;
|
|
1967
1951
|
}) => <A>(task: Task<A>) => Task<Result<E, A>>;
|
|
@@ -1986,7 +1970,7 @@ declare namespace Task {
|
|
|
1986
1970
|
* await poll();
|
|
1987
1971
|
* ```
|
|
1988
1972
|
*/
|
|
1989
|
-
|
|
1973
|
+
abortable: <A>(factory: (signal: AbortSignal) => Thenable<A>) => {
|
|
1990
1974
|
task: Task<A>;
|
|
1991
1975
|
abort: () => void;
|
|
1992
1976
|
};
|
|
@@ -2002,7 +1986,7 @@ declare namespace Task {
|
|
|
2002
1986
|
* );
|
|
2003
1987
|
* ```
|
|
2004
1988
|
*/
|
|
2005
|
-
|
|
1989
|
+
run: (signal?: AbortSignal) => <A>(task: Task<A>) => Deferred<A>;
|
|
2006
1990
|
/**
|
|
2007
1991
|
* Converts a Task value into an object containing a single property.
|
|
2008
1992
|
* Initiates the pipeline accumulator record.
|
|
@@ -2012,7 +1996,7 @@ declare namespace Task {
|
|
|
2012
1996
|
* pipe(Task.resolve(42), Task.bindTo("value")); // Task({ value: 42 })
|
|
2013
1997
|
* ```
|
|
2014
1998
|
*/
|
|
2015
|
-
|
|
1999
|
+
bindTo: <K extends string>(key: K) => <A>(data: Task<A>) => Task<{ [P in K]: A; }>;
|
|
2016
2000
|
/**
|
|
2017
2001
|
* Evaluates a new Task using the current accumulator and attaches the output to a new key.
|
|
2018
2002
|
*
|
|
@@ -2024,7 +2008,7 @@ declare namespace Task {
|
|
|
2024
2008
|
* ); // Task({ a: 1, b: 2 })
|
|
2025
2009
|
* ```
|
|
2026
2010
|
*/
|
|
2027
|
-
|
|
2011
|
+
bind: <K extends string, A, B>(key: K, f: (a: A) => Task<B>) => (data: Task<A>) => Task<A & { [P in K]: B; }>;
|
|
2028
2012
|
/**
|
|
2029
2013
|
* Creates a memoized version of a Task. The task is executed at most once on first call,
|
|
2030
2014
|
* and its resolved value is cached for all subsequent calls.
|
|
@@ -2036,7 +2020,7 @@ declare namespace Task {
|
|
|
2036
2020
|
* const token2 = await loadToken(); // returns cached token immediately
|
|
2037
2021
|
* ```
|
|
2038
2022
|
*/
|
|
2039
|
-
|
|
2023
|
+
memoize: <A>(task: Task<A>) => Task<A>;
|
|
2040
2024
|
/**
|
|
2041
2025
|
* Monitors progress of a Task by calling `onProgress(0)` before execution and `onProgress(1)` upon completion.
|
|
2042
2026
|
*
|
|
@@ -2048,10 +2032,7 @@ declare namespace Task {
|
|
|
2048
2032
|
* );
|
|
2049
2033
|
* ```
|
|
2050
2034
|
*/
|
|
2051
|
-
|
|
2052
|
-
type LabeledTask<L extends string, A> = Task<A> & {
|
|
2053
|
-
readonly label: L;
|
|
2054
|
-
};
|
|
2035
|
+
withProgress: <A>(onProgress: (ratio: number) => void) => (task: Task<A>) => Task<A>;
|
|
2055
2036
|
/**
|
|
2056
2037
|
* Attaches a read-only `.label` property to a Task, preserving the literal string generic type for IDE tooltips.
|
|
2057
2038
|
*
|
|
@@ -2061,17 +2042,141 @@ declare namespace Task {
|
|
|
2061
2042
|
* console.log(labeledTask.label); // "readUser"
|
|
2062
2043
|
* ```
|
|
2063
2044
|
*/
|
|
2064
|
-
|
|
2045
|
+
withLabel: <L extends string>(label: L) => <A>(task: Task<A>) => Task.LabeledTask<L, A>;
|
|
2046
|
+
Maybe: {
|
|
2047
|
+
make: {
|
|
2048
|
+
some: <A>(value: A) => TaskMaybe<A>;
|
|
2049
|
+
none: <A = never>() => TaskMaybe<A>;
|
|
2050
|
+
};
|
|
2051
|
+
some: <A>(value: A) => TaskMaybe<A>;
|
|
2052
|
+
none: <A = never>() => TaskMaybe<A>;
|
|
2053
|
+
from: {
|
|
2054
|
+
Maybe: <A>(option: Maybe<A>) => TaskMaybe<A>;
|
|
2055
|
+
nullable: <A>(value: A | null | undefined) => TaskMaybe<A>;
|
|
2056
|
+
Result: <E, A>(result: Result<E, A>) => TaskMaybe<A>;
|
|
2057
|
+
Task: <A>(task: Task<A>) => TaskMaybe<A>;
|
|
2058
|
+
};
|
|
2059
|
+
tryCatch: <A>(f: (signal?: AbortSignal) => Thenable<A>) => TaskMaybe<A>;
|
|
2060
|
+
map: <A, B>(f: (a: A) => B) => (data: TaskMaybe<A>) => TaskMaybe<B>;
|
|
2061
|
+
chain: <A, B>(f: (a: A) => TaskMaybe<B>) => (data: TaskMaybe<A>) => TaskMaybe<B>;
|
|
2062
|
+
ap: <A>(arg: TaskMaybe<A>) => <// Deferred<10>
|
|
2063
|
+
B>(data: TaskMaybe<(a: A) => B>) => TaskMaybe<B>;
|
|
2064
|
+
fold: <A, B>(onNone: () => B, onSome: (a: A) => B) => (data: TaskMaybe<A>) => Task<B>;
|
|
2065
|
+
match: <A, B>(cases: {
|
|
2066
|
+
none: () => B;
|
|
2067
|
+
some: (a: A) => B;
|
|
2068
|
+
}) => (data: TaskMaybe<A>) => Task<B>;
|
|
2069
|
+
getOrElse: <B>(defaultValue: () => B) => <A>(data: TaskMaybe<A>) => Task<A | B>;
|
|
2070
|
+
tap: <A>(f: (a: A) => void) => (data: TaskMaybe<A>) => TaskMaybe<A>;
|
|
2071
|
+
filter: <A>(predicate: (a: A) => boolean) => (data: TaskMaybe<A>) => TaskMaybe<A>;
|
|
2072
|
+
to: {
|
|
2073
|
+
Result: <E>(onNone: () => E) => <A>(data: TaskMaybe<A>) => Task.Result<E, A>;
|
|
2074
|
+
};
|
|
2075
|
+
bindTo: <K extends string>(key: K) => <A>(data: TaskMaybe<A>) => TaskMaybe<{ [P in K]: A; }>;
|
|
2076
|
+
bind: <K extends string, A, B>(key: K, f: (a: A) => TaskMaybe<B>) => (data: TaskMaybe<A>) => TaskMaybe<A & { [P in K]: B; }>;
|
|
2077
|
+
recover: <B>(fallback: () => TaskMaybe<B>) => <A>(data: TaskMaybe<A>) => TaskMaybe<A | B>;
|
|
2078
|
+
struct: <R extends Record<string, any>>(fields: { [K in keyof R]: TaskMaybe<R[K]>; }) => TaskMaybe<R>;
|
|
2079
|
+
memoize: <A>(task: TaskMaybe<A>) => TaskMaybe<A>;
|
|
2080
|
+
};
|
|
2081
|
+
Result: {
|
|
2082
|
+
make: {
|
|
2083
|
+
ok: <E = never, A = unknown>(value: A) => TaskResult<E, A>;
|
|
2084
|
+
err: <E, A = never>(error: E) => TaskResult<E, A>;
|
|
2085
|
+
};
|
|
2086
|
+
ok: <E = never, A = unknown>(value: A) => TaskResult<E, A>;
|
|
2087
|
+
err: <E, A = never>(error: E) => TaskResult<E, A>;
|
|
2088
|
+
from: {
|
|
2089
|
+
nullable: <E>(onNull: () => E) => <A>(value: A | null | undefined) => TaskResult<E, A>;
|
|
2090
|
+
Maybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => TaskResult<E, A>;
|
|
2091
|
+
Result: <E, A>(result: Result<E, A>) => TaskResult<E, A>;
|
|
2092
|
+
};
|
|
2093
|
+
to: {
|
|
2094
|
+
Maybe: <E, A>(data: TaskResult<E, A>) => TaskMaybe<A>;
|
|
2095
|
+
};
|
|
2096
|
+
tryCatch: <E, A>(f: (signal?: AbortSignal) => Thenable<A>, options: {
|
|
2097
|
+
onError: (error: unknown) => E;
|
|
2098
|
+
}) => TaskResult<E, A>;
|
|
2099
|
+
map: <E, A, B>(f: (a: A) => B) => (data: TaskResult<E, A>) => TaskResult<E, B>;
|
|
2100
|
+
mapError: <E, F, A>(f: (e: E) => F) => (data: TaskResult<E, A>) => TaskResult<F, A>;
|
|
2101
|
+
chain: <E2, A, B>(f: (a: A) => TaskResult<E2, B>) => <E1 = never>(data: TaskResult<E1, A>) => TaskResult<E1 | E2, B>;
|
|
2102
|
+
fold: <E, A, B>(onErr: (e: E) => B, onOk: (a: A) => B) => (data: TaskResult<E, A>) => Task<B>;
|
|
2103
|
+
match: <E, A, B>(cases: {
|
|
2104
|
+
err: (e: E) => B;
|
|
2105
|
+
ok: (a: A) => B;
|
|
2106
|
+
}) => (data: TaskResult<E, A>) => Task<B>;
|
|
2107
|
+
recover: <E, B>(fallback: (e: E) => TaskResult<E, B>) => <A>(data: TaskResult<E, A>) => TaskResult<E, A | B>;
|
|
2108
|
+
recoverUnless: <E, B>(isBlocked: (e: E) => boolean, fallback: (e: E) => TaskResult<E, B>) => <A>(data: TaskResult<E, A>) => TaskResult<E, A | B>;
|
|
2109
|
+
getOrElse: <B>(defaultValue: () => B) => <E, A>(// oxlint-disable-next-line prefer-const
|
|
2110
|
+
data: TaskResult<E, A>) => Task<A | B>;
|
|
2111
|
+
tap: <E, A>(f: (a: A) => void) => (data: TaskResult<E, A>) => TaskResult<E, A>;
|
|
2112
|
+
tapError: <E, A>(f: (e: E) => void) => (data: TaskResult<E, A>) => TaskResult<E, A>;
|
|
2113
|
+
ap: <E, A>(arg: TaskResult<E, A>) => <B>(data: TaskResult<E, (a: A) => B>) => TaskResult<E, B>;
|
|
2114
|
+
run: (signal?: AbortSignal) => <E, A>(task: TaskResult<E, A>) => Deferred<Result<E, A>>;
|
|
2115
|
+
bindTo: <K extends string>(key: K) => <E, A>(data: TaskResult<E, A>) => TaskResult<E, { [P in K]: A; }>;
|
|
2116
|
+
bind: <K extends string, E, A, B>(key: K, f: (a: A) => TaskResult<E, B>) => (data: TaskResult<E, A>) => TaskResult<E, A & { [P in K]: B; }>;
|
|
2117
|
+
struct: <E, R extends Record<string, any>>(fields: { [K in keyof R]: TaskResult<E, R[K]>; }) => TaskResult<E, R>;
|
|
2118
|
+
retry: (policy: RetryPolicy) => <E, A>(task: TaskResult<E, A>) => TaskResult<E, A>;
|
|
2119
|
+
memoize: <E, A>(task: TaskResult<E, A>) => TaskResult<E, A>;
|
|
2120
|
+
timeout: <E2>(options: {
|
|
2121
|
+
duration: Duration;
|
|
2122
|
+
onTimeout: () => E2;
|
|
2123
|
+
}) => <E1 = never, A = unknown>(task: TaskResult<E1, A>) => TaskResult<E1 | E2, A>;
|
|
2124
|
+
allSettled: <E, A>(tasks: ReadonlyArray<TaskResult<E, A>>) => Task<ReadonlyArray<Result<E, A>>>;
|
|
2125
|
+
};
|
|
2126
|
+
Validation: {
|
|
2127
|
+
make: {
|
|
2128
|
+
passed: <E = never, A = unknown>(value: A) => TaskValidation<E, A>;
|
|
2129
|
+
failed: <E, A = never>(error: E) => TaskValidation<E, A>;
|
|
2130
|
+
failedAll: <E, A = never>(errors: NonEmptyArr<E>) => TaskValidation<E, A>;
|
|
2131
|
+
};
|
|
2132
|
+
passed: <E = never, A = unknown>(value: A) => TaskValidation<E, A>;
|
|
2133
|
+
failed: <E, A = never>(error: E) => TaskValidation<E, A>;
|
|
2134
|
+
failedAll: <E, A = never>(errors: NonEmptyArr<E>) => TaskValidation<E, A>;
|
|
2135
|
+
from: {
|
|
2136
|
+
Validation: <E, A>(validation: Validation<E, A>) => TaskValidation<E, A>;
|
|
2137
|
+
nullable: <E>(onNull: () => E) => <A>(value: A | null | undefined) => TaskValidation<E, A>;
|
|
2138
|
+
Maybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => TaskValidation<E, A>;
|
|
2139
|
+
Result: <E, A>(result: Result<E, A>) => TaskValidation<E, A>;
|
|
2140
|
+
};
|
|
2141
|
+
to: {
|
|
2142
|
+
Result: <E1, E2, A>(combineErrors: (errors: NonEmptyArr<E1>) => E2) => (data: TaskValidation<E1, A>) => TaskResult<E2, A>;
|
|
2143
|
+
Maybe: <E, A>(data: TaskValidation<E, A>) => TaskMaybe<A>;
|
|
2144
|
+
};
|
|
2145
|
+
tryCatch: <E, A>(f: (signal?: AbortSignal) => Thenable<A>, options: {
|
|
2146
|
+
onError: (error: unknown) => E;
|
|
2147
|
+
}) => TaskValidation<E, A>;
|
|
2148
|
+
map: <E, A, B>(f: (a: A) => B) => (data: TaskValidation<E, A>) => TaskValidation<E, B>;
|
|
2149
|
+
ap: <E, A>(arg: TaskValidation<E, A>) => <B>(data: TaskValidation<E, (a: A) => B>) => TaskValidation<E, B>;
|
|
2150
|
+
fold: <E, A, B>(onFailed: (errors: NonEmptyArr<E>) => B, onPassed: (a: A) => B) => (data: TaskValidation<E, A>) => Task<B>;
|
|
2151
|
+
match: <E, A, B>(cases: {
|
|
2152
|
+
passed: (a: A) => B;
|
|
2153
|
+
failed: (errors: NonEmptyArr<E>) => B;
|
|
2154
|
+
}) => (data: TaskValidation<E, A>) => Task<B>;
|
|
2155
|
+
getOrElse: <B>(defaultValue: () => B) => <E, A>(data: TaskValidation<E, A>) => Task<A | B>;
|
|
2156
|
+
tap: <E, A>(f: (a: A) => void) => (data: TaskValidation<E, A>) => TaskValidation<E, A>;
|
|
2157
|
+
recover: <E, B>(fallback: (errors: NonEmptyArr<E>) => TaskValidation<E, B>) => <A>(data: TaskValidation<E, A>) => TaskValidation<E, A | B>;
|
|
2158
|
+
recoverUnless: <E, B>(isBlocked: (errors: NonEmptyArr<E>) => boolean, fallback: (errors: NonEmptyArr<E>) => TaskValidation<E, B>) => <A>(data: TaskValidation<E, A>) => TaskValidation<E, A | B>;
|
|
2159
|
+
product: <E, A, B>(first: TaskValidation<E, A>, second: TaskValidation<E, B>) => TaskValidation<E, readonly [A, B]>;
|
|
2160
|
+
productAll: <E, A>(data: NonEmptyArr<TaskValidation<E, A>>) => TaskValidation<E, readonly A[]>;
|
|
2161
|
+
mapError: <E, F, A>(f: (e: E) => F) => (data: TaskValidation<E, A>) => TaskValidation<F, A>;
|
|
2162
|
+
tapError: <E, A>(f: (errors: NonEmptyArr<E>) => void) => (data: TaskValidation<E, A>) => TaskValidation<E, A>;
|
|
2163
|
+
struct: <E, R extends Record<string, any>>(fields: { [K in keyof R]: TaskValidation<E, R[K]>; }) => TaskValidation<E, R>;
|
|
2164
|
+
memoize: <E, A>(task: TaskValidation<E, A>) => TaskValidation<E, A>;
|
|
2165
|
+
};
|
|
2166
|
+
};
|
|
2167
|
+
declare namespace Task {
|
|
2168
|
+
type LabeledTask<L extends string, A> = Task<A> & {
|
|
2169
|
+
readonly label: L;
|
|
2170
|
+
};
|
|
2065
2171
|
type Maybe<A> = TaskMaybe<A>;
|
|
2066
|
-
const Maybe: typeof TaskMaybe;
|
|
2067
2172
|
type Result<E, A> = TaskResult<E, A>;
|
|
2068
|
-
const Result: typeof TaskResult;
|
|
2069
2173
|
type Validation<E, A> = TaskValidation<E, A>;
|
|
2070
|
-
const Validation: typeof TaskValidation;
|
|
2071
2174
|
}
|
|
2072
2175
|
|
|
2073
2176
|
type Passed<A> = WithKind<"Passed"> & WithValue<A>;
|
|
2074
2177
|
type Failed<E> = WithKind<"Failed"> & WithErrors<E>;
|
|
2178
|
+
declare function toResult<E1, E2, A>(combineErrors: (errors: NonEmptyArr<E1>) => E2): (val: Validation<E1, A>) => Result<E2, A>;
|
|
2179
|
+
declare function toResult<E, A>(data: Validation<E, A>): Result<NonEmptyArr<E>, A>;
|
|
2075
2180
|
/**
|
|
2076
2181
|
* Validation represents a value that is either passed with a success value,
|
|
2077
2182
|
* or failed with accumulated errors.
|
|
@@ -2098,8 +2203,8 @@ type Failed<E> = WithKind<"Failed"> & WithErrors<E>;
|
|
|
2098
2203
|
* ```
|
|
2099
2204
|
*/
|
|
2100
2205
|
type Validation<E, A> = Passed<A> | Failed<E>;
|
|
2101
|
-
declare
|
|
2102
|
-
|
|
2206
|
+
declare const Validation: {
|
|
2207
|
+
make: {
|
|
2103
2208
|
/**
|
|
2104
2209
|
* Wraps a value in a passed Validation.
|
|
2105
2210
|
*
|
|
@@ -2108,7 +2213,7 @@ declare namespace Validation {
|
|
|
2108
2213
|
* Validation.make.passed(42); // Passed(42)
|
|
2109
2214
|
* ```
|
|
2110
2215
|
*/
|
|
2111
|
-
|
|
2216
|
+
passed: <E, A>(value: A) => Validation<E, A>;
|
|
2112
2217
|
/**
|
|
2113
2218
|
* Creates a failed Validation from a single error.
|
|
2114
2219
|
*
|
|
@@ -2117,7 +2222,7 @@ declare namespace Validation {
|
|
|
2117
2222
|
* Validation.make.failed("Invalid input");
|
|
2118
2223
|
* ```
|
|
2119
2224
|
*/
|
|
2120
|
-
|
|
2225
|
+
failed: <E>(error: E) => Failed<E>;
|
|
2121
2226
|
/**
|
|
2122
2227
|
* Creates a failed Validation from multiple errors.
|
|
2123
2228
|
*
|
|
@@ -2126,9 +2231,9 @@ declare namespace Validation {
|
|
|
2126
2231
|
* Validation.make.failedAll(["Invalid input"]);
|
|
2127
2232
|
* ```
|
|
2128
2233
|
*/
|
|
2129
|
-
|
|
2130
|
-
}
|
|
2131
|
-
|
|
2234
|
+
failedAll: <E>(errors: NonEmptyArr<E>) => Failed<E>;
|
|
2235
|
+
};
|
|
2236
|
+
is: {
|
|
2132
2237
|
/**
|
|
2133
2238
|
* Type guard that checks if a Validation is passed.
|
|
2134
2239
|
*
|
|
@@ -2140,7 +2245,7 @@ declare namespace Validation {
|
|
|
2140
2245
|
* }
|
|
2141
2246
|
* ```
|
|
2142
2247
|
*/
|
|
2143
|
-
|
|
2248
|
+
passed: <E, A>(data: Validation<E, A>) => data is Passed<A>;
|
|
2144
2249
|
/**
|
|
2145
2250
|
* Type guard that checks if a Validation is failed.
|
|
2146
2251
|
*
|
|
@@ -2152,8 +2257,8 @@ declare namespace Validation {
|
|
|
2152
2257
|
* }
|
|
2153
2258
|
* ```
|
|
2154
2259
|
*/
|
|
2155
|
-
|
|
2156
|
-
}
|
|
2260
|
+
failed: <E, A>(data: Validation<E, A>) => data is Failed<E>;
|
|
2261
|
+
};
|
|
2157
2262
|
/**
|
|
2158
2263
|
* Creates a Validation from a synchronous thunk that may throw.
|
|
2159
2264
|
* Catches any errors and transforms them using the `onError` function into a Failed validation.
|
|
@@ -2166,10 +2271,10 @@ declare namespace Validation {
|
|
|
2166
2271
|
* );
|
|
2167
2272
|
* ```
|
|
2168
2273
|
*/
|
|
2169
|
-
|
|
2274
|
+
tryCatch: <E, A>(f: () => A, options: {
|
|
2170
2275
|
onError: (e: unknown) => E;
|
|
2171
2276
|
}) => Validation<E, A>;
|
|
2172
|
-
|
|
2277
|
+
from: {
|
|
2173
2278
|
/**
|
|
2174
2279
|
* Creates a Validation from a predicate applied to a value.
|
|
2175
2280
|
* Returns Passed if the predicate passes, Failed from `onFalse` otherwise.
|
|
@@ -2185,7 +2290,7 @@ declare namespace Validation {
|
|
|
2185
2290
|
* validateName(""); // Failed(["Name is required"])
|
|
2186
2291
|
* ```
|
|
2187
2292
|
*/
|
|
2188
|
-
|
|
2293
|
+
Predicate: <E, A>(pred: (a: A) => boolean, onFalse: (a: A) => E) => (a: A) => Validation<E, A>;
|
|
2189
2294
|
/**
|
|
2190
2295
|
* Creates a Validation from a nullable value.
|
|
2191
2296
|
* If the value is null or undefined, returns Failed with the error from onNull.
|
|
@@ -2197,7 +2302,7 @@ declare namespace Validation {
|
|
|
2197
2302
|
* pipe(42, Validation.from.nullable(() => "is null")); // Passed(42)
|
|
2198
2303
|
* ```
|
|
2199
2304
|
*/
|
|
2200
|
-
|
|
2305
|
+
nullable: <E>(onNull: () => E) => <A>(value: A | null | undefined) => Validation<E, A>;
|
|
2201
2306
|
/**
|
|
2202
2307
|
* Creates a Validation from a Maybe.
|
|
2203
2308
|
* If the Maybe is None, returns Failed with the error from onNone.
|
|
@@ -2209,7 +2314,7 @@ declare namespace Validation {
|
|
|
2209
2314
|
* pipe(Maybe.make.some(42), Validation.from.Maybe(() => "is none")); // Passed(42)
|
|
2210
2315
|
* ```
|
|
2211
2316
|
*/
|
|
2212
|
-
|
|
2317
|
+
Maybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => Validation<E, A>;
|
|
2213
2318
|
/**
|
|
2214
2319
|
* Converts a `Result` to a `Validation`. `Ok` becomes `Passed`; `Err(e)` becomes `Failed([e])`.
|
|
2215
2320
|
*
|
|
@@ -2222,8 +2327,8 @@ declare namespace Validation {
|
|
|
2222
2327
|
* Validation.from.Result(Result.make.err("bad")); // Failed(["bad"])
|
|
2223
2328
|
* ```
|
|
2224
2329
|
*/
|
|
2225
|
-
|
|
2226
|
-
}
|
|
2330
|
+
Result: <E, A>(data: Result<E, A>) => Validation<E, A>;
|
|
2331
|
+
};
|
|
2227
2332
|
/**
|
|
2228
2333
|
* Transforms the success value inside a Validation.
|
|
2229
2334
|
*
|
|
@@ -2233,7 +2338,7 @@ declare namespace Validation {
|
|
|
2233
2338
|
* pipe(Validation.make.failed("oops"), Validation.map(n => n * 2)); // Failed(["oops"])
|
|
2234
2339
|
* ```
|
|
2235
2340
|
*/
|
|
2236
|
-
|
|
2341
|
+
map: <A, B>(f: (a: A) => B) => <E>(data: Validation<E, A>) => Validation<E, B>;
|
|
2237
2342
|
/**
|
|
2238
2343
|
* Transforms the error list inside a Validation.
|
|
2239
2344
|
*
|
|
@@ -2242,7 +2347,7 @@ declare namespace Validation {
|
|
|
2242
2347
|
* pipe(Validation.make.failed("oops"), Validation.mapError(e => e.toUpperCase())); // Failed(["OOPS"])
|
|
2243
2348
|
* ```
|
|
2244
2349
|
*/
|
|
2245
|
-
|
|
2350
|
+
mapError: <E, F, A>(f: (e: E) => F) => (data: Validation<E, A>) => Validation<F, A>;
|
|
2246
2351
|
/**
|
|
2247
2352
|
* Applies a function wrapped in a Validation to a value wrapped in a Validation.
|
|
2248
2353
|
* Accumulates errors from both sides.
|
|
@@ -2263,7 +2368,7 @@ declare namespace Validation {
|
|
|
2263
2368
|
* ); // Failed(["bad a", "bad b"])
|
|
2264
2369
|
* ```
|
|
2265
2370
|
*/
|
|
2266
|
-
|
|
2371
|
+
ap: <E, A>(arg: Validation<E, A>) => <B>(data: Validation<E, (a: A) => B>) => Validation<E, B>;
|
|
2267
2372
|
/**
|
|
2268
2373
|
* Applies a function wrapped in a Validation to a value wrapped in a Validation,
|
|
2269
2374
|
* using a custom error concatenator function when both sides fail.
|
|
@@ -2275,7 +2380,7 @@ declare namespace Validation {
|
|
|
2275
2380
|
* pipe(fnVal, Validation.apCustom(concat)(argVal));
|
|
2276
2381
|
* ```
|
|
2277
2382
|
*/
|
|
2278
|
-
|
|
2383
|
+
apCustom: <E1, E2, E3>(concat: (e1: NonEmptyArr<E1>, e2: NonEmptyArr<E2>) => NonEmptyArr<E3>) => <A>(arg: Validation<E2, A>) => <B>(data: Validation<E1, (a: A) => B>) => Validation<E3, B>;
|
|
2279
2384
|
/**
|
|
2280
2385
|
* Extracts the value from a Validation by providing handlers for both cases.
|
|
2281
2386
|
*
|
|
@@ -2290,7 +2395,7 @@ declare namespace Validation {
|
|
|
2290
2395
|
* );
|
|
2291
2396
|
* ```
|
|
2292
2397
|
*/
|
|
2293
|
-
|
|
2398
|
+
fold: <E, A, B>(onFailed: (errors: NonEmptyArr<E>) => B, onPassed: (a: A) => B) => (data: Validation<E, A>) => B;
|
|
2294
2399
|
/**
|
|
2295
2400
|
* Pattern matches on a Validation, returning the result of the matching case.
|
|
2296
2401
|
*
|
|
@@ -2305,7 +2410,7 @@ declare namespace Validation {
|
|
|
2305
2410
|
* );
|
|
2306
2411
|
* ```
|
|
2307
2412
|
*/
|
|
2308
|
-
|
|
2413
|
+
match: <E, A, B>(cases: {
|
|
2309
2414
|
passed: (a: A) => B;
|
|
2310
2415
|
failed: (errors: NonEmptyArr<E>) => B;
|
|
2311
2416
|
}) => (data: Validation<E, A>) => B;
|
|
@@ -2320,7 +2425,7 @@ declare namespace Validation {
|
|
|
2320
2425
|
* pipe(Validation.make.failed("oops"), Validation.getOrElse(() => null)); // null — typed as number | null
|
|
2321
2426
|
* ```
|
|
2322
2427
|
*/
|
|
2323
|
-
|
|
2428
|
+
getOrElse: <B>(defaultValue: () => B) => <E, A>(data: Validation<E, A>) => A | B;
|
|
2324
2429
|
/**
|
|
2325
2430
|
* Executes a side effect on the success value without changing the Validation.
|
|
2326
2431
|
*
|
|
@@ -2333,7 +2438,7 @@ declare namespace Validation {
|
|
|
2333
2438
|
* );
|
|
2334
2439
|
* ```
|
|
2335
2440
|
*/
|
|
2336
|
-
|
|
2441
|
+
tap: <E, A>(f: (a: A) => void) => (data: Validation<E, A>) => Validation<E, A>;
|
|
2337
2442
|
/**
|
|
2338
2443
|
* Executes a side effect on the accumulated errors without changing the Validation.
|
|
2339
2444
|
* Useful for logging or reporting validation failures.
|
|
@@ -2347,13 +2452,13 @@ declare namespace Validation {
|
|
|
2347
2452
|
* );
|
|
2348
2453
|
* ```
|
|
2349
2454
|
*/
|
|
2350
|
-
|
|
2455
|
+
tapError: <E, A>(f: (errors: NonEmptyArr<E>) => void) => (data: Validation<E, A>) => Validation<E, A>;
|
|
2351
2456
|
/**
|
|
2352
2457
|
* Recovers from a Failed state by providing a fallback Validation.
|
|
2353
2458
|
* The fallback receives the accumulated error list so callers can inspect which errors occurred.
|
|
2354
2459
|
* The fallback can produce a different success type, widening the result to `Validation<E, A | B>`.
|
|
2355
2460
|
*/
|
|
2356
|
-
|
|
2461
|
+
recover: <E, B>(fallback: (errors: NonEmptyArr<E>) => Validation<E, B>) => <A>(data: Validation<E, A>) => Validation<E, A | B>;
|
|
2357
2462
|
/**
|
|
2358
2463
|
* Recovers from a Failed state unless `isBlocked` returns true for any of the accumulated errors.
|
|
2359
2464
|
* The fallback can produce a different success type, widening the result to `Validation<E, A | B>`.
|
|
@@ -2366,8 +2471,8 @@ declare namespace Validation {
|
|
|
2366
2471
|
* ); // Passed(0)
|
|
2367
2472
|
* ```
|
|
2368
2473
|
*/
|
|
2369
|
-
|
|
2370
|
-
|
|
2474
|
+
recoverUnless: <E, B>(isBlocked: (e: E) => boolean, fallback: () => Validation<E, B>) => <A>(data: Validation<E, A>) => Validation<E, A | B>;
|
|
2475
|
+
to: {
|
|
2371
2476
|
/**
|
|
2372
2477
|
* Converts a Validation to a Result.
|
|
2373
2478
|
* Passed becomes Ok.
|
|
@@ -2381,8 +2486,7 @@ declare namespace Validation {
|
|
|
2381
2486
|
* pipe(Validation.make.failed("oops"), Validation.to.Result(errors => errors.join(", "))); // Err("oops")
|
|
2382
2487
|
* ```
|
|
2383
2488
|
*/
|
|
2384
|
-
|
|
2385
|
-
function Result<E, A>(data: Validation<E, A>): Result<NonEmptyArr<E>, A>;
|
|
2489
|
+
Result: typeof toResult;
|
|
2386
2490
|
/**
|
|
2387
2491
|
* Converts a Validation to a Maybe. `Passed` becomes `Some`; `Failed` becomes `None`
|
|
2388
2492
|
* (errors are discarded).
|
|
@@ -2393,8 +2497,8 @@ declare namespace Validation {
|
|
|
2393
2497
|
* Validation.to.Maybe(Validation.make.failed("bad")); // None
|
|
2394
2498
|
* ```
|
|
2395
2499
|
*/
|
|
2396
|
-
|
|
2397
|
-
}
|
|
2500
|
+
Maybe: <E, A>(data: Validation<E, A>) => Maybe<A>;
|
|
2501
|
+
};
|
|
2398
2502
|
/**
|
|
2399
2503
|
* Combines two independent Validation instances into a tuple.
|
|
2400
2504
|
* If both are Passed, returns Passed with both values as a tuple.
|
|
@@ -2413,7 +2517,7 @@ declare namespace Validation {
|
|
|
2413
2517
|
* ); // Failed(["Name required", "Age must be >= 0"])
|
|
2414
2518
|
* ```
|
|
2415
2519
|
*/
|
|
2416
|
-
|
|
2520
|
+
product: <E, A, B>(first: Validation<E, A>, second: Validation<E, B>) => Validation<E, readonly [A, B]>;
|
|
2417
2521
|
/**
|
|
2418
2522
|
* Combines a non-empty list of Validation instances, accumulating all errors.
|
|
2419
2523
|
* If all are Passed, returns Passed with all values collected into an array.
|
|
@@ -2429,7 +2533,7 @@ declare namespace Validation {
|
|
|
2429
2533
|
* // Passed([name, email, age]) or Failed([...all errors])
|
|
2430
2534
|
* ```
|
|
2431
2535
|
*/
|
|
2432
|
-
|
|
2536
|
+
productAll: <E, A>(data: NonEmptyArr<Validation<E, A>>) => Validation<E, readonly A[]>;
|
|
2433
2537
|
/**
|
|
2434
2538
|
* Combines a record of Validations into a single Validation of a record.
|
|
2435
2539
|
* Accumulates all failed branches' errors.
|
|
@@ -2447,7 +2551,7 @@ declare namespace Validation {
|
|
|
2447
2551
|
* }); // Failed(["Name required", "Age must be >= 0"])
|
|
2448
2552
|
* ```
|
|
2449
2553
|
*/
|
|
2450
|
-
|
|
2451
|
-
}
|
|
2554
|
+
struct: <E, R extends Record<string, any>>(fields: { [K in keyof R]: Validation<E, R[K]>; }) => Validation<E, R>;
|
|
2555
|
+
};
|
|
2452
2556
|
|
|
2453
2557
|
export { Equality as E, type Failed as F, Maybe as M, type None as N, type Ok as O, type Passed as P, Result as R, type Some as S, Task as T, Validation as V, type Err as a, Ordering as b };
|