@nlozgachev/pipelined 0.32.0 → 0.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/core.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { M as Maybe, W as WithValue, c as WithLog, D as Deferred, R as Result, d as WithKind, e as WithError, f as RetryOptions, g as TimeoutOptions, h as WithTimeout, i as WithMinInterval, j as WithCooldown, k as WithConcurrency, l as WithSize, m as WithMs, n as WithN, T as Task, o as WithErrors, p as WithFirst, q as WithSecond } from './Task-CjYKLeTY.js';
2
- export { E as Equality, a as Error, N as None, O as Ok, b as Ordering, S as Some } from './Task-CjYKLeTY.js';
3
- import { N as NonEmptyList } from './NonEmptyList-BlGFjor5.js';
1
+ import { M as Maybe, W as WithValue, c as WithLog, D as Deferred, R as Result, d as WithKind, e as WithError, f as RetryOptions, g as TimeoutOptions, h as WithTimeout, i as WithMinInterval, j as WithCooldown, k as WithConcurrency, l as WithSize, m as WithMs, n as WithN, T as Task, o as WithErrors, p as WithFirst, q as WithSecond } from './Task-DeiWgoeJ.js';
2
+ export { E as Equality, a as Error, N as None, O as Ok, b as Ordering, S as Some } from './Task-DeiWgoeJ.js';
3
+ import { NonEmptyList } from './types.js';
4
4
 
5
5
  /**
6
6
  * A type that can combine two values of type `A` into one, with a neutral starting value.
@@ -1984,6 +1984,25 @@ declare namespace TaskResult {
1984
1984
  * Creates a failed TaskResult with the given error.
1985
1985
  */
1986
1986
  const err: <E, A>(error: E) => TaskResult<E, A>;
1987
+ /**
1988
+ * Creates a TaskResult from a nullable value.
1989
+ * Returns Ok if the value is not null or undefined, error from onNull otherwise.
1990
+ */
1991
+ const fromNullable: <E>(onNull: () => E) => <A>(value: A | null | undefined) => TaskResult<E, A>;
1992
+ /**
1993
+ * Creates a TaskResult from a Maybe.
1994
+ * Some becomes Ok, None becomes error from onNone.
1995
+ */
1996
+ const fromMaybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => TaskResult<E, A>;
1997
+ /**
1998
+ * Lifts a Result into a TaskResult.
1999
+ */
2000
+ const fromResult: <E, A>(result: Result<E, A>) => TaskResult<E, A>;
2001
+ /**
2002
+ * Wraps a Promise-returning function of any arguments, returning a new function
2003
+ * that catches rejections and returns a TaskResult.
2004
+ */
2005
+ const fromThrowable: <Args extends readonly unknown[], A, E>(f: (...args: Args) => Promise<A>, onError: (e: unknown) => E) => (...args: Args) => TaskResult<E, A>;
1987
2006
  /**
1988
2007
  * Creates a TaskResult from a function that may throw.
1989
2008
  * Catches any errors and transforms them using the onError function.
@@ -2392,6 +2411,16 @@ declare namespace TaskMaybe {
2392
2411
  * Lifts an Option into a TaskMaybe.
2393
2412
  */
2394
2413
  const fromMaybe: <A>(option: Maybe<A>) => TaskMaybe<A>;
2414
+ /**
2415
+ * Creates a TaskMaybe from a nullable value.
2416
+ * Returns Some if the value is not null or undefined, None otherwise.
2417
+ */
2418
+ const fromNullable: <A>(value: A | null | undefined) => TaskMaybe<A>;
2419
+ /**
2420
+ * Creates a TaskMaybe from a Result.
2421
+ * Ok becomes Some, Error becomes None (the error value is discarded).
2422
+ */
2423
+ const fromResult: <E, A>(result: Result<E, A>) => TaskMaybe<A>;
2395
2424
  /**
2396
2425
  * Lifts a Task into a TaskMaybe by wrapping its result in Some.
2397
2426
  */
