@nlozgachev/pipelined 0.46.0 → 0.48.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,5 +1,6 @@
1
- import { h as WithKind, o as WithValue, e as WithError, T as Thenable, D as Deferred, a as NonEmptyArr, f as WithErrors } from './InternalTypes-Mssktd7z.js';
2
- import { Duration } from './types.js';
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-LdhLQx3N.js';
2
+ import { D as Duration } from './Duration-B8joKzro.js';
3
+ import { RetryPolicy } from './types.js';
3
4
 
4
5
  /**
5
6
  * A function that checks whether two values of type `A` are equal.
@@ -86,6 +87,28 @@ declare namespace Equality {
86
87
  * ```
87
88
  */
88
89
  const 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
+ const 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
+ const tuple: <T extends readonly unknown[]>(...equalities: { [K in keyof T]: Equality<T[K]>; }) => Equality<T>;
89
112
  }
90
113
 
91
114
  type Some<A> = WithKind<"Some"> & WithValue<A>;
@@ -110,30 +133,68 @@ declare namespace Maybe {
110
133
  namespace make {
111
134
  /**
112
135
  * Creates a Some containing the given value.
136
+ *
137
+ * @example
138
+ * ```ts
139
+ * Maybe.make.some(42); // Some(42)
140
+ * ```
113
141
  */
114
142
  const some: <A>(value: A) => Some<A>;
115
143
  /**
116
144
  * Creates a None (empty Maybe).
145
+ *
146
+ * @example
147
+ * ```ts
148
+ * Maybe.make.none(); // None
149
+ * ```
117
150
  */
118
151
  const none: () => None;
119
152
  }
120
153
  namespace is {
121
154
  /**
122
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
+ * ```
123
164
  */
124
165
  const some: <A>(data: Maybe<A>) => data is Some<A>;
125
166
  /**
126
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
+ * ```
127
176
  */
128
177
  const none: <A>(data: Maybe<A>) => data is None;
129
178
  }
130
179
  namespace to {
131
180
  /**
132
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
+ * ```
133
188
  */
134
189
  const nullable: <A>(data: Maybe<A>) => A | null;
135
190
  /**
136
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
+ * ```
137
198
  */
138
199
  const undefined: <A>(data: Maybe<A>) => A | undefined;
139
200
  /**
@@ -293,6 +354,12 @@ declare namespace Maybe {
293
354
  /**
294
355
  * Recovers from a None by providing a fallback Maybe.
295
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
+ * ```
296
363
  */
297
364
  const recover: <A, B>(fallback: () => Maybe<B>) => (data: Maybe<A>) => Maybe<A | B>;
298
365
  /**
@@ -344,6 +411,18 @@ declare namespace Maybe {
344
411
  * ```
345
412
  */
346
413
  const 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
+ const transposeResult: <E, A>(data: Maybe<Result<E, A>>) => Result<E, Maybe<A>>;
347
426
  }
348
427
 
349
428
  /**
@@ -422,6 +501,28 @@ declare namespace Ordering {
422
501
  * ```
423
502
  */
424
503
  const 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
+ const 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
+ const tuple: <T extends readonly unknown[]>(...orderings: { [K in keyof T]: Ordering<T[K]>; }) => Ordering<T>;
425
526
  }
426
527
 
427
528
  type Ok<A> = WithKind<"Ok"> & WithValue<A>;
