@nlozgachev/pipelined 0.32.0 → 0.34.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/index.mjs CHANGED
@@ -26,7 +26,7 @@ import {
26
26
  uncurry,
27
27
  uncurry3,
28
28
  uncurry4
29
- } from "./chunk-NRF2FVPZ.mjs";
29
+ } from "./chunk-AHEZFTMT.mjs";
30
30
  import {
31
31
  Combinable,
32
32
  Equality,
@@ -48,7 +48,7 @@ import {
48
48
  These,
49
49
  Tuple,
50
50
  Validation
51
- } from "./chunk-L3NC44SN.mjs";
51
+ } from "./chunk-5AWUAG7G.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-IJFFWBKW.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-DLBHVYII.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,
package/dist/types.d.mts CHANGED
@@ -1,4 +1,31 @@
1
- export { N as NonEmptyList, i as isNonEmptyList } from './NonEmptyList-BlGFjor5.mjs';
1
+ /**
2
+ * A list that is guaranteed to have at least one element.
3
+ * Useful for ensuring functions receive non-empty input and for
4
+ * accumulating errors in Validation.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * const errors: NonEmptyList<string> = ["First error", "Second error"];
9
+ *
10
+ * // TypeScript ensures at least one element:
11
+ * const invalid: NonEmptyList<string> = []; // Error!
12
+ * ```
13
+ */
14
+ type NonEmptyList<A> = readonly [A, ...A[]];
15
+ /**
16
+ * Type guard that checks if an array is non-empty.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * const items: string[] = getItems();
21
+ *
22
+ * if (isNonEmptyList(items)) {
23
+ * // TypeScript knows items has at least one element
24
+ * const first = items[0]; // string, not string | undefined
25
+ * }
26
+ * ```
27
+ */
28
+ declare const isNonEmptyList: <A>(list: readonly A[]) => list is NonEmptyList<A>;
2
29
 
3
30
  declare const _brand: unique symbol;
4
31
  /**
@@ -51,4 +78,79 @@ declare namespace Brand {
51
78
  const unwrap: <K extends string, T>(branded: Brand<K, T>) => T;
52
79
  }
53
80
 
54
- export { Brand };
81
+ /**
82
+ * A branded nominal type representing a duration of time in milliseconds.
83
+ * Use Duration to ensure safe time-based operators and clear unit conversions.
84
+ *
85
+ * @example
86
+ * ```ts
87
+ * const halfSecond = Duration.milliseconds(500);
88
+ * const twoSeconds = Duration.seconds(2);
89
+ * const total = pipe(halfSecond, Duration.add(twoSeconds));
90
+ *
91
+ * Duration.toSeconds(total); // 2.5
92
+ * ```
93
+ */
94
+ type Duration = Brand<"Duration", number>;
95
+ declare namespace Duration {
96
+ /**
97
+ * Creates a Duration from milliseconds.
98
+ */
99
+ const milliseconds: (ms: number) => Duration;
100
+ /**
101
+ * Creates a Duration from seconds.
102
+ */
103
+ const seconds: (s: number) => Duration;
104
+ /**
105
+ * Creates a Duration from minutes.
106
+ */
107
+ const minutes: (m: number) => Duration;
108
+ /**
109
+ * Creates a Duration from hours.
110
+ */
111
+ const hours: (h: number) => Duration;
112
+ /**
113
+ * Creates a Duration from days.
114
+ */
115
+ const days: (d: number) => Duration;
116
+ /**
117
+ * Converts a Duration back to raw milliseconds.
118
+ */
119
+ const toMilliseconds: (d: Duration) => number;
120
+ /**
121
+ * Converts a Duration to seconds.
122
+ */
123
+ const toSeconds: (d: Duration) => number;
124
+ /**
125
+ * Converts a Duration to minutes.
126
+ */
127
+ const toMinutes: (d: Duration) => number;
128
+ /**
129
+ * Converts a Duration to hours.
130
+ */
131
+ const toHours: (d: Duration) => number;
132
+ /**
133
+ * Converts a Duration to days.
134
+ */
135
+ const toDays: (d: Duration) => number;
136
+ /**
137
+ * Adds two Durations together.
138
+ *
139
+ * @example
140
+ * ```ts
141
+ * pipe(Duration.seconds(1), Duration.add(Duration.milliseconds(500))); // 1500ms
142
+ * ```
143
+ */
144
+ const add: (other: Duration) => (self: Duration) => Duration;
145
+ /**
146
+ * Subtracts the other Duration from this one.
147
+ *
148
+ * @example
149
+ * ```ts
150
+ * pipe(Duration.seconds(1), Duration.subtract(Duration.milliseconds(500))); // 500ms
151
+ * ```
152
+ */
153
+ const subtract: (other: Duration) => (self: Duration) => Duration;
154
+ }
155
+
156
+ export { Brand, Duration, type NonEmptyList, isNonEmptyList };
package/dist/types.d.ts CHANGED
@@ -1,4 +1,31 @@
1
- export { N as NonEmptyList, i as isNonEmptyList } from './NonEmptyList-BlGFjor5.js';
1
+ /**
2
+ * A list that is guaranteed to have at least one element.
3
+ * Useful for ensuring functions receive non-empty input and for
4
+ * accumulating errors in Validation.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * const errors: NonEmptyList<string> = ["First error", "Second error"];
9
+ *
10
+ * // TypeScript ensures at least one element:
11
+ * const invalid: NonEmptyList<string> = []; // Error!
12
+ * ```
13
+ */
14
+ type NonEmptyList<A> = readonly [A, ...A[]];
15
+ /**
16
+ * Type guard that checks if an array is non-empty.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * const items: string[] = getItems();
21
+ *
22
+ * if (isNonEmptyList(items)) {
23
+ * // TypeScript knows items has at least one element
24
+ * const first = items[0]; // string, not string | undefined
25
+ * }
26
+ * ```
27
+ */
28
+ declare const isNonEmptyList: <A>(list: readonly A[]) => list is NonEmptyList<A>;
2
29
 