@@ -2561,6 +2590,30 @@ declare namespace Validation {
2561
2590
  * ```
2562
2591
  */
2563
2592
  const fromPredicate: <E, A>(pred: (a: A) => boolean, onFalse: (a: A) => E) => (a: A) => Validation<E, A>;
2593
+ /**
2594
+ * Creates a Validation from a nullable value.
2595
+ * If the value is null or undefined, returns Invalid with the error from onNull.
2596
+ * Otherwise, returns Valid.
2597
+ *
2598
+ * @example
2599
+ * ```ts
2600
+ * pipe(null, Validation.fromNullable(() => "is null")); // Invalid(["is null"])
2601
+ * pipe(42, Validation.fromNullable(() => "is null")); // Valid(42)
2602
+ * ```
2603
+ */
2604
+ const fromNullable: <E>(onNull: () => E) => <A>(value: A | null | undefined) => Validation<E, A>;
2605
+ /**
2606
+ * Creates a Validation from a Maybe.
2607
+ * If the Maybe is None, returns Invalid with the error from onNone.
2608
+ * Otherwise, returns Valid.
2609
+ *
2610
+ * @example
2611
+ * ```ts
2612
+ * pipe(Maybe.none(), Validation.fromMaybe(() => "is none")); // Invalid(["is none"])
2613
+ * pipe(Maybe.some(42), Validation.fromMaybe(() => "is none")); // Valid(42)
2614
+ * ```
2615
+ */
2616
+ const fromMaybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => Validation<E, A>;
2564
2617
  /**
2565
2618
  * Transforms the success value inside a Validation.
2566
2619
  *
@@ -2794,6 +2847,22 @@ declare namespace TaskValidation {
2794
2847
  * Lifts a Validation into a TaskValidation.
2795
2848
  */
2796
2849
  const fromValidation: <E, A>(validation: Validation<E, A>) => TaskValidation<E, A>;
2850
+ /**
2851
+ * Creates a TaskValidation from a nullable value.
2852
+ * If the value is null or undefined, returns Invalid with the error from onNull.
2853
+ * Otherwise, returns Valid.
2854
+ */
2855
+ const fromNullable: <E>(onNull: () => E) => <A>(value: A | null | undefined) => TaskValidation<E, A>;
2856
+ /**
2857
+ * Creates a TaskValidation from a Maybe.
2858
+ * Some becomes Valid, None becomes Invalid with the error from onNone.
2859
+ */
2860
+ const fromMaybe: <E>(onNone: () => E) => <A>(maybe: Maybe<A>) => TaskValidation<E, A>;
2861
+ /**
2862
+ * Creates a TaskValidation from a Result.
2863
+ * Ok becomes Valid, Error(e) becomes Invalid([e]).
2864
+ */
2865
+ const fromResult: <E, A>(result: Result<E, A>) => TaskValidation<E, A>;
2797
2866
  /**
2798
2867
  * Creates a TaskValidation from a Promise-returning function.
2799
2868
  * Catches any errors and transforms them using the onError function.
package/dist/core.js CHANGED
@@ -76,6 +76,15 @@ var Result;
76
76
  return data;
77
77
  };
78
78
  Result2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Result2.ok)(a) : (0, Result2.error)(onFalse(a));
79
+ Result2.fromNullable = (onNull) => (value) => value === null || value === void 0 ? (0, Result2.error)(onNull()) : (0, Result2.ok)(value);
80
+ Result2.fromMaybe = (onNone) => (maybe) => Maybe.isNone(maybe) ? (0, Result2.error)(onNone()) : (0, Result2.ok)(maybe.value);
81
+ Result2.fromThrowable = (f, onError) => (...args) => {
82
+ try {
83
+ return (0, Result2.ok)(f(...args));
84
+ } catch (e) {
85
+ return (0, Result2.error)(onError(e));
86
+ }
87
+ };
79
88
  Result2.recover = (fallback) => (data) => (0, Result2.isOk)(data) ? data : fallback(data.error);
80
89
  Result2.recoverUnless = (isBlocked, fallback) => (data) => (0, Result2.isError)(data) && !isBlocked(data.error) ? fallback() : data;
81
90
  Result2.toMaybe = (data) => (0, Result2.isOk)(data) ? Maybe.some(data.value) : Maybe.none();
@@ -1370,8 +1379,34 @@ var RemoteData;
1370
1379
  RemoteData2.filter = (pred, onFalse) => (data) => (0, RemoteData2.isSuccess)(data) ? pred(data.value) ? data : (0, RemoteData2.failure)(onFalse(data.value)) : data;
1371
1380
  })(RemoteData || (RemoteData = {}));
1372
1381
 
1382
+ // src/Types/Brand.ts
1383
+ var Brand;
1384
+ ((Brand2) => {
1385
+ Brand2.wrap = () => (value) => value;
1386
+ Brand2.unwrap = (branded) => branded;
1387
+ })(Brand || (Brand = {}));
1388
+
1389
+ // src/Types/Duration.ts
1390
+ var Duration;
1391
+ ((Duration2) => {
1392
+ const wrap = Brand.wrap();
1393
+ Duration2.milliseconds = (ms) => wrap(ms);
1394
+ Duration2.seconds = (s) => wrap(s * 1e3);
1395
+ Duration2.minutes = (m) => wrap(m * 60 * 1e3);
1396
+ Duration2.hours = (h) => wrap(h * 60 * 60 * 1e3);
1397
+ Duration2.days = (d) => wrap(d * 24 * 60 * 60 * 1e3);
1398
+ Duration2.toMilliseconds = (d) => Brand.unwrap(d);
1399
+ Duration2.toSeconds = (d) => Brand.unwrap(d) / 1e3;
1400
+ Duration2.toMinutes = (d) => Brand.unwrap(d) / (60 * 1e3);
1401
+ Duration2.toHours = (d) => Brand.unwrap(d) / (60 * 60 * 1e3);
1402
+ Duration2.toDays = (d) => Brand.unwrap(d) / (24 * 60 * 60 * 1e3);
1403
+ Duration2.add = (other) => (self) => wrap(Brand.unwrap(self) + Brand.unwrap(other));
1404
+ Duration2.subtract = (other) => (self) => wrap(Brand.unwrap(self) - Brand.unwrap(other));
1405
+ })(Duration || (Duration = {}));
1406
+
1373
1407
  // src/Core/Task.ts
1374
1408
  var toPromise = (task, signal) => Deferred.toPromise(task(signal));
1409
+ var getMs = (ms) => typeof ms === "number" ? ms : Duration.toMilliseconds(ms);
1375
1410
  var Task;
1376
1411
  ((Task2) => {
1377
1412
  Task2.resolve = (value) => () => Deferred.fromPromise(Promise.resolve(value));
@@ -1412,7 +1447,7 @@ var Task;
1412
1447
  timerId = setTimeout(() => {
1413
1448
  signal?.removeEventListener("abort", onAbort);
1414
1449
  resolve2(toPromise(data, signal));
1415
- }, ms);
1450
+ }, getMs(ms));
1416
1451
  })
1417
1452
  );
1418
1453
  Task2.repeat = (options) => (task) => (0, Task2.from)((signal) => {
@@ -1435,7 +1470,7 @@ var Task;
1435
1470
  timerId = setTimeout(() => {
1436
1471
  signal?.removeEventListener("abort", onAbort);
1437
1472
  r();
1438
- }, ms || 0);
1473
+ }, getMs(ms || 0));
1439
1474
  });
1440
1475
  };
1441
1476
  const run2 = (left) => {
@@ -1468,7 +1503,7 @@ var Task;
1468
1503
  timerId = setTimeout(() => {
1469
1504
  signal?.removeEventListener("abort", onAbort);
1470
1505
  r();
1471
- }, ms || 0);
1506
+ }, getMs(ms || 0));
1472
1507
  });
1473
1508
  };
1474
1509
  const run2 = (attempt, lastValue) => {
@@ -1484,7 +1519,39 @@ var Task;
1484
1519
  };
1485
1520
  return run2(1);
1486
1521
  });
1487
- Task2.race = (tasks) => (0, Task2.from)((signal) => Promise.race(tasks.map((t) => toPromise(t, signal))));
1522
+ Task2.race = (tasks) => {
1523
+ if (tasks.length === 0) {
1524
+ return () => Deferred.fromPromise(new Promise(() => {
1525
+ }));
1526
+ }
1527
+ return (0, Task2.from)((outerSignal) => {
1528
+ const controllers = tasks.map(() => new AbortController());
1529
+ const onOuterAbort = () => {
1530
+ for (const ctrl of controllers) ctrl.abort();
1531
+ };
1532
+ if (outerSignal) {
1533
+ if (outerSignal.aborted) {
1534
+ onOuterAbort();
1535
+ } else {
1536
+ outerSignal.addEventListener("abort", onOuterAbort, { once: true });
1537
+ }
1538
+ }
1539
+ const promises = tasks.map((task, idx) => {
1540
+ const ctrl = controllers[idx];
1541
+ return toPromise(task, ctrl.signal).then((result) => {
1542
+ for (let i = 0; i < controllers.length; i++) {
1543
+ if (i !== idx) {
1544
+ controllers[i].abort();
1545
+ }
1546
+ }
1547
+ outerSignal?.removeEventListener("abort", onOuterAbort);
1548
+ return result;
1549
+ });
1550
+ });
1551
+ return Promise.race(promises);
1552
+ });
1553
+ };
1554
+ Task2.sequence = (tasks) => (0, Task2.from)((signal) => Promise.all(tasks.map((t) => toPromise(t, signal))));
1488
1555
  Task2.sequential = (tasks) => (0, Task2.from)(async (signal) => {
1489
1556
  const results = [];
1490
1557
  for (const task of tasks) {
@@ -1525,7 +1592,7 @@ var Task;
1525
1592
  controller.abort();
1526
1593
  cleanUp();
1527
1594
  resolve2(Result.error(onTimeout()));
1528
- }, ms);
1595
+ }, getMs(ms));
1529
1596
  })
1530
1597
  ]);
1531
1598
  });
@@ -1626,6 +1693,8 @@ var TaskMaybe;
1626
1693
  TaskMaybe2.some = (value) => Task.resolve(Maybe.some(value));
1627
1694
  TaskMaybe2.none = () => Task.resolve(Maybe.none());
1628
1695
  TaskMaybe2.fromMaybe = (option) => Task.resolve(option);
1696
+ TaskMaybe2.fromNullable = (value) => Task.resolve(Maybe.fromNullable(value));
1697
+ TaskMaybe2.fromResult = (result) => Task.resolve(Result.toMaybe(result));
1629
1698
  TaskMaybe2.fromTask = (task) => Task.map(Maybe.some)(task);
1630
1699
  TaskMaybe2.tryCatch = (f) => Task.from(
1631
1700
  (signal) => f(signal).then(Maybe.some).catch(() => Maybe.none())
@@ -1651,6 +1720,12 @@ var TaskResult;
1651
1720
  ((TaskResult2) => {
1652
1721
  TaskResult2.ok = (value) => Task.resolve(Result.ok(value));
1653
1722
  TaskResult2.err = (error) => Task.resolve(Result.error(error));
1723
+ TaskResult2.fromNullable = (onNull) => (value) => Task.resolve(value === null || value === void 0 ? Result.error(onNull()) : Result.ok(value));
1724
+ TaskResult2.fromMaybe = (onNone) => (maybe) => Task.resolve(Maybe.isNone(maybe) ? Result.error(onNone()) : Result.ok(maybe.value));
1725
+ TaskResult2.fromResult = (result) => Task.resolve(result);
1726
+ TaskResult2.fromThrowable = (f, onError) => (...args) => Task.from(
1727
+ () => f(...args).then(Result.ok).catch((e) => Result.error(onError(e)))
1728
+ );
1654
1729
  TaskResult2.tryCatch = (f, onError) => Task.from(
1655
1730
  (signal) => f(signal).then(Result.ok).catch((e) => Result.error(onError(e)))
1656
1731
  );
@@ -1696,6 +1771,8 @@ var Validation;
1696
1771
  Validation2.isValid = (data) => data.kind === "Valid";
1697
1772
  Validation2.isInvalid = (data) => data.kind === "Invalid";
1698
1773
  Validation2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Validation2.valid)(a) : (0, Validation2.invalid)(onFalse(a));
1774
+ Validation2.fromNullable = (onNull) => (value) => value === null || value === void 0 ? (0, Validation2.invalid)(onNull()) : (0, Validation2.valid)(value);
1775
+ Validation2.fromMaybe = (onNone) => (maybe) => Maybe.isNone(maybe) ? (0, Validation2.invalid)(onNone()) : (0, Validation2.valid)(maybe.value);
1699
1776
  Validation2.map = (f) => (data) => (0, Validation2.isValid)(data) ? (0, Validation2.valid)(f(data.value)) : data;
1700
1777
  Validation2.ap = (arg) => (data) => {
1701
1778
  if ((0, Validation2.isValid)(data) && (0, Validation2.isValid)(arg)) return (0, Validation2.valid)(data.value(arg.value));
@@ -1747,6 +1824,9 @@ var TaskValidation;
1747
1824
  TaskValidation2.invalid = (error) => Task.resolve(Validation.invalid(error));
1748
1825
  TaskValidation2.invalidAll = (errors) => Task.resolve(Validation.invalidAll(errors));
1749
1826
  TaskValidation2.fromValidation = (validation) => Task.resolve(validation);
1827
+ TaskValidation2.fromNullable = (onNull) => (value) => Task.resolve(value === null || value === void 0 ? Validation.invalid(onNull()) : Validation.valid(value));
1828
+ TaskValidation2.fromMaybe = (onNone) => (maybe) => Task.resolve(Maybe.isNone(maybe) ? Validation.invalid(onNone()) : Validation.valid(maybe.value));
1829
+ TaskValidation2.fromResult = (result) => Task.resolve(Validation.fromResult(result));
1750
1830
  TaskValidation2.tryCatch = (f, onError) => Task.from(
1751
1831
  (signal) => f(signal).then(Validation.valid).catch((e) => Validation.invalid(onError(e)))
1752
1832
  );
package/dist/core.mjs CHANGED
@@ -19,13 +19,14 @@ import {
19
19
  These,
20
20
  Tuple,
21
21
  Validation
22
- } from "./chunk-L3NC44SN.mjs";
22
+ } from "./chunk-FZX4MTRI.mjs";
23
23
  import {
24
24
  Deferred,
25
25
  Maybe,
26
26
  Result,
27
27
  Task
28
- } from "./chunk-TK5ZCGP2.mjs";
28
+ } from "./chunk-GSTKY7MF.mjs";
29
+ import "./chunk-VWVPHDZO.mjs";
29
30
  export {
30
31
  Combinable,
31
32
  Deferred,
package/dist/index.d.mts CHANGED
@@ -1,6 +1,5 @@
1
1
  export { and, compose, constFalse, constNull, constTrue, constUndefined, constVoid, constant, converge, curry, curry3, curry4, flip, flow, identity, juxt, memoize, memoizeWeak, not, on, once, or, pipe, tap, uncurry, uncurry3, uncurry4 } from './composition.mjs';
2
2
  export { Combinable, Failure, Invalid, Lazy, Lens, Loading, Logged, NotAsked, Op, Optional, Predicate, Reader, Refinement, RemoteData, Resource, State, Success, TaskMaybe, TaskResult, TaskValidation, These, TheseBoth, TheseFirst, TheseSecond, Tuple, Valid, Validation } from './core.mjs';
3
- export { D as Deferred, E as Equality, a as Error, M as Maybe, N as None, O as Ok, b as Ordering, R as Result, S as Some, T as Task } from './Task-CJZfcOkO.mjs';
4
- export { Brand } from './types.mjs';
5
- export { N as NonEmptyList, i as isNonEmptyList } from './NonEmptyList-BlGFjor5.mjs';
3
+ export { D as Deferred, E as Equality, a as Error, M as Maybe, N as None, O as Ok, b as Ordering, R as Result, S as Some, T as Task } from './Task-5na0QzS4.mjs';
4
+ export { Brand, Duration, NonEmptyList, isNonEmptyList } from './types.mjs';
6
5
  export { Arr, Dict, Num, Rec, Str, Uniq } from './utils.mjs';
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  export { and, compose, constFalse, constNull, constTrue, constUndefined, constVoid, constant, converge, curry, curry3, curry4, flip, flow, identity, juxt, memoize, memoizeWeak, not, on, once, or, pipe, tap, uncurry, uncurry3, uncurry4 } from './composition.js';
2
2
  export { Combinable, Failure, Invalid, Lazy, Lens, Loading, Logged, NotAsked, Op, Optional, Predicate, Reader, Refinement, RemoteData, Resource, State, Success, TaskMaybe, TaskResult, TaskValidation, These, TheseBoth, TheseFirst, TheseSecond, Tuple, Valid, Validation } from './core.js';
3
- export { D as Deferred, E as Equality, a as Error, M as Maybe, N as None, O as Ok, b as Ordering, R as Result, S as Some, T as Task } from './Task-CjYKLeTY.js';
4
- export { Brand } from './types.js';
5
- export { N as NonEmptyList, i as isNonEmptyList } from './NonEmptyList-BlGFjor5.js';
3
+ export { D as Deferred, E as Equality, a as Error, M as Maybe, N as None, O as Ok, b as Ordering, R as Result, S as Some, T as Task } from './Task-DeiWgoeJ.js';
4
+ export { Brand, Duration, NonEmptyList, isNonEmptyList } from './types.js';
6
5
  export { Arr, Dict, Num, Rec, Str, Uniq } from './utils.js';
package/dist/index.js CHANGED
@@ -25,6 +25,7 @@ __export(src_exports, {
25
25
  Combinable: () => Combinable,
26
26
  Deferred: () => Deferred,
27
27
  Dict: () => Dict,
28
+ Duration: () => Duration,
28
29
  Equality: () => Equality,
29
30
  Lazy: () => Lazy,
30
31
  Lens: () => Lens,
@@ -321,6 +322,15 @@ var Result;
321
322
  return data;
322
323
  };
323
324
  Result2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Result2.ok)(a) : (0, Result2.error)(onFalse(a));
325
+ Result2.fromNullable = (onNull) => (value) => value === null || value === void 0 ? (0, Result2.error)(onNull()) : (0, Result2.ok)(value);
326
+ Result2.fromMaybe = (onNone) => (maybe) => Maybe.isNone(maybe) ? (0, Result2.error)(onNone()) : (0, Result2.ok)(maybe.value);
327
+ Result2.fromThrowable = (f, onError) => (...args) => {
328
+ try {
329
+ return (0, Result2.ok)(f(...args));
330
+ } catch (e) {
331
+ return (0, Result2.error)(onError(e));
332
+ }
333
+ };
324
334
  Result2.recover = (fallback) => (data) => (0, Result2.isOk)(data) ? data : fallback(data.error);
325
335
  Result2.recoverUnless = (isBlocked, fallback) => (data) => (0, Result2.isError)(data) && !isBlocked(data.error) ? fallback() : data;
326
336
  Result2.toMaybe = (data) => (0, Result2.isOk)(data) ? Maybe.some(data.value) : Maybe.none();
@@ -1615,8 +1625,34 @@ var RemoteData;
1615
1625
  RemoteData2.filter = (pred, onFalse) => (data) => (0, RemoteData2.isSuccess)(data) ? pred(data.value) ? data : (0, RemoteData2.failure)(onFalse(data.value)) : data;
1616
1626
  })(RemoteData || (RemoteData = {}));
1617
1627
 
1628
+ // src/Types/Brand.ts
1629
+ var Brand;
1630
+ ((Brand2) => {
1631
+ Brand2.wrap = () => (value) => value;
1632
+ Brand2.unwrap = (branded) => branded;
1633
+ })(Brand || (Brand = {}));
1634
+
1635
+ // src/Types/Duration.ts
1636
+ var Duration;
1637
+ ((Duration2) => {
1638
+ const wrap = Brand.wrap();
1639
+ Duration2.milliseconds = (ms) => wrap(ms);
1640
+ Duration2.seconds = (s) => wrap(s * 1e3);
1641
+ Duration2.minutes = (m) => wrap(m * 60 * 1e3);
1642
+ Duration2.hours = (h) => wrap(h * 60 * 60 * 1e3);
1643
+ Duration2.days = (d) => wrap(d * 24 * 60 * 60 * 1e3);
1644
+ Duration2.toMilliseconds = (d) => Brand.unwrap(d);
1645
+ Duration2.toSeconds = (d) => Brand.unwrap(d) / 1e3;
1646
+ Duration2.toMinutes = (d) => Brand.unwrap(d) / (60 * 1e3);
1647
+ Duration2.toHours = (d) => Brand.unwrap(d) / (60 * 60 * 1e3);
1648
+ Duration2.toDays = (d) => Brand.unwrap(d) / (24 * 60 * 60 * 1e3);
1649
+ Duration2.add = (other) => (self) => wrap(Brand.unwrap(self) + Brand.unwrap(other));
1650
+ Duration2.subtract = (other) => (self) => wrap(Brand.unwrap(self) - Brand.unwrap(other));
1651
+ })(Duration || (Duration = {}));
1652
+
1618
1653
  // src/Core/Task.ts
1619
1654
  var toPromise = (task, signal) => Deferred.toPromise(task(signal));
1655
+ var getMs = (ms) => typeof ms === "number" ? ms : Duration.toMilliseconds(ms);
1620
1656
  var Task;
1621
1657
  ((Task2) => {
1622
1658
  Task2.resolve = (value) => () => Deferred.fromPromise(Promise.resolve(value));
@@ -1657,7 +1693,7 @@ var Task;
1657
1693
  timerId = setTimeout(() => {
1658
1694
  signal?.removeEventListener("abort", onAbort);
1659
1695
  resolve2(toPromise(data, signal));
1660
- }, ms);
1696
+ }, getMs(ms));
1661
1697
  })
1662
1698
  );
1663
1699
  Task2.repeat = (options) => (task) => (0, Task2.from)((signal) => {
@@ -1680,7 +1716,7 @@ var Task;
1680
1716
  timerId = setTimeout(() => {
1681
1717
  signal?.removeEventListener("abort", onAbort);
1682
1718
  r();
1683
- }, ms || 0);
1719
+ }, getMs(ms || 0));
1684
1720
  });
1685
1721
  };
1686
1722
  const run2 = (left) => {
@@ -1713,7 +1749,7 @@ var Task;
1713
1749
  timerId = setTimeout(() => {
1714
1750
  signal?.removeEventListener("abort", onAbort);
1715
1751
  r();
1716
- }, ms || 0);
1752
+ }, getMs(ms || 0));
1717
1753
  });
1718
1754
  };
1719
1755
  const run2 = (attempt, lastValue) => {
@@ -1729,7 +1765,39 @@ var Task;
1729
1765
  };
1730
1766
  return run2(1);
1731
1767
  });
1732
- Task2.race = (tasks) => (0, Task2.from)((signal) => Promise.race(tasks.map((t) => toPromise(t, signal))));
1768
+ Task2.race = (tasks) => {
1769
+ if (tasks.length === 0) {
1770
+ return () => Deferred.fromPromise(new Promise(() => {
1771
+ }));
1772
+ }
1773
+ return (0, Task2.from)((outerSignal) => {
1774
+ const controllers = tasks.map(() => new AbortController());
1775
+ const onOuterAbort = () => {
1776
+ for (const ctrl of controllers) ctrl.abort();
1777
+ };
1778
+ if (outerSignal) {
1779
+ if (outerSignal.aborted) {
1780
+ onOuterAbort();
1781
+ } else {
1782
+ outerSignal.addEventListener("abort", onOuterAbort, { once: true });
1783
+ }
1784
+ }
1785
+ const promises = tasks.map((task, idx) => {
1786
+ const ctrl = controllers[idx];
1787
+ return toPromise(task, ctrl.signal).then((result) => {
1788
+ for (let i = 0; i < controllers.length; i++) {
1789
+ if (i !== idx) {
1790
+ controllers[i].abort();
1791
+ }
1792
+ }
1793
+ outerSignal?.removeEventListener("abort", onOuterAbort);
1794
+ return result;
1795
+ });
1796
+ });
1797
+ return Promise.race(promises);
1798
+ });
1799
+ };
1800
+ Task2.sequence = (tasks) => (0, Task2.from)((signal) => Promise.all(tasks.map((t) => toPromise(t, signal))));
1733
1801
  Task2.sequential = (tasks) => (0, Task2.from)(async (signal) => {
1734
1802
  const results = [];
1735
1803
  for (const task of tasks) {
@@ -1770,7 +1838,7 @@ var Task;
1770
1838
  controller.abort();
1771
1839
  cleanUp();
1772
1840
  resolve2(Result.error(onTimeout()));
1773
- }, ms);
1841
+ }, getMs(ms));
1774
1842
  })
1775
1843
  ]);
1776
1844
  });
@@ -1871,6 +1939,8 @@ var TaskMaybe;
1871
1939
  TaskMaybe2.some = (value) => Task.resolve(Maybe.some(value));
1872
1940
  TaskMaybe2.none = () => Task.resolve(Maybe.none());
1873
1941
  TaskMaybe2.fromMaybe = (option) => Task.resolve(option);
1942
+ TaskMaybe2.fromNullable = (value) => Task.resolve(Maybe.fromNullable(value));
1943
+ TaskMaybe2.fromResult = (result) => Task.resolve(Result.toMaybe(result));
1874
1944
  TaskMaybe2.fromTask = (task) => Task.map(Maybe.some)(task);
1875
1945
  TaskMaybe2.tryCatch = (f) => Task.from(
1876
1946
  (signal) => f(signal).then(Maybe.some).catch(() => Maybe.none())
@@ -1896,6 +1966,12 @@ var TaskResult;
1896
1966
  ((TaskResult2) => {
1897
1967
  TaskResult2.ok = (value) => Task.resolve(Result.ok(value));
1898
1968
  TaskResult2.err = (error) => Task.resolve(Result.error(error));
1969
+ TaskResult2.fromNullable = (onNull) => (value) => Task.resolve(value === null || value === void 0 ? Result.error(onNull()) : Result.ok(value));
1970
+ TaskResult2.fromMaybe = (onNone) => (maybe) => Task.resolve(Maybe.isNone(maybe) ? Result.error(onNone()) : Result.ok(maybe.value));
1971
+ TaskResult2.fromResult = (result) => Task.resolve(result);
1972
+ TaskResult2.fromThrowable = (f, onError) => (...args) => Task.from(
1973
+ () => f(...args).then(Result.ok).catch((e) => Result.error(onError(e)))
1974
+ );
1899
1975
  TaskResult2.tryCatch = (f, onError) => Task.from(
1900
1976
  (signal) => f(signal).then(Result.ok).catch((e) => Result.error(onError(e)))
1901
1977
  );
@@ -1941,6 +2017,8 @@ var Validation;
1941
2017
  Validation2.isValid = (data) => data.kind === "Valid";
1942
2018
  Validation2.isInvalid = (data) => data.kind === "Invalid";
1943
2019
  Validation2.fromPredicate = (pred, onFalse) => (a) => pred(a) ? (0, Validation2.valid)(a) : (0, Validation2.invalid)(onFalse(a));
2020
+ Validation2.fromNullable = (onNull) => (value) => value === null || value === void 0 ? (0, Validation2.invalid)(onNull()) : (0, Validation2.valid)(value);
2021
+ Validation2.fromMaybe = (onNone) => (maybe) => Maybe.isNone(maybe) ? (0, Validation2.invalid)(onNone()) : (0, Validation2.valid)(maybe.value);
1944
2022
  Validation2.map = (f) => (data) => (0, Validation2.isValid)(data) ? (0, Validation2.valid)(f(data.value)) : data;
1945
2023
  Validation2.ap = (arg) => (data) => {
1946
2024
  if ((0, Validation2.isValid)(data) && (0, Validation2.isValid)(arg)) return (0, Validation2.valid)(data.value(arg.value));
@@ -1992,6 +2070,9 @@ var TaskValidation;
1992
2070
  TaskValidation2.invalid = (error) => Task.resolve(Validation.invalid(error));
1993
2071
  TaskValidation2.invalidAll = (errors) => Task.resolve(Validation.invalidAll(errors));
1994
2072
  TaskValidation2.fromValidation = (validation) => Task.resolve(validation);
2073
+ TaskValidation2.fromNullable = (onNull) => (value) => Task.resolve(value === null || value === void 0 ? Validation.invalid(onNull()) : Validation.valid(value));
2074
+ TaskValidation2.fromMaybe = (onNone) => (maybe) => Task.resolve(Maybe.isNone(maybe) ? Validation.invalid(onNone()) : Validation.valid(maybe.value));
2075
+ TaskValidation2.fromResult = (result) => Task.resolve(Validation.fromResult(result));
1995
2076
  TaskValidation2.tryCatch = (f, onError) => Task.from(
1996
2077
  (signal) => f(signal).then(Validation.valid).catch((e) => Validation.invalid(onError(e)))
1997
2078
  );
@@ -2102,13 +2183,6 @@ var Tuple;
2102
2183
  };
2103
2184
  })(Tuple || (Tuple = {}));
2104
2185
 
2105
- // src/Types/Brand.ts
2106
- var Brand;
2107
- ((Brand2) => {
2108
- Brand2.wrap = () => (value) => value;
2109
- Brand2.unwrap = (branded) => branded;
2110
- })(Brand || (Brand = {}));
2111
-
2112
2186
  // src/Types/NonEmptyList.ts
2113
2187
  var isNonEmptyList = (list) => list.length > 0;
2114
2188
 
@@ -2169,6 +2243,40 @@ var Arr;
2169
2243
  }
2170
2244
  return [pass, fail];
2171
2245
  };
2246
+ Arr2.compact = (data) => {
2247
+ const result = [];
2248
+ for (const item of data) {
2249
+ if (item.kind === "Some") {
2250
+ result.push(item.value);
2251
+ }
2252
+ }
2253
+ return result;
2254
+ };
2255
+ Arr2.separate = (data) => {
2256
+ const errors = [];
2257
+ const successes = [];
2258
+ for (const item of data) {
2259
+ if (item.kind === "Ok") {
2260
+ successes.push(item.value);
2261
+ } else {
2262
+ errors.push(item.error);
2263
+ }
2264
+ }
2265
+ return [errors, successes];
2266
+ };
2267
+ Arr2.partitionMap = (f) => (data) => {
2268
+ const errors = [];
2269
+ const successes = [];
2270
+ for (const item of data) {
2271
+ const mapped = f(item);
2272
+ if (mapped.kind === "Ok") {
2273
+ successes.push(mapped.value);
2274
+ } else {
2275
+ errors.push(mapped.error);
2276
+ }
2277
+ }
2278
+ return [errors, successes];
2279
+ };
2172
2280
  Arr2.groupBy = (f) => (data) => {
2173
2281
  const result = {};
2174
2282
  for (const a of data) {
@@ -2700,6 +2808,13 @@ var Str;
2700
2808
  return isNaN(n) ? Maybe.none() : Maybe.some(n);
2701
2809
  }
2702
2810
  };
2811
+ Str2.parseJson = (s) => {
2812
+ try {
2813
+ return Result.ok(JSON.parse(s));
2814
+ } catch (e) {
2815
+ return Result.error(e);
2816
+ }
2817
+ };
2703
2818
  })(Str || (Str = {}));
2704
2819
 
2705
2820
  // src/Utils/Uniq.ts
@@ -2782,6 +2897,7 @@ var Uniq;
2782
2897
  Combinable,
2783
2898
  Deferred,
2784
2899
  Dict,
2900
+ Duration,
2785
2901
  Equality,
2786
2902
  Lazy,
2787
2903
  Lens,
package/dist/index.mjs CHANGED
@@ -48,7 +48,7 @@ import {
48
48
  These,
49
49
  Tuple,
50
50
  Validation
51
- } from "./chunk-L3NC44SN.mjs";
51
+ } from "./chunk-FZX4MTRI.mjs";
52
52
  import {
53
53
  Arr,
54
54
  Dict,
@@ -56,25 +56,28 @@ import {
56
56
  Rec,
57
57
  Str,
58
58
  Uniq
59
- } from "./chunk-EHQFUWZW.mjs";
59
+ } from "./chunk-W53ZYTLX.mjs";
60
60
  import {
61
61
  Deferred,
62
62
  Maybe,
63
63
  Result,
64
64
  Task
65
- } from "./chunk-TK5ZCGP2.mjs";
66
- import {
67
- Brand
68
- } from "./chunk-BYWKZLHM.mjs";
65
+ } from "./chunk-GSTKY7MF.mjs";
66
+ import "./chunk-IPP4XFYH.mjs";
69
67
  import {
70
68
  isNonEmptyList
71
69
  } from "./chunk-DBIC62UV.mjs";
70
+ import {
71
+ Brand,
72
+ Duration
73
+ } from "./chunk-VWVPHDZO.mjs";
72
74
  export {
73
75
  Arr,
74
76
  Brand,
75
77
  Combinable,
76
78
  Deferred,
77
79
  Dict,
80
+ Duration,
78
81
  Equality,
79
82
  Lazy,
80
83
  Lens,