@@ -447,20 +548,46 @@ declare namespace Result {
447
548
  namespace make {
448
549
  /**
449
550
  * Creates a successful Result with the given value.
551
+ *
552
+ * @example
553
+ * ```ts
554
+ * Result.make.ok(42); // Ok(42)
555
+ * ```
450
556
  */
451
557
  const ok: <A>(value: A) => Ok<A>;
452
558
  /**
453
559
  * Creates a failed Result with the given error.
560
+ *
561
+ * @example
562
+ * ```ts
563
+ * Result.make.err("Error message"); // Err("Error message")
564
+ * ```
454
565
  */
455
566
  const err: <E>(e: E) => Err<E>;
456
567
  }
457
568
  namespace is {
458
569
  /**
459
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
+ * ```
460
579
  */
461
580
  const ok: <E, A>(data: Result<E, A>) => data is Ok<A>;
462
581
  /**
463
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
+ * ```
464
591
  */
465
592
  const err: <E, A>(data: Result<E, A>) => data is Err<E>;
466
593
  }
@@ -473,11 +600,13 @@ declare namespace Result {
473
600
  * const parseJson = (s: string): Result<string, unknown> =>
474
601
  * Result.tryCatch(
475
602
  * () => JSON.parse(s),
476
- * (e) => `Parse error: ${e}`
603
+ * { onError: (e) => `Parse error: ${e}` }
477
604
  * );
478
605
  * ```
479
606
  */
480
- const tryCatch: <E, A>(f: () => A, onError: (e: unknown) => E) => Result<E, A>;
607
+ const tryCatch: <E, A>(f: () => A, options: {
608
+ onError: (e: unknown) => E;
609
+ }) => Result<E, A>;
481
610
  /**
482
611
  * Transforms the success value inside a Result.
483
612
  *
@@ -510,7 +639,7 @@ declare namespace Result {
510
639
  * pipe(Result.make.ok(-1), Result.chain(validatePositive)); // Err("Must be positive")
511
640
  * ```
512
641
  */
513
- const chain: <E, A, B>(f: (a: A) => Result<E, B>) => (data: Result<E, A>) => Result<E, B>;
642
+ const chain: <E1, E2, A, B>(f: (a: A) => Result<E2, B>) => (data: Result<E1, A>) => Result<E1 | E2, B>;
514
643
  /**
515
644
  * Extracts the value from a Result by providing handlers for both cases.
516
645
  *
@@ -628,14 +757,26 @@ declare namespace Result {
628
757
  * ```ts
629
758
  * const safeParse = Result.from.throwable(
630
759
  * (s: string) => JSON.parse(s),
631
- * (e) => new Error(`Parse error: ${e}`)
760
+ * { onError: (e) => new Error(`Parse error: ${e}`) }
632
761
  * );
633
762
  *
634
763
  * safeParse('{"a":1}'); // Ok({ a: 1 })
635
764
  * safeParse('invalid'); // Err(Error)
636
765
  * ```
637
766
  */
638
- const throwable: <Args extends readonly unknown[], A, E>(f: (...args: Args) => A, onError: (e: unknown) => E) => (...args: Args) => Result<E, A>;
767
+ const throwable: <Args extends readonly unknown[], A, E>(f: (...args: Args) => A, options: {
768
+ onError: (e: unknown) => E;
769
+ }) => (...args: Args) => Result<E, A>;
770
+ /**
771
+ * Converts a `Validation` to a `Result`, combining accumulated errors using `combineErrors`.
772
+ * `Passed(a)` becomes `Ok(a)`; `Failed(errors)` becomes `Err(combineErrors(errors))`.
773
+ *
774
+ * @example
775
+ * ```ts
776
+ * Result.from.Validation((errors) => errors.join(", "))(Validation.make.failed("error1")); // Err("error1")
777
+ * ```
778
+ */
779
+ const Validation: <E1, E2, A>(combineErrors: (errors: NonEmptyArr<E1>) => E2) => (val: Validation<E1, A>) => Result<E2, A>;
639
780
  }
640
781
  /**
641
782
  * Recovers from an error by providing a fallback Result.
@@ -667,7 +808,29 @@ declare namespace Result {
667
808
  * ```
668
809
  */
669
810
  const Maybe: <E, A>(data: Result<E, A>) => Maybe<A>;
811
+ /**
812
+ * Converts a `Result` to a `Validation`. `Ok(a)` becomes `Passed(a)`; `Err(e)` becomes `Failed([e])`.
813
+ *
814
+ * @example
815
+ * ```ts
816
+ * Result.to.Validation(Result.make.ok(42)); // Passed(42)
817
+ * Result.to.Validation(Result.make.err("bad")); // Failed(["bad"])
818
+ * ```
819
+ */
820
+ const Validation: <E, A>(data: Result<E, A>) => Validation<E, A>;
670
821
  }
822
+ /**
823
+ * Swaps the outer `Result` and inner `Maybe` context.
824
+ * `Ok(Some(a))` becomes `Some(Ok(a))`, `Ok(None)` becomes `None`, and `Err(e)` becomes `Some(Err(e))`.
825
+ *
826
+ * @example
827
+ * ```ts
828
+ * Result.transposeMaybe(Result.make.ok(Maybe.make.some(42))); // Some(Ok(42))
829
+ * Result.transposeMaybe(Result.make.ok(Maybe.make.none())); // None
830
+ * Result.transposeMaybe(Result.make.err("error")); // Some(Err("error"))
831
+ * ```
832
+ */
833
+ const transposeMaybe: <E, A>(data: Result<E, Maybe<A>>) => Maybe<Result<E, A>>;
671
834
  /**
672
835
  * Applies a function wrapped in a Result to a value wrapped in a Result.
673
836
  *
@@ -717,6 +880,34 @@ declare namespace Result {
717
880
  * ```
718
881
  */