3
30
  declare const _brand: unique symbol;
4
31
  /**
@@ -51,4 +78,79 @@ declare namespace Brand {
51
78
  const unwrap: <K extends string, T>(branded: Brand<K, T>) => T;
52
79
  }
53
80
 
54
- export { Brand };
81
+ /**
82
+ * A branded nominal type representing a duration of time in milliseconds.
83
+ * Use Duration to ensure safe time-based operators and clear unit conversions.
84
+ *
85
+ * @example
86
+ * ```ts
87
+ * const halfSecond = Duration.milliseconds(500);
88
+ * const twoSeconds = Duration.seconds(2);
89
+ * const total = pipe(halfSecond, Duration.add(twoSeconds));
90
+ *
91
+ * Duration.toSeconds(total); // 2.5
92
+ * ```
93
+ */
94
+ type Duration = Brand<"Duration", number>;
95
+ declare namespace Duration {
96
+ /**
97
+ * Creates a Duration from milliseconds.
98
+ */
99
+ const milliseconds: (ms: number) => Duration;
100
+ /**
101
+ * Creates a Duration from seconds.
102
+ */
103
+ const seconds: (s: number) => Duration;
104
+ /**
105
+ * Creates a Duration from minutes.
106
+ */
107
+ const minutes: (m: number) => Duration;
108
+ /**
109
+ * Creates a Duration from hours.
110
+ */
111
+ const hours: (h: number) => Duration;
112
+ /**
113
+ * Creates a Duration from days.
114
+ */
115
+ const days: (d: number) => Duration;
116
+ /**
117
+ * Converts a Duration back to raw milliseconds.
118
+ */
119
+ const toMilliseconds: (d: Duration) => number;
120
+ /**
121
+ * Converts a Duration to seconds.
122
+ */
123
+ const toSeconds: (d: Duration) => number;
124
+ /**
125
+ * Converts a Duration to minutes.
126
+ */
127
+ const toMinutes: (d: Duration) => number;
128
+ /**
129
+ * Converts a Duration to hours.
130
+ */
131
+ const toHours: (d: Duration) => number;
132
+ /**
133
+ * Converts a Duration to days.
134
+ */
135
+ const toDays: (d: Duration) => number;
136
+ /**
137
+ * Adds two Durations together.
138
+ *
139
+ * @example
140
+ * ```ts
141
+ * pipe(Duration.seconds(1), Duration.add(Duration.milliseconds(500))); // 1500ms
142
+ * ```
143
+ */
144
+ const add: (other: Duration) => (self: Duration) => Duration;
145
+ /**
146
+ * Subtracts the other Duration from this one.
147
+ *
148
+ * @example
149
+ * ```ts
150
+ * pipe(Duration.seconds(1), Duration.subtract(Duration.milliseconds(500))); // 500ms
151
+ * ```
152
+ */
153
+ const subtract: (other: Duration) => (self: Duration) => Duration;
154
+ }
155
+
156
+ export { Brand, Duration, type NonEmptyList, isNonEmptyList };
package/dist/types.js CHANGED
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var Types_exports = {};
22
22
  __export(Types_exports, {
23
23
  Brand: () => Brand,
24
+ Duration: () => Duration,
24
25
  isNonEmptyList: () => isNonEmptyList
25
26
  });
