@nlozgachev/pipelined 0.64.0 → 0.65.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.
@@ -1,1748 +0,0 @@
1
- import { h as WithKind, o as WithValue, e as WithError, a as NonEmptyArr, f as WithErrors, D as Deferred, T as Thenable } from './InternalTypes-GFn4RTwD.cjs';
2
- import { D as Duration } from './Duration-DeyxG6VQ.cjs';
3
- import { RetryPolicy } from './types.cjs';
4
-
5
- /**
6
- * A function that checks whether two values of type `A` are equal.
7
- * Use built-in instances (`Equality.string`, `Equality.number`, etc.) as starting points,
8
- * then adapt them with `Equality.by` and combine them with `Equality.and`.
9
- *
10
- * @example
11
- * ```ts
12
- * type User = { id: string; name: string };
13
- * const byId = pipe(Equality.string, Equality.by((u: User) => u.id));
14
- *
15
- * pipe(users, Arr.uniqWith(byId));
16
- * ```
17
- */
18
- type Equality<A> = (a: A, b: A) => boolean;
19
- declare const Equality: {
20
- /**
21
- * Equality for strings. Case-sensitive.
22
- *
23
- * @example
24
- * ```ts
25
- * Equality.string("hello", "hello"); // true
26
- * Equality.string("hello", "Hello"); // false
27
- * ```
28
- */
29
- string: Equality<string>;
30
- /**
31
- * Equality for numbers. Uses strict equality.
32
- *
33
- * @example
34
- * ```ts
35
- * Equality.number(42, 42); // true
36
- * ```
37
- */
38
- number: Equality<number>;
39
- /**
40
- * Equality for booleans.
41
- *
42
- * @example
43
- * ```ts
44
- * Equality.boolean(true, true); // true
45
- * ```
46
- */
47
- boolean: Equality<boolean>;
48
- /**
49
- * Equality for `Date` values. Compares by numeric time value.
50
- *
51
- * @example
52
- * ```ts
53
- * Equality.date(new Date("2024-01-01"), new Date("2024-01-01")); // true
54
- * ```
55
- */
56
- date: Equality<Date>;
57
- /**
58
- * Lifts an element equality into an array equality. Two arrays are equal if they have the
59
- * same length and every element pair is equal under `eq`.
60
- *
61
- * @example
62
- * ```ts
63
- * Equality.array(Equality.number)([1, 2, 3], [1, 2, 3]); // true
64
- * ```
65
- */
66
- array: <A>(eq: Equality<A>) => Equality<readonly A[]>;
67
- /**
68
- * Adapts an equality for type `A` into an equality for type `B` by extracting a field.
69
- * Read as "equality by this field": `pipe(Equality.string, Equality.by(u => u.name))`.
70
- *
71
- * @example
72
- * ```ts
73
- * type Product = { id: string; price: number };
74
- * const byId = pipe(Equality.string, Equality.by((p: Product) => p.id));
75
- * byId({ id: "p1", price: 9 }, { id: "p1", price: 12 }); // true
76
- * ```
77
- */
78
- by: <A, B>(f: (b: B) => A) => (eq: Equality<A>) => Equality<B>;
79
- /**
80
- * Combines two equalities with logical AND. Both must pass for two values to be considered equal.
81
- * Data-last: the first equality is the data being piped.
82
- *
83
- * @example
84
- * ```ts
85
- * const exact = pipe(byName, Equality.and(byRole));
86
- * exact(userA, userB); // true only if name AND role match
87
- * ```
88
- */
89
- and: <A>(eq2: Equality<A>) => (eq1: Equality<A>) => Equality<A>;
90
- /**
91
- * Derives deep equality for a record from field-level `Equality` checkers.
92
- *
93
- * @example
94
- * ```ts
95
- * const userEq = Equality.struct({
96
- * id: Equality.string,
97
- * age: Equality.number,
98
- * });
99
- * ```
100
- */
101
- struct: <R extends Record<string, unknown>>(fields: { [K in keyof R]: Equality<R[K]>; }) => Equality<R>;
102
- /**
103
- * Derives element-wise equality for a tuple from positional `Equality` checkers.
104
- *
105
- * @example
106
- * ```ts
107
- * const pairEq = Equality.tuple(Equality.string, Equality.number);
108
- * pairEq(["a", 1], ["a", 1]); // true
109
- * ```
110
- */
111
- tuple: <T extends readonly unknown[]>(...equalities: { [K in keyof T]: Equality<T[K]>; }) => Equality<T>;
112
- };
113
-
114
- type Some<A> = WithKind<"Some"> & WithValue<A>;
115
- type None = WithKind<"None">;
116
- /**
117
- * Maybe represents an optional value: every Maybe is either Some (contains a value) or None (empty).
118
- * Use Maybe instead of null/undefined to make optionality explicit and composable.
119
- *
120
- * @example
121
- * ```ts
122
- * const user = { name: "Alice", email: Maybe.make.some("alice@example.com") };
123
- *
124
- * pipe(
125
- * user.email,
126
- * Maybe.map(email => email.toUpperCase()),
127
- * Maybe.getOrElse(() => "NO EMAIL")
128
- * ); // "ALICE@EXAMPLE.COM"
129
- * ```
130
- */
131
- type Maybe<T> = Some<T> | None;
132
- declare const Maybe: {
133
- make: {
134
- /**
135
- * Creates a Some containing the given value.
136
- *
137
- * @example
138
- * ```ts
139
- * Maybe.make.some(42); // Some(42)
140
- * ```
141
- */
142
- some: <A>(value: A) => Some<A>;
143
- /**
144
- * Creates a None (empty Maybe).
145
- *
146
- * @example
147
- * ```ts
148
- * Maybe.make.none(); // None
149
- * ```
150
- */
151
- none: () => None;
152
- };
153
- is: {
154
- /**
155
- * Type guard that checks if a Maybe is Some.
156
- *
157
- * @example
158
- * ```ts
159
- * const value = Maybe.make.some(42);
160
- * if (Maybe.is.some(value)) {
161
- * console.log(value.value); // 42
162
- * }
163
- * ```
164
- */
165
- some: <A>(data: Maybe<A>) => data is Some<A>;
166
- /**
167
- * Type guard that checks if a Maybe is None.
168
- *
169
- * @example
170
- * ```ts
171
- * const value = Maybe.make.none();
172
- * if (Maybe.is.none(value)) {
173
- * console.log("No value present");
174
- * }
175
- * ```
176
- */
177
- none: <A>(data: Maybe<A>) => data is None;
178
- };
179
- to: {
180
- /**
181
- * Extracts the value from a Maybe, returning null if None.
182
- *
183
- * @example
184
- * ```ts
185
- * Maybe.to.nullable(Maybe.make.some(42)); // 42
186
- * Maybe.to.nullable(Maybe.make.none()); // null
187
- * ```
188
- */
189
- nullable: <A>(data: Maybe<A>) => A | null;
190
- /**
191
- * Extracts the value from a Maybe, returning undefined if None.
192
- *
193
- * @example
194
- * ```ts
195
- * Maybe.to.undefined(Maybe.make.some(42)); // 42
196
- * Maybe.to.undefined(Maybe.make.none()); // undefined
197
- * ```
198
- */
199
- undefined: <A>(data: Maybe<A>) => A | undefined;
200
- /**
201
- * Converts a Maybe to a Result.
202
- * Some becomes Ok, None becomes Err with the provided error.
203
- *
204
- * @example
205
- * ```ts
206
- * pipe(
207
- * Maybe.make.some(42),
208
- * Maybe.to.Result(() => "Value was missing")
209
- * ); // Ok(42)
210
- *
211
- * pipe(
212
- * Maybe.make.none(),
213
- * Maybe.to.Result(() => "Value was missing")
214
- * ); // Err("Value was missing")
215
- * ```
216
- */
217
- Result: <E>(onNone: () => E) => <A>(data: Maybe<A>) => Result<E, A>;
218
- };
219
- from: {
220
- /**
221
- * Creates a Maybe from a nullable value.
222
- * Returns None if the value is null or undefined, Some otherwise.
223
- *
224
- * @example
225
- * ```ts
226
- * Maybe.from.nullable(null); // None
227
- * Maybe.from.nullable(42); // Some(42)
228
- * ```
229
- */
230
- nullable: <A>(value: A | null | undefined) => Maybe<A>;
231
- /**
232
- * Creates a Maybe from a predicate applied to a value.
233
- * Returns Some if the predicate passes, None otherwise.
234
- *
235
- * @example
236
- * ```ts
237
- * Maybe.from.Predicate((n: number) => n >= 18)(21); // Some(21)
238
- * Maybe.from.Predicate((n: number) => n >= 18)(15); // None
239
- *
240
- * pipe("hello", Maybe.from.Predicate((s: string) => s.length > 0)); // Some("hello")
241
- * pipe("", Maybe.from.Predicate((s: string) => s.length > 0)); // None
242
- * ```
243
- */
244
- Predicate: <A>(pred: (a: A) => boolean) => (a: A) => Maybe<A>;
245
- /**
246
- * Creates a Maybe from a Result.
247
- * Ok becomes Some, Err becomes None (the error is discarded).
248
- *
249
- * @example
250
- * ```ts
251
- * Maybe.from.Result(Result.make.ok(42)); // Some(42)
252
- * Maybe.from.Result(Result.make.err("oops")); // None
253
- * ```
254
- */
255
- Result: <E, A>(data: Result<E, A>) => Maybe<A>;
256
- };
257
- /**
258
- * Transforms the value inside a Maybe if it exists.
259
- *
260
- * @example
261
- * ```ts
262
- * pipe(Maybe.make.some(5), Maybe.map(n => n * 2)); // Some(10)
263
- * pipe(Maybe.make.none(), Maybe.map(n => n * 2)); // None
264
- * ```
265
- */
266
- map: <A, B>(f: (a: A) => B) => (data: Maybe<A>) => Maybe<B>;
267
- /**
268
- * Chains Maybe computations. If the first is Some, passes the value to f.
269
- * If the first is None, propagates None.
270
- *
271
- * @example
272
- * ```ts
273
- * const parseNumber = (s: string): Maybe<number> => {
274
- * const n = parseInt(s, 10);
275
- * return isNaN(n) ? Maybe.make.none() : Maybe.make.some(n);
276
- * };
277
- *
278
- * pipe(Maybe.make.some("42"), Maybe.chain(parseNumber)); // Some(42)
279
- * pipe(Maybe.make.some("abc"), Maybe.chain(parseNumber)); // None
280
- * ```
281
- */
282
- chain: <A, B>(f: (a: A) => Maybe<B>) => (data: Maybe<A>) => Maybe<B>;
283
- /**
284
- * Extracts the value from a Maybe by providing handlers for both cases.
285
- *
286
- * @example
287
- * ```ts
288
- * pipe(
289
- * Maybe.make.some(5),
290
- * Maybe.fold(
291
- * () => "No value",
292
- * n => `Value: ${n}`
293
- * )
294
- * ); // "Value: 5"
295
- * ```
296
- */
297
- fold: <A, B>(onNone: () => B, onSome: (a: A) => B) => (data: Maybe<A>) => B;
298
- /**
299
- * Pattern matches on a Maybe, returning the result of the matching case.
300
- *
301
- * @example
302
- * ```ts
303
- * pipe(
304
- * optionUser,
305
- * Maybe.match({
306
- * some: user => `Hello, ${user.name}`,
307
- * none: () => "Hello, stranger"
308
- * })
309
- * );
310
- * ```
311
- */
312
- match: <A, B>(cases: {
313
- none: () => B;
314
- some: (a: A) => B;
315
- }) => (data: Maybe<A>) => B;
316
- /**
317
- * Returns the value inside a Maybe, or a default value if None.
318
- * The default is a thunk `() => B` — evaluated only when the Maybe is None.
319
- * The default can be a different type, widening the result to `A | B`.
320
- *
321
- * @example
322
- * ```ts
323
- * pipe(Maybe.make.some(5), Maybe.getOrElse(() => 0)); // 5
324
- * pipe(Maybe.make.none(), Maybe.getOrElse(() => 0)); // 0
325
- * pipe(Maybe.make.none<string>(), Maybe.getOrElse(() => null)); // null — typed as string | null
326
- * ```
327
- */
328
- getOrElse: <B>(defaultValue: () => B) => <A>(data: Maybe<A>) => A | B;
329
- /**
330
- * Executes a side effect on the value without changing the Maybe.
331
- * Useful for logging or debugging.
332
- *
333
- * @example
334
- * ```ts
335
- * pipe(
336
- * Maybe.make.some(5),
337
- * Maybe.tap(n => console.log("Value:", n)),
338
- * Maybe.map(n => n * 2)
339
- * );
340
- * ```
341
- */
342
- tap: <A>(f: (a: A) => void) => (data: Maybe<A>) => Maybe<A>;
343
- /**
344
- * Filters a Maybe based on a predicate.
345
- * Returns None if the predicate returns false or if the Maybe is already None.
346
- *
347
- * @example
348
- * ```ts
349
- * pipe(Maybe.make.some(5), Maybe.filter(n => n > 3)); // Some(5)
350
- * pipe(Maybe.make.some(2), Maybe.filter(n => n > 3)); // None
351
- * ```
352
- */
353
- filter: <A>(predicate: (a: A) => boolean) => (data: Maybe<A>) => Maybe<A>;
354
- /**
355
- * Recovers from a None by providing a fallback Maybe.
356
- * The fallback can produce a different type, widening the result to `Maybe<A | B>`.
357
- *
358
- * @example
359
- * ```ts
360
- * pipe(Maybe.make.none(), Maybe.recover(() => Maybe.make.some(42))); // Some(42)
361
- * pipe(Maybe.make.some(10), Maybe.recover(() => Maybe.make.some(42))); // Some(10)
362
- * ```
363
- */
364
- recover: <B>(fallback: () => Maybe<B>) => <A>(data: Maybe<A>) => Maybe<A | B>;
365
- /**
366
- * Applies a function wrapped in a Maybe to a value wrapped in a Maybe.
367
- *
368
- * @example
369
- * ```ts
370
- * const add = (a: number) => (b: number) => a + b;
371
- * pipe(
372
- * Maybe.make.some(add),
373
- * Maybe.ap(Maybe.make.some(5)),
374
- * Maybe.ap(Maybe.make.some(3))
375
- * ); // Some(8)
376
- * ```
377
- */
378
- ap: <A>(arg: Maybe<A>) => <B>(data: Maybe<(a: A) => B>) => Maybe<B>;
379
- /**
380
- * Converts a Maybe value into an object containing a single property.
381
- * Initiates the pipeline accumulator record.
382
- *
383
- * @example
384
- * ```ts
385
- * pipe(Maybe.make.some(42), Maybe.bindTo("value")); // Some({ value: 42 })
386
- * ```
387
- */
388
- bindTo: <K extends string>(key: K) => <A>(data: Maybe<A>) => Maybe<{ [P in K]: A; }>;
389
- /**
390
- * Evaluates a new Maybe using the current accumulator and attaches the output to a new key.
391
- *
392
- * @example
393
- * ```ts
394
- * pipe(
395
- * Maybe.make.some({ a: 1 }),
396
- * Maybe.bind("b", ({ a }) => Maybe.make.some(a + 1))
397
- * ); // Some({ a: 1, b: 2 })
398
- * ```
399
- */
400
- bind: <K extends string, A, B>(key: K, f: (a: A) => Maybe<B>) => (data: Maybe<A>) => Maybe<A & { [P in K]: B; }>;
401
- /**
402
- * Combines a record of Maybes into a single Maybe of a record.
403
- * Evaluates fields in key order and short-circuits on the first None.
404
- *
405
- * @example
406
- * ```ts
407
- * Maybe.struct({
408
- * name: Maybe.make.some("Alice"),
409
- * age: Maybe.make.some(30)
410
- * }); // Some({ name: "Alice", age: 30 })
411
- * ```
412
- */
413
- struct: <R extends Record<string, any>>(fields: { [K in keyof R]: Maybe<R[K]>; }) => Maybe<R>;
414
- /**
415
- * Swaps the outer `Maybe` and inner `Result` context.
416
- * `Some(Ok(a))` becomes `Ok(Some(a))`, `Some(Err(e))` becomes `Err(e)`, and `None` becomes `Ok(None)`.
417
- *
418
- * @example
419
- * ```ts
420
- * Maybe.transposeResult(Maybe.make.some(Result.make.ok(42))); // Ok(Some(42))
421
- * Maybe.transposeResult(Maybe.make.some(Result.make.err("e"))); // Err("e")
422
- * Maybe.transposeResult(Maybe.make.none()); // Ok(None)
423
- * ```
424
- */
425
- transposeResult: <E, A>(data: Maybe<Result<E, A>>) => Result<E, Maybe<A>>;
426
- };
427
-
428
- /**
429
- * A function that orders two values of type `A`. Returns a negative number when `a` comes before
430
- * `b`, a positive number when `a` comes after `b`, and `0` when they are equal.
431
- *
432
- * Compatible with `Array.prototype.sort` and `Arr.sortWith`.
433
- *
434
- * @example
435
- * ```ts
436
- * type Employee = { name: string; salary: number };
437
- *
438
- * const byName = pipe(Ordering.string, Ordering.by((e: Employee) => e.name));
439
- * const bySalary = pipe(Ordering.number, Ordering.by((e: Employee) => e.salary));
440
- *
441
- * pipe(employees, Arr.sortWith(pipe(byName, Ordering.thenBy(bySalary))));
442
- * ```
443
- */
444
- type Ordering<A> = (a: A, b: A) => number;
445
- declare const Ordering: {
446
- /**
447
- * Alphabetical ordering for strings.
448
- *
449
- * @example
450
- * ```ts
451
- * Ordering.string("apple", "banana"); // negative
452
- * ```
453
- */
454
- string: Ordering<string>;
455
- /**
456
- * Numeric ordering. Equivalent to `(a, b) => a - b`.
457
- *
458
- * @example
459
- * ```ts
460
- * pipe([3, 1, 2], Arr.sortWith(Ordering.number)); // [1, 2, 3]
461
- * ```
462
- */
463
- number: Ordering<number>;
464
- /**
465
- * Ordering for `Date` values by numeric time value.
466
- *
467
- * @example
468
- * ```ts
469
- * pipe(dates, Arr.sortWith(Ordering.date)); // earliest first
470
- * ```
471
- */
472
- date: Ordering<Date>;
473
- /**
474
- * Flips the direction of an ordering.
475
- *
476
- * @example
477
- * ```ts
478
- * pipe([3, 1, 2], Arr.sortWith(Ordering.reverse(Ordering.number))); // [3, 2, 1]
479
- * ```
480
- */
481
- reverse: <A>(ord: Ordering<A>) => Ordering<A>;
482
- /**
483
- * Chains two orderings: the second is used only when the first returns `0`.
484
- * Data-last: the first ordering is the data being piped.
485
- *
486
- * @example
487
- * ```ts
488
- * const byDeptThenSalary = pipe(byDept, Ordering.thenBy(bySalary));
489
- * ```
490
- */
491
- thenBy: <A>(ord2: Ordering<A>) => (ord1: Ordering<A>) => Ordering<A>;
492
- /**
493
- * Adapts an ordering for type `A` into an ordering for type `B` by extracting a field.
494
- * Read as "ordering by this field": `pipe(Ordering.number, Ordering.by(p => p.price))`.
495
- *
496
- * @example
497
- * ```ts
498
- * type Product = { name: string; price: number };
499
- * const byPrice = pipe(Ordering.number, Ordering.by((p: Product) => p.price));
500
- * pipe(products, Arr.sortWith(byPrice));
501
- * ```
502
- */
503
- by: <A, B>(f: (b: B) => A) => (ord: Ordering<A>) => Ordering<B>;
504
- /**
505
- * Combines a list of orderings into a single composite comparator.
506
- * Evaluates each ordering in sequence until a non-zero comparison result is found.
507
- *
508
- * @example
509
- * ```ts
510
- * const byName = pipe(Ordering.string, Ordering.by((u: User) => u.name));
511
- * const byAge = pipe(Ordering.number, Ordering.by((u: User) => u.age));
512
- * const sortUsers = Ordering.byFields([byName, byAge]);
513
- * ```
514
- */
515
- byFields: <A>(orderings: ReadonlyArray<Ordering<A>>) => Ordering<A>;
516
- /**
517
- * Derives a lexicographical tuple ordering from positional `Ordering` comparators.
518
- *
519
- * @example
520
- * ```ts
521
- * const pairOrd = Ordering.tuple(Ordering.string, Ordering.number);
522
- * pairOrd(["a", 1], ["a", 2]); // negative
523
- * ```
524
- */
525
- tuple: <T extends readonly unknown[]>(...orderings: { [K in keyof T]: Ordering<T[K]>; }) => Ordering<T>;
526
- };
527
-
528
- type Ok<A> = WithKind<"Ok"> & WithValue<A>;
529
- type Err<E> = WithKind<"Err"> & WithError<E>;
530
- /**
531
- * Result represents a value that can be one of two types: a success (Ok) or a failure (Err).
532
- * Use Result when an operation can fail with a meaningful error value.
533
- *
534
- * @example
535
- * ```ts
536
- * const divide = (a: number, b: number): Result<string, number> =>
537
- * b === 0 ? Result.make.err("Division by zero") : Result.make.ok(a / b);
538
- *
539
- * pipe(
540
- * divide(10, 2),
541
- * Result.map(n => n * 2),
542
- * Result.getOrElse(() => 0)
543
- * ); // 10
544
- * ```
545
- */
546
- type Result<E, A> = Ok<A> | Err<E>;
547
- declare const Result: {
548
- make: {
549
- /**
550
- * Creates a successful Result with the given value.
551
- *
552
- * @example
553
- * ```ts
554
- * Result.make.ok(42); // Ok(42)
555
- * ```
556
- */
557
- ok: <A>(value: A) => Ok<A>;
558
- /**
559
- * Creates a failed Result with the given error.
560
- *
561
- * @example
562
- * ```ts
563
- * Result.make.err("Error message"); // Err("Error message")
564
- * ```
565
- */
566
- err: <E>(e: E) => Err<E>;
567
- };
568
- is: {
569
- /**
570
- * Type guard that checks if a Result is Ok.
571
- *
572
- * @example
573
- * ```ts
574
- * const res = Result.make.ok(42);
575
- * if (Result.is.ok(res)) {
576
- * console.log(res.value); // 42
577
- * }
578
- * ```
579
- */
580
- ok: <E, A>(data: Result<E, A>) => data is Ok<A>;
581
- /**
582
- * Type guard that checks if a Result is Err.
583
- *
584
- * @example
585
- * ```ts
586
- * const res = Result.make.err("failed");
587
- * if (Result.is.err(res)) {
588
- * console.log(res.error); // "failed"
589
- * }
590
- * ```
591
- */
592
- err: <E, A>(data: Result<E, A>) => data is Err<E>;
593
- };
594
- /**
595
- * Creates a Result from a synchronous thunk that may throw.
596
- * Catches any errors and transforms them using the `onError` function.
597
- *
598
- * @example
599
- * ```ts
600
- * const result = Result.tryCatch(
601
- * () => JSON.parse(rawString),
602
- * { onError: (e) => `Parse error: ${e}` }
603
- * );
604
- * ```
605
- */
606
- tryCatch: <E, A>(f: () => A, options: {
607
- onError: (e: unknown) => E;
608
- }) => Result<E, A>;
609
- /**
610
- * Transforms the success value inside a Result.
611
- *
612
- * @example
613
- * ```ts
614
- * pipe(Result.make.ok(5), Result.map(n => n * 2)); // Ok(10)
615
- * pipe(Result.make.err("error"), Result.map(n => n * 2)); // Err("error")
616
- * ```
617
- */
618
- map: <E, A, B>(f: (a: A) => B) => (data: Result<E, A>) => Result<E, B>;
619
- /**
620
- * Transforms the error value inside a Result.
621
- *
622
- * @example
623
- * ```ts
624
- * pipe(Result.make.err("oops"), Result.mapError(e => e.toUpperCase())); // Err("OOPS")
625
- * ```
626
- */
627
- mapError: <E, F, A>(f: (e: E) => F) => (data: Result<E, A>) => Result<F, A>;
628
- /**
629
- * Chains Result computations. If the first is Ok, passes the value to f.
630
- * If the first is Err, propagates the error.
631
- *
632
- * @example
633
- * ```ts
634
- * const validatePositive = (n: number): Result<string, number> =>
635
- * n > 0 ? Result.make.ok(n) : Result.make.err("Must be positive");
636
- *
637
- * pipe(Result.make.ok(5), Result.chain(validatePositive)); // Ok(5)
638
- * pipe(Result.make.ok(-1), Result.chain(validatePositive)); // Err("Must be positive")
639
- * ```
640
- */
641
- chain: <E2, A, B>(f: (a: A) => Result<E2, B>) => <E1 = never>(data: Result<E1, A>) => Result<E1 | E2, B>;
642
- /**
643
- * Extracts the value from a Result by providing handlers for both cases.
644
- *
645
- * @example
646
- * ```ts
647
- * pipe(
648
- * Result.make.ok(5),
649
- * Result.fold(
650
- * e => `Error: ${e}`,
651
- * n => `Value: ${n}`
652
- * )
653
- * ); // "Value: 5"
654
- * ```
655
- */
656
- fold: <E, A, B>(onErr: (e: E) => B, onOk: (a: A) => B) => (data: Result<E, A>) => B;
657
- /**
658
- * Pattern matches on a Result, returning the result of the matching case.
659
- *
660
- * @example
661
- * ```ts
662
- * pipe(
663
- * result,
664
- * Result.match({
665
- * ok: value => `Got ${value}`,
666
- * err: error => `Failed: ${error}`
667
- * })
668
- * );
669
- * ```
670
- */
671
- match: <E, A, B>(cases: {
672
- ok: (a: A) => B;
673
- err: (e: E) => B;
674
- }) => (data: Result<E, A>) => B;
675
- /**
676
- * Returns the success value or a default value if the Result is an error.
677
- * The default is a thunk `() => B` — evaluated only when the Result is Err.
678
- * The default can be a different type, widening the result to `A | B`.
679
- *
680
- * @example
681
- * ```ts
682
- * pipe(Result.make.ok(5), Result.getOrElse(() => 0)); // 5
683
- * pipe(Result.make.err("error"), Result.getOrElse(() => 0)); // 0
684
- * pipe(Result.make.err("error"), Result.getOrElse(() => null)); // null — typed as number | null
685
- * ```
686
- */
687
- getOrElse: <B>(defaultValue: () => B) => <E, A>(data: Result<E, A>) => A | B;
688
- /**
689
- * Executes a side effect on the success value without changing the Result.
690
- * Useful for logging or debugging.
691
- *
692
- * @example
693
- * ```ts
694
- * pipe(
695
- * Result.make.ok(5),
696
- * Result.tap(n => console.log("Value:", n)),
697
- * Result.map(n => n * 2)
698
- * );
699
- * ```
700
- */
701
- tap: <E, A>(f: (a: A) => void) => (data: Result<E, A>) => Result<E, A>;
702
- /**
703
- * Executes a side effect on the error value without changing the Result.
704
- * Useful for logging or reporting errors.
705
- *
706
- * @example
707
- * ```ts
708
- * pipe(
709
- * Result.make.err("not found"),
710
- * Result.tapError(e => console.error("validation failed:", e)),
711
- * Result.chain(save),
712
- * )
713
- * ```
714
- */
715
- tapError: <E, A>(f: (e: E) => void) => (data: Result<E, A>) => Result<E, A>;
716
- from: {
717
- /**
718
- * Creates a Result from a predicate applied to a value.
719
- * Returns Ok if the predicate passes, Err from onFalse otherwise.
720
- *
721
- * @example
722
- * ```ts
723
- * pipe(5, Result.from.Predicate(n => n > 0, n => `${n} is not positive`)); // Ok(5)
724
- * pipe(-1, Result.from.Predicate(n => n > 0, n => `${n} is not positive`)); // Err("-1 is not positive")
725
- * pipe("", Result.from.Predicate(s => s.length > 0, () => "empty string")); // Err("empty string")
726
- * ```
727
- */
728
- Predicate: <E, A>(pred: (a: A) => boolean, onFalse: (a: A) => E) => (a: A) => Result<E, A>;
729
- /**
730
- * Creates a Result from a nullable value.
731
- * Returns Ok if the value is not null or undefined, error from onNull otherwise.
732
- *
733
- * @example
734
- * ```ts
735
- * pipe(null, Result.from.nullable(() => "is null")); // Err("is null")
736
- * pipe(42, Result.from.nullable(() => "is null")); // Ok(42)
737
- * ```
738
- */
739
- nullable: <E>(onNull: () => E) => <A>(value: A | null | undefined) => Result<E, A>;
740
- /**
741
- * Creates a Result from a Maybe.
742
- * Some becomes Ok, None becomes error from onNone.
743
- *
744
- * @example
745
- * ```ts
746
- * pipe(Maybe.make.none(), Result.from.Maybe(() => "is none")); // Err("is none")
747
- * pipe(Maybe.make.some(42), Result.from.Maybe(() => "is none")); // Ok(42)
748
- * ```
749
- */
750
- Maybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => Result<E, A>;
751
- /**
752
- * Converts a `Validation` to a `Result`, combining accumulated errors using `combineErrors`.
753
- * `Passed(a)` becomes `Ok(a)`; `Failed(errors)` becomes `Err(combineErrors(errors))`.
754
- *
755
- * @example
756
- * ```ts
757
- * Result.from.Validation((errors) => errors.join(", "))(Validation.make.failed("error1")); // Err("error1")
758
- * ```
759
- */
760
- Validation: <E1, E2, A>(combineErrors: (errors: NonEmptyArr<E1>) => E2) => (val: Validation<E1, A>) => Result<E2, A>;
761
- };
762
- /**
763
- * Recovers from an error by providing a fallback Result.
764
- * The fallback can produce a different success type, widening the result to `Result<E, A | B>`.
765
- */
766
- recover: <E, B>(fallback: (e: E) => Result<E, B>) => <A>(data: Result<E, A>) => Result<E, A | B>;
767
- /**
768
- * Recovers from an error unless the predicate `isBlocked` returns true for that error.
769
- * The fallback can produce a different success type, widening the result to `Result<E, A | B>`.
770
- *
771
- * @example
772
- * ```ts
773
- * pipe(
774
- * Result.make.err(new Error("not found")),
775
- * Result.recoverUnless(e => e.message === "fatal", () => Result.make.ok(0))
776
- * ); // Ok(0)
777
- * ```
778
- */
779
- recoverUnless: <E, B>(isBlocked: (e: E) => boolean, fallback: () => Result<E, B>) => <A>(data: Result<E, A>) => Result<E, A | B>;
780
- to: {
781
- /**
782
- * Converts a Result to a Maybe.
783
- * Ok becomes Some, Err becomes None (the error is discarded).
784
- *
785
- * @example
786
- * ```ts
787
- * Result.to.Maybe(Result.make.ok(42)); // Some(42)
788
- * Result.to.Maybe(Result.make.err("oops")); // None
789
- * ```
790
- */
791
- Maybe: <E, A>(data: Result<E, A>) => Maybe<A>;
792
- /**
793
- * Converts a `Result` to a `Validation`. `Ok(a)` becomes `Passed(a)`; `Err(e)` becomes `Failed([e])`.
794
- *
795
- * @example
796
- * ```ts
797
- * Result.to.Validation(Result.make.ok(42)); // Passed(42)
798
- * Result.to.Validation(Result.make.err("bad")); // Failed(["bad"])
799
- * ```
800
- */
801
- Validation: <E, A>(data: Result<E, A>) => Validation<E, A>;
802
- };
803
- /**
804
- * Swaps the outer `Result` and inner `Maybe` context.
805
- * `Ok(Some(a))` becomes `Some(Ok(a))`, `Ok(None)` becomes `None`, and `Err(e)` becomes `Some(Err(e))`.
806
- *
807
- * @example
808
- * ```ts
809
- * Result.transposeMaybe(Result.make.ok(Maybe.make.some(42))); // Some(Ok(42))
810
- * Result.transposeMaybe(Result.make.ok(Maybe.make.none())); // None
811
- * Result.transposeMaybe(Result.make.err("error")); // Some(Err("error"))
812
- * ```
813
- */
814
- transposeMaybe: <E, A>(data: Result<E, Maybe<A>>) => Maybe<Result<E, A>>;
815
- /**
816
- * Applies a function wrapped in a Result to a value wrapped in a Result.
817
- *
818
- * @example
819
- * ```ts
820
- * const add = (a: number) => (b: number) => a + b;
821
- * pipe(
822
- * Result.make.ok(add),
823
- * Result.ap(Result.make.ok(5)),
824
- * Result.ap(Result.make.ok(3))
825
- * ); // Ok(8)
826
- * ```
827
- */
828
- ap: <E, A>(arg: Result<E, A>) => <B>(data: Result<E, (a: A) => B>) => Result<E, B>;
829
- /**
830
- * Converts a Result value into an object containing a single property.
831
- * Initiates the pipeline accumulator record.
832
- *
833
- * @example
834
- * ```ts
835
- * pipe(Result.make.ok(42), Result.bindTo("value")); // Ok({ value: 42 })
836
- * ```
837
- */
838
- bindTo: <K extends string>(key: K) => <E, A>(data: Result<E, A>) => Result<E, { [P in K]: A; }>;
839
- /**
840
- * Evaluates a new Result using the current accumulator and attaches the output to a new key.
841
- *
842
- * @example
843
- * ```ts
844
- * pipe(
845
- * Result.make.ok({ a: 1 }),
846
- * Result.bind("b", ({ a }) => Result.make.ok(a + 1))
847
- * ); // Ok({ a: 1, b: 2 })
848
- * ```
849
- */
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; }>;
851
- /**
852
- * Combines a record of Results into a single Result of a record.
853
- * Evaluates fields in key order and short-circuits on the first failure.
854
- *
855
- * @example
856
- * ```ts
857
- * Result.struct({
858
- * name: Result.make.ok("Alice"),
859
- * age: Result.make.ok(30)
860
- * }); // Ok({ name: "Alice", age: 30 })
861
- * ```
862
- */
863
- struct: <E, R extends Record<string, any>>(fields: { [K in keyof R]: Result<E, R[K]>; }) => Result<E, R>;
864
- /**
865
- * Narrows an `Ok` value with a predicate, converting to `Err(onFail(a))` if the predicate returns false.
866
- *
867
- * @example
868
- * ```ts
869
- * pipe(
870
- * Result.make.ok(15),
871
- * Result.ensure((n) => n >= 18, (n) => `Age ${n} is below 18`)
872
- * ); // Err("Age 15 is below 18")
873
- * ```
874
- */
875
- ensure: <A, E2>(predicate: (a: A) => boolean, onFail: (a: A) => E2) => <E1 = never>(data: Result<E1, A>) => Result<E1 | E2, A>;
876
- /**
877
- * Transforms both branches of a Result simultaneously.
878
- * Applies `onErr` to `Err` values and `onOk` to `Ok` values.
879
- *
880
- * @example
881
- * ```ts
882
- * pipe(
883
- * Result.make.ok(5),
884
- * Result.bimap(
885
- * (e) => `Error: ${e}`,
886
- * (n) => n * 2
887
- * )
888
- * ); // Ok(10)
889
- * ```
890
- */
891
- bimap: <E1, E2, A, B>(onErr: (e: E1) => E2, onOk: (a: A) => B) => (data: Result<E1, A>) => Result<E2, B>;
892
- };
893
-
894
- type Passed<A> = WithKind<"Passed"> & WithValue<A>;
895
- type Failed<E> = WithKind<"Failed"> & WithErrors<E>;
896
- declare function toResult<E1, E2, A>(combineErrors: (errors: NonEmptyArr<E1>) => E2): (val: Validation<E1, A>) => Result<E2, A>;
897
- declare function toResult<E, A>(data: Validation<E, A>): Result<NonEmptyArr<E>, A>;
898
- /**
899
- * Validation represents a value that is either passed with a success value,
900
- * or failed with accumulated errors.
901
- * Unlike Result, Validation can accumulate multiple errors instead of short-circuiting.
902
- *
903
- * Use Validation when you need to collect all errors (e.g., form validation).
904
- * Use Result when you want to fail fast on the first error.
905
- *
906
- * @example
907
- * ```ts
908
- * const validateName = (name: string): Validation<string, string> =>
909
- * name.length > 0 ? Validation.make.passed(name) : Validation.make.failed("Name is required");
910
- *
911
- * const validateAge = (age: number): Validation<string, number> =>
912
- * age >= 0 ? Validation.make.passed(age) : Validation.make.failed("Age must be positive");
913
- *
914
- * // Accumulates all errors using ap
915
- * pipe(
916
- * Validation.make.passed((name: string) => (age: number) => ({ name, age })),
917
- * Validation.ap(validateName("")),
918
- * Validation.ap(validateAge(-1))
919
- * );
920
- * // Failed(["Name is required", "Age must be positive"])
921
- * ```
922
- */
923
- type Validation<E, A> = Passed<A> | Failed<E>;
924
- declare const Validation: {
925
- make: {
926
- /**
927
- * Wraps a value in a passed Validation.
928
- *
929
- * @example
930
- * ```ts
931
- * Validation.make.passed(42); // Passed(42)
932
- * ```
933
- */
934
- passed: <E, A>(value: A) => Validation<E, A>;
935
- /**
936
- * Creates a failed Validation from a single error.
937
- *
938
- * @example
939
- * ```ts
940
- * Validation.make.failed("Invalid input");
941
- * ```
942
- */
943
- failed: <E>(error: E) => Failed<E>;
944
- /**
945
- * Creates a failed Validation from multiple errors.
946
- *
947
- * @example
948
- * ```ts
949
- * Validation.make.failedAll(["Invalid input"]);
950
- * ```
951
- */
952
- failedAll: <E>(errors: NonEmptyArr<E>) => Failed<E>;
953
- };
954
- is: {
955
- /**
956
- * Type guard that checks if a Validation is passed.
957
- *
958
- * @example
959
- * ```ts
960
- * const v = Validation.make.passed(42);
961
- * if (Validation.is.passed(v)) {
962
- * console.log(v.value); // 42
963
- * }
964
- * ```
965
- */
966
- passed: <E, A>(data: Validation<E, A>) => data is Passed<A>;
967
- /**
968
- * Type guard that checks if a Validation is failed.
969
- *
970
- * @example
971
- * ```ts
972
- * const v = Validation.make.failed("invalid");
973
- * if (Validation.is.failed(v)) {
974
- * console.log(v.errors); // ["invalid"]
975
- * }
976
- * ```
977
- */
978
- failed: <E, A>(data: Validation<E, A>) => data is Failed<E>;
979
- };
980
- /**
981
- * Creates a Validation from a synchronous thunk that may throw.
982
- * Catches any errors and transforms them using the `onError` function into a Failed validation.
983
- *
984
- * @example
985
- * ```ts
986
- * const result = Validation.tryCatch(
987
- * () => JSON.parse(rawString),
988
- * { onError: (e) => `Parse error: ${e}` }
989
- * );
990
- * ```
991
- */
992
- tryCatch: <E, A>(f: () => A, options: {
993
- onError: (e: unknown) => E;
994
- }) => Validation<E, A>;
995
- from: {
996
- /**
997
- * Creates a Validation from a predicate applied to a value.
998
- * Returns Passed if the predicate passes, Failed from `onFalse` otherwise.
999
- *
1000
- * @example
1001
- * ```ts
1002
- * const validateName = Validation.from.Predicate(
1003
- * (s: string) => s.length > 0,
1004
- * () => "Name is required"
1005
- * );
1006
- *
1007
- * validateName("Alice"); // Passed("Alice")
1008
- * validateName(""); // Failed(["Name is required"])
1009
- * ```
1010
- */
1011
- Predicate: <E, A>(pred: (a: A) => boolean, onFalse: (a: A) => E) => (a: A) => Validation<E, A>;
1012
- /**
1013
- * Creates a Validation from a nullable value.
1014
- * If the value is null or undefined, returns Failed with the error from onNull.
1015
- * Otherwise, returns Passed.
1016
- *
1017
- * @example
1018
- * ```ts
1019
- * pipe(null, Validation.from.nullable(() => "is null")); // Failed(["is null"])
1020
- * pipe(42, Validation.from.nullable(() => "is null")); // Passed(42)
1021
- * ```
1022
- */
1023
- nullable: <E>(onNull: () => E) => <A>(value: A | null | undefined) => Validation<E, A>;
1024
- /**
1025
- * Creates a Validation from a Maybe.
1026
- * If the Maybe is None, returns Failed with the error from onNone.
1027
- * Otherwise, returns Passed.
1028
- *
1029
- * @example
1030
- * ```ts
1031
- * pipe(Maybe.make.none(), Validation.from.Maybe(() => "is none")); // Failed(["is none"])
1032
- * pipe(Maybe.make.some(42), Validation.from.Maybe(() => "is none")); // Passed(42)
1033
- * ```
1034
- */
1035
- Maybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => Validation<E, A>;
1036
- /**
1037
- * Converts a `Result` to a `Validation`. `Ok` becomes `Passed`; `Err(e)` becomes `Failed([e])`.
1038
- *
1039
- * Useful when bridging from error-short-circuiting `Result` pipelines into
1040
- * error-accumulating `Validation` pipelines.
1041
- *
1042
- * @example
1043
- * ```ts
1044
- * Validation.from.Result(Result.make.ok(42)); // Passed(42)
1045
- * Validation.from.Result(Result.make.err("bad")); // Failed(["bad"])
1046
- * ```
1047
- */
1048
- Result: <E, A>(data: Result<E, A>) => Validation<E, A>;
1049
- };
1050
- /**
1051
- * Transforms the success value inside a Validation.
1052
- *
1053
- * @example
1054
- * ```ts
1055
- * pipe(Validation.make.passed(5), Validation.map(n => n * 2)); // Passed(10)
1056
- * pipe(Validation.make.failed("oops"), Validation.map(n => n * 2)); // Failed(["oops"])
1057
- * ```
1058
- */
1059
- map: <A, B>(f: (a: A) => B) => <E>(data: Validation<E, A>) => Validation<E, B>;
1060
- /**
1061
- * Transforms the error list inside a Validation.
1062
- *
1063
- * @example
1064
- * ```ts
1065
- * pipe(Validation.make.failed("oops"), Validation.mapError(e => e.toUpperCase())); // Failed(["OOPS"])
1066
- * ```
1067
- */
1068
- mapError: <E, F, A>(f: (e: E) => F) => (data: Validation<E, A>) => Validation<F, A>;
1069
- /**
1070
- * Applies a function wrapped in a Validation to a value wrapped in a Validation.
1071
- * Accumulates errors from both sides.
1072
- *
1073
- * @example
1074
- * ```ts
1075
- * const add = (a: number) => (b: number) => a + b;
1076
- * pipe(
1077
- * Validation.make.passed(add),
1078
- * Validation.ap(Validation.make.passed(5)),
1079
- * Validation.ap(Validation.make.passed(3))
1080
- * ); // Passed(8)
1081
- *
1082
- * pipe(
1083
- * Validation.make.passed(add),
1084
- * Validation.ap(Validation.make.failed<string>("bad a")),
1085
- * Validation.ap(Validation.make.failed<string>("bad b"))
1086
- * ); // Failed(["bad a", "bad b"])
1087
- * ```
1088
- */
1089
- ap: <E, A>(arg: Validation<E, A>) => <B>(data: Validation<E, (a: A) => B>) => Validation<E, B>;
1090
- /**
1091
- * Applies a function wrapped in a Validation to a value wrapped in a Validation,
1092
- * using a custom error concatenator function when both sides fail.
1093
- *
1094
- * @example
1095
- * ```ts
1096
- * const concat = (e1: NonEmptyArr<string>, e2: NonEmptyArr<string>): NonEmptyArr<string> =>
1097
- * [...e1, ...e2];
1098
- * pipe(fnVal, Validation.apCustom(concat)(argVal));
1099
- * ```
1100
- */
1101
- 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>;
1102
- /**
1103
- * Extracts the value from a Validation by providing handlers for both cases.
1104
- *
1105
- * @example
1106
- * ```ts
1107
- * pipe(
1108
- * Validation.make.passed(42),
1109
- * Validation.fold(
1110
- * errors => `Errors: ${errors.join(", ")}`,
1111
- * value => `Value: ${value}`
1112
- * )
1113
- * );
1114
- * ```
1115
- */
1116
- fold: <E, A, B>(onFailed: (errors: NonEmptyArr<E>) => B, onPassed: (a: A) => B) => (data: Validation<E, A>) => B;
1117
- /**
1118
- * Pattern matches on a Validation, returning the result of the matching case.
1119
- *
1120
- * @example
1121
- * ```ts
1122
- * pipe(
1123
- * validation,
1124
- * Validation.match({
1125
- * passed: value => `Got ${value}`,
1126
- * failed: errors => `Failed: ${errors.join(", ")}`
1127
- * })
1128
- * );
1129
- * ```
1130
- */
1131
- match: <E, A, B>(cases: {
1132
- passed: (a: A) => B;
1133
- failed: (errors: NonEmptyArr<E>) => B;
1134
- }) => (data: Validation<E, A>) => B;
1135
- /**
1136
- * Returns the success value or a default value if the Validation is failed.
1137
- * The default can be a different type, widening the result to `A | B`.
1138
- *
1139
- * @example
1140
- * ```ts
1141
- * pipe(Validation.make.passed(5), Validation.getOrElse(() => 0)); // 5
1142
- * pipe(Validation.make.failed("oops"), Validation.getOrElse(() => 0)); // 0
1143
- * pipe(Validation.make.failed("oops"), Validation.getOrElse(() => null)); // null — typed as number | null
1144
- * ```
1145
- */
1146
- getOrElse: <B>(defaultValue: () => B) => <E, A>(data: Validation<E, A>) => A | B;
1147
- /**
1148
- * Executes a side effect on the success value without changing the Validation.
1149
- *
1150
- * @example
1151
- * ```ts
1152
- * pipe(
1153
- * Validation.make.passed(5),
1154
- * Validation.tap(n => console.log("Value:", n)),
1155
- * Validation.map(n => n * 2)
1156
- * );
1157
- * ```
1158
- */
1159
- tap: <E, A>(f: (a: A) => void) => (data: Validation<E, A>) => Validation<E, A>;
1160
- /**
1161
- * Executes a side effect on the accumulated errors without changing the Validation.
1162
- * Useful for logging or reporting validation failures.
1163
- *
1164
- * @example
1165
- * ```ts
1166
- * pipe(
1167
- * Validation.make.failed("Name required"),
1168
- * Validation.tapError(errors => console.error("validation failed:", errors)),
1169
- * Validation.map(toUser)
1170
- * );
1171
- * ```
1172
- */
1173
- tapError: <E, A>(f: (errors: NonEmptyArr<E>) => void) => (data: Validation<E, A>) => Validation<E, A>;
1174
- /**
1175
- * Recovers from a Failed state by providing a fallback Validation.
1176
- * The fallback receives the accumulated error list so callers can inspect which errors occurred.
1177
- * The fallback can produce a different success type, widening the result to `Validation<E, A | B>`.
1178
- */
1179
- recover: <E, B>(fallback: (errors: NonEmptyArr<E>) => Validation<E, B>) => <A>(data: Validation<E, A>) => Validation<E, A | B>;
1180
- /**
1181
- * Recovers from a Failed state unless `isBlocked` returns true for any of the accumulated errors.
1182
- * The fallback can produce a different success type, widening the result to `Validation<E, A | B>`.
1183
- *
1184
- * @example
1185
- * ```ts
1186
- * pipe(
1187
- * Validation.make.failed("field-error"),
1188
- * Validation.recoverUnless(e => e === "fatal", () => Validation.make.passed(0))
1189
- * ); // Passed(0)
1190
- * ```
1191
- */
1192
- recoverUnless: <E, B>(isBlocked: (e: E) => boolean, fallback: () => Validation<E, B>) => <A>(data: Validation<E, A>) => Validation<E, A | B>;
1193
- to: {
1194
- /**
1195
- * Converts a Validation to a Result.
1196
- * Passed becomes Ok.
1197
- * Direct call converts Failed to Err with accumulated error list `NonEmptyArr<E>`.
1198
- * Curried call converts Failed to Err with combined error `E2` via `combineErrors`.
1199
- *
1200
- * @example
1201
- * ```ts
1202
- * Validation.to.Result(Validation.make.passed(42)); // Ok(42)
1203
- * Validation.to.Result(Validation.make.failed("oops")); // Err(["oops"])
1204
- * pipe(Validation.make.failed("oops"), Validation.to.Result(errors => errors.join(", "))); // Err("oops")
1205
- * ```
1206
- */
1207
- Result: typeof toResult;
1208
- /**
1209
- * Converts a Validation to a Maybe. `Passed` becomes `Some`; `Failed` becomes `None`
1210
- * (errors are discarded).
1211
- *
1212
- * @example
1213
- * ```ts
1214
- * Validation.to.Maybe(Validation.make.passed(42)); // Some(42)
1215
- * Validation.to.Maybe(Validation.make.failed("bad")); // None
1216
- * ```
1217
- */
1218
- Maybe: <E, A>(data: Validation<E, A>) => Maybe<A>;
1219
- };
1220
- /**
1221
- * Combines two independent Validation instances into a tuple.
1222
- * If both are Passed, returns Passed with both values as a tuple.
1223
- * If either is Failed, accumulates errors from both sides.
1224
- *
1225
- * @example
1226
- * ```ts
1227
- * Validation.product(
1228
- * Validation.make.passed("alice"),
1229
- * Validation.make.passed(30)
1230
- * ); // Passed(["alice", 30])
1231
- *
1232
- * Validation.product(
1233
- * Validation.make.failed("Name required"),
1234
- * Validation.make.failed("Age must be >= 0")
1235
- * ); // Failed(["Name required", "Age must be >= 0"])
1236
- * ```
1237
- */
1238
- product: <E, A, B>(first: Validation<E, A>, second: Validation<E, B>) => Validation<E, readonly [A, B]>;
1239
- /**
1240
- * Combines a non-empty list of Validation instances, accumulating all errors.
1241
- * If all are Passed, returns Passed with all values collected into an array.
1242
- * If any are Failed, returns Failed with all accumulated errors.
1243
- *
1244
- * @example
1245
- * ```ts
1246
- * Validation.productAll([
1247
- * validateName(name),
1248
- * validateEmail(email),
1249
- * validateAge(age)
1250
- * ]);
1251
- * // Passed([name, email, age]) or Failed([...all errors])
1252
- * ```
1253
- */
1254
- productAll: <E, A>(data: NonEmptyArr<Validation<E, A>>) => Validation<E, readonly A[]>;
1255
- /**
1256
- * Combines a record of Validations into a single Validation of a record.
1257
- * Accumulates all failed branches' errors.
1258
- *
1259
- * @example
1260
- * ```ts
1261
- * Validation.struct({
1262
- * name: Validation.make.passed("Alice"),
1263
- * age: Validation.make.passed(30)
1264
- * }); // Passed({ name: "Alice", age: 30 })
1265
- *
1266
- * Validation.struct({
1267
- * name: Validation.make.failed("Name required"),
1268
- * age: Validation.make.failed("Age must be >= 0")
1269
- * }); // Failed(["Name required", "Age must be >= 0"])
1270
- * ```
1271
- */
1272
- struct: <E, R extends Record<string, any>>(fields: { [K in keyof R]: Validation<E, R[K]>; }) => Validation<E, R>;
1273
- };
1274
-
1275
- type _CoreMaybe<A> = Maybe<A>;
1276
- type _CoreResult<E, A> = Result<E, A>;
1277
- type _CoreValidation<E, A> = Validation<E, A>;
1278
- /**
1279
- * A lazy async computation that always resolves.
1280
- *
1281
- * Two guarantees:
1282
- * - **Lazy** — nothing starts until you call it.
1283
- * - **Infallible** — it never rejects. If failure is possible, encode it in the
1284
- * return type using `Task.Result<E, A>` instead.
1285
- *
1286
- * An optional `AbortSignal` can be passed at the call site. Combinators like
1287
- * `retry`, `pollUntil`, and `timeout` thread it automatically to every inner
1288
- * operation. Existing tasks that ignore the signal continue to work unchanged.
1289
- *
1290
- * Calling a Task returns a `Deferred<A>` — a one-shot async value that supports
1291
- * `await` but has no `.catch()`, `.finally()`, or chainable `.then()`.
1292
- *
1293
- * **Consuming a Task:**
1294
- *
1295
- * Use `await task()` to run it and get the value directly:
1296
- * ```ts
1297
- * const value: number = await task();
1298
- * ```
1299
- *
1300
- * When you need an explicit `Promise<A>` (e.g. for a third-party API), convert
1301
- * the `Deferred` with `Deferred.to.Promise`:
1302
- * ```ts
1303
- * const p: Promise<number> = Deferred.to.Promise(task());
1304
- * ```
1305
- *
1306
- * @example
1307
- * ```ts
1308
- * const getTimestamp: Task<number> = Task.resolve(Date.now());
1309
- *
1310
- * // Nothing runs yet — getTimestamp is just a description
1311
- * const formatted = pipe(
1312
- * getTimestamp,
1313
- * Task.map(ts => new Date(ts).toISOString())
1314
- * );
1315
- *
1316
- * // Execute when ready
1317
- * const result = await formatted();
1318
- * ```
1319
- */
1320
- type Task<A> = (signal?: AbortSignal) => Deferred<A>;
1321
- declare const Task: {
1322
- /**
1323
- * Creates a Task that immediately resolves to the given value.
1324
- *
1325
- * @example
1326
- * ```ts
1327
- * const task = Task.resolve(42);
1328
- * const value = await task(); // 42
1329
- * ```
1330
- */
1331
- resolve: <A>(value: A) => Task<A>;
1332
- from: {
1333
- /**
1334
- * Creates a Task from a lazy synchronous thunk.
1335
- * Unlike `Task.resolve(f())`, `from.sync` does not evaluate `f` until the Task is called.
1336
- *
1337
- * @example
1338
- * ```ts
1339
- * const t = Task.from.sync(() => Date.now()); // Date.now() not called yet
1340
- * const ts = await t(); // called here, every time
1341
- * ```
1342
- */
1343
- sync: <A>(f: () => A) => Task<A>;
1344
- };
1345
- /**
1346
- * Wraps a Promise-returning thunk that may throw or reject,
1347
- * trapping errors with a fallback function and returning a guaranteed `Task<A>`.
1348
- *
1349
- * @example
1350
- * ```ts
1351
- * const loadConfig = Task.tryCatch(
1352
- * () => configStore.get("default"),
1353
- * { onError: () => DEFAULT_CONFIG }
1354
- * );
1355
- * ```
1356
- */
1357
- tryCatch: <A>(f: (signal?: AbortSignal) => globalThis.Promise<A>, options: {
1358
- onError: (error: unknown) => A;
1359
- }) => Task<A>;
1360
- /**
1361
- * Transforms the value inside a Task.
1362
- *
1363
- * @example
1364
- * ```ts
1365
- * pipe(
1366
- * Task.resolve(5),
1367
- * Task.map(n => n * 2)
1368
- * )(); // Deferred<10>
1369
- * ```
1370
- */
1371
- map: <A, B>(f: (a: A) => B) => (data: Task<A>) => Task<B>;
1372
- /**
1373
- * Chains Task computations. Passes the resolved value of the first Task to f.
1374
- *
1375
- * @example
1376
- * ```ts
1377
- * const readUserId: Task<string> = Task.resolve(session.userId);
1378
- * const loadPrefs = (id: string): Task<Preferences> =>
1379
- * Task.resolve(prefsCache.get(id));
1380
- *
1381
- * pipe(
1382
- * readUserId,
1383
- * Task.chain(loadPrefs)
1384
- * )(); // Deferred<Preferences>
1385
- * ```
1386
- */
1387
- chain: <A, B>(f: (a: A) => Task<B>) => (data: Task<A>) => Task<B>;
1388
- /**
1389
- * Applies a function wrapped in a Task to a value wrapped in a Task.
1390
- * Both Tasks run in parallel.
1391
- *
1392
- * @example
1393
- * ```ts
1394
- * const add = (a: number) => (b: number) => a + b;
1395
- * pipe(
1396
- * Task.resolve(add),
1397
- * Task.ap(Task.resolve(5)),
1398
- * Task.ap(Task.resolve(3))
1399
- * )(); // Deferred<8>
1400
- * ```
1401
- */
1402
- ap: <A>(arg: Task<A>) => <B>(data: Task<(a: A) => B>) => Task<B>;
1403
- /**
1404
- * Executes a side effect on the value without changing the Task.
1405
- * Useful for logging or debugging.
1406
- *
1407
- * @example
1408
- * ```ts
1409
- * pipe(
1410
- * loadConfig,
1411
- * Task.tap(cfg => console.log("Config:", cfg)),
1412
- * Task.map(buildReport)
1413
- * );
1414
- * ```
1415
- */
1416
- tap: <A>(f: (a: A) => void) => (data: Task<A>) => Task<A>;
1417
- /**
1418
- * Runs multiple Tasks in parallel and collects their results.
1419
- *
1420
- * @example
1421
- * ```ts
1422
- * Task.all([loadConfig, detectLocale, loadTheme])();
1423
- * // Deferred<[Config, string, Theme]>
1424
- * ```
1425
- */
1426
- all: <T extends readonly Task<unknown>[]>(tasks: T) => Task<{ [K in keyof T]: T[K] extends Task<infer A> ? A : never; }>;
1427
- /**
1428
- * Delays the execution of a Task by the specified duration.
1429
- * Useful for debouncing or rate limiting.
1430
- *
1431
- * @example
1432
- * ```ts
1433
- * pipe(
1434
- * Task.resolve(42),
1435
- * Task.delay(Duration.seconds(1))
1436
- * )(); // Resolves after 1 second
1437
- * ```
1438
- */
1439
- delay: (duration: Duration) => <A>(data: Task<A>) => Task<A>;
1440
- /**
1441
- * Runs a Task a fixed number of times sequentially, collecting all results into an array.
1442
- * An optional delay duration can be inserted between runs.
1443
- *
1444
- * @example
1445
- * ```ts
1446
- * pipe(
1447
- * pollSensor,
1448
- * Task.repeat({ times: 5, delay: Duration.seconds(1) })
1449
- * )(); // Task<Reading[]> — 5 readings, one per second
1450
- * ```
1451
- */
1452
- repeat: (options: {
1453
- times: number;
1454
- delay?: Duration;
1455
- }) => <A>(task: Task<A>) => Task<readonly A[]>;
1456
- /**
1457
- * Runs a Task repeatedly until the result satisfies a predicate, returning that result.
1458
- * An optional delay duration can be inserted between runs.
1459
- * An optional `maxAttempts` cap stops the loop after N calls — the last value is returned
1460
- * regardless of whether the predicate was satisfied.
1461
- *
1462
- * @example
1463
- * ```ts
1464
- * pipe(
1465
- * checkStatus,
1466
- * Task.repeatUntil({ when: (s) => s === "ready", delay: Duration.milliseconds(500) })
1467
- * )(); // polls every 500ms until status is "ready"
1468
- * ```
1469
- */
1470
- repeatUntil: <A>(options: {
1471
- when: (a: A) => boolean;
1472
- delay?: Duration;
1473
- maxAttempts?: number;
1474
- }) => (task: Task<A>) => Task<A>;
1475
- /**
1476
- * Resolves with the value of the first Task to complete. All Tasks start
1477
- * immediately. When one resolves, the other tasks are cancelled (aborted)
1478
- * downstream.
1479
- *
1480
- * @example
1481
- * ```ts
1482
- * const fast = Task.resolve("fast");
1483
- * const slow = Task.delay(Duration.milliseconds(200))(Task.resolve("slow"));
1484
- *
1485
- * await Task.race([fast, slow])(); // "fast"
1486
- * ```
1487
- */
1488
- race: <A>(tasks: ReadonlyArray<Task<A>>) => Task<A>;
1489
- /**
1490
- * Runs an array of Tasks concurrently and collects their results in an array.
1491
- * Forward-propagates the call site's AbortSignal to all subtasks concurrently.
1492
- *
1493
- * @example
1494
- * ```ts
1495
- * Task.sequence([loadConfig, detectLocale, loadTheme])();
1496
- * // Deferred<[Config, string, Theme]>
1497
- * ```
1498
- */
1499
- sequence: <A>(tasks: ReadonlyArray<Task<A>>) => Task<ReadonlyArray<A>>;
1500
- /**
1501
- * Runs an array of Tasks one at a time in order, collecting all results.
1502
- * Each Task starts only after the previous one resolves.
1503
- *
1504
- * @example
1505
- * ```ts
1506
- * let log: number[] = [];
1507
- * const makeTask = (n: number) => Task.resolve(n);
1508
- *
1509
- * await Task.sequential([makeTask(1), makeTask(2), makeTask(3)])();
1510
- * // log = [1, 2, 3] — tasks ran in order
1511
- * ```
1512
- */
1513
- sequential: <A>(tasks: ReadonlyArray<Task<A>>) => Task<ReadonlyArray<A>>;
1514
- /**
1515
- * Converts a `Task<A>` into a `Task<Result<E, A>>`, resolving to `Err` if the
1516
- * Task does not complete within the given duration. The inner Task receives an
1517
- * `AbortSignal` that fires when the deadline passes, so asynchronous operations
1518
- * that accept a signal are cancelled rather than left dangling.
1519
- *
1520
- * @example
1521
- * ```ts
1522
- * pipe(
1523
- * heavyComputation,
1524
- * Task.timeout({ duration: Duration.seconds(5), onTimeout: () => "timed out" }),
1525
- * Task.Result.chain(processResult)
1526
- * );
1527
- * ```
1528
- */
1529
- timeout: <E>(options: {
1530
- duration: Duration;
1531
- onTimeout: () => E;
1532
- }) => <A>(task: Task<A>) => Task<Result<E, A>>;
1533
- /**
1534
- * Creates a Task paired with an `abort` handle. Calling `abort()` cancels the
1535
- * current in-flight call immediately. Unlike a one-shot abort, calling `task()`
1536
- * again after `abort()` starts a fresh call with a new signal.
1537
- *
1538
- * Each invocation of `task()` automatically cancels the previous in-flight call,
1539
- * making it safe to call repeatedly (e.g. on user input) without leaking promises.
1540
- *
1541
- * If an outer signal is also present (passed at the call site), aborting it
1542
- * propagates into the internal controller.
1543
- *
1544
- * @example
1545
- * ```ts
1546
- * const { task: poll, abort } = Task.abortable(
1547
- * (signal) => waitForEvent(bus, "ready", { signal }),
1548
- * );
1549
- *
1550
- * onUnmount(abort);
1551
- * await poll();
1552
- * ```
1553
- */
1554
- abortable: <A>(factory: (signal: AbortSignal) => Thenable<A>) => {
1555
- task: Task<A>;
1556
- abort: () => void;
1557
- };
1558
- /**
1559
- * Executes a task with an optional signal. Use as a terminal step in a `pipe` chain.
1560
- *
1561
- * @example
1562
- * ```ts
1563
- * const name = await pipe(
1564
- * loadConfig,
1565
- * Task.map(config => config.name),
1566
- * Task.run(),
1567
- * );
1568
- * ```
1569
- */
1570
- run: (signal?: AbortSignal) => <A>(task: Task<A>) => Deferred<A>;
1571
- /**
1572
- * Converts a Task value into an object containing a single property.
1573
- * Initiates the pipeline accumulator record.
1574
- *
1575
- * @example
1576
- * ```ts
1577
- * pipe(Task.resolve(42), Task.bindTo("value")); // Task({ value: 42 })
1578
- * ```
1579
- */
1580
- bindTo: <K extends string>(key: K) => <A>(data: Task<A>) => Task<{ [P in K]: A; }>;
1581
- /**
1582
- * Evaluates a new Task using the current accumulator and attaches the output to a new key.
1583
- *
1584
- * @example
1585
- * ```ts
1586
- * pipe(
1587
- * Task.resolve({ a: 1 }),
1588
- * Task.bind("b", ({ a }) => Task.resolve(a + 1))
1589
- * ); // Task({ a: 1, b: 2 })
1590
- * ```
1591
- */
1592
- bind: <K extends string, A, B>(key: K, f: (a: A) => Task<B>) => (data: Task<A>) => Task<A & { [P in K]: B; }>;
1593
- /**
1594
- * Creates a memoized version of a Task. The task is executed at most once on first call,
1595
- * and its resolved value is cached for all subsequent calls.
1596
- *
1597
- * @example
1598
- * ```ts
1599
- * const loadToken = Task.memoize(loadAuthToken);
1600
- * const token1 = await loadToken(); // loads token
1601
- * const token2 = await loadToken(); // returns cached token immediately
1602
- * ```
1603
- */
1604
- memoize: <A>(task: Task<A>) => Task<A>;
1605
- /**
1606
- * Monitors progress of a Task by calling `onProgress(0)` before execution and `onProgress(1)` upon completion.
1607
- *
1608
- * @example
1609
- * ```ts
1610
- * const taskWithProgress = pipe(
1611
- * readTask,
1612
- * Task.withProgress((ratio) => console.log(`Progress: ${ratio * 100}%`))
1613
- * );
1614
- * ```
1615
- */
1616
- withProgress: <A>(onProgress: (ratio: number) => void) => (task: Task<A>) => Task<A>;
1617
- /**
1618
- * Attaches a read-only `.label` property to a Task, preserving the literal string generic type for IDE tooltips.
1619
- *
1620
- * @example
1621
- * ```ts
1622
- * const labeledTask = pipe(readTask, Task.withLabel("readUser"));
1623
- * console.log(labeledTask.label); // "readUser"
1624
- * ```
1625
- */
1626
- withLabel: <L extends string>(label: L) => <A>(task: Task<A>) => Task.LabeledTask<L, A>;
1627
- Maybe: {
1628
- make: {
1629
- some: <A>(value: A) => Task.Maybe<A>;
1630
- none: <A = never>() => Task.Maybe<A>;
1631
- };
1632
- from: {
1633
- Maybe: <A>(option: Maybe<A>) => Task.Maybe<A>;
1634
- nullable: <A>(value: A | null | undefined) => Task.Maybe<A>;
1635
- Result: <E, A>(result: Result<E, A>) => Task.Maybe<A>;
1636
- Task: <A>(task: Task<A>) => Task.Maybe<A>;
1637
- };
1638
- tryCatch: <A>(f: (signal?: AbortSignal) => Thenable<A>) => Task.Maybe<A>;
1639
- map: <A, B>(f: (a: A) => B) => (data: Task.Maybe<A>) => Task.Maybe<B>;
1640
- chain: <A, B>(f: (a: A) => Task.Maybe<B>) => (data: Task.Maybe<A>) => Task.Maybe<B>;
1641
- ap: <A>(arg: Task.Maybe<A>) => <B>(data: Task.Maybe<(a: A) => B>) => Task.Maybe<B>;
1642
- fold: <A, B>(onNone: () => B, onSome: (a: A) => B) => (data: Task.Maybe<A>) => Task<B>;
1643
- match: <A, B>(cases: {
1644
- none: () => B;
1645
- some: (a: A) => B;
1646
- }) => (data: Task.Maybe<A>) => Task<B>;
1647
- getOrElse: <B>(defaultValue: () => B) => <A>(data: Task.Maybe<A>) => Task<A | B>;
1648
- tap: <A>(f: (a: A) => void) => (data: Task.Maybe<A>) => Task.Maybe<A>;
1649
- filter: <A>(predicate: (a: A) => boolean) => (data: Task.Maybe<A>) => Task.Maybe<A>;
1650
- to: {
1651
- Result: <E>(onNone: () => E) => <A>(data: Task.Maybe<A>) => Task.Result<E, A>;
1652
- };
1653
- bindTo: <K extends string>(key: K) => <A>(data: Task.Maybe<A>) => Task.Maybe<{ [P in K]: A; }>;
1654
- bind: <K extends string, A, B>(key: K, f: (a: A) => Task.Maybe<B>) => (data: Task.Maybe<A>) => Task.Maybe<A & { [P in K]: B; }>;
1655
- recover: <B>(fallback: () => Task.Maybe<B>) => <A>(data: Task.Maybe<A>) => Task.Maybe<A | B>;
1656
- struct: <R extends Record<string, any>>(fields: { [K in keyof R]: Task.Maybe<R[K]>; }) => Task.Maybe<R>;
1657
- memoize: <A>(task: Task.Maybe<A>) => Task.Maybe<A>;
1658
- };
1659
- Result: {
1660
- make: {
1661
- ok: <E = never, A = unknown>(value: A) => Task.Result<E, A>;
1662
- err: <E, A = never>(error: E) => Task.Result<E, A>;
1663
- };
1664
- from: {
1665
- nullable: <E>(onNull: () => E) => <A>(value: A | null | undefined) => Task.Result<E, A>;
1666
- Maybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => Task.Result<E, A>;
1667
- Result: <E, A>(result: Result<E, A>) => Task.Result<E, A>;
1668
- };
1669
- to: {
1670
- Maybe: <E, A>(data: Task.Result<E, A>) => Task.Maybe<A>;
1671
- };
1672
- tryCatch: <E, A>(f: (signal?: AbortSignal) => Thenable<A>, options: {
1673
- onError: (error: unknown) => E;
1674
- }) => Task.Result<E, A>;
1675
- map: <E, A, B>(f: (a: A) => B) => (data: Task.Result<E, A>) => Task.Result<E, B>;
1676
- mapError: <E, F, A>(f: (e: E) => F) => (data: Task.Result<E, A>) => Task.Result<F, A>;
1677
- chain: <E2, A, B>(f: (a: A) => Task.Result<E2, B>) => <E1 = never>(data: Task.Result<E1, A>) => Task.Result<E1 | E2, B>;
1678
- fold: <E, A, B>(onErr: (e: E) => B, onOk: (a: A) => B) => (data: Task.Result<E, A>) => Task<B>;
1679
- match: <E, A, B>(cases: {
1680
- err: (e: E) => B;
1681
- ok: (a: A) => B;
1682
- }) => (data: Task.Result<E, A>) => Task<B>;
1683
- recover: <E, B>(fallback: (e: E) => Task.Result<E, B>) => <A>(data: Task.Result<E, A>) => Task.Result<E, A | B>;
1684
- recoverUnless: <E, B>(isBlocked: (e: E) => boolean, fallback: (e: E) => Task.Result<E, B>) => <A>(data: Task.Result<E, A>) => Task.Result<E, A | B>;
1685
- getOrElse: <B>(defaultValue: () => B) => <E, A>(data: Task.Result<E, A>) => Task<A | B>;
1686
- tap: <E, A>(f: (a: A) => void) => (data: Task.Result<E, A>) => Task.Result<E, A>;
1687
- tapError: <E, A>(f: (e: E) => void) => (data: Task.Result<E, A>) => Task.Result<E, A>;
1688
- ap: <E, A>(arg: Task.Result<E, A>) => <B>(data: Task.Result<E, (a: A) => B>) => Task.Result<E, B>;
1689
- run: (signal?: AbortSignal) => <E, A>(task: Task.Result<E, A>) => Deferred<Result<E, A>>;
1690
- bindTo: <K extends string>(key: K) => <E, A>(data: Task.Result<E, A>) => Task.Result<E, { [P in K]: A; }>;
1691
- bind: <K extends string, E, A, B>(key: K, f: (a: A) => Task.Result<E, B>) => (data: Task.Result<E, A>) => Task.Result<E, A & { [P in K]: B; }>;
1692
- struct: <E, R extends Record<string, any>>(fields: { [K in keyof R]: Task.Result<E, R[K]>; }) => Task.Result<E, R>;
1693
- retry: (policy: RetryPolicy) => <E, A>(task: Task.Result<E, A>) => Task.Result<E, A>;
1694
- memoize: <E, A>(task: Task.Result<E, A>) => Task.Result<E, A>;
1695
- timeout: <E2>(options: {
1696
- duration: Duration;
1697
- onTimeout: () => E2;
1698
- }) => <E1 = never, A = unknown>(task: Task.Result<E1, A>) => Task.Result<E1 | E2, A>;
1699
- allSettled: <E, A>(tasks: ReadonlyArray<Task.Result<E, A>>) => Task<ReadonlyArray<Result<E, A>>>;
1700
- };
1701
- Validation: {
1702
- make: {
1703
- passed: <E = never, A = unknown>(value: A) => Task.Validation<E, A>;
1704
- failed: <E, A = never>(error: E) => Task.Validation<E, A>;
1705
- failedAll: <E, A = never>(errors: NonEmptyArr<E>) => Task.Validation<E, A>;
1706
- };
1707
- from: {
1708
- Validation: <E, A>(validation: Validation<E, A>) => Task.Validation<E, A>;
1709
- nullable: <E>(onNull: () => E) => <A>(value: A | null | undefined) => Task.Validation<E, A>;
1710
- Maybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => Task.Validation<E, A>;
1711
- Result: <E, A>(result: Result<E, A>) => Task.Validation<E, A>;
1712
- };
1713
- to: {
1714
- Result: <E1, E2, A>(combineErrors: (errors: NonEmptyArr<E1>) => E2) => (data: Task.Validation<E1, A>) => Task.Result<E2, A>;
1715
- Maybe: <E, A>(data: Task.Validation<E, A>) => Task.Maybe<A>;
1716
- };
1717
- tryCatch: <E, A>(f: (signal?: AbortSignal) => Thenable<A>, options: {
1718
- onError: (error: unknown) => E;
1719
- }) => Task.Validation<E, A>;
1720
- map: <E, A, B>(f: (a: A) => B) => (data: Task.Validation<E, A>) => Task.Validation<E, B>;
1721
- ap: <E, A>(arg: Task.Validation<E, A>) => <B>(data: Task.Validation<E, (a: A) => B>) => Task.Validation<E, B>;
1722
- fold: <E, A, B>(onFailed: (errors: NonEmptyArr<E>) => B, onPassed: (a: A) => B) => (data: Task.Validation<E, A>) => Task<B>;
1723
- match: <E, A, B>(cases: {
1724
- passed: (a: A) => B;
1725
- failed: (errors: NonEmptyArr<E>) => B;
1726
- }) => (data: Task.Validation<E, A>) => Task<B>;
1727
- getOrElse: <B>(defaultValue: () => B) => <E, A>(data: Task.Validation<E, A>) => Task<A | B>;
1728
- tap: <E, A>(f: (a: A) => void) => (data: Task.Validation<E, A>) => Task.Validation<E, A>;
1729
- recover: <E, B>(fallback: (errors: NonEmptyArr<E>) => Task.Validation<E, B>) => <A>(data: Task.Validation<E, A>) => Task.Validation<E, A | B>;
1730
- recoverUnless: <E, B>(isBlocked: (errors: NonEmptyArr<E>) => boolean, fallback: (errors: NonEmptyArr<E>) => Task.Validation<E, B>) => <A>(data: Task.Validation<E, A>) => Task.Validation<E, A | B>;
1731
- product: <E, A, B>(first: Task.Validation<E, A>, second: Task.Validation<E, B>) => Task.Validation<E, readonly [A, B]>;
1732
- productAll: <E, A>(data: NonEmptyArr<Task.Validation<E, A>>) => Task.Validation<E, readonly A[]>;
1733
- mapError: <E, F, A>(f: (e: E) => F) => (data: Task.Validation<E, A>) => Task.Validation<F, A>;
1734
- tapError: <E, A>(f: (errors: NonEmptyArr<E>) => void) => (data: Task.Validation<E, A>) => Task.Validation<E, A>;
1735
- struct: <E, R extends Record<string, any>>(fields: { [K in keyof R]: Task.Validation<E, R[K]>; }) => Task.Validation<E, R>;
1736
- memoize: <E, A>(task: Task.Validation<E, A>) => Task.Validation<E, A>;
1737
- };
1738
- };
1739
- declare namespace Task {
1740
- type LabeledTask<L extends string, A> = Task<A> & {
1741
- readonly label: L;
1742
- };
1743
- type Maybe<A> = Task<_CoreMaybe<A>>;
1744
- type Result<E, A> = Task<_CoreResult<E, A>>;
1745
- type Validation<E, A> = Task<_CoreValidation<E, A>>;
1746
- }
1747
-
1748
- 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 };