719
882
  const struct: <E, R extends Record<string, any>>(fields: { [K in keyof R]: Result<E, R[K]>; }) => Result<E, R>;
883
+ /**
884
+ * Narrows an `Ok` value with a predicate, converting to `Err(onFail(a))` if the predicate returns false.
885
+ *
886
+ * @example
887
+ * ```ts
888
+ * pipe(
889
+ * Result.make.ok(15),
890
+ * Result.ensure((n) => n >= 18, (n) => `Age ${n} is below 18`)
891
+ * ); // Err("Age 15 is below 18")
892
+ * ```
893
+ */
894
+ const ensure: <A, E2>(predicate: (a: A) => boolean, onFail: (a: A) => E2) => <E1>(data: Result<E1, A>) => Result<E1 | E2, A>;
895
+ /**
896
+ * Transforms both branches of a Result simultaneously.
897
+ * Applies `onErr` to `Err` values and `onOk` to `Ok` values.
898
+ *
899
+ * @example
900
+ * ```ts
901
+ * pipe(
902
+ * Result.make.ok(5),
903
+ * Result.bimap(
904
+ * (e) => `Error: ${e}`,
905
+ * (n) => n * 2
906
+ * )
907
+ * ); // Ok(10)
908
+ * ```
909
+ */
910
+ const bimap: <E1, E2, A, B>(onErr: (e: E1) => E2, onOk: (a: A) => B) => (data: Result<E1, A>) => Result<E2, B>;
720
911
  }
721
912
 
722
913
  /**
@@ -737,29 +928,76 @@ type TaskMaybe<A> = Task<Maybe<A>>;
737
928
  declare namespace TaskMaybe {
738
929
  /**
739
930
  * Wraps a value in a Some inside a Task.
931
+ *
932
+ * @example
933
+ * ```ts
934
+ * const task = Task.Maybe.some(42);
935
+ * const res = await task(); // Some(42)
936
+ * ```
740
937
  */
938
+ namespace make {
939
+ /**
940
+ * Creates a Task.Maybe that resolves to Some(value).
941
+ *
942
+ * @example
943
+ * ```ts
944
+ * const task = Task.Maybe.make.some(42);
945
+ * const res = await task(); // Some(42)
946
+ * ```
947
+ */
948
+ const some: <A>(value: A) => TaskMaybe<A>;
949
+ /**
950
+ * Creates a Task.Maybe that resolves to None.
951
+ *
952
+ * @example
953
+ * ```ts
954
+ * const task = Task.Maybe.make.none();
955
+ * const res = await task(); // None
956
+ * ```
957
+ */
958
+ const none: <A = never>() => TaskMaybe<A>;
959
+ }
741
960
  const some: <A>(value: A) => TaskMaybe<A>;
742
- /**
743
- * Creates a Task.Maybe that resolves to None.
744
- */
745
961
  const none: <A = never>() => TaskMaybe<A>;
746
962
  namespace from {
747
963
  /**
748
- * Lifts an Option into a Task.Maybe.
964
+ * Lifts a Maybe into a Task.Maybe.
965
+ *
966
+ * @example
967
+ * ```ts
968
+ * Task.Maybe.from.Maybe(Maybe.make.some(42));
969
+ * ```
749
970
  */
750
971
  const Maybe: <A>(option: Maybe<A>) => TaskMaybe<A>;
751
972
  /**
752
973
  * Creates a Task.Maybe from a nullable value.
753
974
  * Returns Some if the value is not null or undefined, None otherwise.
975
+ *
976
+ * @example
977
+ * ```ts
978
+ * Task.Maybe.from.nullable(42); // resolves to Some(42)
979
+ * Task.Maybe.from.nullable(null); // resolves to None
980
+ * ```
754
981
  */
755
982
  const nullable: <A>(value: A | null | undefined) => TaskMaybe<A>;
756
983
  /**
757
984
  * Creates a Task.Maybe from a Result.
758
985
  * Ok becomes Some, Error becomes None (the error value is discarded).
986
+ *
987
+ * @example
988
+ * ```ts
989
+ * Task.Maybe.from.Result(Result.make.ok(42)); // resolves to Some(42)
990
+ * Task.Maybe.from.Result(Result.make.err("e")); // resolves to None
991
+ * ```
759
992
  */
760
993
  const Result: <E, A>(result: Result<E, A>) => TaskMaybe<A>;
761
994
  /**
762
995
  * Lifts a Task into a Task.Maybe by wrapping its result in Some.
996
+ *
997
+ * @example
998
+ * ```ts
999
+ * Task.Maybe.from.Task(Task.resolve(42)); // resolves to Some(42)
1000
+ * ```
763
1001
  */
764
1002
  const Task: <A>(task: Task<A>) => TaskMaybe<A>;
765
1003
  }