26
27
  module.exports = __toCommonJS(Types_exports);
@@ -32,10 +33,29 @@ var Brand;
32
33
  Brand2.unwrap = (branded) => branded;
33
34
  })(Brand || (Brand = {}));
34
35
 
36
+ // src/Types/Duration.ts
37
+ var Duration;
38
+ ((Duration2) => {
39
+ const wrap = Brand.wrap();
40
+ Duration2.milliseconds = (ms) => wrap(ms);
41
+ Duration2.seconds = (s) => wrap(s * 1e3);
42
+ Duration2.minutes = (m) => wrap(m * 60 * 1e3);
43
+ Duration2.hours = (h) => wrap(h * 60 * 60 * 1e3);
44
+ Duration2.days = (d) => wrap(d * 24 * 60 * 60 * 1e3);
45
+ Duration2.toMilliseconds = (d) => Brand.unwrap(d);
46
+ Duration2.toSeconds = (d) => Brand.unwrap(d) / 1e3;
47
+ Duration2.toMinutes = (d) => Brand.unwrap(d) / (60 * 1e3);
48
+ Duration2.toHours = (d) => Brand.unwrap(d) / (60 * 60 * 1e3);
49
+ Duration2.toDays = (d) => Brand.unwrap(d) / (24 * 60 * 60 * 1e3);
50
+ Duration2.add = (other) => (self) => wrap(Brand.unwrap(self) + Brand.unwrap(other));
51
+ Duration2.subtract = (other) => (self) => wrap(Brand.unwrap(self) - Brand.unwrap(other));
52
+ })(Duration || (Duration = {}));
53
+
35
54
  // src/Types/NonEmptyList.ts
36
55
  var isNonEmptyList = (list) => list.length > 0;
37
56
  // Annotate the CommonJS export names for ESM import in node:
38
57
  0 && (module.exports = {
39
58
  Brand,
59
+ Duration,
40
60
  isNonEmptyList
41
61
  });
package/dist/types.mjs CHANGED
@@ -1,10 +1,13 @@
1
- import {
2
- Brand
3
- } from "./chunk-BYWKZLHM.mjs";
1
+ import "./chunk-IPP4XFYH.mjs";
4
2
  import {
5
3
  isNonEmptyList
6
4
  } from "./chunk-DBIC62UV.mjs";
5
+ import {
6
+ Brand,
7
+ Duration
8
+ } from "./chunk-VWVPHDZO.mjs";
7
9
  export {
8
10
  Brand,
11
+ Duration,
9
12
  isNonEmptyList
10
13
  };
package/dist/utils.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { M as Maybe, E as Equality, b as Ordering, R as Result, T as Task } from './Task-CJZfcOkO.mjs';
2
- import { N as NonEmptyList } from './NonEmptyList-BlGFjor5.mjs';
1
+ import { M as Maybe, R as Result, E as Equality, b as Ordering, T as Task } from './Task-DXsuurnc.mjs';
2
+ import { NonEmptyList } from './types.mjs';
3
3
 
4
4
  /**
5
5
  * Functional array utilities that compose well with pipe.
@@ -140,6 +140,38 @@ declare namespace Arr {
140
140
  * ```
141
141
  */
142
142
  const partition: <A>(predicate: (a: A) => boolean) => (data: readonly A[]) => readonly [readonly A[], readonly A[]];
