@nlozgachev/pipelined 0.31.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/index.mjs CHANGED
@@ -28,10 +28,14 @@ import {
28
28
  uncurry4
29
29
  } from "./chunk-NRF2FVPZ.mjs";
30
30
  import {
31
+ Combinable,
32
+ Equality,
33
+ Lazy,
31
34
  Lens,
32
35
  Logged,
33
36
  Op,
34
37
  Optional,
38
+ Ordering,
35
39
  Predicate,
36
40
  Reader,
37
41
  Refinement,
@@ -44,7 +48,7 @@ import {
44
48
  These,
45
49
  Tuple,
46
50
  Validation
47
- } from "./chunk-VIC54JR4.mjs";
51
+ } from "./chunk-FZX4MTRI.mjs";
48
52
  import {
49
53
  Arr,
50
54
  Dict,
@@ -52,30 +56,37 @@ import {
52
56
  Rec,
53
57
  Str,
54
58
  Uniq
55
- } from "./chunk-FWYOEWJ2.mjs";
59
+ } from "./chunk-W53ZYTLX.mjs";
56
60
  import {
57
61
  Deferred,
58
62
  Maybe,
59
63
  Result,
60
64
  Task
61
- } from "./chunk-SDGDJ7CU.mjs";
62
- import {
63
- Brand
64
- } from "./chunk-BYWKZLHM.mjs";
65
+ } from "./chunk-GSTKY7MF.mjs";
66
+ import "./chunk-IPP4XFYH.mjs";
65
67
  import {
66
68
  isNonEmptyList
67
69
  } from "./chunk-DBIC62UV.mjs";
70
+ import {
71
+ Brand,
72
+ Duration
73
+ } from "./chunk-VWVPHDZO.mjs";
68
74
  export {
69
75
  Arr,
70
76
  Brand,
77
+ Combinable,
71
78
  Deferred,
72
79
  Dict,
80
+ Duration,
81
+ Equality,
82
+ Lazy,
73
83
  Lens,
74
84
  Logged,
75
85
  Maybe,
76
86
  Num,
77
87
  Op,
78
88
  Optional,
89
+ Ordering,
79
90
  Predicate,
80
91
  Reader,
81
92
  Rec,
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, R as Result, T as Task } from './Task-BDcKwFAj.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-5na0QzS4.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.error("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.error(`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
  *
