@nlozgachev/pipelined 0.66.0 → 0.67.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.
@@ -667,6 +667,19 @@ const chainLogged = (f) => (data) => {
667
667
  };
668
668
  };
669
669
  const Logged = {
670
+ /**
671
+ * Creates a `Logged` with a value and an optional initial log array.
672
+ *
673
+ * @example
674
+ * ```ts
675
+ * Logged.make(42); // { value: 42, log: [] }
676
+ * Logged.make(42, ["initialized"]); // { value: 42, log: ["initialized"] }
677
+ * ```
678
+ */
679
+ make: (value, log = []) => ({
680
+ value,
681
+ log: [...log]
682
+ }),
670
683
  from: {
671
684
  /**
672
685
  * Wraps a pure value into a `Logged` with an empty log.
@@ -731,11 +744,11 @@ const Logged = {
731
744
  * };
732
745
  * const arg: Logged<string, number> = { value: 5, log: ["arg-loaded"] };
733
746
  *
734
- * const result = pipe(fn, Logged.ap(arg));
747
+ * const result = pipe(fn, Logged.apply(arg));
735
748
  * Logged.run(result); // [10, ["fn-loaded", "arg-loaded"]]
736
749
  * ```
737
750
  */
738
- ap: (arg) => (data) => ({
751
+ apply: (arg) => (data) => ({
739
752
  value: data.value(arg.value),
740
753
  log: [...data.log, ...arg.log]
741
754
  }),
@@ -845,6 +858,8 @@ const Maybe = {
845
858
  /**
846
859
  * Type guard that checks if a Maybe is Some.
847
860
  *
861
+ * @see {@link Maybe.is.none}
862
+ *
848
863
  * @example
849
864
  * ```ts
850
865
  * const value = Maybe.make.some(42);
@@ -857,6 +872,8 @@ const Maybe = {
857
872
  /**
858
873
  * Type guard that checks if a Maybe is None.
859
874
  *
875
+ * @see {@link Maybe.is.some}
876
+ *
860
877
  * @example
861
878
  * ```ts
862
879
  * const value = Maybe.make.none();
@@ -905,7 +922,18 @@ const Maybe = {
905
922
  * ); // Err("Value was missing")
906
923
  * ```
907
924
  */
908
- Result: (onNone) => (data) => isSome(data) ? Result.make.ok(data.value) : Result.make.err(onNone())
925
+ Result: (onNone) => (data) => isSome(data) ? Result.make.ok(data.value) : Result.make.err(onNone()),
926
+ /**
927
+ * Converts a Maybe to a Validation.
928
+ * Some becomes Passed, None becomes Failed with error produced by `onNone`.
929
+ *
930
+ * @example
931
+ * ```ts
932
+ * pipe(Maybe.make.some(42), Maybe.to.Validation(() => "missing")); // Passed(42)
933
+ * pipe(Maybe.make.none(), Maybe.to.Validation(() => "missing")); // Failed(["missing"])
934
+ * ```
935
+ */
936
+ Validation: (onNone) => (data) => isSome(data) ? Validation.make.passed(data.value) : Validation.make.failed(onNone())
909
937
  },
910
938
  from: {
911
939
  /**
@@ -966,17 +994,21 @@ const Maybe = {
966
994
  /**
967
995
  * Transforms the value inside a Maybe if it exists.
968
996
  *
997
+ * @see {@link Maybe.chain} for functions that return a Maybe.
998
+ *
969
999
  * @example
970
1000
  * ```ts
971
1001
  * pipe(Maybe.make.some(5), Maybe.map(n => n * 2)); // Some(10)
972
1002
  * pipe(Maybe.make.none(), Maybe.map(n => n * 2)); // None
973
1003
  * ```
974
1004
  */
975
- map: (f) => (data) => isSome(data) ? makeSome$1(f(data.value)) : data,
1005
+ map: (transform) => (maybe) => isSome(maybe) ? makeSome$1(transform(maybe.value)) : maybe,
976
1006
  /**
977
- * Chains Maybe computations. If the first is Some, passes the value to f.
1007
+ * Chains Maybe computations. If the first is Some, passes the value to `transform`.
978
1008
  * If the first is None, propagates None.
979
1009
  *
1010
+ * @see {@link Maybe.map} for transforming with plain non-optional functions.
1011
+ *
980
1012
  * @example
981
1013
  * ```ts
982
1014
  * const parseNumber = (s: string): Maybe<number> => {
@@ -988,10 +1020,12 @@ const Maybe = {
988
1020
  * pipe(Maybe.make.some("abc"), Maybe.chain(parseNumber)); // None
989
1021
  * ```
990
1022
  */
991
- chain: (f) => (data) => isSome(data) ? f(data.value) : data,
1023
+ chain: (transform) => (maybe) => isSome(maybe) ? transform(maybe.value) : maybe,
992
1024
  /**
993
1025
  * Extracts the value from a Maybe by providing handlers for both cases.
994
1026
  *
1027
+ * @see {@link Maybe.match} for named-case handling using an object.
1028
+ *
995
1029
  * @example
996
1030
  * ```ts
997
1031
  * pipe(
@@ -1003,10 +1037,12 @@ const Maybe = {
1003
1037
  * ); // "Value: 5"
1004
1038
  * ```
1005
1039
  */
1006
- fold: (onNone, onSome) => (data) => isSome(data) ? onSome(data.value) : onNone(),
1040
+ fold: (onNone, onSome) => (maybe) => isSome(maybe) ? onSome(maybe.value) : onNone(),
1007
1041
  /**
1008
1042
  * Pattern matches on a Maybe, returning the result of the matching case.
1009
1043
  *
1044
+ * @see {@link Maybe.fold} for positional arguments (onNone, onSome).
1045
+ *
1010
1046
  * @example
1011
1047
  * ```ts
1012
1048
  * pipe(
@@ -1018,12 +1054,15 @@ const Maybe = {
1018
1054
  * );
1019
1055
  * ```
1020
1056
  */
1021
- match: (cases) => (data) => isSome(data) ? cases.some(data.value) : cases.none(),
1057
+ match: (cases) => (maybe) => isSome(maybe) ? cases.some(maybe.value) : cases.none(),
1022
1058
  /**
1023
1059
  * Returns the value inside a Maybe, or a default value if None.
1024
1060
  * The default is a thunk `() => B` — evaluated only when the Maybe is None.
1025
1061
  * The default can be a different type, widening the result to `A | B`.
1026
1062
  *
1063
+ * @see {@link Maybe.match}
1064
+ * @see {@link Maybe.to.nullable}
1065
+ *
1027
1066
  * @example
1028
1067
  * ```ts
1029
1068
  * pipe(Maybe.make.some(5), Maybe.getOrElse(() => 0)); // 5
@@ -1031,11 +1070,13 @@ const Maybe = {
1031
1070
  * pipe(Maybe.make.none<string>(), Maybe.getOrElse(() => null)); // null — typed as string | null
1032
1071
  * ```
1033
1072
  */
1034
- getOrElse: (defaultValue) => (data) => isSome(data) ? data.value : defaultValue(),
1073
+ getOrElse: (defaultValue) => (maybe) => isSome(maybe) ? maybe.value : defaultValue(),
1035
1074
  /**
1036
1075
  * Executes a side effect on the value without changing the Maybe.
1037
1076
  * Useful for logging or debugging.
1038
1077
  *
1078
+ * @see {@link Maybe.tapNone} for running side effects on None.
1079
+ *
1039
1080
  * @example
1040
1081
  * ```ts
1041
1082
  * pipe(
@@ -1045,13 +1086,15 @@ const Maybe = {
1045
1086
  * );
1046
1087
  * ```
1047
1088
  */
1048
- tap: (f) => (data) => {
1049
- if (isSome(data)) f(data.value);
1050
- return data;
1089
+ tap: (sideEffect) => (maybe) => {
1090
+ if (isSome(maybe)) sideEffect(maybe.value);
1091
+ return maybe;
1051
1092
  },
1052
1093
  /**
1053
1094
  * Executes a side effect when the Maybe is None, without changing the Maybe.
1054
1095
  *
1096
+ * @see {@link Maybe.tap} for running side effects on Some.
1097
+ *
1055
1098
  * @example
1056
1099
  * ```ts
1057
1100
  * pipe(
@@ -1060,14 +1103,16 @@ const Maybe = {
1060
1103
  * );
1061
1104
  * ```
1062
1105
  */
1063
- tapNone: (f) => (data) => {
1064
- if (isNone(data)) f();
1065
- return data;
1106
+ tapNone: (sideEffect) => (maybe) => {
1107
+ if (isNone(maybe)) sideEffect();
1108
+ return maybe;
1066
1109
  },
1067
1110
  /**
1068
1111
  * Filters a Maybe based on a predicate or type guard.
1069
1112
  * Returns None if the predicate returns false or if the Maybe is already None.
1070
1113
  *
1114
+ * @see {@link Maybe.map}
1115
+ *
1071
1116
  * @example
1072
1117
  * ```ts
1073
1118
  * pipe(Maybe.make.some(5), Maybe.filter(n => n > 3)); // Some(5)
@@ -1075,18 +1120,20 @@ const Maybe = {
1075
1120
  * pipe(Maybe.make.some("hi"), Maybe.filter((x): x is string => typeof x === "string")); // Some("hi")
1076
1121
  * ```
1077
1122
  */
1078
- filter: ((predicate) => (data) => isSome(data) ? predicate(data.value) ? data : makeNone$1() : data),
1123
+ filter: ((predicate) => (maybe) => isSome(maybe) ? predicate(maybe.value) ? maybe : makeNone$1() : maybe),
1079
1124
  /**
1080
1125
  * Recovers from a None by providing a fallback Maybe.
1081
1126
  * The fallback can produce a different type, widening the result to `Maybe<A | B>`.
1082
1127
  *
1128
+ * @see {@link Maybe.getOrElse}
1129
+ *
1083
1130
  * @example
1084
1131
  * ```ts
1085
1132
  * pipe(Maybe.make.none(), Maybe.recover(() => Maybe.make.some(42))); // Some(42)
1086
1133
  * pipe(Maybe.make.some(10), Maybe.recover(() => Maybe.make.some(42))); // Some(10)
1087
1134
  * ```
1088
1135
  */
1089
- recover: (fallback) => (data) => isSome(data) ? data : fallback(),
1136
+ recover: (fallback) => (maybe) => isSome(maybe) ? maybe : fallback(),
1090
1137
  /**
1091
1138
  * Applies a function wrapped in a Maybe to a value wrapped in a Maybe.
1092
1139
  *
@@ -1095,12 +1142,12 @@ const Maybe = {
1095
1142
  * const add = (a: number) => (b: number) => a + b;
1096
1143
  * pipe(
1097
1144
  * Maybe.make.some(add),
1098
- * Maybe.ap(Maybe.make.some(5)),
1099
- * Maybe.ap(Maybe.make.some(3))
1145
+ * Maybe.apply(Maybe.make.some(5)),
1146
+ * Maybe.apply(Maybe.make.some(3))
1100
1147
  * ); // Some(8)
1101
1148
  * ```
1102
1149
  */
1103
- ap: (arg) => (data) => isSome(data) && isSome(arg) ? makeSome$1(data.value(arg.value)) : makeNone$1(),
1150
+ apply: (arg) => (data) => isSome(data) && isSome(arg) ? makeSome$1(data.value(arg.value)) : makeNone$1(),
1104
1151
  /**
1105
1152
  * Converts a Maybe value into an object containing a single property.
1106
1153
  * Initiates the pipeline accumulator record.
@@ -1197,6 +1244,8 @@ const err = (error) => ({
1197
1244
  error
1198
1245
  });
1199
1246
  const getMs$1 = (duration) => Duration.to.milliseconds(duration);
1247
+ const OP_FACTORY = Symbol.for("@nlozgachev/pipelined/Op.factory");
1248
+ const toInternalOp = (op) => op;
1200
1249
  /** Waits by the specified duration. Resolves early if the signal fires (non-blocking abort). */
1201
1250
  const cancellableWait = (duration, signal) => {
1202
1251
  const rawMs = getMs$1(duration);
@@ -1213,14 +1262,14 @@ const cancellableWait = (duration, signal) => {
1213
1262
  * Runs the factory with retry logic. Calls `onRetrying` before each retry delay.
1214
1263
  * Stops on Ok, Nil (null), abort, or exhausted attempts.
1215
1264
  */
1216
- const runWithRetry = (op, input, signal, options, onRetrying) => {
1265
+ const runWithRetry = (op, args, signal, options, onRetrying) => {
1217
1266
  const { attempts, backoff, when: shouldRetry } = options;
1218
1267
  const getDelay = (n) => {
1219
1268
  if (backoff === void 0) return;
1220
1269
  return typeof backoff === "function" ? backoff(n) : backoff;
1221
1270
  };
1222
1271
  const attempt = async (left) => {
1223
- const result = await Deferred.to.Promise(op._factory(input, signal));
1272
+ const result = await Deferred.to.Promise(toInternalOp(op)[OP_FACTORY](args, signal));
1224
1273
  if (result === null || signal.aborted) return null;
1225
1274
  if (result.kind === "Ok") return result;
1226
1275
  if (left <= 1) return result;
@@ -1246,10 +1295,10 @@ const runWithRetry = (op, input, signal, options, onRetrying) => {
1246
1295
  * If the deadline fires, it aborts the `controller` and returns `Err(onTimeout())`.
1247
1296
  * A null result from the factory (signal aborted) becomes `_abortedNil`.
1248
1297
  */
1249
- const execute = (op, input, controller, retryOptions, timeoutOptions, onRetrying) => {
1298
+ const execute = (op, args, controller, retryOptions, timeoutOptions, onRetrying) => {
1250
1299
  const { signal } = controller;
1251
1300
  const toOutcome = (r) => r === null ? _abortedNil : r.kind === "Ok" ? ok(r.value) : err(r.error);
1252
- const runPromise = retryOptions !== void 0 && onRetrying !== void 0 ? runWithRetry(op, input, signal, retryOptions, onRetrying).then(toOutcome) : Deferred.to.Promise(op._factory(input, signal)).then(toOutcome);
1301
+ const runPromise = retryOptions !== void 0 && onRetrying !== void 0 ? runWithRetry(op, args, signal, retryOptions, onRetrying).then(toOutcome) : Deferred.to.Promise(toInternalOp(op)[OP_FACTORY](args, signal)).then(toOutcome);
1253
1302
  if (timeoutOptions === void 0) return Deferred.from.Promise(runPromise);
1254
1303
  let timerId;
1255
1304
  return Deferred.from.Promise(Promise.race([runPromise.then((outcome) => {
@@ -1273,7 +1322,7 @@ const makeRestartable = (op, minInterval, retryOptions, timeoutOptions) => {
1273
1322
  currentState = state;
1274
1323
  subscribers.forEach((cb) => cb(state));
1275
1324
  };
1276
- const run = (input) => Deferred.from.Promise(new Promise((resolve) => {
1325
+ const run = (...args) => Deferred.from.Promise(new Promise((resolve) => {
1277
1326
  waitController?.abort();
1278
1327
  waitController = void 0;
1279
1328
  currentController?.abort();
@@ -1286,7 +1335,7 @@ const makeRestartable = (op, minInterval, retryOptions, timeoutOptions) => {
1286
1335
  if (currentController !== controller) return;
1287
1336
  lastStartTime = Date.now();
1288
1337
  emit(_pending);
1289
- execute(op, input, controller, retryOptions, timeoutOptions, retryOptions ? (r) => {
1338
+ execute(op, args, controller, retryOptions, timeoutOptions, retryOptions ? (r) => {
1290
1339
  if (currentController === controller) emit(r);
1291
1340
  } : void 0).then((outcome) => {
1292
1341
  if (currentController !== controller) return;
@@ -1329,9 +1378,9 @@ const makeRestartable = (op, minInterval, retryOptions, timeoutOptions) => {
1329
1378
  return () => subscribers.delete(cb);
1330
1379
  },
1331
1380
  reset: () => emit(_idle),
1332
- poll: (input, { interval }) => {
1333
- run(input);
1334
- const id = setInterval(() => void run(input), getMs$1(interval));
1381
+ poll: ({ interval }) => (...args) => {
1382
+ run(...args);
1383
+ const id = setInterval(() => void run(...args), getMs$1(interval));
1335
1384
  return () => clearInterval(id);
1336
1385
  }
1337
1386
  };
@@ -1346,14 +1395,14 @@ const makeExclusive = (op, cooldown, retryOptions, timeoutOptions) => {
1346
1395
  currentState = state;
1347
1396
  subscribers.forEach((cb) => cb(state));
1348
1397
  };
1349
- const run = (input) => {
1398
+ const run = (...args) => {
1350
1399
  if (currentController !== void 0 || cooldownTimer !== void 0) return Deferred.from.Promise(Promise.resolve(_droppedNil));
1351
1400
  return Deferred.from.Promise(new Promise((resolve) => {
1352
1401
  currentResolve = resolve;
1353
1402
  currentController = new AbortController();
1354
1403
  const controller = currentController;
1355
1404
  emit(_pending);
1356
- execute(op, input, controller, retryOptions, timeoutOptions, retryOptions ? (r) => {
1405
+ execute(op, args, controller, retryOptions, timeoutOptions, retryOptions ? (r) => {
1357
1406
  if (currentController === controller) emit(r);
1358
1407
  } : void 0).then((outcome) => {
1359
1408
  if (currentController !== controller) return;
@@ -1395,9 +1444,9 @@ const makeExclusive = (op, cooldown, retryOptions, timeoutOptions) => {
1395
1444
  return () => subscribers.delete(cb);
1396
1445
  },
1397
1446
  reset: () => emit(_idle),
1398
- poll: (input, { interval }) => {
1399
- run(input);
1400
- const id = setInterval(() => void run(input), getMs$1(interval));
1447
+ poll: ({ interval }) => (...args) => {
1448
+ run(...args);
1449
+ const id = setInterval(() => void run(...args), getMs$1(interval));
1401
1450
  return () => clearInterval(id);
1402
1451
  }
1403
1452
  };
@@ -1415,13 +1464,13 @@ const makeQueue = (op, maxSize, overflow, concurrency, dedupe, retryOptions, tim
1415
1464
  currentState = state;
1416
1465
  subscribers.forEach((cb) => cb(state));
1417
1466
  };
1418
- const startOne = (input, resolve, myGeneration) => {
1467
+ const startOne = (args, resolve, myGeneration) => {
1419
1468
  inFlight++;
1420
1469
  const controller = new AbortController();
1421
1470
  inflightControllers.add(controller);
1422
1471
  inflightResolvers.push(resolve);
1423
1472
  emit(_pending);
1424
- execute(op, input, controller, retryOptions, timeoutOptions, retryOptions ? (r) => {
1473
+ execute(op, args, controller, retryOptions, timeoutOptions, retryOptions ? (r) => {
1425
1474
  if (generation === myGeneration && inflightControllers.has(controller)) emit(r);
1426
1475
  } : void 0).then((outcome) => {
1427
1476
  inflightControllers.delete(controller);
@@ -1440,18 +1489,18 @@ const makeQueue = (op, maxSize, overflow, concurrency, dedupe, retryOptions, tim
1440
1489
  }
1441
1490
  });
1442
1491
  };
1443
- const run = (input) => {
1492
+ const run = (...args) => {
1444
1493
  const myGeneration = generation;
1445
1494
  if (dedupe !== void 0) {
1446
- const idx = queue.findIndex((item) => dedupe(input, item.input));
1495
+ const idx = queue.findIndex((item) => dedupe(args, item.input));
1447
1496
  if (idx !== -1) queue.splice(idx, 1)[0].resolve(_droppedNil);
1448
1497
  }
1449
1498
  if (inFlight < maxConcurrency) return Deferred.from.Promise(new Promise((resolve) => {
1450
- startOne(input, resolve, myGeneration);
1499
+ startOne(args, resolve, myGeneration);
1451
1500
  }));
1452
1501
  if (maxSize === void 0 || queue.length < maxSize) return Deferred.from.Promise(new Promise((resolve) => {
1453
1502
  queue.push({
1454
- input,
1503
+ input: args,
1455
1504
  resolve
1456
1505
  });
1457
1506
  emit({
@@ -1462,7 +1511,7 @@ const makeQueue = (op, maxSize, overflow, concurrency, dedupe, retryOptions, tim
1462
1511
  if (overflow === "replace-last") return Deferred.from.Promise(new Promise((resolve) => {
1463
1512
  queue.pop().resolve(_evictedNil);
1464
1513
  queue.push({
1465
- input,
1514
+ input: args,
1466
1515
  resolve
1467
1516
  });
1468
1517
  emit({
@@ -1495,9 +1544,9 @@ const makeQueue = (op, maxSize, overflow, concurrency, dedupe, retryOptions, tim
1495
1544
  return () => subscribers.delete(cb);
1496
1545
  },
1497
1546
  reset: () => emit(_idle),
1498
- poll: (input, { interval }) => {
1499
- run(input);
1500
- const id = setInterval(() => void run(input), getMs$1(interval));
1547
+ poll: ({ interval }) => (...args) => {
1548
+ run(...args);
1549
+ const id = setInterval(() => void run(...args), getMs$1(interval));
1501
1550
  return () => clearInterval(id);
1502
1551
  }
1503
1552
  };
@@ -1513,12 +1562,12 @@ const makeBuffered = (op, size, retryOptions, timeoutOptions) => {
1513
1562
  currentState = state;
1514
1563
  subscribers.forEach((cb) => cb(state));
1515
1564
  };
1516
- const startRun = (input, resolve) => {
1565
+ const startRun = (args, resolve) => {
1517
1566
  currentResolve = resolve;
1518
1567
  currentController = new AbortController();
1519
1568
  const controller = currentController;
1520
1569
  emit(_pending);
1521
- execute(op, input, controller, retryOptions, timeoutOptions, retryOptions ? (r) => {
1570
+ execute(op, args, controller, retryOptions, timeoutOptions, retryOptions ? (r) => {
1522
1571
  if (currentController === controller) emit(r);
1523
1572
  } : void 0).then((outcome) => {
1524
1573
  if (currentController !== controller) return;
@@ -1533,11 +1582,11 @@ const makeBuffered = (op, size, retryOptions, timeoutOptions) => {
1533
1582
  }
1534
1583
  });
1535
1584
  };
1536
- const run = (input) => Deferred.from.Promise(new Promise((resolve) => {
1537
- if (currentController === void 0) startRun(input, resolve);
1585
+ const run = (...args) => Deferred.from.Promise(new Promise((resolve) => {
1586
+ if (currentController === void 0) startRun(args, resolve);
1538
1587
  else if (buffer.length < bufferSize) {
1539
1588
  buffer.push({
1540
- input,
1589
+ input: args,
1541
1590
  resolve
1542
1591
  });
1543
1592
  emit({
@@ -1547,7 +1596,7 @@ const makeBuffered = (op, size, retryOptions, timeoutOptions) => {
1547
1596
  } else {
1548
1597
  buffer.shift().resolve(_evictedNil);
1549
1598
  buffer.push({
1550
- input,
1599
+ input: args,
1551
1600
  resolve
1552
1601
  });
1553
1602
  emit({
@@ -1578,9 +1627,9 @@ const makeBuffered = (op, size, retryOptions, timeoutOptions) => {
1578
1627
  return () => subscribers.delete(cb);
1579
1628
  },
1580
1629
  reset: () => emit(_idle),
1581
- poll: (input, { interval }) => {
1582
- run(input);
1583
- const id = setInterval(() => void run(input), getMs$1(interval));
1630
+ poll: ({ interval }) => (...args) => {
1631
+ run(...args);
1632
+ const id = setInterval(() => void run(...args), getMs$1(interval));
1584
1633
  return () => clearInterval(id);
1585
1634
  }
1586
1635
  };
@@ -1600,12 +1649,12 @@ const makeDebounced = (op, duration, leading, maxWait, retryOptions, timeoutOpti
1600
1649
  currentState = state;
1601
1650
  subscribers.forEach((cb) => cb(state));
1602
1651
  };
1603
- const fireLeading = (input, resolve) => {
1652
+ const fireLeading = (args, resolve) => {
1604
1653
  leadingController = new AbortController();
1605
1654
  const controller = leadingController;
1606
1655
  leadingResolve = resolve;
1607
1656
  emit(_pending);
1608
- execute(op, input, controller, retryOptions, timeoutOptions, retryOptions ? (r) => {
1657
+ execute(op, args, controller, retryOptions, timeoutOptions, retryOptions ? (r) => {
1609
1658
  if (leadingController === controller) emit(r);
1610
1659
  } : void 0).then((outcome) => {
1611
1660
  if (leadingController !== controller) return;
@@ -1649,20 +1698,20 @@ const makeDebounced = (op, duration, leading, maxWait, retryOptions, timeoutOpti
1649
1698
  timerId = setTimeout(fireTrailing, delay);
1650
1699
  };
1651
1700
  const inDebounceWindow = () => timerId !== void 0 || leadingController !== void 0 || currentController !== void 0;
1652
- const run = (input) => Deferred.from.Promise(new Promise((resolve) => {
1701
+ const run = (...args) => Deferred.from.Promise(new Promise((resolve) => {
1653
1702
  if (!inDebounceWindow()) {
1654
1703
  firstCallAt = Date.now();
1655
1704
  if (leading) {
1656
- fireLeading(input, resolve);
1705
+ fireLeading(args, resolve);
1657
1706
  scheduleTrailing();
1658
1707
  } else {
1659
- pendingInput = input;
1708
+ pendingInput = args;
1660
1709
  pendingResolve = resolve;
1661
1710
  scheduleTrailing();
1662
1711
  }
1663
1712
  } else {
1664
1713
  const prev = pendingResolve;
1665
- pendingInput = input;
1714
+ pendingInput = args;
1666
1715
  pendingResolve = resolve;
1667
1716
  prev?.(_evictedNil);
1668
1717
  scheduleTrailing();
@@ -1702,9 +1751,9 @@ const makeDebounced = (op, duration, leading, maxWait, retryOptions, timeoutOpti
1702
1751
  return () => subscribers.delete(cb);
1703
1752
  },
1704
1753
  reset: () => emit(_idle),
1705
- poll: (input, { interval }) => {
1706
- run(input);
1707
- const id = setInterval(() => void run(input), getMs$1(interval));
1754
+ poll: ({ interval }) => (...args) => {
1755
+ run(...args);
1756
+ const id = setInterval(() => void run(...args), getMs$1(interval));
1708
1757
  return () => clearInterval(id);
1709
1758
  }
1710
1759
  };
@@ -1721,12 +1770,12 @@ const makeThrottled = (op, duration, trailing, retryOptions, timeoutOptions) =>
1721
1770
  currentState = state;
1722
1771
  subscribers.forEach((cb) => cb(state));
1723
1772
  };
1724
- const fireOp = (input, resolve) => {
1773
+ const fireOp = (args, resolve) => {
1725
1774
  currentResolve = resolve;
1726
1775
  currentController = new AbortController();
1727
1776
  const controller = currentController;
1728
1777
  emit(_pending);
1729
- execute(op, input, controller, retryOptions, timeoutOptions, retryOptions ? (r) => {
1778
+ execute(op, args, controller, retryOptions, timeoutOptions, retryOptions ? (r) => {
1730
1779
  if (currentController === controller) emit(r);
1731
1780
  } : void 0).then((outcome) => {
1732
1781
  if (currentController !== controller) return;
@@ -1741,27 +1790,27 @@ const makeThrottled = (op, duration, trailing, retryOptions, timeoutOptions) =>
1741
1790
  cooldownTimer = setTimeout(() => {
1742
1791
  cooldownTimer = void 0;
1743
1792
  if (trailing && pendingInput !== void 0) {
1744
- const input = pendingInput;
1793
+ const toRun = pendingInput;
1745
1794
  const resolve = pendingResolve;
1746
1795
  pendingInput = void 0;
1747
1796
  pendingResolve = void 0;
1748
- fireOp(input, resolve);
1797
+ fireOp(toRun, resolve);
1749
1798
  startCooldown();
1750
1799
  }
1751
1800
  }, getMs$1(duration));
1752
1801
  };
1753
- const run = (input) => {
1802
+ const run = (...args) => {
1754
1803
  if (cooldownTimer !== void 0) {
1755
1804
  if (!trailing) return Deferred.from.Promise(Promise.resolve(_droppedNil));
1756
1805
  return Deferred.from.Promise(new Promise((resolve) => {
1757
1806
  const prev = pendingResolve;
1758
- pendingInput = input;
1807
+ pendingInput = args;
1759
1808
  pendingResolve = resolve;
1760
1809
  prev?.(_evictedNil);
1761
1810
  }));
1762
1811
  }
1763
1812
  return Deferred.from.Promise(new Promise((resolve) => {
1764
- fireOp(input, resolve);
1813
+ fireOp(args, resolve);
1765
1814
  startCooldown();
1766
1815
  }));
1767
1816
  };
@@ -1793,9 +1842,9 @@ const makeThrottled = (op, duration, trailing, retryOptions, timeoutOptions) =>
1793
1842
  return () => subscribers.delete(cb);
1794
1843
  },
1795
1844
  reset: () => emit(_idle),
1796
- poll: (input, { interval }) => {
1797
- run(input);
1798
- const id = setInterval(() => void run(input), getMs$1(interval));
1845
+ poll: ({ interval }) => (...args) => {
1846
+ run(...args);
1847
+ const id = setInterval(() => void run(...args), getMs$1(interval));
1799
1848
  return () => clearInterval(id);
1800
1849
  }
1801
1850
  };
@@ -1812,13 +1861,13 @@ const makeConcurrent = (op, n, overflow, retryOptions, timeoutOptions) => {
1812
1861
  currentState = state;
1813
1862
  subscribers.forEach((cb) => cb(state));
1814
1863
  };
1815
- const startOne = (input, resolve, myGeneration) => {
1864
+ const startOne = (args, resolve, myGeneration) => {
1816
1865
  inflight++;
1817
1866
  const controller = new AbortController();
1818
1867
  controllers.add(controller);
1819
1868
  inflightResolvers.push(resolve);
1820
1869
  emit(_pending);
1821
- execute(op, input, controller, retryOptions, timeoutOptions, retryOptions ? (r) => {
1870
+ execute(op, args, controller, retryOptions, timeoutOptions, retryOptions ? (r) => {
1822
1871
  if (generation === myGeneration && controllers.has(controller)) emit(r);
1823
1872
  } : void 0).then((outcome) => {
1824
1873
  controllers.delete(controller);
@@ -1837,15 +1886,15 @@ const makeConcurrent = (op, n, overflow, retryOptions, timeoutOptions) => {
1837
1886
  }
1838
1887
  });
1839
1888
  };
1840
- const run = (input) => {
1889
+ const run = (...args) => {
1841
1890
  const myGeneration = generation;
1842
1891
  if (inflight < n) return Deferred.from.Promise(new Promise((resolve) => {
1843
- startOne(input, resolve, myGeneration);
1892
+ startOne(args, resolve, myGeneration);
1844
1893
  }));
1845
1894
  if (overflow === "drop") return Deferred.from.Promise(Promise.resolve(_droppedNil));
1846
1895
  return Deferred.from.Promise(new Promise((resolve) => {
1847
1896
  overflowQueue.push({
1848
- input,
1897
+ input: args,
1849
1898
  resolve
1850
1899
  });
1851
1900
  emit({
@@ -1877,9 +1926,9 @@ const makeConcurrent = (op, n, overflow, retryOptions, timeoutOptions) => {
1877
1926
  return () => subscribers.delete(cb);
1878
1927
  },
1879
1928
  reset: () => emit(_idle),
1880
- poll: (input, { interval }) => {
1881
- run(input);
1882
- const id = setInterval(() => void run(input), getMs$1(interval));
1929
+ poll: ({ interval }) => (...args) => {
1930
+ run(...args);
1931
+ const id = setInterval(() => void run(...args), getMs$1(interval));
1883
1932
  return () => clearInterval(id);
1884
1933
  }
1885
1934
  };
@@ -1892,8 +1941,8 @@ const makeKeyed = (op, keyFn, perKey, timeoutOptions) => {
1892
1941
  const snapshot = new Map(stateMap);
1893
1942
  subscribers.forEach((cb) => cb(snapshot));
1894
1943
  };
1895
- const run = (input) => {
1896
- const k = keyFn(input);
1944
+ const run = (...args) => {
1945
+ const k = keyFn(...args);
1897
1946
  if (slots.has(k)) {
1898
1947
  if (perKey === "exclusive") return Deferred.from.Promise(Promise.resolve(_droppedNil));
1899
1948
  const existing = slots.get(k);
@@ -1910,7 +1959,7 @@ const makeKeyed = (op, keyFn, perKey, timeoutOptions) => {
1910
1959
  });
1911
1960
  stateMap.set(k, _pending);
1912
1961
  emitSnapshot();
1913
- execute(op, input, controller, void 0, timeoutOptions).then((outcome) => {
1962
+ execute(op, args, controller, void 0, timeoutOptions).then((outcome) => {
1914
1963
  const slot = slots.get(k);
1915
1964
  if (!slot || slot.controller !== controller) {
1916
1965
  resolve(_abortedNil);
@@ -1961,9 +2010,9 @@ const makeKeyed = (op, keyFn, perKey, timeoutOptions) => {
1961
2010
  stateMap.clear();
1962
2011
  emitSnapshot();
1963
2012
  },
1964
- poll: (input, { interval }) => {
1965
- run(input);
1966
- const id = setInterval(() => void run(input), getMs$1(interval));
2013
+ poll: ({ interval }) => (...args) => {
2014
+ run(...args);
2015
+ const id = setInterval(() => void run(...args), getMs$1(interval));
1967
2016
  return () => clearInterval(id);
1968
2017
  }
1969
2018
  };
@@ -1977,14 +2026,14 @@ const makeOnce = (op, retryOptions, timeoutOptions) => {
1977
2026
  currentState = state;
1978
2027
  subscribers.forEach((cb) => cb(state));
1979
2028
  };
1980
- const run = (input) => {
2029
+ const run = (...args) => {
1981
2030
  if (currentState.kind !== "Idle") return Deferred.from.Promise(Promise.resolve(_droppedNil));
1982
2031
  return Deferred.from.Promise(new Promise((resolve) => {
1983
2032
  currentResolve = resolve;
1984
2033
  currentController = new AbortController();
1985
2034
  const controller = currentController;
1986
2035
  emit(_pending);
1987
- execute(op, input, controller, retryOptions, timeoutOptions, retryOptions ? (r) => {
2036
+ execute(op, args, controller, retryOptions, timeoutOptions, retryOptions ? (r) => {
1988
2037
  if (currentController === controller) emit(r);
1989
2038
  } : void 0).then((outcome) => {
1990
2039
  if (currentController !== controller) return;
@@ -2016,9 +2065,9 @@ const makeOnce = (op, retryOptions, timeoutOptions) => {
2016
2065
  return () => subscribers.delete(cb);
2017
2066
  },
2018
2067
  reset: () => emit(_idle),
2019
- poll: (input, { interval }) => {
2020
- run(input);
2021
- const id = setInterval(() => void run(input), getMs$1(interval));
2068
+ poll: ({ interval }) => (...args) => {
2069
+ run(...args);
2070
+ const id = setInterval(() => void run(...args), getMs$1(interval));
2022
2071
  return () => clearInterval(id);
2023
2072
  }
2024
2073
  };
@@ -2055,7 +2104,7 @@ function interpretFn(op, options) {
2055
2104
  case "debounced": return makeDebounced(op, options.duration, options.leading ?? false, options.maxWait, retryOptions, timeoutOptions);
2056
2105
  case "throttled": return makeThrottled(op, options.duration, options.trailing ?? false, retryOptions, timeoutOptions);
2057
2106
  case "concurrent": return makeConcurrent(op, options.n ?? 1, options.overflow ?? "drop", retryOptions, timeoutOptions);
2058
- case "keyed": return makeKeyed(op, options.key ?? ((i) => i), options.perKey ?? "exclusive", timeoutOptions);
2107
+ case "keyed": return makeKeyed(op, options.key ?? ((...args) => args[0]), options.perKey ?? "exclusive", timeoutOptions);
2059
2108
  }
2060
2109
  }
2061
2110
  const Op = {
@@ -2167,8 +2216,24 @@ const Op = {
2167
2216
  */
2168
2217
  nil: isNil
2169
2218
  },
2170
- create: (factory, onError) => ({ _factory: (input, signal) => Deferred.from.Promise(factory(signal)(input).then((value) => Result.make.ok(value)).catch((error) => signal.aborted ? null : Result.make.err(onError(error)))) }),
2171
- lift: (f) => Op.create((signal) => (input) => f(input, signal), (e) => e),
2219
+ /**
2220
+ * Creates an Op from a signal-accepting factory function that returns the async action,
2221
+ * along with an error mapping handler.
2222
+ *
2223
+ * Arguments to the returned function are automatically inferred as tuple parameters via `Parameters<Fn>`.
2224
+ *
2225
+ * @example
2226
+ * ```ts
2227
+ * const fetchUser = Op.create(
2228
+ * (signal) => (id: string) => fetch(`/users/${id}`, { signal }).then(r => r.json() as Promise<User>),
2229
+ * { onError: (e) => new ApiError(e) },
2230
+ * );
2231
+ * ```
2232
+ */
2233
+ create: (factory, options) => ({ [OP_FACTORY]: (args, signal) => Deferred.from.Promise((async () => {
2234
+ return await factory(signal)(...args);
2235
+ })().then((value) => Result.make.ok(value)).catch((error) => signal.aborted ? null : Result.make.err(options.onError(error)))) }),
2236
+ lift: (f) => Op.create(f, { onError: (e) => e }),
2172
2237
  match: (cases) => (outcome) => {
2173
2238
  if (outcome.kind === "OpOk") return cases.ok(outcome.value);
2174
2239
  if (outcome.kind === "OpErr") return cases.err(outcome.error);
@@ -2478,71 +2543,79 @@ const Ordering = {
2478
2543
  //#endregion
2479
2544
  //#region src/Core/Pair.ts
2480
2545
  const makePair = (first, second) => [first, second];
2481
- const makeArray = (arr) => arr;
2546
+ const makeArray = (items) => items;
2482
2547
  const Pair = {
2483
- from: {
2484
- /**
2485
- * Creates a Pair from two values.
2486
- *
2487
- * @example
2488
- * ```ts
2489
- * Pair.from.pair("Paris", 2_161_000); // ["Paris", 2161000]
2490
- * ```
2491
- */
2492
- pair: makePair,
2493
- /**
2494
- * Creates a Pair from a two-element array.
2495
- *
2496
- * @example
2497
- * ```ts
2498
- * Pair.from.array(["Paris", 2_161_000] as const); // ["Paris", 2161000]
2499
- * ```
2500
- */
2501
- array: makeArray
2502
- },
2548
+ /**
2549
+ * Creates a Pair from two values.
2550
+ *
2551
+ * @example
2552
+ * ```ts
2553
+ * Pair.make("Paris", 2_161_000); // ["Paris", 2161000]
2554
+ * ```
2555
+ */
2556
+ make: makePair,
2557
+ from: {
2558
+ /**
2559
+ * Creates a Pair from a two-element array.
2560
+ *
2561
+ * @example
2562
+ * ```ts
2563
+ * Pair.from.array(["Paris", 2_161_000] as const); // ["Paris", 2161000]
2564
+ * ```
2565
+ */
2566
+ array: makeArray },
2503
2567
  /**
2504
2568
  * Returns the first value from the pair.
2505
2569
  *
2506
2570
  * @example
2507
2571
  * ```ts
2508
- * Pair.first(Pair.from.pair("Paris", 2_161_000)); // "Paris"
2572
+ * Pair.first(Pair.make("Paris", 2_161_000)); // "Paris"
2509
2573
  * ```
2510
2574
  */
2511
- first: (p) => p[0],
2575
+ first: (pair) => pair[0],
2512
2576
  /**
2513
2577
  * Returns the second value from the pair.
2514
2578
  *
2515
2579
  * @example
2516
2580
  * ```ts
2517
- * Pair.second(Pair.from.pair("Paris", 2_161_000)); // 2161000
2581
+ * Pair.second(Pair.make("Paris", 2_161_000)); // 2161000
2518
2582
  * ```
2519
2583
  */
2520
- second: (p) => p[1],
2584
+ second: (pair) => pair[1],
2521
2585
  /**
2522
2586
  * Transforms the first value, leaving the second unchanged.
2523
2587
  *
2588
+ * @see {@link Pair.mapSecond} to transform the second element instead.
2589
+ * @see {@link Pair.mapBoth} to transform both elements at once.
2590
+ *
2524
2591
  * @example
2525
2592
  * ```ts
2526
- * pipe(Pair.from.pair("alice", 42), Pair.mapFirst((s) => s.toUpperCase())); // ["ALICE", 42]
2593
+ * pipe(Pair.make("alice", 42), Pair.mapFirst((s) => s.toUpperCase())); // ["ALICE", 42]
2527
2594
  * ```
2528
2595
  */
2529
- mapFirst: (f) => (p) => [f(p[0]), p[1]],
2596
+ mapFirst: (transform) => (pair) => [transform(pair[0]), pair[1]],
2530
2597
  /**
2531
2598
  * Transforms the second value, leaving the first unchanged.
2532
2599
  *
2600
+ * @see {@link Pair.mapFirst} to transform the first element instead.
2601
+ * @see {@link Pair.mapBoth} to transform both elements at once.
2602
+ *
2533
2603
  * @example
2534
2604
  * ```ts
2535
- * pipe(Pair.from.pair("alice", 42), Pair.mapSecond((n) => n * 2)); // ["alice", 84]
2605
+ * pipe(Pair.make("alice", 42), Pair.mapSecond((n) => n * 2)); // ["alice", 84]
2536
2606
  * ```
2537
2607
  */
2538
- mapSecond: (f) => (p) => [p[0], f(p[1])],
2608
+ mapSecond: (transform) => (pair) => [pair[0], transform(pair[1])],
2539
2609
  /**
2540
2610
  * Transforms both values independently in a single step.
2541
2611
  *
2612
+ * @see {@link Pair.mapFirst} to transform only the first element.
2613
+ * @see {@link Pair.mapSecond} to transform only the second element.
2614
+ *
2542
2615
  * @example
2543
2616
  * ```ts
2544
2617
  * pipe(
2545
- * Pair.from.pair("alice", 42),
2618
+ * Pair.make("alice", 42),
2546
2619
  * Pair.mapBoth(
2547
2620
  * (name) => name.toUpperCase(),
2548
2621
  * (score) => score * 2,
@@ -2550,37 +2623,37 @@ const Pair = {
2550
2623
  * ); // ["ALICE", 84]
2551
2624
  * ```
2552
2625
  */
2553
- mapBoth: (onFirst, onSecond) => (p) => [onFirst(p[0]), onSecond(p[1])],
2626
+ mapBoth: (onFirst, onSecond) => (pair) => [onFirst(pair[0]), onSecond(pair[1])],
2554
2627
  /**
2555
2628
  * Applies a binary function to both values, collapsing the pair into a single value.
2556
2629
  * Useful as the final step when consuming a pair in a pipeline.
2557
2630
  *
2558
2631
  * @example
2559
2632
  * ```ts
2560
- * pipe(Pair.from.pair("Alice", 100), Pair.fold((name, score) => `${name}: ${score}`));
2633
+ * pipe(Pair.make("Alice", 100), Pair.fold((name, score) => `${name}: ${score}`));
2561
2634
  * // "Alice: 100"
2562
2635
  * ```
2563
2636
  */
2564
- fold: (f) => (p) => f(p[0], p[1]),
2637
+ fold: (reducer) => (pair) => reducer(pair[0], pair[1]),
2565
2638
  /**
2566
2639
  * Swaps the two values: `[A, B]` becomes `[B, A]`.
2567
2640
  *
2568
2641
  * @example
2569
2642
  * ```ts
2570
- * Pair.swap(Pair.from.pair("key", 1)); // [1, "key"]
2643
+ * Pair.swap(Pair.make("key", 1)); // [1, "key"]
2571
2644
  * ```
2572
2645
  */
2573
- swap: (p) => [p[1], p[0]],
2646
+ swap: (pair) => [pair[1], pair[0]],
2574
2647
  to: {
2575
2648
  /**
2576
2649
  * Converts the pair to a heterogeneous readonly array `readonly (A | B)[]`.
2577
2650
  *
2578
2651
  * @example
2579
2652
  * ```ts
2580
- * Pair.to.Array(Pair.from.pair("hello", 42)); // ["hello", 42]
2653
+ * Pair.to.array(Pair.make("hello", 42)); // ["hello", 42]
2581
2654
  * ```
2582
2655
  */
2583
- Array: (p) => [...p] },
2656
+ array: (pair) => [...pair] },
2584
2657
  /**
2585
2658
  * Runs a side effect with both values without changing the pair.
2586
2659
  * Useful for logging or debugging in the middle of a pipeline.
@@ -2588,15 +2661,15 @@ Array: (p) => [...p] },
2588
2661
  * @example
2589
2662
  * ```ts
2590
2663
  * pipe(
2591
- * Pair.from.pair("Paris", 2_161_000),
2664
+ * Pair.make("Paris", 2_161_000),
2592
2665
  * Pair.tap((city, pop) => console.log(`${city}: ${pop}`)),
2593
2666
  * Pair.mapSecond((n) => n / 1_000_000),
2594
2667
  * ); // logs "Paris: 2161000", returns ["Paris", 2.161]
2595
2668
  * ```
2596
2669
  */
2597
- tap: (f) => (p) => {
2598
- f(p[0], p[1]);
2599
- return p;
2670
+ tap: (sideEffect) => (pair) => {
2671
+ sideEffect(pair[0], pair[1]);
2672
+ return pair;
2600
2673
  }
2601
2674
  };
2602
2675
  //#endregion
@@ -2839,12 +2912,12 @@ const Reader = {
2839
2912
  * const add = (a: number) => (b: number) => a + b;
2840
2913
  * pipe(
2841
2914
  * Reader.resolve<Config, typeof add>(add),
2842
- * Reader.ap(Reader.asks(c => c.timeout)),
2843
- * Reader.ap(Reader.resolve(5))
2915
+ * Reader.apply(Reader.asks(c => c.timeout)),
2916
+ * Reader.apply(Reader.resolve(5))
2844
2917
  * )(appConfig);
2845
2918
  * ```
2846
2919
  */
2847
- ap: (arg) => (data) => (env) => data(env)(arg(env)),
2920
+ apply: (arg) => (data) => (env) => data(env)(arg(env)),
2848
2921
  /**
2849
2922
  * Executes a side effect on the produced value without changing the Reader.
2850
2923
  * Useful for logging or debugging inside a pipeline.
@@ -3053,10 +3126,10 @@ const makeSuccess = (value) => ({
3053
3126
  kind: "Success",
3054
3127
  value
3055
3128
  });
3056
- const isNotAsked = (data) => data.kind === "NotAsked";
3057
- const isLoading = (data) => data.kind === "Loading";
3058
- const isFailure = (data) => data.kind === "Failure";
3059
- const isSuccess = (data) => data.kind === "Success";
3129
+ const isNotAsked = (remoteData) => remoteData.kind === "NotAsked";
3130
+ const isLoading = (remoteData) => remoteData.kind === "Loading";
3131
+ const isFailure = (remoteData) => remoteData.kind === "Failure";
3132
+ const isSuccess = (remoteData) => remoteData.kind === "Success";
3060
3133
  const RemoteData = {
3061
3134
  make: {
3062
3135
  /**
@@ -3124,6 +3197,8 @@ const RemoteData = {
3124
3197
  /**
3125
3198
  * Type guard that checks if a RemoteData is Failure.
3126
3199
  *
3200
+ * @see {@link RemoteData.is.success} to check if data loaded successfully.
3201
+ *
3127
3202
  * @example
3128
3203
  * ```ts
3129
3204
  * const data = RemoteData.make.failure("Failed");
@@ -3136,6 +3211,8 @@ const RemoteData = {
3136
3211
  /**
3137
3212
  * Type guard that checks if a RemoteData is Success.
3138
3213
  *
3214
+ * @see {@link RemoteData.is.failure} to check if data loading failed.
3215
+ *
3139
3216
  * @example
3140
3217
  * ```ts
3141
3218
  * const data = RemoteData.make.success(42);
@@ -3149,26 +3226,33 @@ const RemoteData = {
3149
3226
  /**
3150
3227
  * Transforms the success value inside a RemoteData.
3151
3228
  *
3229
+ * @see {@link RemoteData.chain} to sequence operations that themselves return a RemoteData.
3230
+ * @see {@link RemoteData.mapError} to transform the error value instead of the success value.
3231
+ *
3152
3232
  * @example
3153
3233
  * ```ts
3154
3234
  * pipe(RemoteData.make.success(5), RemoteData.map(n => n * 2)); // Success(10)
3155
3235
  * pipe(RemoteData.make.loading(), RemoteData.map(n => n * 2)); // Loading
3156
3236
  * ```
3157
3237
  */
3158
- map: (f) => (data) => isSuccess(data) ? makeSuccess(f(data.value)) : data,
3238
+ map: (transform) => (remoteData) => isSuccess(remoteData) ? makeSuccess(transform(remoteData.value)) : remoteData,
3159
3239
  /**
3160
3240
  * Transforms the error value inside a RemoteData.
3161
3241
  *
3242
+ * @see {@link RemoteData.map} to transform the success value instead of the error value.
3243
+ *
3162
3244
  * @example
3163
3245
  * ```ts
3164
3246
  * pipe(RemoteData.make.failure("oops"), RemoteData.mapError(e => e.toUpperCase())); // Failure("OOPS")
3165
3247
  * ```
3166
3248
  */
3167
- mapError: (f) => (data) => isFailure(data) ? makeFailure(f(data.error)) : data,
3249
+ mapError: (transform) => (remoteData) => isFailure(remoteData) ? makeFailure(transform(remoteData.error)) : remoteData,
3168
3250
  /**
3169
- * Chains RemoteData computations. If the input is Success, passes the value to f.
3251
+ * Chains RemoteData computations. If the input is Success, passes the value to transform.
3170
3252
  * Otherwise, propagates the current state.
3171
3253
  *
3254
+ * @see {@link RemoteData.map} to transform the success value without returning a new RemoteData.
3255
+ *
3172
3256
  * @example
3173
3257
  * ```ts
3174
3258
  * pipe(
@@ -3177,7 +3261,7 @@ const RemoteData = {
3177
3261
  * );
3178
3262
  * ```
3179
3263
  */
3180
- chain: (f) => (data) => isSuccess(data) ? f(data.value) : data,
3264
+ chain: (transform) => (remoteData) => isSuccess(remoteData) ? transform(remoteData.value) : remoteData,
3181
3265
  /**
3182
3266
  * Applies a function wrapped in a RemoteData to a value wrapped in a RemoteData.
3183
3267
  *
@@ -3186,27 +3270,29 @@ const RemoteData = {
3186
3270
  * const add = (a: number) => (b: number) => a + b;
3187
3271
  * pipe(
3188
3272
  * RemoteData.make.success(add),
3189
- * RemoteData.ap(RemoteData.make.success(5)),
3190
- * RemoteData.ap(RemoteData.make.success(3))
3273
+ * RemoteData.apply(RemoteData.make.success(5)),
3274
+ * RemoteData.apply(RemoteData.make.success(3))
3191
3275
  * ); // Success(8)
3192
3276
  * ```
3193
3277
  */
3194
- ap: (arg) => (data) => {
3195
- if (isSuccess(data) && isSuccess(arg)) return makeSuccess(data.value(arg.value));
3196
- if (isFailure(data)) return data;
3278
+ apply: (arg) => (remoteData) => {
3279
+ if (isSuccess(remoteData) && isSuccess(arg)) return makeSuccess(remoteData.value(arg.value));
3280
+ if (isFailure(remoteData)) return remoteData;
3197
3281
  if (isFailure(arg)) return arg;
3198
- if (isLoading(data) || isLoading(arg)) return makeLoading();
3282
+ if (isLoading(remoteData) || isLoading(arg)) return makeLoading();
3199
3283
  return makeNotAsked();
3200
3284
  },
3201
3285
  /**
3202
3286
  * Extracts the value from a RemoteData by providing handlers for all four cases.
3203
3287
  *
3288
+ * @see {@link RemoteData.match} for named-case pattern matching with an object literal.
3289
+ *
3204
3290
  * @example
3205
3291
  * ```ts
3206
3292
  * pipe(
3207
3293
  * userData,
3208
3294
  * RemoteData.fold(
3209
- * e => `Error: ${e}`,
3295
+ * error => `Error: ${error}`,
3210
3296
  * () => "Not asked",
3211
3297
  * () => "Loading...",
3212
3298
  * value => `Got: ${value}`
@@ -3214,17 +3300,19 @@ const RemoteData = {
3214
3300
  * );
3215
3301
  * ```
3216
3302
  */
3217
- fold: (onFailure, onNotAsked, onLoading, onSuccess) => (data) => {
3218
- switch (data.kind) {
3219
- case "Failure": return onFailure(data.error);
3303
+ fold: (onFailure, onNotAsked, onLoading, onSuccess) => (remoteData) => {
3304
+ switch (remoteData.kind) {
3305
+ case "Failure": return onFailure(remoteData.error);
3220
3306
  case "NotAsked": return onNotAsked();
3221
3307
  case "Loading": return onLoading();
3222
- case "Success": return onSuccess(data.value);
3308
+ case "Success": return onSuccess(remoteData.value);
3223
3309
  }
3224
3310
  },
3225
3311
  /**
3226
3312
  * Pattern matches on a RemoteData, returning the result of the matching case.
3227
3313
  *
3314
+ * @see {@link RemoteData.fold} for positional argument pattern matching.
3315
+ *
3228
3316
  * @example
3229
3317
  * ```ts
3230
3318
  * pipe(
@@ -3232,24 +3320,26 @@ const RemoteData = {
3232
3320
  * RemoteData.match({
3233
3321
  * notAsked: () => "Click to load",
3234
3322
  * loading: () => "Loading...",
3235
- * failure: e => `Error: ${e}`,
3323
+ * failure: error => `Error: ${error}`,
3236
3324
  * success: user => `Hello, ${user.name}!`
3237
3325
  * })
3238
3326
  * );
3239
3327
  * ```
3240
3328
  */
3241
- match: (cases) => (data) => {
3242
- switch (data.kind) {
3329
+ match: (cases) => (remoteData) => {
3330
+ switch (remoteData.kind) {
3243
3331
  case "NotAsked": return cases.notAsked();
3244
3332
  case "Loading": return cases.loading();
3245
- case "Failure": return cases.failure(data.error);
3246
- case "Success": return cases.success(data.value);
3333
+ case "Failure": return cases.failure(remoteData.error);
3334
+ case "Success": return cases.success(remoteData.value);
3247
3335
  }
3248
3336
  },
3249
3337
  /**
3250
3338
  * Returns the success value or a default value if the RemoteData is not Success.
3251
3339
  * The default can be a different type, widening the result to `A | B`.
3252
3340
  *
3341
+ * @see {@link RemoteData.fold} to handle all four lifecycle states.
3342
+ *
3253
3343
  * @example
3254
3344
  * ```ts
3255
3345
  * pipe(RemoteData.make.success(5), RemoteData.getOrElse(() => 0)); // 5
@@ -3257,10 +3347,12 @@ const RemoteData = {
3257
3347
  * pipe(RemoteData.make.loading<string, number>(), RemoteData.getOrElse(() => null)); // null — typed as number | null
3258
3348
  * ```
3259
3349
  */
3260
- getOrElse: (defaultValue) => (data) => isSuccess(data) ? data.value : defaultValue(),
3350
+ getOrElse: (fallback) => (remoteData) => isSuccess(remoteData) ? remoteData.value : fallback(),
3261
3351
  /**
3262
3352
  * Executes a side effect on the success value without changing the RemoteData.
3263
3353
  *
3354
+ * @see {@link RemoteData.tapError} to perform a side effect on the failure error.
3355
+ *
3264
3356
  * @example
3265
3357
  * ```ts
3266
3358
  * pipe(
@@ -3270,14 +3362,16 @@ const RemoteData = {
3270
3362
  * );
3271
3363
  * ```
3272
3364
  */
3273
- tap: (f) => (data) => {
3274
- if (isSuccess(data)) f(data.value);
3275
- return data;
3365
+ tap: (sideEffect) => (remoteData) => {
3366
+ if (isSuccess(remoteData)) sideEffect(remoteData.value);
3367
+ return remoteData;
3276
3368
  },
3277
3369
  /**
3278
3370
  * Executes a side effect on the failure error without changing the RemoteData.
3279
3371
  * Useful for logging errors.
3280
3372
  *
3373
+ * @see {@link RemoteData.tap} to perform a side effect on the success value.
3374
+ *
3281
3375
  * @example
3282
3376
  * ```ts
3283
3377
  * pipe(
@@ -3287,21 +3381,21 @@ const RemoteData = {
3287
3381
  * );
3288
3382
  * ```
3289
3383
  */
3290
- tapError: (f) => (data) => {
3291
- if (isFailure(data)) f(data.error);
3292
- return data;
3384
+ tapError: (sideEffect) => (remoteData) => {
3385
+ if (isFailure(remoteData)) sideEffect(remoteData.error);
3386
+ return remoteData;
3293
3387
  },
3294
3388
  /**
3295
3389
  * Recovers from a Failure state by providing a fallback RemoteData.
3296
- * The fallback can produce a different success type, widening the result to `RemoteData<E, A | B>`.
3390
+ * The fallback can produce a different success type or resolve with a different error type.
3297
3391
  */
3298
- recover: (fallback) => (data) => isFailure(data) ? fallback(data.error) : data,
3392
+ recover: (fallback) => (remoteData) => isFailure(remoteData) ? fallback(remoteData.error) : remoteData,
3299
3393
  to: {
3300
3394
  /**
3301
3395
  * Converts a RemoteData to a Maybe.
3302
3396
  * Success becomes Some, all other states become None.
3303
3397
  */
3304
- Maybe: (data) => isSuccess(data) ? Maybe.make.some(data.value) : Maybe.make.none(),
3398
+ Maybe: (remoteData) => isSuccess(remoteData) ? Maybe.make.some(remoteData.value) : Maybe.make.none(),
3305
3399
  /**
3306
3400
  * Converts a RemoteData to a Result.
3307
3401
  * Success becomes Ok, Failure becomes Err.
@@ -3315,7 +3409,7 @@ const RemoteData = {
3315
3409
  * ); // Ok(42)
3316
3410
  * ```
3317
3411
  */
3318
- Result: (onNotReady) => (data) => isSuccess(data) ? Result.make.ok(data.value) : Result.make.err(isFailure(data) ? data.error : onNotReady())
3412
+ Result: (onNotReady) => (remoteData) => isSuccess(remoteData) ? Result.make.ok(remoteData.value) : Result.make.err(isFailure(remoteData) ? remoteData.error : onNotReady())
3319
3413
  },
3320
3414
  from: {
3321
3415
  /**
@@ -3328,7 +3422,7 @@ const RemoteData = {
3328
3422
  * setState(RemoteData.from.Result(result)); // Success(user) or Failure(msg)
3329
3423
  * ```
3330
3424
  */
3331
- Result: (data) => Result.is.ok(data) ? makeSuccess(data.value) : makeFailure(data.error),
3425
+ Result: (result) => Result.is.ok(result) ? makeSuccess(result.value) : makeFailure(result.error),
3332
3426
  /**
3333
3427
  * Converts a Maybe to a RemoteData.
3334
3428
  * Some becomes Success, None becomes Failure using the onNone error producer.
@@ -3339,7 +3433,7 @@ const RemoteData = {
3339
3433
  * pipe(Maybe.make.none(), RemoteData.from.Maybe(() => "not found")); // Failure("not found")
3340
3434
  * ```
3341
3435
  */
3342
- Maybe: (onNone) => (data) => Maybe.is.some(data) ? makeSuccess(data.value) : makeFailure(onNone())
3436
+ Maybe: (onNone) => (maybe) => Maybe.is.some(maybe) ? makeSuccess(maybe.value) : makeFailure(onNone())
3343
3437
  },
3344
3438
  /**
3345
3439
  * Filters a `Success` value. When the predicate passes, the value is kept. When it fails,
@@ -3354,7 +3448,7 @@ const RemoteData = {
3354
3448
  * RemoteData.filter(n => n > 0, () => "error")(RemoteData.make.loading()); // Loading
3355
3449
  * ```
3356
3450
  */
3357
- filter: (pred, onFalse) => (data) => isSuccess(data) ? pred(data.value) ? data : makeFailure(onFalse(data.value)) : data
3451
+ filter: (predicate, onFalse) => (remoteData) => isSuccess(remoteData) ? predicate(remoteData.value) ? remoteData : makeFailure(onFalse(remoteData.value)) : remoteData
3358
3452
  };
3359
3453
  //#endregion
3360
3454
  //#region src/Core/Resource.ts
@@ -3362,7 +3456,7 @@ const makeHandlers = (acquire, release) => ({
3362
3456
  acquire,
3363
3457
  release
3364
3458
  });
3365
- const makeTask = (acquire, release) => ({
3459
+ const makeTask$1 = (acquire, release) => ({
3366
3460
  acquire: Task.map((a) => Result.make.ok(a))(acquire),
3367
3461
  release
3368
3462
  });
@@ -3393,7 +3487,7 @@ const Resource = {
3393
3487
  * );
3394
3488
  * ```
3395
3489
  */
3396
- Task: makeTask
3490
+ Task: makeTask$1
3397
3491
  },
3398
3492
  /**
3399
3493
  * Acquires the resource, runs `f` with it, then releases it.
@@ -3456,12 +3550,12 @@ const makeOk$1 = (value) => ({
3456
3550
  kind: "Ok",
3457
3551
  value
3458
3552
  });
3459
- const makeErr$1 = (e) => ({
3553
+ const makeErr$1 = (error) => ({
3460
3554
  kind: "Err",
3461
- error: e
3555
+ error
3462
3556
  });
3463
- const isOk = (data) => data.kind === "Ok";
3464
- const isErr = (data) => data.kind === "Err";
3557
+ const isOk = (result) => result.kind === "Ok";
3558
+ const isErr = (result) => result.kind === "Err";
3465
3559
  const Result = {
3466
3560
  make: {
3467
3561
  /**
@@ -3487,6 +3581,8 @@ const Result = {
3487
3581
  /**
3488
3582
  * Type guard that checks if a Result is Ok.
3489
3583
  *
3584
+ * @see {@link Result.is.err} to check if a Result is an Err failure.
3585
+ *
3490
3586
  * @example
3491
3587
  * ```ts
3492
3588
  * const res = Result.make.ok(42);
@@ -3499,6 +3595,8 @@ const Result = {
3499
3595
  /**
3500
3596
  * Type guard that checks if a Result is Err.
3501
3597
  *
3598
+ * @see {@link Result.is.ok} to check if a Result is an Ok success.
3599
+ *
3502
3600
  * @example
3503
3601
  * ```ts
3504
3602
  * const res = Result.make.err("failed");
@@ -3517,13 +3615,13 @@ const Result = {
3517
3615
  * ```ts
3518
3616
  * const result = Result.tryCatch(
3519
3617
  * () => JSON.parse(rawString),
3520
- * { onError: (e) => `Parse error: ${e}` }
3618
+ * { onError: (error) => `Parse error: ${error}` }
3521
3619
  * );
3522
3620
  * ```
3523
3621
  */
3524
- tryCatch: (f, options) => {
3622
+ tryCatch: (fn, options) => {
3525
3623
  try {
3526
- return makeOk$1(f());
3624
+ return makeOk$1(fn());
3527
3625
  } catch (error) {
3528
3626
  return makeErr$1(options.onError(error));
3529
3627
  }
@@ -3531,26 +3629,33 @@ const Result = {
3531
3629
  /**
3532
3630
  * Transforms the success value inside a Result.
3533
3631
  *
3632
+ * @see {@link Result.chain} to sequence operations that themselves return a Result.
3633
+ * @see {@link Result.mapError} to transform the error value instead of the success value.
3634
+ *
3534
3635
  * @example
3535
3636
  * ```ts
3536
3637
  * pipe(Result.make.ok(5), Result.map(n => n * 2)); // Ok(10)
3537
3638
  * pipe(Result.make.err("error"), Result.map(n => n * 2)); // Err("error")
3538
3639
  * ```
3539
3640
  */
3540
- map: (f) => (data) => isOk(data) ? makeOk$1(f(data.value)) : data,
3641
+ map: (transform) => (result) => isOk(result) ? makeOk$1(transform(result.value)) : result,
3541
3642
  /**
3542
3643
  * Transforms the error value inside a Result.
3543
3644
  *
3645
+ * @see {@link Result.map} to transform the success value instead of the error value.
3646
+ *
3544
3647
  * @example
3545
3648
  * ```ts
3546
3649
  * pipe(Result.make.err("oops"), Result.mapError(e => e.toUpperCase())); // Err("OOPS")
3547
3650
  * ```
3548
3651
  */
3549
- mapError: (f) => (data) => isErr(data) ? makeErr$1(f(data.error)) : data,
3652
+ mapError: (transform) => (result) => isErr(result) ? makeErr$1(transform(result.error)) : result,
3550
3653
  /**
3551
- * Chains Result computations. If the first is Ok, passes the value to f.
3654
+ * Chains Result computations. If the first is Ok, passes the value to transform.
3552
3655
  * If the first is Err, propagates the error.
3553
3656
  *
3657
+ * @see {@link Result.map} to transform the inner value without returning a new Result.
3658
+ *
3554
3659
  * @example
3555
3660
  * ```ts
3556
3661
  * const validatePositive = (n: number): Result<string, number> =>
@@ -3560,25 +3665,29 @@ const Result = {
3560
3665
  * pipe(Result.make.ok(-1), Result.chain(validatePositive)); // Err("Must be positive")
3561
3666
  * ```
3562
3667
  */
3563
- chain: (f) => (data) => isOk(data) ? f(data.value) : data,
3668
+ chain: (transform) => (result) => isOk(result) ? transform(result.value) : result,
3564
3669
  /**
3565
3670
  * Extracts the value from a Result by providing handlers for both cases.
3566
3671
  *
3672
+ * @see {@link Result.match} for named-case pattern matching with an object literal.
3673
+ *
3567
3674
  * @example
3568
3675
  * ```ts
3569
3676
  * pipe(
3570
3677
  * Result.make.ok(5),
3571
3678
  * Result.fold(
3572
- * e => `Error: ${e}`,
3573
- * n => `Value: ${n}`
3679
+ * error => `Error: ${error}`,
3680
+ * value => `Value: ${value}`
3574
3681
  * )
3575
3682
  * ); // "Value: 5"
3576
3683
  * ```
3577
3684
  */
3578
- fold: (onErr, onOk) => (data) => isOk(data) ? onOk(data.value) : onErr(data.error),
3685
+ fold: (onErr, onOk) => (result) => isOk(result) ? onOk(result.value) : onErr(result.error),
3579
3686
  /**
3580
3687
  * Pattern matches on a Result, returning the result of the matching case.
3581
3688
  *
3689
+ * @see {@link Result.fold} for positional argument pattern matching.
3690
+ *
3582
3691
  * @example
3583
3692
  * ```ts
3584
3693
  * pipe(
@@ -3590,12 +3699,14 @@ const Result = {
3590
3699
  * );
3591
3700
  * ```
3592
3701
  */
3593
- match: (cases) => (data) => isOk(data) ? cases.ok(data.value) : cases.err(data.error),
3702
+ match: (cases) => (result) => isOk(result) ? cases.ok(result.value) : cases.err(result.error),
3594
3703
  /**
3595
3704
  * Returns the success value or a default value if the Result is an error.
3596
3705
  * The default is a thunk `() => B` — evaluated only when the Result is Err.
3597
3706
  * The default can be a different type, widening the result to `A | B`.
3598
3707
  *
3708
+ * @see {@link Result.fold} to handle both the Ok and Err cases.
3709
+ *
3599
3710
  * @example
3600
3711
  * ```ts
3601
3712
  * pipe(Result.make.ok(5), Result.getOrElse(() => 0)); // 5
@@ -3603,11 +3714,13 @@ const Result = {
3603
3714
  * pipe(Result.make.err("error"), Result.getOrElse(() => null)); // null — typed as number | null
3604
3715
  * ```
3605
3716
  */
3606
- getOrElse: (defaultValue) => (data) => isOk(data) ? data.value : defaultValue(),
3717
+ getOrElse: (fallback) => (result) => isOk(result) ? result.value : fallback(),
3607
3718
  /**
3608
3719
  * Executes a side effect on the success value without changing the Result.
3609
3720
  * Useful for logging or debugging.
3610
3721
  *
3722
+ * @see {@link Result.tapError} to perform a side effect on the error value.
3723
+ *
3611
3724
  * @example
3612
3725
  * ```ts
3613
3726
  * pipe(
@@ -3617,14 +3730,16 @@ const Result = {
3617
3730
  * );
3618
3731
  * ```
3619
3732
  */
3620
- tap: (f) => (data) => {
3621
- if (isOk(data)) f(data.value);
3622
- return data;
3733
+ tap: (sideEffect) => (result) => {
3734
+ if (isOk(result)) sideEffect(result.value);
3735
+ return result;
3623
3736
  },
3624
3737
  /**
3625
3738
  * Executes a side effect on the error value without changing the Result.
3626
3739
  * Useful for logging or reporting errors.
3627
3740
  *
3741
+ * @see {@link Result.tap} to perform a side effect on the success value.
3742
+ *
3628
3743
  * @example
3629
3744
  * ```ts
3630
3745
  * pipe(
@@ -3634,9 +3749,9 @@ const Result = {
3634
3749
  * )
3635
3750
  * ```
3636
3751
  */
3637
- tapError: (f) => (data) => {
3638
- if (isErr(data)) f(data.error);
3639
- return data;
3752
+ tapError: (sideEffect) => (result) => {
3753
+ if (isErr(result)) sideEffect(result.error);
3754
+ return result;
3640
3755
  },
3641
3756
  from: {
3642
3757
  /**
@@ -3650,7 +3765,7 @@ const Result = {
3650
3765
  * pipe("", Result.from.Predicate(s => s.length > 0, () => "empty string")); // Err("empty string")
3651
3766
  * ```
3652
3767
  */
3653
- Predicate: (pred, onFalse) => (a) => pred(a) ? makeOk$1(a) : makeErr$1(onFalse(a)),
3768
+ Predicate: (predicate, onFalse) => (value) => predicate(value) ? makeOk$1(value) : makeErr$1(onFalse(value)),
3654
3769
  /**
3655
3770
  * Creates a Result from a nullable value.
3656
3771
  * Returns Ok if the value is not null or undefined, error from onNull otherwise.
@@ -3682,16 +3797,20 @@ const Result = {
3682
3797
  * Result.from.Validation((errors) => errors.join(", "))(Validation.make.failed("error1")); // Err("error1")
3683
3798
  * ```
3684
3799
  */
3685
- Validation: (combineErrors) => (val) => Validation.is.passed(val) ? makeOk$1(val.value) : makeErr$1(combineErrors(val.errors))
3800
+ Validation: (combineErrors) => (validation) => Validation.is.passed(validation) ? makeOk$1(validation.value) : makeErr$1(combineErrors(validation.errors))
3686
3801
  },
3687
3802
  /**
3688
3803
  * Recovers from an error by providing a fallback Result.
3689
- * The fallback can produce a different success type, widening the result to `Result<E, A | B>`.
3804
+ * The fallback can produce a different success type or resolve with a different error type.
3805
+ *
3806
+ * @see {@link Result.recoverUnless} to conditionally recover based on the error value.
3690
3807
  */
3691
- recover: (fallback) => (data) => isOk(data) ? data : fallback(data.error),
3808
+ recover: (fallback) => (result) => isOk(result) ? result : fallback(result.error),
3692
3809
  /**
3693
3810
  * Recovers from an error unless the predicate `isBlocked` returns true for that error.
3694
- * The fallback can produce a different success type, widening the result to `Result<E, A | B>`.
3811
+ * The fallback can produce a different success type, widening the result to `Result<E1 | E2, A | B>`.
3812
+ *
3813
+ * @see {@link Result.recover} for unconditional error recovery.
3695
3814
  *
3696
3815
  * @example
3697
3816
  * ```ts
@@ -3701,7 +3820,7 @@ const Result = {
3701
3820
  * ); // Ok(0)
3702
3821
  * ```
3703
3822
  */
3704
- recoverUnless: (isBlocked, fallback) => (data) => isErr(data) && !isBlocked(data.error) ? fallback() : data,
3823
+ recoverUnless: (isBlocked, fallback) => (result) => isErr(result) && !isBlocked(result.error) ? fallback(result.error) : result,
3705
3824
  to: {
3706
3825
  /**
3707
3826
  * Converts a Result to a Maybe.
@@ -3713,7 +3832,7 @@ const Result = {
3713
3832
  * Result.to.Maybe(Result.make.err("oops")); // None
3714
3833
  * ```
3715
3834
  */
3716
- Maybe: (data) => isOk(data) ? Maybe.make.some(data.value) : Maybe.make.none(),
3835
+ Maybe: (result) => isOk(result) ? Maybe.make.some(result.value) : Maybe.make.none(),
3717
3836
  /**
3718
3837
  * Converts a `Result` to a `Validation`. `Ok(a)` becomes `Passed(a)`; `Err(e)` becomes `Failed([e])`.
3719
3838
  *
@@ -3723,7 +3842,7 @@ const Result = {
3723
3842
  * Result.to.Validation(Result.make.err("bad")); // Failed(["bad"])
3724
3843
  * ```
3725
3844
  */
3726
- Validation: (data) => Validation.from.Result(data)
3845
+ Validation: (result) => Validation.from.Result(result)
3727
3846
  },
3728
3847
  /**
3729
3848
  * Swaps the outer `Result` and inner `Maybe` context.
@@ -3736,7 +3855,7 @@ const Result = {
3736
3855
  * Result.transposeMaybe(Result.make.err("error")); // Some(Err("error"))
3737
3856
  * ```
3738
3857
  */
3739
- transposeMaybe: (data) => isErr(data) ? Maybe.make.some(data) : Maybe.is.some(data.value) ? Maybe.make.some(makeOk$1(data.value.value)) : Maybe.make.none(),
3858
+ transposeMaybe: (result) => isErr(result) ? Maybe.make.some(result) : Maybe.is.some(result.value) ? Maybe.make.some(makeOk$1(result.value.value)) : Maybe.make.none(),
3740
3859
  /**
3741
3860
  * Applies a function wrapped in a Result to a value wrapped in a Result.
3742
3861
  *
@@ -3745,12 +3864,12 @@ const Result = {
3745
3864
  * const add = (a: number) => (b: number) => a + b;
3746
3865
  * pipe(
3747
3866
  * Result.make.ok(add),
3748
- * Result.ap(Result.make.ok(5)),
3749
- * Result.ap(Result.make.ok(3))
3867
+ * Result.apply(Result.make.ok(5)),
3868
+ * Result.apply(Result.make.ok(3))
3750
3869
  * ); // Ok(8)
3751
3870
  * ```
3752
3871
  */
3753
- ap: (arg) => (data) => isOk(data) && isOk(arg) ? makeOk$1(data.value(arg.value)) : isErr(data) ? data : arg,
3872
+ apply: (arg) => (result) => isOk(result) && isOk(arg) ? makeOk$1(result.value(arg.value)) : isErr(result) ? result : arg,
3754
3873
  /**
3755
3874
  * Converts a Result value into an object containing a single property.
3756
3875
  * Initiates the pipeline accumulator record.
@@ -3760,7 +3879,7 @@ const Result = {
3760
3879
  * pipe(Result.make.ok(42), Result.bindTo("value")); // Ok({ value: 42 })
3761
3880
  * ```
3762
3881
  */
3763
- bindTo: (key) => (data) => isOk(data) ? makeOk$1({ [key]: data.value }) : data,
3882
+ bindTo: (key) => (result) => isOk(result) ? makeOk$1({ [key]: result.value }) : result,
3764
3883
  /**
3765
3884
  * Evaluates a new Result using the current accumulator and attaches the output to a new key.
3766
3885
  *
@@ -3772,11 +3891,11 @@ const Result = {
3772
3891
  * ); // Ok({ a: 1, b: 2 })
3773
3892
  * ```
3774
3893
  */
3775
- bind: (key, f) => (data) => {
3776
- if (!isOk(data)) return data;
3777
- const res = f(data.value);
3894
+ bind: (key, transform) => (result) => {
3895
+ if (!isOk(result)) return result;
3896
+ const res = transform(result.value);
3778
3897
  return isOk(res) ? makeOk$1({
3779
- ...data.value,
3898
+ ...result.value,
3780
3899
  [key]: res.value
3781
3900
  }) : res;
3782
3901
  },
@@ -3802,7 +3921,7 @@ const Result = {
3802
3921
  return makeOk$1(result);
3803
3922
  },
3804
3923
  /**
3805
- * Narrows an `Ok` value with a predicate, converting to `Err(onFail(a))` if the predicate returns false.
3924
+ * Narrows an `Ok` value with a predicate, converting to `Err(onFail(value))` if the predicate returns false.
3806
3925
  *
3807
3926
  * @example
3808
3927
  * ```ts
@@ -3812,7 +3931,7 @@ const Result = {
3812
3931
  * ); // Err("Age 15 is below 18")
3813
3932
  * ```
3814
3933
  */
3815
- ensure: (predicate, onFail) => (data) => isErr(data) ? data : predicate(data.value) ? data : makeErr$1(onFail(data.value)),
3934
+ ensure: (predicate, onFail) => (result) => isErr(result) ? result : predicate(result.value) ? result : makeErr$1(onFail(result.value)),
3816
3935
  /**
3817
3936
  * Transforms both branches of a Result simultaneously.
3818
3937
  * Applies `onErr` to `Err` values and `onOk` to `Ok` values.
@@ -3828,7 +3947,7 @@ const Result = {
3828
3947
  * ); // Ok(10)
3829
3948
  * ```
3830
3949
  */
3831
- bimap: (onErr, onOk) => (data) => isOk(data) ? makeOk$1(onOk(data.value)) : makeErr$1(onErr(data.error))
3950
+ bimap: (onErr, onOk) => (result) => isOk(result) ? makeOk$1(onOk(result.value)) : makeErr$1(onErr(result.error))
3832
3951
  };
3833
3952
  //#endregion
3834
3953
  //#region src/Core/State.ts
@@ -3941,14 +4060,14 @@ const State = {
3941
4060
  * const addCounted = (n: number) => (m: number) => n + m;
3942
4061
  * const program = pipe(
3943
4062
  * State.resolve<number, typeof addCounted>(addCounted),
3944
- * State.ap(State.gets((s: number) => s * 2)),
3945
- * State.ap(State.gets((s: number) => s)),
4063
+ * State.apply(State.gets((s: number) => s * 2)),
4064
+ * State.apply(State.gets((s: number) => s)),
3946
4065
  * );
3947
4066
  *
3948
4067
  * State.evaluate(3)(program); // 6 + 3 = 9
3949
4068
  * ```
3950
4069
  */
3951
- ap: (arg) => (fn) => (s) => {
4070
+ apply: (arg) => (fn) => (s) => {
3952
4071
  const [f, s1] = fn(s);
3953
4072
  const [a, s2] = arg(s1);
3954
4073
  return [f(a), s2];
@@ -4055,10 +4174,10 @@ const State = {
4055
4174
  };
4056
4175
  //#endregion
4057
4176
  //#region src/Core/TaskMaybe.ts
4058
- const makeSome = (value) => Task.resolve(Maybe.make.some(value));
4059
- const makeNone = () => Task.resolve(Maybe.make.none());
4060
- const mapTaskMaybe = (f) => (data) => Task.map(Maybe.map(f))(data);
4061
- const chainTaskMaybe = (f) => (data) => Task.chain((option) => Maybe.is.some(option) ? f(option.value) : Task.resolve(Maybe.make.none()))(data);
4177
+ const makeSome = (value) => Task.make(Maybe.make.some(value));
4178
+ const makeNone = () => Task.make(Maybe.make.none());
4179
+ const mapTaskMaybe = (transform) => (task) => Task.map(Maybe.map(transform))(task);
4180
+ const chainTaskMaybe = (transform) => (task) => Task.chain((maybe) => Maybe.is.some(maybe) ? transform(maybe.value) : Task.make(Maybe.make.none()))(task);
4062
4181
  const TaskMaybe = {
4063
4182
  /**
4064
4183
  * Wraps a value in a Some inside a Task.
@@ -4100,7 +4219,7 @@ const TaskMaybe = {
4100
4219
  * Task.Maybe.from.Maybe(Maybe.make.some(42));
4101
4220
  * ```
4102
4221
  */
4103
- Maybe: (option) => Task.resolve(option),
4222
+ Maybe: (maybe) => Task.make(maybe),
4104
4223
  /**
4105
4224
  * Creates a Task.Maybe from a nullable value.
4106
4225
  * Returns Some if the value is not null or undefined, None otherwise.
@@ -4111,7 +4230,7 @@ const TaskMaybe = {
4111
4230
  * Task.Maybe.from.nullable(null); // resolves to None
4112
4231
  * ```
4113
4232
  */
4114
- nullable: (value) => Task.resolve(Maybe.from.nullable(value)),
4233
+ nullable: (value) => Task.make(Maybe.from.nullable(value)),
4115
4234
  /**
4116
4235
  * Creates a Task.Maybe from a Result.
4117
4236
  * Ok becomes Some, Error becomes None (the error value is discarded).
@@ -4122,7 +4241,7 @@ const TaskMaybe = {
4122
4241
  * Task.Maybe.from.Result(Result.make.err("e")); // resolves to None
4123
4242
  * ```
4124
4243
  */
4125
- Result: (result) => Task.resolve(Result.to.Maybe(result)),
4244
+ Result: (result) => Task.make(Result.to.Maybe(result)),
4126
4245
  /**
4127
4246
  * Lifts a Task into a Task.Maybe by wrapping its result in Some.
4128
4247
  *
@@ -4145,14 +4264,18 @@ const TaskMaybe = {
4145
4264
  * );
4146
4265
  * ```
4147
4266
  */
4148
- tryCatch: (f) => (signal) => Deferred.from.Promise(Promise.resolve(f(signal)).then(Maybe.make.some).catch(() => Maybe.make.none())),
4267
+ tryCatch: (fn) => (signal) => Deferred.from.Promise(Promise.resolve(fn(signal)).then(Maybe.make.some).catch(() => Maybe.make.none())),
4149
4268
  /**
4150
4269
  * Transforms the value inside a Task.Maybe.
4270
+ *
4271
+ * @see {@link Task.Maybe.chain} to sequence operations that themselves return a Task.Maybe.
4151
4272
  */
4152
4273
  map: mapTaskMaybe,
4153
4274
  /**
4154
4275
  * Chains Task.Maybe computations. If the first resolves to Some, passes the
4155
- * value to f. If the first resolves to None, propagates None.
4276
+ * value to transform. If the first resolves to None, propagates None.
4277
+ *
4278
+ * @see {@link Task.Maybe.map} to transform the inner value without returning a new Task.Maybe.
4156
4279
  *
4157
4280
  * @example
4158
4281
  * ```ts
@@ -4167,14 +4290,18 @@ const TaskMaybe = {
4167
4290
  * Applies a function wrapped in a Task.Maybe to a value wrapped in a Task.Maybe.
4168
4291
  * Both Tasks run in parallel.
4169
4292
  */
4170
- ap: (arg) => (data) => (signal) => Deferred.from.Promise(Promise.all([Deferred.to.Promise(data(signal)), Deferred.to.Promise(arg(signal))]).then(([of_, oa]) => Maybe.ap(oa)(of_))),
4293
+ apply: (arg) => (task) => (signal) => Deferred.from.Promise(Promise.all([Deferred.to.Promise(task(signal)), Deferred.to.Promise(arg(signal))]).then(([of_, oa]) => Maybe.apply(oa)(of_))),
4171
4294
  /**
4172
4295
  * Extracts a value from a Task.Maybe by providing handlers for both cases.
4296
+ *
4297
+ * @see {@link Task.Maybe.match} for named-case pattern matching with an object literal.
4173
4298
  */
4174
- fold: (onNone, onSome) => (data) => Task.map(Maybe.fold(onNone, onSome))(data),
4299
+ fold: (onNone, onSome) => (task) => Task.map(Maybe.fold(onNone, onSome))(task),
4175
4300
  /**
4176
4301
  * Pattern matches on a Task.Maybe, returning a Task of the result.
4177
4302
  *
4303
+ * @see {@link Task.Maybe.fold} for positional argument pattern matching.
4304
+ *
4178
4305
  * @example
4179
4306
  * ```ts
4180
4307
  * pipe(
@@ -4186,21 +4313,21 @@ const TaskMaybe = {
4186
4313
  * )();
4187
4314
  * ```
4188
4315
  */
4189
- match: (cases) => (data) => Task.map(Maybe.match(cases))(data),
4316
+ match: (cases) => (task) => Task.map(Maybe.match(cases))(task),
4190
4317
  /**
4191
4318
  * Returns the value or a default if the Task.Maybe resolves to None.
4192
4319
  * The default can be a different type, widening the result to `Task<A | B>`.
4193
4320
  */
4194
- getOrElse: (defaultValue) => (data) => Task.map(Maybe.getOrElse(defaultValue))(data),
4321
+ getOrElse: (fallback) => (task) => Task.map(Maybe.getOrElse(fallback))(task),
4195
4322
  /**
4196
4323
  * Executes a side effect on the value without changing the Task.Maybe.
4197
4324
  * Useful for logging or debugging.
4198
4325
  */
4199
- tap: (f) => (data) => Task.map(Maybe.tap(f))(data),
4326
+ tap: (sideEffect) => (task) => Task.map(Maybe.tap(sideEffect))(task),
4200
4327
  /**
4201
4328
  * Filters the value inside a Task.Maybe. Returns None if the predicate fails.
4202
4329
  */
4203
- filter: (predicate) => (data) => Task.map(Maybe.filter(predicate))(data),
4330
+ filter: (predicate) => (task) => Task.map(Maybe.filter(predicate))(task),
4204
4331
  to: {
4205
4332
  /**
4206
4333
  * Converts a Task.Maybe to a Task.Result, using onNone to produce the error value.
@@ -4213,7 +4340,7 @@ const TaskMaybe = {
4213
4340
  * );
4214
4341
  * ```
4215
4342
  */
4216
- Result: (onNone) => (data) => Task.map(Maybe.to.Result(onNone))(data) },
4343
+ Result: (onNone) => (task) => Task.map(Maybe.to.Result(onNone))(task) },
4217
4344
  /**
4218
4345
  * Lifts a Task.Maybe value into an accumulator object.
4219
4346
  *
@@ -4222,7 +4349,7 @@ Result: (onNone) => (data) => Task.map(Maybe.to.Result(onNone))(data) },
4222
4349
  * pipe(Task.Maybe.make.some(42), Task.Maybe.bindTo("value")); // Task.Maybe({ value: 42 })
4223
4350
  * ```
4224
4351
  */
4225
- bindTo: (key) => (data) => mapTaskMaybe((a) => ({ [key]: a }))(data),
4352
+ bindTo: (key) => (task) => mapTaskMaybe((value) => ({ [key]: value }))(task),
4226
4353
  /**
4227
4354
  * Evaluates a new Task.Maybe using the current accumulator and attaches the output to a new key.
4228
4355
  *
@@ -4234,10 +4361,10 @@ Result: (onNone) => (data) => Task.map(Maybe.to.Result(onNone))(data) },
4234
4361
  * ); // Task.Maybe({ a: 1, b: 2 })
4235
4362
  * ```
4236
4363
  */
4237
- bind: (key, f) => (data) => chainTaskMaybe((a) => mapTaskMaybe((b) => ({
4238
- ...a,
4239
- [key]: b
4240
- }))(f(a)))(data),
4364
+ bind: (key, transform) => (task) => chainTaskMaybe((acc) => mapTaskMaybe((val) => ({
4365
+ ...acc,
4366
+ [key]: val
4367
+ }))(transform(acc)))(task),
4241
4368
  /**
4242
4369
  * Recovers from a None state by providing a fallback Task.Maybe.
4243
4370
  *
@@ -4249,7 +4376,7 @@ Result: (onNone) => (data) => Task.map(Maybe.to.Result(onNone))(data) },
4249
4376
  * ); // Task.Maybe(42)
4250
4377
  * ```
4251
4378
  */
4252
- recover: (fallback) => (data) => Task.chain((maybe) => Maybe.is.none(maybe) ? fallback() : Task.resolve(maybe))(data),
4379
+ recover: (fallback) => (task) => Task.chain((maybe) => Maybe.is.none(maybe) ? fallback() : Task.make(maybe))(task),
4253
4380
  /**
4254
4381
  * Combines a record of Task.Maybes into a single Task.Maybe of a record.
4255
4382
  * Evaluates fields in parallel and returns None if any task resolves to None.
@@ -4288,10 +4415,10 @@ Result: (onNone) => (data) => Task.map(Maybe.to.Result(onNone))(data) },
4288
4415
  };
4289
4416
  //#endregion
4290
4417
  //#region src/Core/TaskResult.ts
4291
- const makeOk = (value) => Task.resolve(Result.make.ok(value));
4292
- const makeErr = (error) => Task.resolve(Result.make.err(error));
4293
- const mapTaskResult = (f) => (data) => Task.map(Result.map(f))(data);
4294
- const chainTaskResult = (f) => (data) => Task.chain((result) => Result.is.ok(result) ? f(result.value) : Task.resolve(Result.make.err(result.error)))(data);
4418
+ const makeOk = (value) => Task.make(Result.make.ok(value));
4419
+ const makeErr = (error) => Task.make(Result.make.err(error));
4420
+ const mapTaskResult = (transform) => (task) => Task.map(Result.map(transform))(task);
4421
+ const chainTaskResult = (transform) => (task) => Task.chain((result) => Result.is.ok(result) ? transform(result.value) : Task.make(Result.make.err(result.error)))(task);
4295
4422
  const TaskResult = {
4296
4423
  make: {
4297
4424
  /**
@@ -4326,7 +4453,7 @@ const TaskResult = {
4326
4453
  * Task.Result.from.nullable(() => "missing")(null); // resolves to Err("missing")
4327
4454
  * ```
4328
4455
  */
4329
- nullable: (onNull) => (value) => Task.resolve(value === null || value === void 0 ? Result.make.err(onNull()) : Result.make.ok(value)),
4456
+ nullable: (onNull) => (value) => Task.make(value === null || value === void 0 ? Result.make.err(onNull()) : Result.make.ok(value)),
4330
4457
  /**
4331
4458
  * Creates a Task.Result from a Maybe.
4332
4459
  * Some becomes Ok, None becomes err from onNone.
@@ -4337,7 +4464,7 @@ const TaskResult = {
4337
4464
  * Task.Result.from.Maybe(() => "empty")(Maybe.make.none()); // resolves to Err("empty")
4338
4465
  * ```
4339
4466
  */
4340
- Maybe: (onNone) => (maybe) => Task.resolve(Maybe.is.none(maybe) ? Result.make.err(onNone()) : Result.make.ok(maybe.value)),
4467
+ Maybe: (onNone) => (maybe) => Task.make(Maybe.is.none(maybe) ? Result.make.err(onNone()) : Result.make.ok(maybe.value)),
4341
4468
  /**
4342
4469
  * Lifts a Result into a Task.Result.
4343
4470
  *
@@ -4346,7 +4473,7 @@ const TaskResult = {
4346
4473
  * Task.Result.from.Result(Result.make.ok(42)); // resolves to Ok(42)
4347
4474
  * ```
4348
4475
  */
4349
- Result: (result) => Task.resolve(result)
4476
+ Result: (result) => Task.make(result)
4350
4477
  },
4351
4478
  to: {
4352
4479
  /**
@@ -4358,7 +4485,7 @@ const TaskResult = {
4358
4485
  * const taskMaybe = pipe(taskResult, Task.Result.to.Maybe);
4359
4486
  * ```
4360
4487
  */
4361
- Maybe: (data) => Task.map(Result.to.Maybe)(data) },
4488
+ Maybe: (task) => Task.map(Result.to.Maybe)(task) },
4362
4489
  /**
4363
4490
  * Creates a Task.Result from a Promise-returning thunk that may throw or reject.
4364
4491
  * Catches any errors and transforms them using the `onError` function into an `Err`.
@@ -4372,36 +4499,51 @@ Maybe: (data) => Task.map(Result.to.Maybe)(data) },
4372
4499
  * );
4373
4500
  * ```
4374
4501
  */
4375
- tryCatch: (f, options) => (signal) => Deferred.from.Promise(globalThis.Promise.resolve().then(async () => f(signal)).then(Result.make.ok).catch((error) => Result.make.err(options.onError(error)))),
4502
+ tryCatch: (fn, options) => (signal) => Deferred.from.Promise(globalThis.Promise.resolve().then(async () => fn(signal)).then(Result.make.ok).catch((error) => Result.make.err(options.onError(error)))),
4376
4503
  /**
4377
4504
  * Transforms the success value inside a Task.Result.
4505
+ *
4506
+ * @see {@link Task.Result.chain} to sequence operations that themselves return a Task.Result.
4507
+ * @see {@link Task.Result.mapError} to transform the error value instead of the success value.
4378
4508
  */
4379
4509
  map: mapTaskResult,
4380
4510
  /**
4381
4511
  * Transforms the error value inside a Task.Result.
4512
+ *
4513
+ * @see {@link Task.Result.map} to transform the success value instead of the error value.
4382
4514
  */
4383
- mapError: (f) => (data) => Task.map(Result.mapError(f))(data),
4515
+ mapError: (transform) => (task) => Task.map(Result.mapError(transform))(task),
4384
4516
  /**
4385
- * Chains Task.Result computations. If the first succeeds, passes the value to f.
4517
+ * Chains Task.Result computations. If the first succeeds, passes the value to transform.
4386
4518
  * If the first fails, propagates the error.
4519
+ *
4520
+ * @see {@link Task.Result.map} to transform the inner value without returning a new Task.Result.
4387
4521
  */
4388
4522
  chain: chainTaskResult,
4389
4523
  /**
4390
4524
  * Extracts the value from a Task.Result by providing handlers for both cases.
4525
+ *
4526
+ * @see {@link Task.Result.match} for named-case pattern matching with an object literal.
4391
4527
  */
4392
- fold: (onErr, onOk) => (data) => Task.map(Result.fold(onErr, onOk))(data),
4528
+ fold: (onErr, onOk) => (task) => Task.map(Result.fold(onErr, onOk))(task),
4393
4529
  /**
4394
4530
  * Pattern matches on a Task.Result, returning a Task of the result.
4531
+ *
4532
+ * @see {@link Task.Result.fold} for positional argument pattern matching.
4395
4533
  */
4396
- match: (cases) => (data) => Task.map(Result.match(cases))(data),
4534
+ match: (cases) => (task) => Task.map(Result.match(cases))(task),
4397
4535
  /**
4398
4536
  * Recovers from an error by providing a fallback Task.Result.
4399
- * The fallback can produce a different success type, widening the result to `Task.Result<E, A | B>`.
4537
+ * The fallback can produce a different success type or resolve with a different error type.
4538
+ *
4539
+ * @see {@link Task.Result.recoverUnless} to conditionally recover based on the error value.
4400
4540
  */
4401
- recover: (fallback) => (data) => Task.chain((result) => Result.is.err(result) ? fallback(result.error) : Task.resolve(result))(data),
4541
+ recover: (fallback) => (task) => Task.chain((result) => Result.is.err(result) ? fallback(result.error) : Task.make(result))(task),
4402
4542
  /**
4403
4543
  * Recovers from an error unless the predicate `isBlocked` returns true for that error.
4404
- * The fallback can produce a different success type, widening the result to `Task.Result<E, A | B>`.
4544
+ * The fallback can produce a different success type, widening the result to `Task.Result<E1 | E2, A | B>`.
4545
+ *
4546
+ * @see {@link Task.Result.recover} for unconditional error recovery.
4405
4547
  *
4406
4548
  * @example
4407
4549
  * ```ts
@@ -4414,21 +4556,25 @@ Maybe: (data) => Task.map(Result.to.Maybe)(data) },
4414
4556
  * );
4415
4557
  * ```
4416
4558
  */
4417
- recoverUnless: (isBlocked, fallback) => (data) => Task.chain((result) => Result.is.err(result) && !isBlocked(result.error) ? fallback(result.error) : Task.resolve(result))(data),
4559
+ recoverUnless: (isBlocked, fallback) => (task) => Task.chain((result) => Result.is.err(result) && !isBlocked(result.error) ? fallback(result.error) : Task.make(result))(task),
4418
4560
  /**
4419
4561
  * Returns the success value or a default value if the Task.Result is an error.
4420
4562
  * The default can be a different type, widening the result to `Task<A | B>`.
4421
4563
  */
4422
- getOrElse: (defaultValue) => (data) => Task.map(Result.getOrElse(defaultValue))(data),
4564
+ getOrElse: (fallback) => (task) => Task.map(Result.getOrElse(fallback))(task),
4423
4565
  /**
4424
4566
  * Executes a side effect on the success value without changing the Task.Result.
4425
4567
  * Useful for logging or debugging.
4568
+ *
4569
+ * @see {@link Task.Result.tapError} to perform a side effect on the error value.
4426
4570
  */
4427
- tap: (f) => (data) => Task.map(Result.tap(f))(data),
4571
+ tap: (sideEffect) => (task) => Task.map(Result.tap(sideEffect))(task),
4428
4572
  /**
4429
4573
  * Executes a side effect on the error value without changing the Task.Result.
4430
4574
  * Useful for logging or reporting async errors.
4431
4575
  *
4576
+ * @see {@link Task.Result.tap} to perform a side effect on the success value.
4577
+ *
4432
4578
  * @example
4433
4579
  * ```ts
4434
4580
  * pipe(
@@ -4438,12 +4584,12 @@ Maybe: (data) => Task.map(Result.to.Maybe)(data) },
4438
4584
  * )
4439
4585
  * ```
4440
4586
  */
4441
- tapError: (f) => (data) => Task.map(Result.tapError(f))(data),
4587
+ tapError: (sideEffect) => (task) => Task.map(Result.tapError(sideEffect))(task),
4442
4588
  /**
4443
4589
  * Applies a function wrapped in a Task.Result to a value wrapped in a Task.Result.
4444
4590
  * Both Tasks run in parallel.
4445
4591
  */
4446
- ap: (arg) => (data) => (signal) => Deferred.from.Promise(Promise.all([Deferred.to.Promise(data(signal)), Deferred.to.Promise(arg(signal))]).then(([of_, oa]) => Result.ap(oa)(of_))),
4592
+ apply: (arg) => (task) => (signal) => Deferred.from.Promise(Promise.all([Deferred.to.Promise(task(signal)), Deferred.to.Promise(arg(signal))]).then(([of_, oa]) => Result.apply(oa)(of_))),
4447
4593
  /**
4448
4594
  * Executes a `Task.Result` with an optional signal, returning `Promise<Result<E, A>>`.
4449
4595
  * Use as a terminal step in a `pipe` chain.
@@ -4469,7 +4615,7 @@ Maybe: (data) => Task.map(Result.to.Maybe)(data) },
4469
4615
  * pipe(Task.Result.make.ok(42), Task.Result.bindTo("value")); // Task.Result({ value: 42 })
4470
4616
  * ```
4471
4617
  */
4472
- bindTo: (key) => (data) => mapTaskResult((a) => ({ [key]: a }))(data),
4618
+ bindTo: (key) => (task) => mapTaskResult((value) => ({ [key]: value }))(task),
4473
4619
  /**
4474
4620
  * Evaluates a new Task.Result using the current accumulator and attaches the output to a new key.
4475
4621
  *
@@ -4481,10 +4627,10 @@ Maybe: (data) => Task.map(Result.to.Maybe)(data) },
4481
4627
  * ); // Task.Result({ a: 1, b: 2 })
4482
4628
  * ```
4483
4629
  */
4484
- bind: (key, f) => (data) => chainTaskResult((a) => mapTaskResult((b) => ({
4485
- ...a,
4486
- [key]: b
4487
- }))(f(a)))(data),
4630
+ bind: (key, transform) => (task) => chainTaskResult((acc) => mapTaskResult((val) => ({
4631
+ ...acc,
4632
+ [key]: val
4633
+ }))(transform(acc)))(task),
4488
4634
  /**
4489
4635
  * Combines a record of Task.Results into a single Task.Result of a record.
4490
4636
  * Evaluates all tasks in parallel, forwarding the AbortSignal down to each sub-task.
@@ -4644,12 +4790,12 @@ const makeFailedAll$1 = (errors) => ({
4644
4790
  kind: "Failed",
4645
4791
  errors
4646
4792
  });
4647
- const isPassed = (data) => data.kind === "Passed";
4648
- const isFailed = (data) => data.kind === "Failed";
4793
+ const isPassed = (validation) => validation.kind === "Passed";
4794
+ const isFailed = (validation) => validation.kind === "Failed";
4649
4795
  function toResult(arg) {
4650
4796
  if (typeof arg === "function") {
4651
4797
  const combine = arg;
4652
- return (val) => isPassed(val) ? Result.make.ok(val.value) : Result.make.err(combine(val.errors));
4798
+ return (validation) => isPassed(validation) ? Result.make.ok(validation.value) : Result.make.err(combine(validation.errors));
4653
4799
  }
4654
4800
  return isPassed(arg) ? Result.make.ok(arg.value) : Result.make.err(arg.errors);
4655
4801
  }
@@ -4687,6 +4833,8 @@ const Validation = {
4687
4833
  /**
4688
4834
  * Type guard that checks if a Validation is passed.
4689
4835
  *
4836
+ * @see {@link Validation.is.failed} to check if a Validation is failed.
4837
+ *
4690
4838
  * @example
4691
4839
  * ```ts
4692
4840
  * const v = Validation.make.passed(42);
@@ -4699,6 +4847,8 @@ const Validation = {
4699
4847
  /**
4700
4848
  * Type guard that checks if a Validation is failed.
4701
4849
  *
4850
+ * @see {@link Validation.is.passed} to check if a Validation is passed.
4851
+ *
4702
4852
  * @example
4703
4853
  * ```ts
4704
4854
  * const v = Validation.make.failed("invalid");
@@ -4717,13 +4867,13 @@ const Validation = {
4717
4867
  * ```ts
4718
4868
  * const result = Validation.tryCatch(
4719
4869
  * () => JSON.parse(rawString),
4720
- * { onError: (e) => `Parse error: ${e}` }
4870
+ * { onError: (error) => `Parse error: ${error}` }
4721
4871
  * );
4722
4872
  * ```
4723
4873
  */
4724
- tryCatch: (f, options) => {
4874
+ tryCatch: (fn, options) => {
4725
4875
  try {
4726
- return makePassed$1(f());
4876
+ return makePassed$1(fn());
4727
4877
  } catch (error) {
4728
4878
  return makeFailed$1(options.onError(error));
4729
4879
  }
@@ -4744,7 +4894,7 @@ const Validation = {
4744
4894
  * validateName(""); // Failed(["Name is required"])
4745
4895
  * ```
4746
4896
  */
4747
- Predicate: (pred, onFalse) => (a) => pred(a) ? makePassed$1(a) : makeFailed$1(onFalse(a)),
4897
+ Predicate: (predicate, onFalse) => (value) => predicate(value) ? makePassed$1(value) : makeFailed$1(onFalse(value)),
4748
4898
  /**
4749
4899
  * Creates a Validation from a nullable value.
4750
4900
  * If the value is null or undefined, returns Failed with the error from onNull.
@@ -4781,69 +4931,74 @@ const Validation = {
4781
4931
  * Validation.from.Result(Result.make.err("bad")); // Failed(["bad"])
4782
4932
  * ```
4783
4933
  */
4784
- Result: (data) => data.kind === "Ok" ? makePassed$1(data.value) : makeFailed$1(data.error)
4934
+ Result: (result) => result.kind === "Ok" ? makePassed$1(result.value) : makeFailed$1(result.error)
4785
4935
  },
4786
4936
  /**
4787
4937
  * Transforms the success value inside a Validation.
4788
4938
  *
4939
+ * @see {@link Validation.mapError} to transform accumulated errors.
4940
+ * @see {@link Validation.apply} to combine multiple validations.
4941
+ *
4789
4942
  * @example
4790
4943
  * ```ts
4791
4944
  * pipe(Validation.make.passed(5), Validation.map(n => n * 2)); // Passed(10)
4792
4945
  * pipe(Validation.make.failed("oops"), Validation.map(n => n * 2)); // Failed(["oops"])
4793
4946
  * ```
4794
4947
  */
4795
- map: (f) => (data) => isPassed(data) ? makePassed$1(f(data.value)) : data,
4948
+ map: (transform) => (validation) => isPassed(validation) ? makePassed$1(transform(validation.value)) : validation,
4796
4949
  /**
4797
4950
  * Transforms the error list inside a Validation.
4798
4951
  *
4952
+ * @see {@link Validation.map} to transform the success value.
4953
+ *
4799
4954
  * @example
4800
4955
  * ```ts
4801
4956
  * pipe(Validation.make.failed("oops"), Validation.mapError(e => e.toUpperCase())); // Failed(["OOPS"])
4802
4957
  * ```
4803
4958
  */
4804
- mapError: (f) => (data) => isFailed(data) ? makeFailedAll$1(data.errors.map(f)) : data,
4959
+ mapError: (transform) => (validation) => isFailed(validation) ? makeFailedAll$1(validation.errors.map(transform)) : validation,
4805
4960
  /**
4806
4961
  * Applies a function wrapped in a Validation to a value wrapped in a Validation.
4807
- * Accumulates errors from both sides.
4962
+ * Accumulates errors from both sides if both fail, using optional `combineErrors`
4963
+ * or default concatenation.
4964
+ *
4965
+ * @see {@link Validation.product} to combine two validations into a tuple.
4808
4966
  *
4809
4967
  * @example
4810
4968
  * ```ts
4811
4969
  * const add = (a: number) => (b: number) => a + b;
4812
4970
  * pipe(
4813
4971
  * Validation.make.passed(add),
4814
- * Validation.ap(Validation.make.passed(5)),
4815
- * Validation.ap(Validation.make.passed(3))
4972
+ * Validation.apply(Validation.make.passed(5)),
4973
+ * Validation.apply(Validation.make.passed(3))
4816
4974
  * ); // Passed(8)
4817
4975
  *
4818
4976
  * pipe(
4819
4977
  * Validation.make.passed(add),
4820
- * Validation.ap(Validation.make.failed<string>("bad a")),
4821
- * Validation.ap(Validation.make.failed<string>("bad b"))
4978
+ * Validation.apply(Validation.make.failed<string>("bad a")),
4979
+ * Validation.apply(Validation.make.failed<string>("bad b"))
4822
4980
  * ); // Failed(["bad a", "bad b"])
4823
- * ```
4824
- */
4825
- ap: (arg) => (data) => {
4826
- if (isPassed(data)) return isPassed(arg) ? makePassed$1(data.value(arg.value)) : makeFailedAll$1(arg.errors);
4827
- return isPassed(arg) ? makeFailedAll$1(data.errors) : makeFailedAll$1([...data.errors, ...arg.errors]);
4828
- },
4829
- /**
4830
- * Applies a function wrapped in a Validation to a value wrapped in a Validation,
4831
- * using a custom error concatenator function when both sides fail.
4832
4981
  *
4833
- * @example
4834
- * ```ts
4835
- * const concat = (e1: NonEmptyArr<string>, e2: NonEmptyArr<string>): NonEmptyArr<string> =>
4836
- * [...e1, ...e2];
4837
- * pipe(fnVal, Validation.apCustom(concat)(argVal));
4982
+ * // Custom error combination:
4983
+ * pipe(
4984
+ * Validation.make.passed(add),
4985
+ * Validation.apply(Validation.make.failed("err"), {
4986
+ * combineErrors: (e1, e2) => [...e1, ...e2],
4987
+ * })
4988
+ * );
4838
4989
  * ```
4839
4990
  */
4840
- apCustom: (concat) => (arg) => (data) => {
4841
- if (isPassed(data)) return isPassed(arg) ? makePassed$1(data.value(arg.value)) : makeFailedAll$1(arg.errors);
4842
- return isPassed(arg) ? makeFailedAll$1(data.errors) : makeFailedAll$1(concat(data.errors, arg.errors));
4991
+ apply: (arg, options) => (validation) => {
4992
+ if (isPassed(validation)) return isPassed(arg) ? makePassed$1(validation.value(arg.value)) : makeFailedAll$1(arg.errors);
4993
+ if (isPassed(arg)) return makeFailedAll$1(validation.errors);
4994
+ const combined = options?.combineErrors ? options.combineErrors(validation.errors, arg.errors) : [...validation.errors, ...arg.errors];
4995
+ return makeFailedAll$1(combined);
4843
4996
  },
4844
4997
  /**
4845
4998
  * Extracts the value from a Validation by providing handlers for both cases.
4846
4999
  *
5000
+ * @see {@link Validation.match} for named-case pattern matching with an object literal.
5001
+ *
4847
5002
  * @example
4848
5003
  * ```ts
4849
5004
  * pipe(
@@ -4855,10 +5010,12 @@ const Validation = {
4855
5010
  * );
4856
5011
  * ```
4857
5012
  */
4858
- fold: (onFailed, onPassed) => (data) => isPassed(data) ? onPassed(data.value) : onFailed(data.errors),
5013
+ fold: (onFailed, onPassed) => (validation) => isPassed(validation) ? onPassed(validation.value) : onFailed(validation.errors),
4859
5014
  /**
4860
5015
  * Pattern matches on a Validation, returning the result of the matching case.
4861
5016
  *
5017
+ * @see {@link Validation.fold} for positional argument pattern matching.
5018
+ *
4862
5019
  * @example
4863
5020
  * ```ts
4864
5021
  * pipe(
@@ -4870,11 +5027,13 @@ const Validation = {
4870
5027
  * );
4871
5028
  * ```
4872
5029
  */
4873
- match: (cases) => (data) => isPassed(data) ? cases.passed(data.value) : cases.failed(data.errors),
5030
+ match: (cases) => (validation) => isPassed(validation) ? cases.passed(validation.value) : cases.failed(validation.errors),
4874
5031
  /**
4875
5032
  * Returns the success value or a default value if the Validation is failed.
4876
5033
  * The default can be a different type, widening the result to `A | B`.
4877
5034
  *
5035
+ * @see {@link Validation.fold} to handle both the passed and failed cases.
5036
+ *
4878
5037
  * @example
4879
5038
  * ```ts
4880
5039
  * pipe(Validation.make.passed(5), Validation.getOrElse(() => 0)); // 5
@@ -4882,10 +5041,12 @@ const Validation = {
4882
5041
  * pipe(Validation.make.failed("oops"), Validation.getOrElse(() => null)); // null — typed as number | null
4883
5042
  * ```
4884
5043
  */
4885
- getOrElse: (defaultValue) => (data) => isPassed(data) ? data.value : defaultValue(),
5044
+ getOrElse: (fallback) => (validation) => isPassed(validation) ? validation.value : fallback(),
4886
5045
  /**
4887
5046
  * Executes a side effect on the success value without changing the Validation.
4888
5047
  *
5048
+ * @see {@link Validation.tapError} to perform a side effect on accumulated errors.
5049
+ *
4889
5050
  * @example
4890
5051
  * ```ts
4891
5052
  * pipe(
@@ -4895,14 +5056,16 @@ const Validation = {
4895
5056
  * );
4896
5057
  * ```
4897
5058
  */
4898
- tap: (f) => (data) => {
4899
- if (isPassed(data)) f(data.value);
4900
- return data;
5059
+ tap: (sideEffect) => (validation) => {
5060
+ if (isPassed(validation)) sideEffect(validation.value);
5061
+ return validation;
4901
5062
  },
4902
5063
  /**
4903
5064
  * Executes a side effect on the accumulated errors without changing the Validation.
4904
5065
  * Useful for logging or reporting validation failures.
4905
5066
  *
5067
+ * @see {@link Validation.tap} to perform a side effect on the success value.
5068
+ *
4906
5069
  * @example
4907
5070
  * ```ts
4908
5071
  * pipe(
@@ -4912,19 +5075,23 @@ const Validation = {
4912
5075
  * );
4913
5076
  * ```
4914
5077
  */
4915
- tapError: (f) => (data) => {
4916
- if (isFailed(data)) f(data.errors);
4917
- return data;
5078
+ tapError: (sideEffect) => (validation) => {
5079
+ if (isFailed(validation)) sideEffect(validation.errors);
5080
+ return validation;
4918
5081
  },
4919
5082
  /**
4920
5083
  * Recovers from a Failed state by providing a fallback Validation.
4921
5084
  * The fallback receives the accumulated error list so callers can inspect which errors occurred.
4922
- * The fallback can produce a different success type, widening the result to `Validation<E, A | B>`.
5085
+ * The fallback can produce a different success type or resolve with a different error type.
5086
+ *
5087
+ * @see {@link Validation.recoverUnless} to conditionally recover based on accumulated errors.
4923
5088
  */
4924
- recover: (fallback) => (data) => isPassed(data) ? data : fallback(data.errors),
5089
+ recover: (fallback) => (validation) => isPassed(validation) ? validation : fallback(validation.errors),
4925
5090
  /**
4926
5091
  * Recovers from a Failed state unless `isBlocked` returns true for any of the accumulated errors.
4927
- * The fallback can produce a different success type, widening the result to `Validation<E, A | B>`.
5092
+ * The fallback can produce a different success type, widening the result to `Validation<E1 | E2, A | B>`.
5093
+ *
5094
+ * @see {@link Validation.recover} for unconditional error recovery.
4928
5095
  *
4929
5096
  * @example
4930
5097
  * ```ts
@@ -4934,7 +5101,7 @@ const Validation = {
4934
5101
  * ); // Passed(0)
4935
5102
  * ```
4936
5103
  */
4937
- recoverUnless: (isBlocked, fallback) => (data) => isFailed(data) && !data.errors.some(isBlocked) ? fallback() : data,
5104
+ recoverUnless: (isBlocked, fallback) => (validation) => isFailed(validation) && !validation.errors.some(isBlocked) ? fallback(validation.errors) : validation,
4938
5105
  to: {
4939
5106
  /**
4940
5107
  * Converts a Validation to a Result.
@@ -4960,13 +5127,16 @@ const Validation = {
4960
5127
  * Validation.to.Maybe(Validation.make.failed("bad")); // None
4961
5128
  * ```
4962
5129
  */
4963
- Maybe: (data) => isPassed(data) ? Maybe.make.some(data.value) : Maybe.make.none()
5130
+ Maybe: (validation) => isPassed(validation) ? Maybe.make.some(validation.value) : Maybe.make.none()
4964
5131
  },
4965
5132
  /**
4966
5133
  * Combines two independent Validation instances into a tuple.
4967
5134
  * If both are Passed, returns Passed with both values as a tuple.
4968
5135
  * If either is Failed, accumulates errors from both sides.
4969
5136
  *
5137
+ * @see {@link Validation.productAll} to combine a non-empty list of validations.
5138
+ * @see {@link Validation.apply} to apply a curried function across validations.
5139
+ *
4970
5140
  * @example
4971
5141
  * ```ts
4972
5142
  * Validation.product(
@@ -4989,6 +5159,8 @@ const Validation = {
4989
5159
  * If all are Passed, returns Passed with all values collected into an array.
4990
5160
  * If any are Failed, returns Failed with all accumulated errors.
4991
5161
  *
5162
+ * @see {@link Validation.product} to combine exactly two validations into a pair.
5163
+ *
4992
5164
  * @example
4993
5165
  * ```ts
4994
5166
  * Validation.productAll([
@@ -4999,10 +5171,10 @@ const Validation = {
4999
5171
  * // Passed([name, email, age]) or Failed([...all errors])
5000
5172
  * ```
5001
5173
  */
5002
- productAll: (data) => {
5174
+ productAll: (validations) => {
5003
5175
  const values = [];
5004
5176
  const errors = [];
5005
- for (const v of data) if (isPassed(v)) values.push(v.value);
5177
+ for (const v of validations) if (isPassed(v)) values.push(v.value);
5006
5178
  else errors.push(...v.errors);
5007
5179
  return isNonEmptyArr(errors) ? makeFailedAll$1(errors) : makePassed$1(values);
5008
5180
  },
@@ -5032,13 +5204,116 @@ const Validation = {
5032
5204
  else errors.push(...val.errors);
5033
5205
  }
5034
5206
  return isNonEmptyArr(errors) ? makeFailedAll$1(errors) : makePassed$1(record);
5207
+ },
5208
+ keyed: {
5209
+ /**
5210
+ * Creates a keyed validator function from a schema of field validators.
5211
+ * Evaluates each validator against its corresponding field in the input object,
5212
+ * returning a record where every key holds its own Validation outcome.
5213
+ *
5214
+ * @example
5215
+ * ```ts
5216
+ * const validateUser = Validation.keyed.make({
5217
+ * name: (s: string) => s.length > 0 ? Validation.make.passed(s) : Validation.make.failed("Name required"),
5218
+ * age: (n: number) => n >= 18 ? Validation.make.passed(n) : Validation.make.failed("Must be 18+"),
5219
+ * });
5220
+ *
5221
+ * const result = validateUser({ name: "", age: 16 });
5222
+ * // { name: Failed(["Name required"]), age: Failed(["Must be 18+"]) }
5223
+ * ```
5224
+ */
5225
+ make: (validators) => (input) => {
5226
+ const out = {};
5227
+ for (const key of Object.keys(validators)) out[key] = validators[key](input[key]);
5228
+ return out;
5229
+ },
5230
+ is: {
5231
+ /**
5232
+ * Type guard checking if every keyed field is Passed.
5233
+ *
5234
+ * @see {@link Validation.keyed.is.failed} to check if any keyed field failed.
5235
+ *
5236
+ * @example
5237
+ * ```ts
5238
+ * if (Validation.keyed.is.passed(results)) {
5239
+ * // results.name is Passed<string>, results.age is Passed<number>
5240
+ * }
5241
+ * ```
5242
+ */
5243
+ passed: (keyed) => {
5244
+ for (const key of Object.keys(keyed)) if (keyed[key].kind !== "Passed") return false;
5245
+ return true;
5246
+ },
5247
+ /**
5248
+ * Checks if at least one keyed field is Failed.
5249
+ *
5250
+ * @see {@link Validation.keyed.is.passed} to check if all keyed fields passed.
5251
+ *
5252
+ * @example
5253
+ * ```ts
5254
+ * if (Validation.keyed.is.failed(results)) {
5255
+ * console.log("Validation errors occurred");
5256
+ * }
5257
+ * ```
5258
+ */
5259
+ failed: (keyed) => {
5260
+ for (const key of Object.keys(keyed)) if (keyed[key].kind === "Failed") return true;
5261
+ return false;
5262
+ }
5263
+ },
5264
+ /**
5265
+ * Extracts all validated field values if every field passed.
5266
+ * Returns `Some(data)` if all passed, `None` if any field failed.
5267
+ *
5268
+ * @see {@link Validation.keyed.getErrors} to extract keyed field errors when failures occur.
5269
+ *
5270
+ * @example
5271
+ * ```ts
5272
+ * const passed = Validation.keyed.getPassed(results);
5273
+ * // Some({ name: "Alice", age: 30 }) or None
5274
+ * ```
5275
+ */
5276
+ getPassed: (keyed) => {
5277
+ const out = {};
5278
+ for (const key of Object.keys(keyed)) {
5279
+ const v = keyed[key];
5280
+ if (v.kind !== "Passed") return Maybe.make.none();
5281
+ out[key] = v.value;
5282
+ }
5283
+ return Maybe.make.some(out);
5284
+ },
5285
+ /**
5286
+ * Extracts keyed field errors if any field failed.
5287
+ * Symmetrical to `getPassed`: returns `Some(errors)` when there are failures,
5288
+ * or `None` if every field passed.
5289
+ *
5290
+ * @see {@link Validation.keyed.getPassed} to extract keyed values when all fields pass.
5291
+ *
5292
+ * @example
5293
+ * ```ts
5294
+ * const errors = Validation.keyed.getErrors(results);
5295
+ * // Some({ name: ["Name required"] }) or None
5296
+ * ```
5297
+ */
5298
+ getErrors: (keyed) => {
5299
+ let hasFailed = false;
5300
+ const out = {};
5301
+ for (const key of Object.keys(keyed)) {
5302
+ const v = keyed[key];
5303
+ if (v.kind === "Failed") {
5304
+ hasFailed = true;
5305
+ out[key] = v.errors;
5306
+ }
5307
+ }
5308
+ return hasFailed ? Maybe.make.some(out) : Maybe.make.none();
5309
+ }
5035
5310
  }
5036
5311
  };
5037
5312
  //#endregion
5038
5313
  //#region src/Core/TaskValidation.ts
5039
- const makePassed = (value) => Task.resolve(Validation.make.passed(value));
5040
- const makeFailed = (error) => Task.resolve(Validation.make.failed(error));
5041
- const makeFailedAll = (errors) => Task.resolve(Validation.make.failedAll(errors));
5314
+ const makePassed = (value) => Task.make(Validation.make.passed(value));
5315
+ const makeFailed = (error) => Task.make(Validation.make.failed(error));
5316
+ const makeFailedAll = (errors) => Task.make(Validation.make.failedAll(errors));
5042
5317
  const TaskValidation = {
5043
5318
  make: {
5044
5319
  /**
@@ -5081,7 +5356,7 @@ const TaskValidation = {
5081
5356
  * Task.Validation.from.Validation(Validation.make.passed(42));
5082
5357
  * ```
5083
5358
  */
5084
- Validation: (validation) => Task.resolve(validation),
5359
+ Validation: (validation) => Task.make(validation),
5085
5360
  /**
5086
5361
  * Creates a Task.Validation from a nullable value.
5087
5362
  * If the value is null or undefined, returns Failed with the error from onNull.
@@ -5093,7 +5368,7 @@ const TaskValidation = {
5093
5368
  * Task.Validation.from.nullable(() => "missing")(null); // resolves to Failed(["missing"])
5094
5369
  * ```
5095
5370
  */
5096
- nullable: (onNull) => (value) => Task.resolve(value === null || value === void 0 ? Validation.make.failed(onNull()) : Validation.make.passed(value)),
5371
+ nullable: (onNull) => (value) => Task.make(value === null || value === void 0 ? Validation.make.failed(onNull()) : Validation.make.passed(value)),
5097
5372
  /**
5098
5373
  * Creates a Task.Validation from a Maybe.
5099
5374
  * Some becomes Passed, None becomes Failed with the error from onNone.
@@ -5104,7 +5379,7 @@ const TaskValidation = {
5104
5379
  * Task.Validation.from.Maybe(() => "empty")(Maybe.make.none()); // resolves to Failed(["empty"])
5105
5380
  * ```
5106
5381
  */
5107
- Maybe: (onNone) => (maybe) => Task.resolve(Maybe.is.none(maybe) ? Validation.make.failed(onNone()) : Validation.make.passed(maybe.value)),
5382
+ Maybe: (onNone) => (maybe) => Task.make(Maybe.is.none(maybe) ? Validation.make.failed(onNone()) : Validation.make.passed(maybe.value)),
5108
5383
  /**
5109
5384
  * Creates a Task.Validation from a Result.
5110
5385
  * Ok becomes Passed, Err(e) becomes Failed([e]).
@@ -5115,7 +5390,7 @@ const TaskValidation = {
5115
5390
  * Task.Validation.from.Result(Result.make.err("bad")); // resolves to Failed(["bad"])
5116
5391
  * ```
5117
5392
  */
5118
- Result: (result) => Task.resolve(Validation.from.Result(result))
5393
+ Result: (result) => Task.make(Validation.from.Result(result))
5119
5394
  },
5120
5395
  to: {
5121
5396
  /**
@@ -5127,7 +5402,7 @@ const TaskValidation = {
5127
5402
  * Task.Validation.to.Result((errors) => errors.join(", "))(validationTask);
5128
5403
  * ```
5129
5404
  */
5130
- Result: (combineErrors) => (data) => Task.map(Validation.to.Result(combineErrors))(data),
5405
+ Result: (combineErrors) => (task) => Task.map(Validation.to.Result(combineErrors))(task),
5131
5406
  /**
5132
5407
  * Converts a `Task.Validation` to a `Task.Maybe`.
5133
5408
  * `Passed(a)` becomes `Some(a)`; `Failed(errors)` becomes `None` (errors are discarded).
@@ -5137,7 +5412,7 @@ const TaskValidation = {
5137
5412
  * Task.Validation.to.Maybe(validationTask);
5138
5413
  * ```
5139
5414
  */
5140
- Maybe: (data) => Task.map(Validation.to.Maybe)(data)
5415
+ Maybe: (task) => Task.map(Validation.to.Maybe)(task)
5141
5416
  },
5142
5417
  /**
5143
5418
  * Creates a Task.Validation from a Promise-returning thunk that may throw or reject.
@@ -5152,33 +5427,42 @@ const TaskValidation = {
5152
5427
  * );
5153
5428
  * ```
5154
5429
  */
5155
- tryCatch: (f, options) => (signal) => Deferred.from.Promise(globalThis.Promise.resolve().then(async () => f(signal)).then(Validation.make.passed).catch((error) => Validation.make.failed(options.onError(error)))),
5430
+ tryCatch: (fn, options) => (signal) => Deferred.from.Promise(globalThis.Promise.resolve().then(async () => fn(signal)).then(Validation.make.passed).catch((error) => Validation.make.failed(options.onError(error)))),
5156
5431
  /**
5157
5432
  * Transforms the success value inside a Task.Validation.
5433
+ *
5434
+ * @see {@link Task.Validation.mapError} to transform accumulated errors.
5435
+ * @see {@link Task.Validation.apply} to combine multiple validations in parallel.
5158
5436
  */
5159
- map: (f) => (data) => Task.map(Validation.map(f))(data),
5437
+ map: (transform) => (task) => Task.map(Validation.map(transform))(task),
5160
5438
  /**
5161
5439
  * Applies a function wrapped in a Task.Validation to a value wrapped in a
5162
5440
  * Task.Validation. Both Tasks run in parallel and errors from both sides
5163
5441
  * are accumulated.
5164
5442
  *
5443
+ * @see {@link Task.Validation.product} to combine two validations into a tuple.
5444
+ *
5165
5445
  * @example
5166
5446
  * ```ts
5167
5447
  * pipe(
5168
5448
  * Task.Validation.make.passed((name: string) => (age: number) => ({ name, age })),
5169
- * Task.Validation.ap(validateName(name)),
5170
- * Task.Validation.ap(validateAge(age))
5449
+ * Task.Validation.apply(validateName(name)),
5450
+ * Task.Validation.apply(validateAge(age))
5171
5451
  * )();
5172
5452
  * ```
5173
5453
  */
5174
- ap: (arg) => (data) => (signal) => Deferred.from.Promise(Promise.all([Deferred.to.Promise(data(signal)), Deferred.to.Promise(arg(signal))]).then(([vf, va]) => Validation.ap(va)(vf))),
5454
+ apply: (arg) => (task) => (signal) => Deferred.from.Promise(Promise.all([Deferred.to.Promise(task(signal)), Deferred.to.Promise(arg(signal))]).then(([vf, va]) => Validation.apply(va)(vf))),
5175
5455
  /**
5176
5456
  * Extracts a value from a Task.Validation by providing handlers for both cases.
5457
+ *
5458
+ * @see {@link Task.Validation.match} for named-case pattern matching with an object literal.
5177
5459
  */
5178
- fold: (onFailed, onPassed) => (data) => Task.map(Validation.fold(onFailed, onPassed))(data),
5460
+ fold: (onFailed, onPassed) => (task) => Task.map(Validation.fold(onFailed, onPassed))(task),
5179
5461
  /**
5180
5462
  * Pattern matches on a Task.Validation, returning a Task of the result.
5181
5463
  *
5464
+ * @see {@link Task.Validation.fold} for positional argument pattern matching.
5465
+ *
5182
5466
  * @example
5183
5467
  * ```ts
5184
5468
  * pipe(
@@ -5190,26 +5474,32 @@ const TaskValidation = {
5190
5474
  * )();
5191
5475
  * ```
5192
5476
  */
5193
- match: (cases) => (data) => Task.map(Validation.match(cases))(data),
5477
+ match: (cases) => (task) => Task.map(Validation.match(cases))(task),
5194
5478
  /**
5195
5479
  * Returns the success value or a default value if the Task.Validation is failed.
5196
5480
  * The default can be a different type, widening the result to `Task<A | B>`.
5197
5481
  */
5198
- getOrElse: (defaultValue) => (data) => Task.map(Validation.getOrElse(defaultValue))(data),
5482
+ getOrElse: (fallback) => (task) => Task.map(Validation.getOrElse(fallback))(task),
5199
5483
  /**
5200
5484
  * Executes a side effect on the success value without changing the Task.Validation.
5201
5485
  * Useful for logging or debugging.
5486
+ *
5487
+ * @see {@link Task.Validation.tapError} to perform a side effect on accumulated errors.
5202
5488
  */
5203
- tap: (f) => (data) => Task.map(Validation.tap(f))(data),
5489
+ tap: (sideEffect) => (task) => Task.map(Validation.tap(sideEffect))(task),
5204
5490
  /**
5205
5491
  * Recovers from a Failed state by providing a fallback Task.Validation.
5206
5492
  * The fallback receives the accumulated error list so callers can inspect which errors occurred.
5207
- * The fallback can produce a different success type, widening the result to `Task.Validation<E, A | B>`.
5493
+ * The fallback can produce a different success type or resolve with a different error type.
5494
+ *
5495
+ * @see {@link Task.Validation.recoverUnless} to conditionally recover based on accumulated errors.
5208
5496
  */
5209
- recover: (fallback) => (data) => Task.chain((validation) => Validation.is.passed(validation) ? Task.resolve(validation) : fallback(validation.errors))(data),
5497
+ recover: (fallback) => (task) => Task.chain((validation) => Validation.is.passed(validation) ? Task.make(validation) : fallback(validation.errors))(task),
5210
5498
  /**
5211
5499
  * Recovers from a Failed state unless the predicate `isBlocked` returns true for the accumulated errors.
5212
- * The fallback receives the accumulated errors and can produce a different success type, widening the result to `Task.Validation<E, A | B>`.
5500
+ * The fallback receives the accumulated errors and can produce a different success type, widening the result to `Task.Validation<E1 | E2, A | B>`.
5501
+ *
5502
+ * @see {@link Task.Validation.recover} for unconditional error recovery.
5213
5503
  *
5214
5504
  * @example
5215
5505
  * ```ts
@@ -5222,12 +5512,15 @@ const TaskValidation = {
5222
5512
  * );
5223
5513
  * ```
5224
5514
  */
5225
- recoverUnless: (isBlocked, fallback) => (data) => Task.chain((validation) => Validation.is.passed(validation) ? Task.resolve(validation) : isBlocked(validation.errors) ? Task.resolve(validation) : fallback(validation.errors))(data),
5515
+ recoverUnless: (isBlocked, fallback) => (task) => Task.chain((validation) => Validation.is.passed(validation) ? Task.make(validation) : isBlocked(validation.errors) ? Task.make(validation) : fallback(validation.errors))(task),
5226
5516
  /**
5227
5517
  * Runs two Task.Validations concurrently and combines their results into a tuple.
5228
5518
  * If both are Passed, returns Passed with both values. If either fails, accumulates
5229
5519
  * errors from both sides.
5230
5520
  *
5521
+ * @see {@link Task.Validation.productAll} to combine a list of validations.
5522
+ * @see {@link Task.Validation.apply} to apply a curried function across validations.
5523
+ *
5231
5524
  * @example
5232
5525
  * ```ts
5233
5526
  * await Task.Validation.product(
@@ -5242,6 +5535,8 @@ const TaskValidation = {
5242
5535
  * If all are Passed, returns Passed with all values as an array.
5243
5536
  * If any fail, returns Failed with all accumulated errors.
5244
5537
  *
5538
+ * @see {@link Task.Validation.product} to combine two validations into a pair.
5539
+ *
5245
5540
  * @example
5246
5541
  * ```ts
5247
5542
  * await Task.Validation.productAll([
@@ -5251,13 +5546,15 @@ const TaskValidation = {
5251
5546
  * ])(); // Passed([name, email, age]) or Failed([...all errors])
5252
5547
  * ```
5253
5548
  */
5254
- productAll: (data) => (signal) => Deferred.from.Promise(Promise.all(data.map((t) => Deferred.to.Promise(t(signal)))).then((results) => {
5549
+ productAll: (validations) => (signal) => Deferred.from.Promise(Promise.all(validations.map((t) => Deferred.to.Promise(t(signal)))).then((results) => {
5255
5550
  const [first, ...rest] = results;
5256
5551
  return Validation.productAll([first, ...rest]);
5257
5552
  })),
5258
5553
  /**
5259
5554
  * Transforms all accumulated errors inside a Task.Validation.
5260
5555
  *
5556
+ * @see {@link Task.Validation.map} to transform the success value.
5557
+ *
5261
5558
  * @example
5262
5559
  * ```ts
5263
5560
  * pipe(
@@ -5266,10 +5563,12 @@ const TaskValidation = {
5266
5563
  * ); // Task.Validation(Failed(["OOPS"]))
5267
5564
  * ```
5268
5565
  */
5269
- mapError: (f) => (data) => Task.map(Validation.mapError(f))(data),
5566
+ mapError: (transform) => (task) => Task.map(Validation.mapError(transform))(task),
5270
5567
  /**
5271
5568
  * Executes a side effect on the accumulated errors without changing the Task.Validation.
5272
5569
  *
5570
+ * @see {@link Task.Validation.tap} to perform a side effect on the success value.
5571
+ *
5273
5572
  * @example
5274
5573
  * ```ts
5275
5574
  * pipe(
@@ -5278,7 +5577,7 @@ const TaskValidation = {
5278
5577
  * );
5279
5578
  * ```
5280
5579
  */
5281
- tapError: (f) => (data) => Task.map(Validation.tapError(f))(data),
5580
+ tapError: (sideEffect) => (task) => Task.map(Validation.tapError(sideEffect))(task),
5282
5581
  /**
5283
5582
  * Combines a record of Task.Validations into a single Task.Validation of a record.
5284
5583
  * Evaluates fields in parallel and accumulates all validation errors.
@@ -5321,23 +5620,23 @@ const TaskValidation = {
5321
5620
  const toPromise = (task, signal) => Deferred.to.Promise(task(signal));
5322
5621
  const fromPromise = (f) => (signal) => Deferred.from.Promise(f(signal));
5323
5622
  const getMs = (duration) => Duration.to.milliseconds(duration);
5324
- const resolveTask = (value) => () => Deferred.from.Promise(globalThis.Promise.resolve(value));
5325
- const syncTask = (f) => () => Deferred.from.Promise(globalThis.Promise.resolve(f()));
5623
+ const makeTask = (value) => () => Deferred.from.Promise(globalThis.Promise.resolve(value));
5624
+ const syncTask = (fn) => () => Deferred.from.Promise(globalThis.Promise.resolve(fn()));
5326
5625
  const Task = {
5327
5626
  /**
5328
5627
  * Creates a Task that immediately resolves to the given value.
5329
5628
  *
5330
5629
  * @example
5331
5630
  * ```ts
5332
- * const task = Task.resolve(42);
5631
+ * const task = Task.make(42);
5333
5632
  * const value = await task(); // 42
5334
5633
  * ```
5335
5634
  */
5336
- resolve: resolveTask,
5635
+ make: makeTask,
5337
5636
  from: {
5338
5637
  /**
5339
5638
  * Creates a Task from a lazy synchronous thunk.
5340
- * Unlike `Task.resolve(f())`, `from.sync` does not evaluate `f` until the Task is called.
5639
+ * Unlike `Task.make(f())`, `from.sync` does not evaluate `f` until the Task is called.
5341
5640
  *
5342
5641
  * @example
5343
5642
  * ```ts
@@ -5358,10 +5657,12 @@ sync: syncTask },
5358
5657
  * );
5359
5658
  * ```
5360
5659
  */
5361
- tryCatch: (f, options) => fromPromise((signal) => globalThis.Promise.resolve().then(() => f(signal)).catch((err) => options.onError(err))),
5660
+ tryCatch: (fn, options) => fromPromise((signal) => globalThis.Promise.resolve().then(() => fn(signal)).catch((err) => options.onError(err))),
5362
5661
  /**
5363
5662
  * Transforms the value inside a Task.
5364
5663
  *
5664
+ * @see {@link Task.chain} to sequence operations that return a Task.
5665
+ *
5365
5666
  * @example
5366
5667
  * ```ts
5367
5668
  * pipe(
@@ -5370,9 +5671,11 @@ sync: syncTask },
5370
5671
  * )(); // Deferred<10>
5371
5672
  * ```
5372
5673
  */
5373
- map: (f) => (data) => fromPromise((signal) => toPromise(data, signal).then(f)),
5674
+ map: (transform) => (task) => fromPromise((signal) => toPromise(task, signal).then(transform)),
5374
5675
  /**
5375
- * Chains Task computations. Passes the resolved value of the first Task to f.
5676
+ * Chains Task computations. Passes the resolved value of the first Task to transform.
5677
+ *
5678
+ * @see {@link Task.map} to transform the resolved value without creating a new Task.
5376
5679
  *
5377
5680
  * @example
5378
5681
  * ```ts
@@ -5386,22 +5689,24 @@ sync: syncTask },
5386
5689
  * )(); // Deferred<Preferences>
5387
5690
  * ```
5388
5691
  */
5389
- chain: (f) => (data) => fromPromise((signal) => toPromise(data, signal).then((a) => toPromise(f(a), signal))),
5692
+ chain: (transform) => (task) => fromPromise((signal) => toPromise(task, signal).then((a) => toPromise(transform(a), signal))),
5390
5693
  /**
5391
5694
  * Applies a function wrapped in a Task to a value wrapped in a Task.
5392
5695
  * Both Tasks run in parallel.
5393
5696
  *
5697
+ * @see {@link Task.all} to run multiple independent Tasks in parallel.
5698
+ *
5394
5699
  * @example
5395
5700
  * ```ts
5396
5701
  * const add = (a: number) => (b: number) => a + b;
5397
5702
  * pipe(
5398
- * Task.resolve(add),
5399
- * Task.ap(Task.resolve(5)),
5400
- * Task.ap(Task.resolve(3))
5703
+ * Task.make(add),
5704
+ * Task.apply(Task.make(5)),
5705
+ * Task.apply(Task.make(3))
5401
5706
  * )(); // Deferred<8>
5402
5707
  * ```
5403
5708
  */
5404
- ap: (arg) => (data) => fromPromise((signal) => Promise.all([toPromise(data, signal), toPromise(arg, signal)]).then(([f, a]) => f(a))),
5709
+ apply: (arg) => (task) => fromPromise((signal) => Promise.all([toPromise(task, signal), toPromise(arg, signal)]).then(([f, a]) => f(a))),
5405
5710
  /**
5406
5711
  * Executes a side effect on the value without changing the Task.
5407
5712
  * Useful for logging or debugging.
@@ -5415,14 +5720,17 @@ sync: syncTask },
5415
5720
  * );
5416
5721
  * ```
5417
5722
  */
5418
- tap: (f) => (data) => fromPromise((signal) => toPromise(data, signal).then((a) => {
5419
- f(a);
5723
+ tap: (sideEffect) => (task) => fromPromise((signal) => toPromise(task, signal).then((a) => {
5724
+ sideEffect(a);
5420
5725
  return a;
5421
5726
  })),
5422
5727
  /**
5423
5728
  * Runs multiple Tasks in parallel and collects their results.
5424
5729
  * An optional `concurrency` option limits the number of tasks executing at any given time.
5425
5730
  *
5731
+ * @see {@link Task.sequence} to run an array of Tasks concurrently.
5732
+ * @see {@link Task.sequential} to run an array of Tasks one after another in order.
5733
+ *
5426
5734
  * @example
5427
5735
  * ```ts
5428
5736
  * Task.all([loadConfig, detectLocale, loadTheme])();
@@ -5455,30 +5763,32 @@ sync: syncTask },
5455
5763
  * @example
5456
5764
  * ```ts
5457
5765
  * pipe(
5458
- * Task.resolve(42),
5766
+ * Task.make(42),
5459
5767
  * Task.delay(Duration.seconds(1))
5460
5768
  * )(); // Resolves after 1 second
5461
5769
  * ```
5462
5770
  */
5463
- delay: (duration) => (data) => fromPromise((signal) => new Promise((res) => {
5771
+ delay: (duration) => (task) => fromPromise((signal) => new Promise((res) => {
5464
5772
  let timerId;
5465
5773
  const onAbort = () => {
5466
5774
  clearTimeout(timerId);
5467
- res(toPromise(data, signal));
5775
+ res(toPromise(task, signal));
5468
5776
  };
5469
5777
  if (signal) {
5470
- if (signal.aborted) return res(toPromise(data, signal));
5778
+ if (signal.aborted) return res(toPromise(task, signal));
5471
5779
  signal.addEventListener("abort", onAbort, { once: true });
5472
5780
  }
5473
5781
  timerId = setTimeout(() => {
5474
5782
  signal?.removeEventListener("abort", onAbort);
5475
- res(toPromise(data, signal));
5783
+ res(toPromise(task, signal));
5476
5784
  }, getMs(duration));
5477
5785
  })),
5478
5786
  /**
5479
5787
  * Runs a Task a fixed number of times sequentially, collecting all results into an array.
5480
5788
  * An optional delay duration can be inserted between runs.
5481
5789
  *
5790
+ * @see {@link Task.poll} to repeatedly run a Task until a predicate is satisfied.
5791
+ *
5482
5792
  * @example
5483
5793
  * ```ts
5484
5794
  * pipe(
@@ -5519,6 +5829,8 @@ sync: syncTask },
5519
5829
  * An optional `attempts` cap stops the loop after N calls — the last value is returned
5520
5830
  * regardless of whether the predicate was satisfied.
5521
5831
  *
5832
+ * @see {@link Task.repeat} to run a Task a fixed number of times.
5833
+ *
5522
5834
  * @example
5523
5835
  * ```ts
5524
5836
  * pipe(
@@ -5559,8 +5871,8 @@ sync: syncTask },
5559
5871
  *
5560
5872
  * @example
5561
5873
  * ```ts
5562
- * const fast = Task.resolve("fast");
5563
- * const slow = Task.delay(Duration.milliseconds(200))(Task.resolve("slow"));
5874
+ * const fast = Task.make("fast");
5875
+ * const slow = Task.delay(Duration.milliseconds(200))(Task.make("slow"));
5564
5876
  *
5565
5877
  * await Task.race([fast, slow])(); // "fast"
5566
5878
  * ```
@@ -5591,6 +5903,9 @@ sync: syncTask },
5591
5903
  * Runs an array of Tasks concurrently and collects their results in an array.
5592
5904
  * Forward-propagates the call site's AbortSignal to all subtasks concurrently.
5593
5905
  *
5906
+ * @see {@link Task.sequential} to run an array of tasks one after another in order.
5907
+ * @see {@link Task.all} to run an array or tuple of tasks in parallel with optional concurrency limit.
5908
+ *
5594
5909
  * @example
5595
5910
  * ```ts
5596
5911
  * Task.sequence([loadConfig, detectLocale, loadTheme])();
@@ -5602,10 +5917,12 @@ sync: syncTask },
5602
5917
  * Runs an array of Tasks one at a time in order, collecting all results.
5603
5918
  * Each Task starts only after the previous one resolves.
5604
5919
  *
5920
+ * @see {@link Task.sequence} to run an array of tasks concurrently.
5921
+ *
5605
5922
  * @example
5606
5923
  * ```ts
5607
5924
  * let log: number[] = [];
5608
- * const makeTask = (n: number) => Task.resolve(n);
5925
+ * const makeTask = (n: number) => Task.make(n);
5609
5926
  *
5610
5927
  * await Task.sequential([makeTask(1), makeTask(2), makeTask(3)])();
5611
5928
  * // log = [1, 2, 3] — tasks ran in order
@@ -5720,22 +6037,22 @@ sync: syncTask },
5720
6037
  *
5721
6038
  * @example
5722
6039
  * ```ts
5723
- * pipe(Task.resolve(42), Task.bindTo("value")); // Task({ value: 42 })
6040
+ * pipe(Task.make(42), Task.bindTo("value")); // Task({ value: 42 })
5724
6041
  * ```
5725
6042
  */
5726
- bindTo: (key) => (data) => fromPromise((signal) => toPromise(data, signal).then((a) => ({ [key]: a }))),
6043
+ bindTo: (key) => (task) => fromPromise((signal) => toPromise(task, signal).then((a) => ({ [key]: a }))),
5727
6044
  /**
5728
6045
  * Evaluates a new Task using the current accumulator and attaches the output to a new key.
5729
6046
  *
5730
6047
  * @example
5731
6048
  * ```ts
5732
6049
  * pipe(
5733
- * Task.resolve({ a: 1 }),
5734
- * Task.bind("b", ({ a }) => Task.resolve(a + 1))
6050
+ * Task.make({ a: 1 }),
6051
+ * Task.bind("b", ({ a }) => Task.make(a + 1))
5735
6052
  * ); // Task({ a: 1, b: 2 })
5736
6053
  * ```
5737
6054
  */
5738
- bind: (key, f) => (data) => fromPromise((signal) => toPromise(data, signal).then((a) => toPromise(f(a), signal).then((b) => ({
6055
+ bind: (key, transform) => (task) => fromPromise((signal) => toPromise(task, signal).then((a) => toPromise(transform(a), signal).then((b) => ({
5739
6056
  ...a,
5740
6057
  [key]: b
5741
6058
  })))),
@@ -5809,16 +6126,16 @@ const makeSecond = (value) => ({
5809
6126
  kind: "Second",
5810
6127
  second: value
5811
6128
  });
5812
- const makeBoth = (f, s) => ({
6129
+ const makeBoth = (first, second) => ({
5813
6130
  kind: "Both",
5814
- first: f,
5815
- second: s
6131
+ first,
6132
+ second
5816
6133
  });
5817
- const isFirst = (data) => data.kind === "First";
5818
- const isSecond = (data) => data.kind === "Second";
5819
- const isBoth = (data) => data.kind === "Both";
5820
- const hasFirst = (data) => data.kind === "First" || data.kind === "Both";
5821
- const hasSecond = (data) => data.kind === "Second" || data.kind === "Both";
6134
+ const isFirst = (these) => these.kind === "First";
6135
+ const isSecond = (these) => these.kind === "Second";
6136
+ const isBoth = (these) => these.kind === "Both";
6137
+ const hasFirst = (these) => these.kind === "First" || these.kind === "Both";
6138
+ const hasSecond = (these) => these.kind === "Second" || these.kind === "Both";
5822
6139
  const These = {
5823
6140
  make: {
5824
6141
  /**
@@ -5890,6 +6207,8 @@ const These = {
5890
6207
  /**
5891
6208
  * Returns true if the These contains a first value (First or Both).
5892
6209
  *
6210
+ * @see {@link These.hasSecond} to check if These contains a second value.
6211
+ *
5893
6212
  * @example
5894
6213
  * ```ts
5895
6214
  * These.hasFirst(These.make.first(42)); // true
@@ -5901,6 +6220,8 @@ const These = {
5901
6220
  /**
5902
6221
  * Returns true if the These contains a second value (Second or Both).
5903
6222
  *
6223
+ * @see {@link These.hasFirst} to check if These contains a first value.
6224
+ *
5904
6225
  * @example
5905
6226
  * ```ts
5906
6227
  * These.hasSecond(These.make.second("warn")); // true
@@ -5912,6 +6233,9 @@ const These = {
5912
6233
  /**
5913
6234
  * Transforms the first value, leaving the second unchanged.
5914
6235
  *
6236
+ * @see {@link These.mapSecond} to transform the second element.
6237
+ * @see {@link These.mapBoth} to transform both elements.
6238
+ *
5915
6239
  * @example
5916
6240
  * ```ts
5917
6241
  * pipe(These.make.first(5), These.mapFirst(n => n * 2)); // First(10)
@@ -5919,28 +6243,34 @@ const These = {
5919
6243
  * pipe(These.make.second("warn"), These.mapFirst(n => n * 2)); // Second("warn")
5920
6244
  * ```
5921
6245
  */
5922
- mapFirst: (f) => (data) => {
5923
- if (isSecond(data)) return data;
5924
- if (isFirst(data)) return makeFirst(f(data.first));
5925
- return makeBoth(f(data.first), data.second);
6246
+ mapFirst: (transform) => (these) => {
6247
+ if (isSecond(these)) return these;
6248
+ if (isFirst(these)) return makeFirst(transform(these.first));
6249
+ return makeBoth(transform(these.first), these.second);
5926
6250
  },
5927
6251
  /**
5928
6252
  * Transforms the second value, leaving the first unchanged.
5929
6253
  *
6254
+ * @see {@link These.mapFirst} to transform the first element.
6255
+ * @see {@link These.mapBoth} to transform both elements.
6256
+ *
5930
6257
  * @example
5931
6258
  * ```ts
5932
6259
  * pipe(These.make.second("warn"), These.mapSecond(e => e.toUpperCase())); // Second("WARN")
5933
6260
  * pipe(These.make.both(5, "warn"), These.mapSecond(e => e.toUpperCase())); // Both(5, "WARN")
5934
6261
  * ```
5935
6262
  */
5936
- mapSecond: (f) => (data) => {
5937
- if (isFirst(data)) return data;
5938
- if (isSecond(data)) return makeSecond(f(data.second));
5939
- return makeBoth(data.first, f(data.second));
6263
+ mapSecond: (transform) => (these) => {
6264
+ if (isFirst(these)) return these;
6265
+ if (isSecond(these)) return makeSecond(transform(these.second));
6266
+ return makeBoth(these.first, transform(these.second));
5940
6267
  },
5941
6268
  /**
5942
6269
  * Transforms both the first and second values independently.
5943
6270
  *
6271
+ * @see {@link These.mapFirst} to transform only the first element.
6272
+ * @see {@link These.mapSecond} to transform only the second element.
6273
+ *
5944
6274
  * @example
5945
6275
  * ```ts
5946
6276
  * pipe(
@@ -5949,14 +6279,16 @@ const These = {
5949
6279
  * ); // Both(10, "WARN")
5950
6280
  * ```
5951
6281
  */
5952
- mapBoth: (onFirst, onSecond) => (data) => {
5953
- if (isSecond(data)) return makeSecond(onSecond(data.second));
5954
- if (isFirst(data)) return makeFirst(onFirst(data.first));
5955
- return makeBoth(onFirst(data.first), onSecond(data.second));
6282
+ mapBoth: (onFirst, onSecond) => (these) => {
6283
+ if (isSecond(these)) return makeSecond(onSecond(these.second));
6284
+ if (isFirst(these)) return makeFirst(onFirst(these.first));
6285
+ return makeBoth(onFirst(these.first), onSecond(these.second));
5956
6286
  },
5957
6287
  /**
5958
- * Chains These computations by passing the first value to f.
5959
- * Second propagates unchanged; First and Both apply f to the first value.
6288
+ * Chains These computations by passing the first value to transform.
6289
+ * Second propagates unchanged; First and Both apply transform to the first value.
6290
+ *
6291
+ * @see {@link These.chainSecond} to chain based on the second value.
5960
6292
  *
5961
6293
  * @example
5962
6294
  * ```ts
@@ -5967,13 +6299,15 @@ const These = {
5967
6299
  * pipe(These.make.second("warn"), These.chainFirst(double)); // Second("warn")
5968
6300
  * ```
5969
6301
  */
5970
- chainFirst: (f) => (data) => {
5971
- if (isSecond(data)) return data;
5972
- return f(data.first);
6302
+ chainFirst: (transform) => (these) => {
6303
+ if (isSecond(these)) return these;
6304
+ return transform(these.first);
5973
6305
  },
5974
6306
  /**
5975
- * Chains These computations by passing the second value to f.
5976
- * First propagates unchanged; Second and Both apply f to the second value.
6307
+ * Chains These computations by passing the second value to transform.
6308
+ * First propagates unchanged; Second and Both apply transform to the second value.
6309
+ *
6310
+ * @see {@link These.chainFirst} to chain based on the first value.
5977
6311
  *
5978
6312
  * @example
5979
6313
  * ```ts
@@ -5984,13 +6318,15 @@ const These = {
5984
6318
  * pipe(These.make.first(5), These.chainSecond(shout)); // First(5)
5985
6319
  * ```
5986
6320
  */
5987
- chainSecond: (f) => (data) => {
5988
- if (isFirst(data)) return data;
5989
- return f(data.second);
6321
+ chainSecond: (transform) => (these) => {
6322
+ if (isFirst(these)) return these;
6323
+ return transform(these.second);
5990
6324
  },
5991
6325
  /**
5992
6326
  * Extracts a value from a These by providing handlers for all three cases.
5993
6327
  *
6328
+ * @see {@link These.match} for named-case pattern matching with an object literal.
6329
+ *
5994
6330
  * @example
5995
6331
  * ```ts
5996
6332
  * pipe(
@@ -6003,14 +6339,16 @@ const These = {
6003
6339
  * );
6004
6340
  * ```
6005
6341
  */
6006
- fold: (onFirst, onSecond, onBoth) => (data) => {
6007
- if (isSecond(data)) return onSecond(data.second);
6008
- if (isFirst(data)) return onFirst(data.first);
6009
- return onBoth(data.first, data.second);
6342
+ fold: (onFirst, onSecond, onBoth) => (these) => {
6343
+ if (isSecond(these)) return onSecond(these.second);
6344
+ if (isFirst(these)) return onFirst(these.first);
6345
+ return onBoth(these.first, these.second);
6010
6346
  },
6011
6347
  /**
6012
6348
  * Pattern matches on a These, returning the result of the matching case.
6013
6349
  *
6350
+ * @see {@link These.fold} for positional argument pattern matching.
6351
+ *
6014
6352
  * @example
6015
6353
  * ```ts
6016
6354
  * pipe(
@@ -6023,15 +6361,17 @@ const These = {
6023
6361
  * );
6024
6362
  * ```
6025
6363
  */
6026
- match: (cases) => (data) => {
6027
- if (isSecond(data)) return cases.second(data.second);
6028
- if (isFirst(data)) return cases.first(data.first);
6029
- return cases.both(data.first, data.second);
6364
+ match: (cases) => (these) => {
6365
+ if (isSecond(these)) return cases.second(these.second);
6366
+ if (isFirst(these)) return cases.first(these.first);
6367
+ return cases.both(these.first, these.second);
6030
6368
  },
6031
6369
  /**
6032
6370
  * Returns the first value, or a default if the These has no first value.
6033
6371
  * The default can be a different type, widening the result to `A | C`.
6034
6372
  *
6373
+ * @see {@link These.getSecondOrElse} to retrieve the second value with fallback.
6374
+ *
6035
6375
  * @example
6036
6376
  * ```ts
6037
6377
  * pipe(These.make.first(5), These.getFirstOrElse(() => 0)); // 5
@@ -6040,11 +6380,13 @@ const These = {
6040
6380
  * pipe(These.make.second("warn"), These.getFirstOrElse(() => null)); // null — typed as number | null
6041
6381
  * ```
6042
6382
  */
6043
- getFirstOrElse: (defaultValue) => (data) => hasFirst(data) ? data.first : defaultValue(),
6383
+ getFirstOrElse: (fallback) => (these) => hasFirst(these) ? these.first : fallback(),
6044
6384
  /**
6045
6385
  * Returns the second value, or a default if the These has no second value.
6046
6386
  * The default can be a different type, widening the result to `B | D`.
6047
6387
  *
6388
+ * @see {@link These.getFirstOrElse} to retrieve the first value with fallback.
6389
+ *
6048
6390
  * @example
6049
6391
  * ```ts
6050
6392
  * pipe(These.make.second("warn"), These.getSecondOrElse(() => "none")); // "warn"
@@ -6053,7 +6395,7 @@ const These = {
6053
6395
  * pipe(These.make.first(5), These.getSecondOrElse(() => null)); // null — typed as string | null
6054
6396
  * ```
6055
6397
  */
6056
- getSecondOrElse: (defaultValue) => (data) => hasSecond(data) ? data.second : defaultValue(),
6398
+ getSecondOrElse: (fallback) => (these) => hasSecond(these) ? these.second : fallback(),
6057
6399
  /**
6058
6400
  * Runs a side effect on the first value without changing the These.
6059
6401
  * Useful for logging or debugging.
@@ -6063,9 +6405,9 @@ const These = {
6063
6405
  * pipe(These.make.first(5), These.tap(console.log)); // logs 5, returns First(5)
6064
6406
  * ```
6065
6407
  */
6066
- tap: (f) => (data) => {
6067
- if (hasFirst(data)) f(data.first);
6068
- return data;
6408
+ tap: (sideEffect) => (these) => {
6409
+ if (hasFirst(these)) sideEffect(these.first);
6410
+ return these;
6069
6411
  },
6070
6412
  /**
6071
6413
  * Swaps the roles of first and second values.
@@ -6080,10 +6422,10 @@ const These = {
6080
6422
  * These.swap(These.make.both(5, "warn")); // Both("warn", 5)
6081
6423
  * ```
6082
6424
  */
6083
- swap: (data) => {
6084
- if (isSecond(data)) return makeFirst(data.second);
6085
- if (isFirst(data)) return makeSecond(data.first);
6086
- return makeBoth(data.second, data.first);
6425
+ swap: (these) => {
6426
+ if (isSecond(these)) return makeFirst(these.second);
6427
+ if (isFirst(these)) return makeSecond(these.first);
6428
+ return makeBoth(these.second, these.first);
6087
6429
  }
6088
6430
  };
6089
6431
  //#endregion