@nlozgachev/pipelined 0.54.0 → 0.56.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,4 +1,4 @@
1
- import { D as Duration } from './Duration-B8joKzro.mjs';
1
+ import { D as Duration } from './Duration-B8joKzro.cjs';
2
2
 
3
3
  declare const _deferred: unique symbol;
4
4
  /**
@@ -1,6 +1,6 @@
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-CDiDBAY4.mjs';
2
- import { D as Duration } from './Duration-B8joKzro.mjs';
3
- import { RetryPolicy } from './types.mjs';
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-DuK_XpTi.cjs';
2
+ import { D as Duration } from './Duration-B8joKzro.cjs';
3
+ import { RetryPolicy } from './types.cjs';
4
4
 
5
5
  /**
6
6
  * A function that checks whether two values of type `A` are equal.
@@ -595,13 +595,16 @@ declare namespace Result {
595
595
  * Creates a Result from a function that may throw.
596
596
  * Catches any errors and transforms them using the onError function.
597
597
  *
598
+ /**
599
+ * Creates a Result from a synchronous thunk that may throw.
600
+ * Catches any errors and transforms them using the `onError` function.
601
+ *
598
602
  * @example
599
603
  * ```ts
600
- * const parseJson = (s: string): Result<string, unknown> =>
601
- * Result.tryCatch(
602
- * () => JSON.parse(s),
603
- * { onError: (e) => `Parse error: ${e}` }
604
- * );
604
+ * const result = Result.tryCatch(
605
+ * () => JSON.parse(rawString),
606
+ * { onError: (e) => `Parse error: ${e}` }
607
+ * );
605
608
  * ```
606
609
  */