@@ -173,8 +205,26 @@ declare namespace Arr {
173
205
  * ```
174
206
  */
175
207
  const uniqBy: <A, B>(f: (a: A) => B) => (data: readonly A[]) => readonly A[];
208
+ /**
209
+ * Removes duplicate elements using a custom equality check.
210
+ * Preserves the order of first occurrences. Complements `uniq` (reference equality)
211
+ * and `uniqBy` (key extraction).
212
+ *
213
+ * @example
214
+ * ```ts
215
+ * type Point = { x: number; y: number };
216
+ * const eqPoint: Equality<Point> = (a, b) => a.x === b.x && a.y === b.y;
217
+ *
218
+ * pipe(
219
+ * [{ x: 1, y: 1 }, { x: 2, y: 2 }, { x: 1, y: 1 }],
220
+ * Arr.uniqWith(eqPoint),
221
+ * ); // [{ x: 1, y: 1 }, { x: 2, y: 2 }]
222
+ * ```
223
+ */
224
+ const uniqWith: <A>(eq: Equality<A>) => (data: readonly A[]) => readonly A[];
176
225
  /**
177
226
  * Sorts an array using a comparison function. Returns a new array.
227
+ * To sort with a typed `Ordering<A>`, prefer `Arr.sortWith`.
178
228
  *
179
229
  * @example
180
230
  * ```ts
@@ -182,6 +232,19 @@ declare namespace Arr {
182
232
  * ```
183
233
  */
184
234
  const sortBy: <A>(compare: (a: A, b: A) => number) => (data: readonly A[]) => readonly A[];
235
+ /**
236
+ * Sorts an array using an `Ordering<A>`. Returns a new array without mutating the original.
237
+ * Use this over `sortBy` when you have a typed `Ordering<A>` from the `Ordering` module.
238
+ *
239
+ * @example
240
+ * ```ts
241
+ * pipe([3, 1, 2], Arr.sortWith(Ordering.number)); // [1, 2, 3]
242
+ *
243
+ * const byPrice = pipe(Ordering.number, Ordering.by((p: Product) => p.price));
244
+ * pipe(products, Arr.sortWith(byPrice));
245
+ * ```
246
+ */
247
+ const sortWith: <A>(ord: Ordering<A>) => (data: readonly A[]) => readonly A[];
185
248
  /**
186
249
  * Pairs up elements from two arrays. Stops at the shorter array.
187
250
  *
@@ -945,6 +1008,46 @@ declare namespace Num {
945
1008
  * ```
946
1009
  */
947
1010
  const remainder: (divisor: number) => (n: number) => Maybe<number>;
1011
+ /**
1012
+ * Computes the sum of a list of numbers. Returns `0` if the list is empty.
1013
+ *
1014
+ * @example
1015
+ * ```ts
1016
+ * Num.sum([1, 2, 3]); // 6
1017
+ * Num.sum([]); // 0
1018
+ * ```
1019
+ */
1020
+ const sum: (ns: readonly number[]) => number;
1021
+ /**
1022
+ * Computes the mean of a list of numbers. Returns `None` if the list is empty.
1023
+ *
1024
+ * @example
1025
+ * ```ts
1026
+ * Num.mean([1, 2, 3]); // Some(2)
1027
+ * Num.mean([]); // None
1028
+ * ```
1029
+ */
1030
+ const mean: (ns: readonly number[]) => Maybe<number>;
1031
+ /**
1032
+ * Computes the minimum of a list of numbers. Returns `None` if the list is empty.
1033
+ *
1034
+ * @example
1035
+ * ```ts
1036
+ * Num.min([5, 1, 3]); // Some(1)
1037
+ * Num.min([]); // None
1038
+ * ```
1039
+ */
1040
+ const min: (ns: readonly number[]) => Maybe<number>;
1041
+ /**
1042
+ * Computes the maximum of a list of numbers. Returns `None` if the list is empty.
1043
+ *
1044
+ * @example
1045
+ * ```ts
1046
+ * Num.max([1, 5, 3]); // Some(5)
1047
+ * Num.max([]); // None
1048
+ * ```
1049
+ */
1050
+ const max: (ns: readonly number[]) => Maybe<number>;
948
1051
  }
949
1052
 
950
1053
  /**
@@ -1204,6 +1307,15 @@ declare namespace Str {
1204
1307
  * ```
1205
1308
  */
1206
1309
  const toLowerCase: (s: string) => string;
1310
+ /**
1311
+ * Converts the first character of a string to uppercase.
1312
+ *
1313
+ * @example
1314
+ * ```ts
1315
+ * pipe("hello", Str.capitalize); // "Hello"
1316
+ * ```
1317
+ */
1318
+ const capitalize: (s: string) => string;
1207
1319
  /**
1208
1320
  * Splits a string into lines, normalising `\r\n` and `\r` line endings.
1209
1321
  *
@@ -1310,6 +1422,16 @@ declare namespace Str {
1310
1422
  */
1311
1423
  float: (s: string) => Maybe<number>;
1312
1424
  };
1425
+ /**
1426
+ * Safely parses a JSON string, returning a `Result<SyntaxError, unknown>`.
1427
+ *
1428
+ * @example
1429
+ * ```ts
1430
+ * Str.parseJson('{"a": 1}'); // Ok({ a: 1 })
1431
+ * Str.parseJson('invalid'); // Error(SyntaxError)
1432
+ * ```
1433
+ */
1434
+ const parseJson: (s: string) => Result<SyntaxError, unknown>;
1313
1435
  }
1314
1436
 
1315
1437
  /**
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { M as Maybe, R as Result, T as Task } from './Task-CnF22Q2o.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-DeiWgoeJ.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.error("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.error(`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
  *
@@ -173,8 +205,26 @@ declare namespace Arr {
173
205
  * ```
174
206
  */
175
207
  const uniqBy: <A, B>(f: (a: A) => B) => (data: readonly A[]) => readonly A[];
208
+ /**
209
+ * Removes duplicate elements using a custom equality check.
210
+ * Preserves the order of first occurrences. Complements `uniq` (reference equality)
211
+ * and `uniqBy` (key extraction).
212
+ *
213
+ * @example
214
+ * ```ts
215
+ * type Point = { x: number; y: number };
216
+ * const eqPoint: Equality<Point> = (a, b) => a.x === b.x && a.y === b.y;
217
+ *
218
+ * pipe(
219
+ * [{ x: 1, y: 1 }, { x: 2, y: 2 }, { x: 1, y: 1 }],
220
+ * Arr.uniqWith(eqPoint),
221
+ * ); // [{ x: 1, y: 1 }, { x: 2, y: 2 }]
222
+ * ```
223
+ */
224
+ const uniqWith: <A>(eq: Equality<A>) => (data: readonly A[]) => readonly A[];
176
225
  /**
177
226
  * Sorts an array using a comparison function. Returns a new array.
227
+ * To sort with a typed `Ordering<A>`, prefer `Arr.sortWith`.
178
228
  *
179
229
  * @example
180
230
  * ```ts
@@ -182,6 +232,19 @@ declare namespace Arr {
182
232
  * ```
183
233
  */