@@ -905,40 +1143,87 @@ declare namespace TaskMaybe {
905
1143
  * const fetchUser = (id: string): Task.Result<Error, User> =>
906
1144
  * Task.Result.tryCatch(
907
1145
  * (signal) => fetch(`/users/${id}`, { signal }).then(r => r.json()),
908
- * (e) => new Error(`Failed to fetch user: ${e}`)
1146
+ * { onError: (e) => new Error(`Failed to fetch user: ${e}`) }
909
1147
  * );
910
1148
  * ```
911
1149
  */
912
1150
  type TaskResult<E, A> = Task<Result<E, A>>;
913
1151
  declare namespace TaskResult {
914
- /**
915
- * Wraps a value in a successful Task.Result.
916
- */
1152
+ namespace make {
1153
+ /**
1154
+ * Wraps a value in a successful Task.Result.
1155
+ *
1156
+ * @example
1157
+ * ```ts
1158
+ * const task = Task.Result.make.ok(42);
1159
+ * const res = await task(); // Ok(42)
1160
+ * ```
1161
+ */
1162
+ const ok: <E, A>(value: A) => TaskResult<E, A>;
1163
+ /**
1164
+ * Creates a failed Task.Result with the given error.
1165
+ *
1166
+ * @example
1167
+ * ```ts
1168
+ * const task = Task.Result.make.err("failed");
1169
+ * const res = await task(); // Err("failed")
1170
+ * ```
1171
+ */
1172
+ const err: <E, A>(error: E) => TaskResult<E, A>;
1173
+ }
917
1174
  const ok: <E, A>(value: A) => TaskResult<E, A>;
918
- /**
919
- * Creates a failed Task.Result with the given error.
920
- */
921
1175
  const err: <E, A>(error: E) => TaskResult<E, A>;
922
1176
  namespace from {
923
1177
  /**
924
1178
  * Creates a Task.Result from a nullable value.
925
1179
  * Returns Ok if the value is not null or undefined, err from onNull otherwise.
1180
+ *
1181
+ * @example
1182
+ * ```ts
1183
+ * Task.Result.from.nullable(() => "missing")(42); // resolves to Ok(42)
1184
+ * Task.Result.from.nullable(() => "missing")(null); // resolves to Err("missing")
1185
+ * ```
926
1186
  */
927
1187
  const nullable: <E>(onNull: () => E) => <A>(value: A | null | undefined) => TaskResult<E, A>;
928
1188
  /**
929
1189
  * Creates a Task.Result from a Maybe.
930
1190
  * Some becomes Ok, None becomes err from onNone.
1191
+ *
1192
+ * @example
1193
+ * ```ts
1194
+ * Task.Result.from.Maybe(() => "empty")(Maybe.make.some(42)); // resolves to Ok(42)
1195
+ * Task.Result.from.Maybe(() => "empty")(Maybe.make.none()); // resolves to Err("empty")
1196
+ * ```
931
1197
  */
932
1198
  const Maybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => TaskResult<E, A>;
933
1199
  /**
934
1200
  * Lifts a Result into a Task.Result.
1201
+ *
1202
+ * @example
1203
+ * ```ts
1204
+ * Task.Result.from.Result(Result.make.ok(42)); // resolves to Ok(42)
1205
+ * ```
935
1206
  */
936
1207
  const Result: <E, A>(result: Result<E, A>) => TaskResult<E, A>;
937
1208
  /**
938
1209
  * Wraps a Promise-returning function of any arguments, returning a new function
939
1210
  * that catches rejections and returns a Task.Result.
940
1211
  */
941
- const throwable: <Args extends readonly unknown[], A, E>(f: (...args: Args) => Promise<A>, onError: (e: unknown) => E) => (...args: Args) => TaskResult<E, A>;
1212
+ const throwable: <Args extends readonly unknown[], A, E>(f: (...args: Args) => Promise<A>, options: {
1213
+ onError: (e: unknown) => E;
1214
+ }) => (...args: Args) => TaskResult<E, A>;
1215
+ }
1216
+ namespace to {
1217
+ /**
1218
+ * Converts a Task.Result to a Task.Maybe, dropping the error value on Err.
1219
+ *
1220
+ * @example
1221
+ * ```ts
1222
+ * const taskResult = Task.Result.ok(42);
1223
+ * const taskMaybe = pipe(taskResult, Task.Result.to.Maybe);
1224
+ * ```
1225
+ */
1226
+ const Maybe: <E, A>(data: TaskResult<E, A>) => TaskMaybe<A>;
942
1227
  }
943
1228
  /**
944
1229
  * Creates a Task.Result from a function that may throw.
@@ -950,11 +1235,13 @@ declare namespace TaskResult {
950
1235
  * const fetchUser = (id: string): Task.Result<string, User> =>
951
1236
  * Task.Result.tryCatch(
952
1237
  * (signal) => fetch(`/users/${id}`, { signal }).then(r => r.json()),
953
- * String
1238
+ * { onError: String }
954
1239
  * );
955
1240
  * ```
956
1241
  */
957
- const tryCatch: <E, A>(f: (signal?: AbortSignal) => Thenable<A>, onError: (e: unknown) => E) => TaskResult<E, A>;
1242
+ const tryCatch: <E, A>(f: (signal?: AbortSignal) => Thenable<A>, options: {
1243
+ onError: (e: unknown) => E;
1244
+ }) => TaskResult<E, A>;
958
1245
  /**
959
1246
  * Transforms the success value inside a Task.Result.
960
1247
  */
@@ -967,7 +1254,7 @@ declare namespace TaskResult {
967
1254
  * Chains Task.Result computations. If the first succeeds, passes the value to f.
968
1255
  * If the first fails, propagates the error.
969
1256
  */
970
- const chain: <E, A, B>(f: (a: A) => TaskResult<E, B>) => (data: TaskResult<E, A>) => TaskResult<E, B>;
1257
+ const chain: <E1, E2, A, B>(f: (a: A) => TaskResult<E2, B>) => (data: TaskResult<E1, A>) => TaskResult<E1 | E2, B>;
971
1258
  /**
972
1259
  * Extracts the value from a Task.Result by providing handlers for both cases.
973
1260
  */
@@ -1065,6 +1352,55 @@ declare namespace TaskResult {
1065
1352
  * ```
1066
1353
  */
1067
1354
  const struct: <E, R extends Record<string, any>>(fields: { [K in keyof R]: TaskResult<E, R[K]>; }) => TaskResult<E, R>;
1355
+ /**
1356
+ * Retries a fallible Task.Result according to a RetryPolicy.
1357
+ * If the task succeeds, returns Ok immediately.
1358
+ * If the task fails, retries up to policy.attempts times with delays generated by policy.
1359
+ *
1360
+ * @example
1361
+ * ```ts
1362
+ * const policy = RetryPolicy.exponential({ attempts: 3, initial: Duration.milliseconds(100) });
1363
+ * const retryableFetch = pipe(fetchData, Task.Result.retry(policy));
1364
+ * ```
1365
+ */
1366
+ const retry: (policy: RetryPolicy) => <E, A>(task: TaskResult<E, A>) => TaskResult<E, A>;
1367
+ /**
1368
+ * Creates a memoized version of a Task.Result. The task is executed at most once on first call,
1369
+ * and its resolved Result is cached for all subsequent calls.
1370
+ *
1371
+ * @example
1372
+ * ```ts
1373
+ * const loadConfig = Task.Result.memoize(fetchConfigTask);
1374
+ * ```
1375
+ */
1376
+ const memoize: <E, A>(task: TaskResult<E, A>) => TaskResult<E, A>;
1377
+ /**
1378
+ * Times out a fallible task, resolving to `Err(onTimeout())` if the duration elapses
1379
+ * before the task completes.
1380
+ *
1381
+ * @example
1382
+ * ```ts
1383
+ * const fetchWithTimeout = pipe(
1384
+ * fetchTask,
1385
+ * Task.Result.timeout({ duration: Duration.seconds(5), onTimeout: () => "Request timed out" })
1386
+ * );
1387
+ * ```
1388
+ */
1389
+ const timeout: <E2>(options: {
1390
+ duration: Duration;
1391
+ onTimeout: () => E2;
1392
+ }) => <E1, A>(task: TaskResult<E1, A>) => TaskResult<E1 | E2, A>;
1393
+ /**
1394
+ * Runs a list of fallible tasks in parallel and collects all outcomes (`Ok` and `Err`)
1395
+ * without short-circuiting on failure.
1396
+ *
1397
+ * @example
1398
+ * ```ts
1399
+ * const results = await Task.Result.allSettled([task1, task2, task3])();
1400
+ * // [Ok(val1), Err(err2), Ok(val3)]
1401
+ * ```
1402
+ */
1403
+ const allSettled: <E, A>(tasks: ReadonlyArray<TaskResult<E, A>>) => Task<ReadonlyArray<Result<E, A>>>;
1068
1404
  }
1069
1405
 
1070
1406
  /**
@@ -1090,37 +1426,83 @@ declare namespace TaskResult {
1090
1426
  */
1091
1427
  type TaskValidation<E, A> = Task<Validation<E, A>>;
1092
1428
  declare namespace TaskValidation {
1093
- /**
1094
- * Wraps a value in a passed Task.Validation.
1095
- */
1429
+ namespace make {
1430
+ /**
1431
+ * Wraps a value in a passed Task.Validation.
1432
+ *
1433
+ * @example
1434
+ * ```ts
1435
+ * const task = Task.Validation.make.passed(42);
1436
+ * const res = await task(); // Passed(42)
1437
+ * ```
1438
+ */
1439
+ const passed: <E, A>(value: A) => TaskValidation<E, A>;
1440
+ /**
1441
+ * Creates a failed Task.Validation with a single error.
1442
+ *
1443
+ * @example
1444
+ * ```ts
1445
+ * const task = Task.Validation.make.failed("invalid");
1446
+ * const res = await task(); // Failed(["invalid"])
1447
+ * ```
1448
+ */
1449
+ const failed: <E, A>(error: E) => TaskValidation<E, A>;
1450
+ /**
1451
+ * Creates a failed Task.Validation from multiple errors.
1452
+ *
1453
+ * @example
1454
+ * ```ts
1455
+ * const task = Task.Validation.make.failedAll(["err1", "err2"]);
1456
+ * const res = await task(); // Failed(["err1", "err2"])
1457
+ * ```
1458
+ */
1459
+ const failedAll: <E, A>(errors: NonEmptyArr<E>) => TaskValidation<E, A>;
1460
+ }
1096
1461
  const passed: <E, A>(value: A) => TaskValidation<E, A>;
1097
- /**
1098
- * Creates a failed Task.Validation with a single error.
1099
- */
1100
1462
  const failed: <E, A>(error: E) => TaskValidation<E, A>;
1101
- /**
1102
- * Creates a failed Task.Validation from multiple errors.
1103
- */
1104
1463
  const failedAll: <E, A>(errors: NonEmptyArr<E>) => TaskValidation<E, A>;
1105
1464
  namespace from {
1106
1465
  /**
1107
1466
  * Lifts a Validation into a Task.Validation.
1467
+ *
1468
+ * @example
1469
+ * ```ts
1470
+ * Task.Validation.from.Validation(Validation.make.passed(42));
1471
+ * ```
1108
1472
  */
1109
1473
  const Validation: <E, A>(validation: Validation<E, A>) => TaskValidation<E, A>;
1110
1474
  /**
1111
1475
  * Creates a Task.Validation from a nullable value.
1112
1476
  * If the value is null or undefined, returns Failed with the error from onNull.
1113
1477
  * Otherwise, returns Passed.
1478
+ *
1479
+ * @example
1480
+ * ```ts
1481
+ * Task.Validation.from.nullable(() => "missing")(42); // resolves to Passed(42)
1482
+ * Task.Validation.from.nullable(() => "missing")(null); // resolves to Failed(["missing"])
1483
+ * ```
1114
1484
  */
1115
1485
  const nullable: <E>(onNull: () => E) => <A>(value: A | null | undefined) => TaskValidation<E, A>;
1116
1486
  /**
1117
1487
  * Creates a Task.Validation from a Maybe.
1118
1488
  * Some becomes Passed, None becomes Failed with the error from onNone.
1489
+ *
1490
+ * @example
1491
+ * ```ts
1492
+ * Task.Validation.from.Maybe(() => "empty")(Maybe.make.some(42)); // resolves to Passed(42)
1493
+ * Task.Validation.from.Maybe(() => "empty")(Maybe.make.none()); // resolves to Failed(["empty"])
1494
+ * ```
1119
1495
  */
1120
1496
  const Maybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => TaskValidation<E, A>;
1121
1497
  /**
1122
1498
  * Creates a Task.Validation from a Result.
1123
1499
  * Ok becomes Passed, Err(e) becomes Failed([e]).
1500
+ *
1501
+ * @example
1502
+ * ```ts
1503
+ * Task.Validation.from.Result(Result.make.ok(42)); // resolves to Passed(42)
1504
+ * Task.Validation.from.Result(Result.make.err("bad")); // resolves to Failed(["bad"])
1505
+ * ```
1124
1506
  */
1125
1507
  const Result: <E, A>(result: Result<E, A>) => TaskValidation<E, A>;
1126
1508
  }
@@ -1508,12 +1890,15 @@ declare namespace Task {
1508
1890
  * ```ts
1509
1891
  * pipe(
1510
1892
  * heavyComputation,
1511
- * Task.timeout(Duration.seconds(5), () => "timed out"),
1893
+ * Task.timeout({ duration: Duration.seconds(5), onTimeout: () => "timed out" }),
1512
1894
  * Task.Result.chain(processResult)
1513
1895
  * );
1514
1896
  * ```
1515
1897
  */
1516
- const timeout: <E>(duration: Duration, onTimeout: () => E) => <A>(task: Task<A>) => Task<Result<E, A>>;
1898
+ const timeout: <E>(options: {
1899
+ duration: Duration;
1900
+ onTimeout: () => E;
1901
+ }) => <A>(task: Task<A>) => Task<Result<E, A>>;
1517
1902
  /**
1518
1903
  * Creates a Task paired with an `abort` handle. Calling `abort()` cancels the
1519
1904
  * current in-flight call immediately. Unlike a one-shot abort, calling `task()`
@@ -1574,6 +1959,43 @@ declare namespace Task {
1574
1959
  * ```
1575
1960
  */
1576
1961
  const bind: <K extends string, A, B>(key: K, f: (a: A) => Task<B>) => (data: Task<A>) => Task<A & { [P in K]: B; }>;
1962
+ /**
1963
+ * Creates a memoized version of a Task. The task is executed at most once on first call,
1964
+ * and its resolved value is cached for all subsequent calls.
1965
+ *
1966
+ * @example
1967
+ * ```ts
1968
+ * const loadToken = Task.memoize(loadAuthToken);
1969
+ * const token1 = await loadToken(); // loads token
1970
+ * const token2 = await loadToken(); // returns cached token immediately
1971
+ * ```
1972
+ */
1973
+ const memoize: <A>(task: Task<A>) => Task<A>;
1974
+ /**
1975
+ * Monitors progress of a Task by calling `onProgress(0)` before execution and `onProgress(1)` upon completion.
1976
+ *
1977
+ * @example
1978
+ * ```ts
1979
+ * const taskWithProgress = pipe(
1980
+ * readTask,
1981
+ * Task.withProgress((ratio) => console.log(`Progress: ${ratio * 100}%`))
1982
+ * );
1983
+ * ```
1984
+ */
1985
+ const withProgress: <A>(onProgress: (ratio: number) => void) => (task: Task<A>) => Task<A>;
1986
+ type LabeledTask<L extends string, A> = Task<A> & {
1987
+ readonly label: L;
1988
+ };
1989
+ /**
1990
+ * Attaches a read-only `.label` property to a Task, preserving the literal string generic type for IDE tooltips.
1991
+ *
1992
+ * @example
1993
+ * ```ts
1994
+ * const labeledTask = pipe(readTask, Task.withLabel("readUser"));
1995
+ * console.log(labeledTask.label); // "readUser"
1996
+ * ```
1997
+ */
1998
+ const withLabel: <L extends string>(label: L) => <A>(task: Task<A>) => LabeledTask<L, A>;
1577
1999
  type Maybe<A> = TaskMaybe<A>;
1578
2000
  const Maybe: typeof TaskMaybe;
1579
2001
  type Result<E, A> = TaskResult<E, A>;
@@ -1643,13 +2065,45 @@ declare namespace Validation {
1643
2065
  namespace is {
1644
2066
  /**
1645
2067
  * Type guard that checks if a Validation is passed.
2068
+ *
2069
+ * @example
2070
+ * ```ts
2071
+ * const v = Validation.make.passed(42);
2072
+ * if (Validation.is.passed(v)) {
2073
+ * console.log(v.value); // 42
2074
+ * }
2075
+ * ```
1646
2076
  */
1647
2077
  const passed: <E, A>(data: Validation<E, A>) => data is Passed<A>;
1648
2078
  /**
1649
2079
  * Type guard that checks if a Validation is failed.
2080
+ *
2081
+ * @example
2082
+ * ```ts
2083
+ * const v = Validation.make.failed("invalid");
2084
+ * if (Validation.is.failed(v)) {
2085
+ * console.log(v.errors); // ["invalid"]
2086
+ * }
2087
+ * ```
1650
2088
  */
1651
2089
  const failed: <E, A>(data: Validation<E, A>) => data is Failed<E>;
1652
2090
  }
2091
+ /**
2092
+ * Creates a Validation from a function that may throw.
2093
+ * Catches any errors and transforms them using the onError function into a Failed validation.
2094
+ *
2095
+ * @example
2096
+ * ```ts
2097
+ * const parseJson = (s: string): Validation<string, unknown> =>
2098
+ * Validation.tryCatch(
2099
+ * () => JSON.parse(s),
2100
+ * { onError: (e) => `Parse error: ${e}` }
2101
+ * );
2102
+ * ```
2103
+ */
2104
+ const tryCatch: <E, A>(f: () => A, options: {
2105
+ onError: (e: unknown) => E;
2106
+ }) => Validation<E, A>;
1653
2107
  namespace from {
1654
2108
  /**
1655
2109
  * Creates a Validation from a predicate applied to a value.
@@ -1739,12 +2193,24 @@ declare namespace Validation {
1739
2193
  *
1740
2194
  * pipe(
1741
2195
  * Validation.make.passed(add),
1742
- * Validation.ap(Validation.make.failed<string, number>("bad a")),
1743
- * Validation.ap(Validation.make.failed<string, number>("bad b"))
2196
+ * Validation.ap(Validation.make.failed<string>("bad a")),
2197
+ * Validation.ap(Validation.make.failed<string>("bad b"))
1744
2198
  * ); // Failed(["bad a", "bad b"])
1745
2199
  * ```
1746
2200
  */
1747
2201
  const ap: <E, A>(arg: Validation<E, A>) => <B>(data: Validation<E, (a: A) => B>) => Validation<E, B>;
2202
+ /**
2203
+ * Applies a function wrapped in a Validation to a value wrapped in a Validation,
2204
+ * using a custom error concatenator function when both sides fail.
2205
+ *
2206
+ * @example
2207
+ * ```ts
2208
+ * const concat = (e1: NonEmptyArr<string>, e2: NonEmptyArr<string>): NonEmptyArr<string> =>
2209
+ * [...e1, ...e2];
2210
+ * pipe(fnVal, Validation.apCustom(concat)(argVal));
2211
+ * ```
2212
+ */
2213
+ const 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>;
1748
2214
  /**
1749
2215
  * Extracts the value from a Validation by providing handlers for both cases.
1750
2216
  *
@@ -1839,15 +2305,19 @@ declare namespace Validation {
1839
2305
  namespace to {
1840
2306
  /**
1841
2307
  * Converts a Validation to a Result.
1842
- * Passed becomes Ok, Failed becomes Err with the accumulated error list.
2308
+ * Passed becomes Ok.
2309
+ * Direct call converts Failed to Err with accumulated error list `NonEmptyArr<E>`.
2310
+ * Curried call converts Failed to Err with combined error `E2` via `combineErrors`.
1843
2311
  *
1844
2312
  * @example
1845
2313
  * ```ts
1846
2314
  * Validation.to.Result(Validation.make.passed(42)); // Ok(42)
1847
2315
  * Validation.to.Result(Validation.make.failed("oops")); // Err(["oops"])
2316
+ * pipe(Validation.make.failed("oops"), Validation.to.Result(errors => errors.join(", "))); // Err("oops")
1848
2317
  * ```
1849
2318
  */
1850
- const Result: <E, A>(data: Validation<E, A>) => Result<NonEmptyArr<E>, A>;
2319
+ function Result<E1, E2, A>(combineErrors: (errors: NonEmptyArr<E1>) => E2): (val: Validation<E1, A>) => Result<E2, A>;
2320
+ function Result<E, A>(data: Validation<E, A>): Result<NonEmptyArr<E>, A>;
1851
2321
  /**
1852
2322
  * Converts a Validation to a Maybe. `Passed` becomes `Some`; `Failed` becomes `None`
1853
2323
  * (errors are discarded).