143
+ /**
144
+ * Narrows a list of Maybe values down to a list of their underlying values,
145
+ * discarding all None instances.
146
+ *
147
+ * @example
148
+ * ```ts
149
+ * Arr.compact([Maybe.some(1), Maybe.none(), Maybe.some(3)]); // [1, 3]
150
+ * ```
151
+ */
152
+ const compact: <A>(data: readonly Maybe<A>[]) => readonly A[];
153
+ /**
154
+ * Separates an array of Result values into two separate lists of errors and successes.
155
+ * Returns a tuple containing `[errors, successes]`.
156
+ *
157
+ * @example
158
+ * ```ts
159
+ * Arr.separate([Result.ok(1), Result.err("bad"), Result.ok(3)]); // [["bad"], [1, 3]]
160
+ * ```
161
+ */
162
+ const separate: <E, A>(data: readonly Result<E, A>[]) => readonly [readonly E[], readonly A[]];
163
+ /**
164
+ * Maps each element to a Result, and separates the results into a tuple of failures and successes.
165
+ *
166
+ * @example
167
+ * ```ts
168
+ * pipe(
169
+ * [1, 2, 3, 4],
170
+ * Arr.partitionMap(n => n % 2 === 0 ? Result.ok(n) : Result.err(`odd: ${n}`))
171
+ * ); // [["odd: 1", "odd: 3"], [2, 4]]
172
+ * ```
173
+ */
174
+ const partitionMap: <A, E, B>(f: (a: A) => Result<E, B>) => (data: readonly A[]) => readonly [readonly E[], readonly B[]];
143
175
  /**
144
176
  * Groups elements by a key function.
145
177
  *
@@ -277,7 +309,7 @@ declare namespace Arr {
277
309
  */
278
310
  const reduce: <A, B>(initial: B, f: (acc: B, a: A) => B) => (data: readonly A[]) => B;
279
311
  /**
280
- * Maps each element to an Maybe and collects the results.
312
+ * Maps each element to a Maybe and collects the results.
281
313
  * Returns None if any mapping returns None.
282
314
  *
283
315
  * @example
@@ -300,7 +332,7 @@ declare namespace Arr {
300
332
  * ```ts
301
333
  * pipe(
302
334
  * [1, 2, 3],
303
- * Arr.traverseResult(n => n > 0 ? Result.ok(n) : Result.error("negative"))
335
+ * Arr.traverseResult(n => n > 0 ? Result.ok(n) : Result.err("negative"))
304
336
  * ); // Ok([1, 2, 3])
305
337
  * ```
306
338
  */
@@ -318,7 +350,7 @@ declare namespace Arr {
318
350
  */
319
351
  const traverseTask: <A, B>(f: (a: A) => Task<B>) => (data: readonly A[]) => Task<readonly B[]>;
320
352
  /**
321
- * Collects an array of Options into an Maybe of array.
353
+ * Collects an array of Maybe instances into a Maybe of array.
322
354
  * Returns None if any element is None.
323
355
  *
324
356
  * @example
@@ -1041,6 +1073,7 @@ declare namespace Rec {
1041
1073
  * ```
1042
1074
  */
1043
1075
  const map: <A, B>(f: (a: A) => B) => (data: Readonly<Record<string, A>>) => Readonly<Record<string, B>>;
1076
+ const filterMap: <A, B>(f: (a: A) => Maybe<B>) => (data: Readonly<Record<string, A>>) => Readonly<Record<string, B>>;
1044
1077
  /**
1045
1078
  * Transforms each value in a record, also receiving the key.
1046
1079
  *
@@ -1390,6 +1423,16 @@ declare namespace Str {
1390
1423
  */
1391
1424
  float: (s: string) => Maybe<number>;
1392
1425
  };
1426
+ /**
1427
+ * Safely parses a JSON string, returning a `Result<SyntaxError, unknown>`.
1428
+ *
1429
+ * @example
1430
+ * ```ts
1431
+ * Str.parseJson('{"a": 1}'); // Ok({ a: 1 })
1432
+ * Str.parseJson('invalid'); // Err(SyntaxError)
1433
+ * ```
1434
+ */
1435
+ const parseJson: (s: string) => Result<SyntaxError, unknown>;
1393
1436
  }
1394
1437
 
1395
1438
  /**
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { M as Maybe, E as Equality, b as Ordering, R as Result, T as Task } from './Task-CjYKLeTY.js';
2
- import { N as NonEmptyList } from './NonEmptyList-BlGFjor5.js';
1
+ import { M as Maybe, R as Result, E as Equality, b as Ordering, T as Task } from './Task-zAY4kSVB.js';
2
+ import { NonEmptyList } from './types.js';
3
3
 
4
4
  /**
5
5
  * Functional array utilities that compose well with pipe.
@@ -140,6 +140,38 @@ declare namespace Arr {
140
140
  * ```
141
141
  */