184
234
  const sortBy: <A>(compare: (a: A, b: A) => number) => (data: readonly A[]) => readonly A[];
235
+ /**
236
+ * Sorts an array using an `Ordering<A>`. Returns a new array without mutating the original.
237
+ * Use this over `sortBy` when you have a typed `Ordering<A>` from the `Ordering` module.
238
+ *
239
+ * @example
240
+ * ```ts
241
+ * pipe([3, 1, 2], Arr.sortWith(Ordering.number)); // [1, 2, 3]
242
+ *
243
+ * const byPrice = pipe(Ordering.number, Ordering.by((p: Product) => p.price));
244
+ * pipe(products, Arr.sortWith(byPrice));
245
+ * ```
246
+ */
247
+ const sortWith: <A>(ord: Ordering<A>) => (data: readonly A[]) => readonly A[];
185
248
  /**
186
249
  * Pairs up elements from two arrays. Stops at the shorter array.
187
250
  *
@@ -945,6 +1008,46 @@ declare namespace Num {
945
1008
  * ```
946
1009
  */
947
1010
  const remainder: (divisor: number) => (n: number) => Maybe<number>;
1011
+ /**
1012
+ * Computes the sum of a list of numbers. Returns `0` if the list is empty.
1013
+ *
1014
+ * @example
1015
+ * ```ts
1016
+ * Num.sum([1, 2, 3]); // 6
1017
+ * Num.sum([]); // 0
1018
+ * ```
1019
+ */
1020
+ const sum: (ns: readonly number[]) => number;
1021
+ /**
1022
+ * Computes the mean of a list of numbers. Returns `None` if the list is empty.
1023
+ *
1024
+ * @example
1025
+ * ```ts
1026
+ * Num.mean([1, 2, 3]); // Some(2)
1027
+ * Num.mean([]); // None
1028
+ * ```
1029
+ */
1030
+ const mean: (ns: readonly number[]) => Maybe<number>;
1031
+ /**
1032
+ * Computes the minimum of a list of numbers. Returns `None` if the list is empty.
1033
+ *
1034
+ * @example
1035
+ * ```ts
1036
+ * Num.min([5, 1, 3]); // Some(1)
1037
+ * Num.min([]); // None
1038
+ * ```
1039
+ */
1040
+ const min: (ns: readonly number[]) => Maybe<number>;
1041
+ /**
1042
+ * Computes the maximum of a list of numbers. Returns `None` if the list is empty.
1043
+ *
1044
+ * @example
1045
+ * ```ts
1046
+ * Num.max([1, 5, 3]); // Some(5)
1047
+ * Num.max([]); // None
1048
+ * ```
1049
+ */
1050
+ const max: (ns: readonly number[]) => Maybe<number>;
948
1051
  }
949
1052
 
950
1053
  /**
@@ -1204,6 +1307,15 @@ declare namespace Str {
1204
1307
  * ```
1205
1308
  */
1206
1309
  const toLowerCase: (s: string) => string;
1310
+ /**
1311
+ * Converts the first character of a string to uppercase.
1312
+ *
1313
+ * @example
1314
+ * ```ts
1315
+ * pipe("hello", Str.capitalize); // "Hello"
1316
+ * ```
1317
+ */
1318
+ const capitalize: (s: string) => string;
1207
1319
  /**
1208
1320
  * Splits a string into lines, normalising `\r\n` and `\r` line endings.
1209
1321
  *
@@ -1310,6 +1422,16 @@ declare namespace Str {
1310
1422
  */
1311
1423
  float: (s: string) => Maybe<number>;
1312
1424
  };
1425
+ /**
1426
+ * Safely parses a JSON string, returning a `Result<SyntaxError, unknown>`.
1427
+ *
1428
+ * @example
1429
+ * ```ts
1430
+ * Str.parseJson('{"a": 1}'); // Ok({ a: 1 })
1431
+ * Str.parseJson('invalid'); // Error(SyntaxError)
1432
+ * ```
1433
+ */
1434
+ const parseJson: (s: string) => Result<SyntaxError, unknown>;
1313
1435
  }
1314
1436
 
1315
1437
  /**