607
610
  const tryCatch: <E, A>(f: () => A, options: {
@@ -749,24 +752,6 @@ declare namespace Result {
749
752
  * ```
750
753
  */
751
754
  const Maybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => Result<E, A>;
752
- /**
753
- * Wraps a throwing function of any arguments, returning a new function
754
- * that catches errors and returns a Result.
755
- *
756
- * @example
757
- * ```ts
758
- * const safeParse = Result.from.throwable(
759
- * (s: string) => JSON.parse(s),
760
- * { onError: (e) => new Error(`Parse error: ${e}`) }
761
- * );
762
- *
763
- * safeParse('{"a":1}'); // Ok({ a: 1 })
764
- * safeParse('invalid'); // Err(Error)
765
- * ```
766
- */
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
755
  /**
771
756
  * Converts a `Validation` to a `Result`, combining accumulated errors using `combineErrors`.
772
757
  * `Passed(a)` becomes `Ok(a)`; `Failed(errors)` becomes `Err(combineErrors(errors))`.
@@ -1132,6 +1117,16 @@ declare namespace TaskMaybe {
1132
1117
  * ```
1133
1118
  */
1134
1119
  const struct: <R extends Record<string, any>>(fields: { [K in keyof R]: TaskMaybe<R[K]>; }) => TaskMaybe<R>;
1120
+ /**
1121
+ * Creates a memoized version of a Task.Maybe. The task is executed at most once on first call,
1122
+ * and its resolved Maybe is cached for all subsequent calls.
1123
+ *
1124
+ * @example
1125
+ * ```ts
1126
+ * const loadUser = Task.Maybe.memoize(fetchUserMaybeTask);
1127
+ * ```
1128
+ */
1129
+ const memoize: <A>(task: TaskMaybe<A>) => TaskMaybe<A>;
1135
1130
  }
1136
1131
 
1137
1132
  /**
@@ -1159,7 +1154,7 @@ declare namespace TaskResult {
1159
1154
  * const res = await task(); // Ok(42)
1160
1155
  * ```
1161
1156
  */
1162
- const ok: <E, A>(value: A) => TaskResult<E, A>;
1157
+ const ok: <E = never, A = unknown>(value: A) => TaskResult<E, A>;
1163
1158
  /**
1164
1159
  * Creates a failed Task.Result with the given error.
1165
1160
  *
@@ -1169,10 +1164,10 @@ declare namespace TaskResult {
1169
1164
  * const res = await task(); // Err("failed")
1170
1165
  * ```
1171
1166
  */
1172
- const err: <E, A>(error: E) => TaskResult<E, A>;
1167
+ const err: <E, A = never>(error: E) => TaskResult<E, A>;
1173
1168
  }
1174
- const ok: <E, A>(value: A) => TaskResult<E, A>;
1175
- const err: <E, A>(error: E) => TaskResult<E, A>;
1169
+ const ok: <E = never, A = unknown>(value: A) => TaskResult<E, A>;
1170
+ const err: <E, A = never>(error: E) => TaskResult<E, A>;
1176
1171
  namespace from {
1177
1172
  /**
1178
1173
  * Creates a Task.Result from a nullable value.
@@ -1204,14 +1199,15 @@ declare namespace TaskResult {
1204
1199
  * Task.Result.from.Result(Result.make.ok(42)); // resolves to Ok(42)
1205
1200
  * ```
1206
1201
  */
1207
- const Result: <E, A>(result: Result<E, A>) => TaskResult<E, A>;
1208
1202
  /**
1209
- * Wraps a Promise-returning function of any arguments, returning a new function
1210
- * that catches rejections and returns a Task.Result.
1203
+ * Lifts a Result into a Task.Result.
1204
+ *
1205
+ * @example
1206
+ * ```ts
1207
+ * Task.Result.from.Result(Result.make.ok(42)); // resolves to Ok(42)
1208
+ * ```
1211
1209
  */
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>;
1210
+ const Result: <E, A>(result: Result<E, A>) => TaskResult<E, A>;
1215
1211
  }
1216
1212
  namespace to {
1217
1213
  /**
@@ -1226,21 +1222,20 @@ declare namespace TaskResult {
1226
1222
  const Maybe: <E, A>(data: TaskResult<E, A>) => TaskMaybe<A>;
1227
1223
  }
1228
1224
  /**
1229
- * Creates a Task.Result from a function that may throw.
1230
- * Catches any errors and transforms them using the onError function.
1231
- * The factory optionally receives an `AbortSignal` forwarded from the call site.
1225
+ * Creates a Task.Result from a Promise-returning thunk that may throw or reject.
1226
+ * Catches any errors and transforms them using the `onError` function into an `Err`.
1227
+ * The thunk optionally receives an `AbortSignal` forwarded from the call site.
1232
1228
  *
1233
1229
  * @example
1234
1230
  * ```ts
1235
- * const fetchUser = (id: string): Task.Result<string, User> =>
1236
- * Task.Result.tryCatch(
1237
- * (signal) => fetch(`/users/${id}`, { signal }).then(r => r.json()),
1238
- * { onError: String }
1239
- * );
1231
+ * const loadUser = Task.Result.tryCatch(
1232
+ * (signal) => userStore.get("u_123", { signal }),
1233
+ * { onError: (e) => new DbError(e) }
1234
+ * );
1240
1235
  * ```
1241
1236
  */
1242
1237
  const tryCatch: <E, A>(f: (signal?: AbortSignal) => Thenable<A>, options: {
1243
- onError: (e: unknown) => E;
1238
+ onError: (error: unknown) => E;
1244
1239
  }) => TaskResult<E, A>;
1245
1240
  /**
1246
1241
  * Transforms the success value inside a Task.Result.
@@ -1436,7 +1431,7 @@ declare namespace TaskValidation {
1436
1431
  * const res = await task(); // Passed(42)
1437
1432
  * ```
1438
1433
  */
1439
- const passed: <E, A>(value: A) => TaskValidation<E, A>;
1434
+ const passed: <E = never, A = unknown>(value: A) => TaskValidation<E, A>;
1440
1435
  /**
1441
1436
  * Creates a failed Task.Validation with a single error.
1442
1437
  *
@@ -1446,7 +1441,7 @@ declare namespace TaskValidation {
1446
1441
  * const res = await task(); // Failed(["invalid"])
1447
1442
  * ```
1448
1443
  */
1449
- const failed: <E, A>(error: E) => TaskValidation<E, A>;
1444
+ const failed: <E, A = never>(error: E) => TaskValidation<E, A>;
1450
1445
  /**
1451
1446
  * Creates a failed Task.Validation from multiple errors.
1452
1447
  *
@@ -1456,11 +1451,11 @@ declare namespace TaskValidation {
1456
1451
  * const res = await task(); // Failed(["err1", "err2"])
1457
1452
  * ```
1458
1453
  */
1459
- const failedAll: <E, A>(errors: NonEmptyArr<E>) => TaskValidation<E, A>;
1454
+ const failedAll: <E, A = never>(errors: NonEmptyArr<E>) => TaskValidation<E, A>;
1460
1455
  }
1461
- const passed: <E, A>(value: A) => TaskValidation<E, A>;
1462
- const failed: <E, A>(error: E) => TaskValidation<E, A>;
1463
- const failedAll: <E, A>(errors: NonEmptyArr<E>) => TaskValidation<E, A>;
1456
+ const passed: <E = never, A = unknown>(value: A) => TaskValidation<E, A>;
1457
+ const failed: <E, A = never>(error: E) => TaskValidation<E, A>;
1458
+ const failedAll: <E, A = never>(errors: NonEmptyArr<E>) => TaskValidation<E, A>;
1464
1459
  namespace from {
1465
1460
  /**
1466
1461
  * Lifts a Validation into a Task.Validation.
@@ -1510,17 +1505,22 @@ declare namespace TaskValidation {
1510
1505
  * Creates a Task.Validation from a Promise-returning function.
1511
1506
  * Catches any errors and transforms them using the onError function.
1512
1507
  * The factory optionally receives an `AbortSignal` forwarded from the call site.
1508
+ /**
1509
+ * Creates a Task.Validation from a Promise-returning thunk that may throw or reject.
1510
+ * Catches any errors and transforms them using the `onError` function into a Failed validation.
1511
+ * The thunk optionally receives an `AbortSignal` forwarded from the call site.
1513
1512
  *
1514
1513
  * @example
1515
1514
  * ```ts
1516
- * const fetchUser = (id: string): Task.Validation<string, User> =>
1517
- * Task.Validation.tryCatch(
1518
- * (signal) => fetch(`/users/${id}`, { signal }).then(r => r.json()),
1519
- * e => `Failed to fetch user: ${e}`
1520
- * );
1515
+ * const loadConfig = Task.Validation.tryCatch(
1516
+ * (signal) => configStore.get("default", { signal }),
1517
+ * { onError: (e) => `Failed to load config: ${e}` }
1518
+ * );
1521
1519
  * ```
1522
1520
  */
1523
- const tryCatch: <E, A>(f: (signal?: AbortSignal) => Thenable<A>, onError: (e: unknown) => E) => TaskValidation<E, A>;
1521
+ const tryCatch: <E, A>(f: (signal?: AbortSignal) => Thenable<A>, options: {
1522
+ onError: (error: unknown) => E;
1523
+ }) => TaskValidation<E, A>;
1524
1524
  /**
1525
1525
  * Transforms the success value inside a Task.Validation.
1526
1526
  */
@@ -1644,6 +1644,16 @@ declare namespace TaskValidation {
1644
1644
  * ```
1645
1645
  */
1646
1646
  const struct: <E, R extends Record<string, any>>(fields: { [K in keyof R]: TaskValidation<E, R[K]>; }) => TaskValidation<E, R>;
1647
+ /**
1648
+ * Creates a memoized version of a Task.Validation. The task is executed at most once on first call,
1649
+ * and its resolved Validation is cached for all subsequent calls.
1650
+ *
1651
+ * @example
1652
+ * ```ts
1653
+ * const validate = Task.Validation.memoize(validateFormTask);
1654
+ * ```
1655
+ */
1656
+ const memoize: <E, A>(task: TaskValidation<E, A>) => TaskValidation<E, A>;
1647
1657
  }
1648
1658
 
1649
1659
  /**
@@ -1701,16 +1711,6 @@ declare namespace Task {
1701
1711
  */
1702
1712
  const resolve: <A>(value: A) => Task<A>;
1703
1713
  namespace from {
1704
- /**
1705
- * Creates a Task from a function that returns a Promise.
1706
- * The factory optionally receives an `AbortSignal` forwarded from the call site.
1707
- *
1708
- * @example
1709
- * ```ts
1710
- * const getTimestamp = Task.from.Promise(() => Promise.resolve(Date.now()));
1711
- * ```
1712
- */
1713
- const Promise: <A>(f: (signal?: AbortSignal) => Thenable<A>) => Task<A>;
1714
1714
  /**
1715
1715
  * Creates a Task from a lazy synchronous thunk.
1716
1716
  * Unlike `Task.resolve(f())`, `from.sync` does not evaluate `f` until the Task is called.
@@ -1723,6 +1723,21 @@ declare namespace Task {
1723
1723
  */
1724
1724
  const sync: <A>(f: () => A) => Task<A>;
1725
1725
  }
1726
+ /**
1727
+ * Wraps a Promise-returning thunk that may throw or reject,
1728
+ * trapping errors with a fallback function and returning a guaranteed `Task<A>`.
1729
+ *
1730
+ * @example
1731
+ * ```ts
1732
+ * const loadConfig = Task.tryCatch(
1733
+ * () => configStore.get("default"),
1734
+ * { onError: () => DEFAULT_CONFIG }
1735
+ * );
1736
+ * ```
1737
+ */
1738
+ const tryCatch: <A>(f: (signal?: AbortSignal) => globalThis.Promise<A>, options: {
1739
+ onError: (error: unknown) => A;
1740
+ }) => Task<A>;
1726
1741
  /**
1727
1742
  * Transforms the value inside a Task.
1728
1743
  *
@@ -1845,8 +1860,8 @@ declare namespace Task {
1845
1860
  *
1846
1861
  * @example
1847
1862
  * ```ts
1848
- * const fast = Task.from.Promise(() => new Promise<string>(r => setTimeout(() => r("fast"), 10)));
1849
- * const slow = Task.from.Promise(() => new Promise<string>(r => setTimeout(() => r("slow"), 200)));
1863
+ * const fast = Task.resolve("fast");
1864
+ * const slow = Task.delay(Duration.milliseconds(200))(Task.resolve("slow"));
1850
1865
  *
1851
1866
  * await Task.race([fast, slow])(); // "fast"
1852
1867
  * ```
@@ -1870,10 +1885,7 @@ declare namespace Task {
1870
1885
  * @example
1871
1886
  * ```ts
1872
1887
  * let log: number[] = [];
1873
- * const makeTask = (n: number) => Task.from.Promise(() => {
1874
- * log.push(n);
1875
- * return Promise.resolve(n);
1876
- * });
1888
+ * const makeTask = (n: number) => Task.resolve(n);
1877
1889
  *
1878
1890
  * await Task.sequential([makeTask(1), makeTask(2), makeTask(3)])();
1879
1891
  * // log = [1, 2, 3] — tasks ran in order
@@ -2089,16 +2101,15 @@ declare namespace Validation {
2089
2101
  const failed: <E, A>(data: Validation<E, A>) => data is Failed<E>;
2090
2102
  }
2091
2103
  /**
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.
2104
+ * Creates a Validation from a synchronous thunk that may throw.
2105
+ * Catches any errors and transforms them using the `onError` function into a Failed validation.
2094
2106
  *
2095
2107
  * @example
2096
2108
  * ```ts
2097
- * const parseJson = (s: string): Validation<string, unknown> =>
2098
- * Validation.tryCatch(
2099
- * () => JSON.parse(s),
2100
- * { onError: (e) => `Parse error: ${e}` }
2101
- * );
2109
+ * const result = Validation.tryCatch(
2110
+ * () => JSON.parse(rawString),
2111
+ * { onError: (e) => `Parse error: ${e}` }
2112
+ * );
2102
2113
  * ```
2103
2114
  */
2104
2115
  const tryCatch: <E, A>(f: () => A, options: {
@@ -595,13 +595,16 @@ declare namespace Result {
595
595
  * Creates a Result from a function that may throw.
596
596
  * Catches any errors and transforms them using the onError function.
597
597
  *
598
+ /**
599
+ * Creates a Result from a synchronous thunk that may throw.
600
+ * Catches any errors and transforms them using the `onError` function.
601
+ *
598
602
  * @example
599
603
  * ```ts
600
- * const parseJson = (s: string): Result<string, unknown> =>
601
- * Result.tryCatch(
602
- * () => JSON.parse(s),
603
- * { onError: (e) => `Parse error: ${e}` }
604
- * );
604
+ * const result = Result.tryCatch(
605
+ * () => JSON.parse(rawString),
606
+ * { onError: (e) => `Parse error: ${e}` }
607
+ * );
605
608
  * ```
606
609
  */
607
610
  const tryCatch: <E, A>(f: () => A, options: {
@@ -749,24 +752,6 @@ declare namespace Result {
749
752
  * ```
750
753
  */
751
754
  const Maybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => Result<E, A>;
752
- /**
753
- * Wraps a throwing function of any arguments, returning a new function
754
- * that catches errors and returns a Result.
755
- *
756
- * @example
757
- * ```ts
758
- * const safeParse = Result.from.throwable(
759
- * (s: string) => JSON.parse(s),
760
- * { onError: (e) => new Error(`Parse error: ${e}`) }
761
- * );
762
- *
763
- * safeParse('{"a":1}'); // Ok({ a: 1 })
764
- * safeParse('invalid'); // Err(Error)
765
- * ```
766
- */
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
755
  /**
771
756
  * Converts a `Validation` to a `Result`, combining accumulated errors using `combineErrors`.
772
757
  * `Passed(a)` becomes `Ok(a)`; `Failed(errors)` becomes `Err(combineErrors(errors))`.
@@ -1132,6 +1117,16 @@ declare namespace TaskMaybe {
1132
1117
  * ```
1133
1118
  */
1134
1119
  const struct: <R extends Record<string, any>>(fields: { [K in keyof R]: TaskMaybe<R[K]>; }) => TaskMaybe<R>;
1120
+ /**
1121
+ * Creates a memoized version of a Task.Maybe. The task is executed at most once on first call,
1122
+ * and its resolved Maybe is cached for all subsequent calls.
1123
+ *
1124
+ * @example
1125
+ * ```ts
1126
+ * const loadUser = Task.Maybe.memoize(fetchUserMaybeTask);
1127
+ * ```
1128
+ */
1129
+ const memoize: <A>(task: TaskMaybe<A>) => TaskMaybe<A>;
1135
1130
  }
1136
1131
 
1137
1132
  /**
@@ -1159,7 +1154,7 @@ declare namespace TaskResult {
1159
1154
  * const res = await task(); // Ok(42)
1160
1155
  * ```
1161
1156
  */
1162
- const ok: <E, A>(value: A) => TaskResult<E, A>;
1157
+ const ok: <E = never, A = unknown>(value: A) => TaskResult<E, A>;
1163
1158
  /**
1164
1159
  * Creates a failed Task.Result with the given error.
1165
1160
  *
@@ -1169,10 +1164,10 @@ declare namespace TaskResult {
1169
1164
  * const res = await task(); // Err("failed")
1170
1165
  * ```
1171
1166
  */
1172
- const err: <E, A>(error: E) => TaskResult<E, A>;
1167
+ const err: <E, A = never>(error: E) => TaskResult<E, A>;
1173
1168
  }
1174
- const ok: <E, A>(value: A) => TaskResult<E, A>;
1175
- const err: <E, A>(error: E) => TaskResult<E, A>;
1169
+ const ok: <E = never, A = unknown>(value: A) => TaskResult<E, A>;
1170
+ const err: <E, A = never>(error: E) => TaskResult<E, A>;
1176
1171
  namespace from {
1177
1172
  /**
1178
1173
  * Creates a Task.Result from a nullable value.
@@ -1204,14 +1199,15 @@ declare namespace TaskResult {
1204
1199
  * Task.Result.from.Result(Result.make.ok(42)); // resolves to Ok(42)
1205
1200
  * ```
1206
1201
  */
1207
- const Result: <E, A>(result: Result<E, A>) => TaskResult<E, A>;
1208
1202
  /**
1209
- * Wraps a Promise-returning function of any arguments, returning a new function
1210
- * that catches rejections and returns a Task.Result.
1203
+ * Lifts a Result into a Task.Result.
1204
+ *
1205
+ * @example
1206
+ * ```ts
1207
+ * Task.Result.from.Result(Result.make.ok(42)); // resolves to Ok(42)
1208
+ * ```
1211
1209
  */
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>;
1210
+ const Result: <E, A>(result: Result<E, A>) => TaskResult<E, A>;
1215
1211
  }
1216
1212
  namespace to {
1217
1213
  /**
@@ -1226,21 +1222,20 @@ declare namespace TaskResult {
1226
1222
  const Maybe: <E, A>(data: TaskResult<E, A>) => TaskMaybe<A>;
1227
1223
  }
1228
1224
  /**
1229
- * Creates a Task.Result from a function that may throw.
1230
- * Catches any errors and transforms them using the onError function.
1231
- * The factory optionally receives an `AbortSignal` forwarded from the call site.
1225
+ * Creates a Task.Result from a Promise-returning thunk that may throw or reject.
1226
+ * Catches any errors and transforms them using the `onError` function into an `Err`.
1227
+ * The thunk optionally receives an `AbortSignal` forwarded from the call site.
1232
1228
  *
1233
1229
  * @example
1234
1230
  * ```ts
1235
- * const fetchUser = (id: string): Task.Result<string, User> =>
1236
- * Task.Result.tryCatch(
1237
- * (signal) => fetch(`/users/${id}`, { signal }).then(r => r.json()),
1238
- * { onError: String }
1239
- * );
1231
+ * const loadUser = Task.Result.tryCatch(
1232
+ * (signal) => userStore.get("u_123", { signal }),
1233
+ * { onError: (e) => new DbError(e) }
1234
+ * );
1240
1235
  * ```
1241
1236
  */
1242
1237
  const tryCatch: <E, A>(f: (signal?: AbortSignal) => Thenable<A>, options: {
1243
- onError: (e: unknown) => E;
1238
+ onError: (error: unknown) => E;
1244
1239
  }) => TaskResult<E, A>;
1245
1240
  /**
1246
1241
  * Transforms the success value inside a Task.Result.
@@ -1436,7 +1431,7 @@ declare namespace TaskValidation {
1436
1431
  * const res = await task(); // Passed(42)
1437
1432
  * ```
1438
1433
  */
1439
- const passed: <E, A>(value: A) => TaskValidation<E, A>;
1434
+ const passed: <E = never, A = unknown>(value: A) => TaskValidation<E, A>;
1440
1435
  /**
1441
1436
  * Creates a failed Task.Validation with a single error.
1442
1437
  *
@@ -1446,7 +1441,7 @@ declare namespace TaskValidation {
1446
1441
  * const res = await task(); // Failed(["invalid"])
1447
1442
  * ```
1448
1443
  */
1449
- const failed: <E, A>(error: E) => TaskValidation<E, A>;
1444
+ const failed: <E, A = never>(error: E) => TaskValidation<E, A>;
1450
1445
  /**
1451
1446
  * Creates a failed Task.Validation from multiple errors.
1452
1447
  *
@@ -1456,11 +1451,11 @@ declare namespace TaskValidation {
1456
1451
  * const res = await task(); // Failed(["err1", "err2"])
1457
1452
  * ```
1458
1453
  */
1459
- const failedAll: <E, A>(errors: NonEmptyArr<E>) => TaskValidation<E, A>;
1454
+ const failedAll: <E, A = never>(errors: NonEmptyArr<E>) => TaskValidation<E, A>;
1460
1455
  }
1461
- const passed: <E, A>(value: A) => TaskValidation<E, A>;
1462
- const failed: <E, A>(error: E) => TaskValidation<E, A>;
1463
- const failedAll: <E, A>(errors: NonEmptyArr<E>) => TaskValidation<E, A>;
1456
+ const passed: <E = never, A = unknown>(value: A) => TaskValidation<E, A>;
1457
+ const failed: <E, A = never>(error: E) => TaskValidation<E, A>;
1458
+ const failedAll: <E, A = never>(errors: NonEmptyArr<E>) => TaskValidation<E, A>;
1464
1459
  namespace from {
1465
1460
  /**
1466
1461
  * Lifts a Validation into a Task.Validation.
@@ -1510,17 +1505,22 @@ declare namespace TaskValidation {
1510
1505
  * Creates a Task.Validation from a Promise-returning function.
1511
1506
  * Catches any errors and transforms them using the onError function.
1512
1507
  * The factory optionally receives an `AbortSignal` forwarded from the call site.
1508
+ /**
1509
+ * Creates a Task.Validation from a Promise-returning thunk that may throw or reject.
1510
+ * Catches any errors and transforms them using the `onError` function into a Failed validation.
1511
+ * The thunk optionally receives an `AbortSignal` forwarded from the call site.
1513
1512
  *
1514
1513
  * @example
1515
1514
  * ```ts
1516
- * const fetchUser = (id: string): Task.Validation<string, User> =>
1517
- * Task.Validation.tryCatch(
1518
- * (signal) => fetch(`/users/${id}`, { signal }).then(r => r.json()),
1519
- * e => `Failed to fetch user: ${e}`
1520
- * );
1515
+ * const loadConfig = Task.Validation.tryCatch(
1516
+ * (signal) => configStore.get("default", { signal }),
1517
+ * { onError: (e) => `Failed to load config: ${e}` }
1518
+ * );
1521
1519
  * ```
1522
1520
  */
1523
- const tryCatch: <E, A>(f: (signal?: AbortSignal) => Thenable<A>, onError: (e: unknown) => E) => TaskValidation<E, A>;
1521
+ const tryCatch: <E, A>(f: (signal?: AbortSignal) => Thenable<A>, options: {
1522
+ onError: (error: unknown) => E;
1523
+ }) => TaskValidation<E, A>;
1524
1524
  /**
1525
1525
  * Transforms the success value inside a Task.Validation.
1526
1526
  */
@@ -1644,6 +1644,16 @@ declare namespace TaskValidation {
1644
1644
  * ```
1645
1645
  */
1646
1646
  const struct: <E, R extends Record<string, any>>(fields: { [K in keyof R]: TaskValidation<E, R[K]>; }) => TaskValidation<E, R>;
1647
+ /**
1648
+ * Creates a memoized version of a Task.Validation. The task is executed at most once on first call,
1649
+ * and its resolved Validation is cached for all subsequent calls.
1650
+ *
1651
+ * @example
1652
+ * ```ts
1653
+ * const validate = Task.Validation.memoize(validateFormTask);
1654
+ * ```
1655
+ */
1656
+ const memoize: <E, A>(task: TaskValidation<E, A>) => TaskValidation<E, A>;
1647
1657
  }
1648
1658
 
1649
1659
  /**
@@ -1701,16 +1711,6 @@ declare namespace Task {
1701
1711
  */
1702
1712
  const resolve: <A>(value: A) => Task<A>;
1703
1713
  namespace from {
1704
- /**
1705
- * Creates a Task from a function that returns a Promise.
1706
- * The factory optionally receives an `AbortSignal` forwarded from the call site.
1707
- *
1708
- * @example
1709
- * ```ts
1710
- * const getTimestamp = Task.from.Promise(() => Promise.resolve(Date.now()));
1711
- * ```
1712
- */
1713
- const Promise: <A>(f: (signal?: AbortSignal) => Thenable<A>) => Task<A>;
1714
1714
  /**
1715
1715
  * Creates a Task from a lazy synchronous thunk.
1716
1716
  * Unlike `Task.resolve(f())`, `from.sync` does not evaluate `f` until the Task is called.
@@ -1723,6 +1723,21 @@ declare namespace Task {
1723
1723
  */
1724
1724
  const sync: <A>(f: () => A) => Task<A>;
1725
1725
  }
1726
+ /**
1727
+ * Wraps a Promise-returning thunk that may throw or reject,
1728
+ * trapping errors with a fallback function and returning a guaranteed `Task<A>`.
1729
+ *
1730
+ * @example
1731
+ * ```ts
1732
+ * const loadConfig = Task.tryCatch(
1733
+ * () => configStore.get("default"),
1734
+ * { onError: () => DEFAULT_CONFIG }
1735
+ * );
1736
+ * ```
1737
+ */
1738
+ const tryCatch: <A>(f: (signal?: AbortSignal) => globalThis.Promise<A>, options: {
1739
+ onError: (error: unknown) => A;
1740
+ }) => Task<A>;
1726
1741
  /**
1727
1742
  * Transforms the value inside a Task.
1728
1743
  *
@@ -1845,8 +1860,8 @@ declare namespace Task {
1845
1860
  *
1846
1861
  * @example
1847
1862
  * ```ts
1848
- * const fast = Task.from.Promise(() => new Promise<string>(r => setTimeout(() => r("fast"), 10)));
1849
- * const slow = Task.from.Promise(() => new Promise<string>(r => setTimeout(() => r("slow"), 200)));
1863
+ * const fast = Task.resolve("fast");
1864
+ * const slow = Task.delay(Duration.milliseconds(200))(Task.resolve("slow"));
1850
1865
  *
1851
1866
  * await Task.race([fast, slow])(); // "fast"
1852
1867
  * ```
@@ -1870,10 +1885,7 @@ declare namespace Task {
1870
1885
  * @example
1871
1886
  * ```ts
1872
1887
  * let log: number[] = [];
1873
- * const makeTask = (n: number) => Task.from.Promise(() => {
1874
- * log.push(n);
1875
- * return Promise.resolve(n);
1876
- * });
1888
+ * const makeTask = (n: number) => Task.resolve(n);
1877
1889
  *
1878
1890
  * await Task.sequential([makeTask(1), makeTask(2), makeTask(3)])();
1879
1891
  * // log = [1, 2, 3] — tasks ran in order
@@ -2089,16 +2101,15 @@ declare namespace Validation {
2089
2101
  const failed: <E, A>(data: Validation<E, A>) => data is Failed<E>;
2090
2102
  }
2091
2103
  /**
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.
2104
+ * Creates a Validation from a synchronous thunk that may throw.
2105
+ * Catches any errors and transforms them using the `onError` function into a Failed validation.
2094
2106
  *
2095
2107
  * @example
2096
2108
  * ```ts
2097
- * const parseJson = (s: string): Validation<string, unknown> =>
2098
- * Validation.tryCatch(
2099
- * () => JSON.parse(s),
2100
- * { onError: (e) => `Parse error: ${e}` }
2101
- * );
2109
+ * const result = Validation.tryCatch(
2110
+ * () => JSON.parse(rawString),
2111
+ * { onError: (e) => `Parse error: ${e}` }
2112
+ * );
2102
2113
  * ```
2103
2114
  */
2104
2115
  const tryCatch: <E, A>(f: () => A, options: {
@@ -2,9 +2,8 @@ import {
2
2
  Deferred,
3
3
  Maybe,
4
4
  Result,
5
- Task,
6
5
  isNonEmptyArr
7
- } from "./chunk-XFE3SQEE.mjs";
6
+ } from "./chunk-K7HHEACE.js";
8
7
 
9
8
  // src/Data/Arr.ts
10
9
  var ArrMaybe;
@@ -41,7 +40,7 @@ var ArrResult;
41
40
  })(ArrResult || (ArrResult = {}));
42
41
  var ArrTaskResult;
43
42
  ((ArrTaskResult2) => {
44
- ArrTaskResult2.traverse = (f) => (data) => Task.from.Promise(async () => {
43
+ ArrTaskResult2.traverse = (f) => (data) => () => Deferred.from.Promise((async () => {
45
44
  const result = [];
46
45
  for (const a of data) {
47
46
  const r = await Deferred.to.Promise(f(a)());
@@ -51,12 +50,12 @@ var ArrTaskResult;
51
50
  result.push(r.value);
52
51
  }
53
52
  return Result.make.ok(result);
54
- });
53
+ })());
55
54
  ArrTaskResult2.sequence = (data) => (0, ArrTaskResult2.traverse)((a) => a)(data);
56
55
  })(ArrTaskResult || (ArrTaskResult = {}));
57
56
  var ArrTask;
58
57
  ((ArrTask2) => {
59
- ArrTask2.traverse = (f) => (data) => Task.from.Promise(() => Promise.all(data.map((a) => Deferred.to.Promise(f(a)()))));
58
+ ArrTask2.traverse = (f) => (data) => () => Deferred.from.Promise(Promise.all(data.map((a) => Deferred.to.Promise(f(a)()))));
60
59
  ArrTask2.sequence = (data) => (0, ArrTask2.traverse)((a) => a)(data);
61
60
  ArrTask2.Result = ArrTaskResult;
62
61
  })(ArrTask || (ArrTask = {}));
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Duration
3
- } from "./chunk-DENXUTKL.mjs";
3
+ } from "./chunk-OIIOGDHK.js";
4
4
 
5
5
  // src/Composition/compose.ts
6
6
  function compose(f0, f1, f2, f3, f4, f5, f6, f7, f8, f9) {