142
142
  const partition: <A>(predicate: (a: A) => boolean) => (data: readonly A[]) => readonly [readonly A[], readonly A[]];
143
+ /**
144
+ * Narrows a list of Maybe values down to a list of their underlying values,
145
+ * discarding all None instances.
146
+ *
147
+ * @example
148
+ * ```ts
149
+ * Arr.compact([Maybe.some(1), Maybe.none(), Maybe.some(3)]); // [1, 3]
150
+ * ```
151
+ */
152
+ const compact: <A>(data: readonly Maybe<A>[]) => readonly A[];
153
+ /**
154
+ * Separates an array of Result values into two separate lists of errors and successes.
155
+ * Returns a tuple containing `[errors, successes]`.
156
+ *
157
+ * @example
158
+ * ```ts
159
+ * Arr.separate([Result.ok(1), Result.err("bad"), Result.ok(3)]); // [["bad"], [1, 3]]
160
+ * ```
161
+ */
162
+ const separate: <E, A>(data: readonly Result<E, A>[]) => readonly [readonly E[], readonly A[]];
163
+ /**
164
+ * Maps each element to a Result, and separates the results into a tuple of failures and successes.
165
+ *
166
+ * @example
167
+ * ```ts
168
+ * pipe(
169
+ * [1, 2, 3, 4],
170
+ * Arr.partitionMap(n => n % 2 === 0 ? Result.ok(n) : Result.err(`odd: ${n}`))
171
+ * ); // [["odd: 1", "odd: 3"], [2, 4]]
172
+ * ```
173
+ */
174
+ const partitionMap: <A, E, B>(f: (a: A) => Result<E, B>) => (data: readonly A[]) => readonly [readonly E[], readonly B[]];
143
175
  /**
144
176
  * Groups elements by a key function.
145
177
  *
@@ -277,7 +309,7 @@ declare namespace Arr {
277
309
  */
278
310
  const reduce: <A, B>(initial: B, f: (acc: B, a: A) => B) => (data: readonly A[]) => B;
279
311
  /**
280
- * Maps each element to an Maybe and collects the results.
312
+ * Maps each element to a Maybe and collects the results.
281
313
  * Returns None if any mapping returns None.
282
314
  *
283
315
  * @example
@@ -300,7 +332,7 @@ declare namespace Arr {
300
332
  * ```ts
301
333
  * pipe(
302
334
  * [1, 2, 3],
303
- * Arr.traverseResult(n => n > 0 ? Result.ok(n) : Result.error("negative"))
335
+ * Arr.traverseResult(n => n > 0 ? Result.ok(n) : Result.err("negative"))
304
336
  * ); // Ok([1, 2, 3])
305
337
  * ```
306
338
  */
@@ -318,7 +350,7 @@ declare namespace Arr {
318
350
  */
319
351
  const traverseTask: <A, B>(f: (a: A) => Task<B>) => (data: readonly A[]) => Task<readonly B[]>;
320
352
  /**
321
- * Collects an array of Options into an Maybe of array.
353
+ * Collects an array of Maybe instances into a Maybe of array.
322
354
  * Returns None if any element is None.
323
355
  *
324
356
  * @example
@@ -1041,6 +1073,7 @@ declare namespace Rec {
1041
1073
  * ```
1042
1074
  */
1043
1075
  const map: <A, B>(f: (a: A) => B) => (data: Readonly<Record<string, A>>) => Readonly<Record<string, B>>;
1076
+ const filterMap: <A, B>(f: (a: A) => Maybe<B>) => (data: Readonly<Record<string, A>>) => Readonly<Record<string, B>>;
1044
1077
  /**
1045
1078
  * Transforms each value in a record, also receiving the key.
1046
1079
  *
@@ -1390,6 +1423,16 @@ declare namespace Str {
1390
1423
  */
1391
1424
  float: (s: string) => Maybe<number>;
1392
1425
  };
1426
+ /**
1427
+ * Safely parses a JSON string, returning a `Result<SyntaxError, unknown>`.
1428
+ *
1429
+ * @example
1430
+ * ```ts
1431
+ * Str.parseJson('{"a": 1}'); // Ok({ a: 1 })
1432
+ * Str.parseJson('invalid'); // Err(SyntaxError)
1433
+ * ```
1434
+ */
1435
+ const parseJson: (s: string) => Result<SyntaxError, unknown>;
1393
1436
  }
1394
1437
 
1395
1438
  /**