@nlozgachev/pipelined 0.44.0 → 0.46.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/README.md +12 -6
- package/dist/{InternalTypes-BL23H8Qr.d.mts → InternalTypes-CLE7qlOc.d.mts} +33 -28
- package/dist/{InternalTypes-7o9-yrHq.d.ts → InternalTypes-Mssktd7z.d.ts} +33 -28
- package/dist/{Validation-DM2eh6wj.d.ts → Validation-BMsvixWH.d.ts} +475 -443
- package/dist/{Validation-Dz70wtcG.d.mts → Validation-v38R0qH-.d.mts} +475 -443
- package/dist/{chunk-X6XQX3OZ.mjs → chunk-KOYYDQH4.mjs} +2 -2
- package/dist/{chunk-ND476266.mjs → chunk-VSU36S2K.mjs} +432 -309
- package/dist/{chunk-LKTOK5IT.mjs → chunk-W2L244AS.mjs} +188 -73
- package/dist/{chunk-74JKKJ4R.mjs → chunk-XTVF5R6R.mjs} +8 -5
- package/dist/composition.d.mts +10 -10
- package/dist/composition.d.ts +10 -10
- package/dist/composition.js +9 -6
- package/dist/composition.mjs +2 -2
- package/dist/core.d.mts +453 -402
- package/dist/core.d.ts +453 -402
- package/dist/core.js +439 -313
- package/dist/core.mjs +2 -2
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +627 -386
- package/dist/index.mjs +4 -4
- package/dist/types.d.mts +23 -21
- package/dist/types.d.ts +23 -21
- package/dist/types.js +8 -5
- package/dist/types.mjs +1 -1
- package/dist/utils.d.mts +522 -370
- package/dist/utils.d.ts +522 -370
- package/dist/utils.js +434 -243
- package/dist/utils.mjs +3 -3
- package/package.json +15 -5
package/dist/utils.d.ts
CHANGED
|
@@ -1,56 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { M as Maybe, R as Result, E as Equality, b as Ordering, T as Task } from './Validation-
|
|
3
|
-
import './types.js';
|
|
1
|
+
import { a as NonEmptyArr, N as NonEmpty } from './InternalTypes-Mssktd7z.js';
|
|
2
|
+
import { M as Maybe, R as Result, E as Equality, b as Ordering, T as Task } from './Validation-BMsvixWH.js';
|
|
3
|
+
import { Brand } from './types.js';
|
|
4
4
|
|
|
5
|
-
declare namespace ArrMaybe {
|
|
6
|
-
/**
|
|
7
|
-
* Maps each element to a Maybe and collects the results.
|
|
8
|
-
* Returns None if any mapping returns None.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```ts
|
|
12
|
-
* const parseNum = (s: string): Maybe<number> => {
|
|
13
|
-
* const n = Number(s);
|
|
14
|
-
* return isNaN(n) ? Maybe.none() : Maybe.some(n);
|
|
15
|
-
* };
|
|
16
|
-
*
|
|
17
|
-
* pipe(["1", "2", "3"], Arr.Maybe.traverse(parseNum)); // Some([1, 2, 3])
|
|
18
|
-
* pipe(["1", "x", "3"], Arr.Maybe.traverse(parseNum)); // None
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
const traverse: <A, B>(f: (a: A) => Maybe<B>) => (data: readonly A[]) => Maybe<readonly B[]>;
|
|
22
|
-
/**
|
|
23
|
-
* Collects an array of Maybe instances into a Maybe of array.
|
|
24
|
-
* Returns None if any element is None.
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```ts
|
|
28
|
-
* Arr.Maybe.sequence([Maybe.some(1), Maybe.some(2)]); // Some([1, 2])
|
|
29
|
-
* Arr.Maybe.sequence([Maybe.some(1), Maybe.none()]); // None
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
const sequence: <A>(data: readonly Maybe<A>[]) => Maybe<readonly A[]>;
|
|
33
|
-
}
|
|
34
|
-
declare namespace ArrResult {
|
|
35
|
-
/**
|
|
36
|
-
* Maps each element to a Result and collects the results.
|
|
37
|
-
* Returns the first Err if any mapping fails.
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```ts
|
|
41
|
-
* pipe(
|
|
42
|
-
* [1, 2, 3],
|
|
43
|
-
* Arr.Result.traverse(n => n > 0 ? Result.ok(n) : Result.err("negative"))
|
|
44
|
-
* ); // Ok([1, 2, 3])
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
const traverse: <E, A, B>(f: (a: A) => Result<E, B>) => (data: readonly A[]) => Result<E, readonly B[]>;
|
|
48
|
-
/**
|
|
49
|
-
* Collects an array of Results into a Result of array.
|
|
50
|
-
* Returns the first Err if any element is Err.
|
|
51
|
-
*/
|
|
52
|
-
const sequence: <E, A>(data: readonly Result<E, A>[]) => Result<E, readonly A[]>;
|
|
53
|
-
}
|
|
54
5
|
declare namespace ArrTaskResult {
|
|
55
6
|
/**
|
|
56
7
|
* Maps each element to a Task.Result and runs them sequentially.
|
|
@@ -79,25 +30,6 @@ declare namespace ArrTaskResult {
|
|
|
79
30
|
*/
|
|
80
31
|
const sequence: <E, A>(data: readonly Task<Result<E, A>>[]) => Task<Result<E, readonly A[]>>;
|
|
81
32
|
}
|
|
82
|
-
declare namespace ArrTask {
|
|
83
|
-
/**
|
|
84
|
-
* Maps each element to a Task and runs all in parallel.
|
|
85
|
-
*
|
|
86
|
-
* @example
|
|
87
|
-
* ```ts
|
|
88
|
-
* pipe(
|
|
89
|
-
* [1, 2, 3],
|
|
90
|
-
* Arr.Task.traverse(n => Task.resolve(n * 2))
|
|
91
|
-
* )(); // Promise<[2, 4, 6]>
|
|
92
|
-
* ```
|
|
93
|
-
*/
|
|
94
|
-
const traverse: <A, B>(f: (a: A) => Task<B>) => (data: readonly A[]) => Task<readonly B[]>;
|
|
95
|
-
/**
|
|
96
|
-
* Collects an array of Tasks into a Task of array. Runs in parallel.
|
|
97
|
-
*/
|
|
98
|
-
const sequence: <A>(data: readonly Task<A>[]) => Task<readonly A[]>;
|
|
99
|
-
const Result: typeof ArrTaskResult;
|
|
100
|
-
}
|
|
101
33
|
declare namespace ArrNonEmpty {
|
|
102
34
|
/**
|
|
103
35
|
* Creates a single-element list.
|
|
@@ -108,16 +40,18 @@ declare namespace ArrNonEmpty {
|
|
|
108
40
|
* ```
|
|
109
41
|
*/
|
|
110
42
|
const singleton: <A>(value: A) => NonEmptyArr<A>;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
43
|
+
namespace from {
|
|
44
|
+
/**
|
|
45
|
+
* Returns Some if the array is non-empty, None otherwise.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* Arr.NonEmpty.from.Array([1, 2]); // Some([1, 2])
|
|
50
|
+
* Arr.NonEmpty.from.Array([]); // None
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
const Array: <A>(data: readonly A[]) => Maybe<NonEmptyArr<A>>;
|
|
54
|
+
}
|
|
121
55
|
/**
|
|
122
56
|
* Returns the first element of a NonEmptyArr.
|
|
123
57
|
*
|
|
@@ -154,6 +88,51 @@ declare namespace ArrNonEmpty {
|
|
|
154
88
|
* ```
|
|
155
89
|
*/
|
|
156
90
|
const reduce: <A>(f: (acc: A, a: A) => A) => (data: NonEmptyArr<A>) => A;
|
|
91
|
+
/**
|
|
92
|
+
* Transforms each element of a NonEmptyArr.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* pipe(Arr.NonEmpty.singleton(1), Arr.NonEmpty.map(n => n * 2)); // [2]
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
const map: <A, B>(f: (a: A) => B) => (data: NonEmptyArr<A>) => NonEmptyArr<B>;
|
|
100
|
+
/**
|
|
101
|
+
* Transforms each element of a NonEmptyArr, also receiving the index.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* pipe(Arr.NonEmpty.singleton("a"), Arr.NonEmpty.mapWithIndex((i, s) => `${i}:${s}`)); // ["0:a"]
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
const mapWithIndex: <A, B>(f: (i: number, a: A) => B) => (data: NonEmptyArr<A>) => NonEmptyArr<B>;
|
|
109
|
+
/**
|
|
110
|
+
* Inserts a separator between every element of a NonEmptyArr.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* pipe([1, 2] as Arr.NonEmpty<number>, Arr.NonEmpty.intersperse(0)); // [1, 0, 2]
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
const intersperse: <A>(sep: A) => (data: NonEmptyArr<A>) => NonEmptyArr<A>;
|
|
118
|
+
/**
|
|
119
|
+
* Concatenates a NonEmptyArr with a standard array.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* pipe(Arr.NonEmpty.singleton(1), Arr.NonEmpty.concat([2, 3])); // [1, 2, 3]
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
const concat: <A>(other: readonly A[]) => (data: NonEmptyArr<A>) => NonEmptyArr<A>;
|
|
127
|
+
/**
|
|
128
|
+
* Reverses a NonEmptyArr.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* pipe(Arr.NonEmpty.singleton(1), Arr.NonEmpty.reverse); // [1]
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
const reverse: <A>(data: NonEmptyArr<A>) => NonEmptyArr<A>;
|
|
157
136
|
}
|
|
158
137
|
/**
|
|
159
138
|
* Functional array utilities that compose well with pipe.
|
|
@@ -180,7 +159,7 @@ declare namespace Arr {
|
|
|
180
159
|
* const list: Arr.NonEmpty<number> = [1, 2, 3];
|
|
181
160
|
* ```
|
|
182
161
|
*/
|
|
183
|
-
type NonEmpty<A> = NonEmptyArr<A>;
|
|
162
|
+
export type NonEmpty<A> = NonEmptyArr<A>;
|
|
184
163
|
/**
|
|
185
164
|
* Returns the first element of an array, or None if the array is empty.
|
|
186
165
|
*
|
|
@@ -190,7 +169,7 @@ declare namespace Arr {
|
|
|
190
169
|
* Arr.head([]); // None
|
|
191
170
|
* ```
|
|
192
171
|
*/
|
|
193
|
-
const head: <A>(data: readonly A[]) => Maybe<A>;
|
|
172
|
+
export const head: <A>(data: readonly A[]) => Maybe<A>;
|
|
194
173
|
/**
|
|
195
174
|
* Returns the last element of an array, or None if the array is empty.
|
|
196
175
|
*
|
|
@@ -200,7 +179,7 @@ declare namespace Arr {
|
|
|
200
179
|
* Arr.last([]); // None
|
|
201
180
|
* ```
|
|
202
181
|
*/
|
|
203
|
-
const last: <A>(data: readonly A[]) => Maybe<A>;
|
|
182
|
+
export const last: <A>(data: readonly A[]) => Maybe<A>;
|
|
204
183
|
/**
|
|
205
184
|
* Returns all elements except the first, or None if the array is empty.
|
|
206
185
|
*
|
|
@@ -210,7 +189,7 @@ declare namespace Arr {
|
|
|
210
189
|
* Arr.tail([]); // None
|
|
211
190
|
* ```
|
|
212
191
|
*/
|
|
213
|
-
const tail: <A>(data: readonly A[]) => Maybe<readonly A[]>;
|
|
192
|
+
export const tail: <A>(data: readonly A[]) => Maybe<readonly A[]>;
|
|
214
193
|
/**
|
|
215
194
|
* Returns all elements except the last, or None if the array is empty.
|
|
216
195
|
*
|
|
@@ -220,7 +199,7 @@ declare namespace Arr {
|
|
|
220
199
|
* Arr.init([]); // None
|
|
221
200
|
* ```
|
|
222
201
|
*/
|
|
223
|
-
const init: <A>(data: readonly A[]) => Maybe<readonly A[]>;
|
|
202
|
+
export const init: <A>(data: readonly A[]) => Maybe<readonly A[]>;
|
|
224
203
|
/**
|
|
225
204
|
* Returns the first element matching the predicate, or None.
|
|
226
205
|
*
|
|
@@ -229,7 +208,7 @@ declare namespace Arr {
|
|
|
229
208
|
* pipe([1, 2, 3, 4], Arr.findFirst(n => n > 2)); // Some(3)
|
|
230
209
|
* ```
|
|
231
210
|
*/
|
|
232
|
-
const findFirst: <A>(predicate: (a: A) => boolean) => (data: readonly A[]) => Maybe<A>;
|
|
211
|
+
export const findFirst: <A>(predicate: (a: A) => boolean) => (data: readonly A[]) => Maybe<A>;
|
|
233
212
|
/**
|
|
234
213
|
* Returns the last element matching the predicate, or None.
|
|
235
214
|
*
|
|
@@ -238,7 +217,7 @@ declare namespace Arr {
|
|
|
238
217
|
* pipe([1, 2, 3, 4], Arr.findLast(n => n > 2)); // Some(4)
|
|
239
218
|
* ```
|
|
240
219
|
*/
|
|
241
|
-
const findLast: <A>(predicate: (a: A) => boolean) => (data: readonly A[]) => Maybe<A>;
|
|
220
|
+
export const findLast: <A>(predicate: (a: A) => boolean) => (data: readonly A[]) => Maybe<A>;
|
|
242
221
|
/**
|
|
243
222
|
* Returns the index of the first element matching the predicate, or None.
|
|
244
223
|
*
|
|
@@ -247,7 +226,7 @@ declare namespace Arr {
|
|
|
247
226
|
* pipe([1, 2, 3, 4], Arr.findIndex(n => n > 2)); // Some(2)
|
|
248
227
|
* ```
|
|
249
228
|
*/
|
|
250
|
-
const findIndex: <A>(predicate: (a: A) => boolean) => (data: readonly A[]) => Maybe<number>;
|
|
229
|
+
export const findIndex: <A>(predicate: (a: A) => boolean) => (data: readonly A[]) => Maybe<number>;
|
|
251
230
|
/**
|
|
252
231
|
* Transforms each element of an array.
|
|
253
232
|
*
|
|
@@ -256,10 +235,7 @@ declare namespace Arr {
|
|
|
256
235
|
* pipe([1, 2, 3], Arr.map(n => n * 2)); // [2, 4, 6]
|
|
257
236
|
* ```
|
|
258
237
|
*/
|
|
259
|
-
const map: <A, B>(f: (a: A) => B) =>
|
|
260
|
-
(data: NonEmpty<A>): NonEmpty<B>;
|
|
261
|
-
(data: readonly A[]): readonly B[];
|
|
262
|
-
};
|
|
238
|
+
export const map: <A, B>(f: (a: A) => B) => (data: readonly A[]) => readonly B[];
|
|
263
239
|
/**
|
|
264
240
|
* Transforms each element using both its value and its zero-based index.
|
|
265
241
|
*
|
|
@@ -271,10 +247,7 @@ declare namespace Arr {
|
|
|
271
247
|
* ); // [{ position: 1, value: "a" }, { position: 2, value: "b" }, { position: 3, value: "c" }]
|
|
272
248
|
* ```
|
|
273
249
|
*/
|
|
274
|
-
const mapWithIndex: <A, B>(f: (i: number, a: A) => B) =>
|
|
275
|
-
(data: NonEmpty<A>): NonEmpty<B>;
|
|
276
|
-
(data: readonly A[]): readonly B[];
|
|
277
|
-
};
|
|
250
|
+
export const mapWithIndex: <A, B>(f: (i: number, a: A) => B) => (data: readonly A[]) => readonly B[];
|
|
278
251
|
/**
|
|
279
252
|
* Filters elements that satisfy the predicate.
|
|
280
253
|
*
|
|
@@ -283,7 +256,7 @@ declare namespace Arr {
|
|
|
283
256
|
* pipe([1, 2, 3, 4], Arr.filter(n => n % 2 === 0)); // [2, 4]
|
|
284
257
|
* ```
|
|
285
258
|
*/
|
|
286
|
-
const filter: <A>(predicate: (a: A) => boolean) => (data: readonly A[]) => readonly A[];
|
|
259
|
+
export const filter: <A>(predicate: (a: A) => boolean) => (data: readonly A[]) => readonly A[];
|
|
287
260
|
/**
|
|
288
261
|
* Maps each element to a Maybe and collects only the Some values.
|
|
289
262
|
* Combines map and filter in a single pass.
|
|
@@ -292,13 +265,13 @@ declare namespace Arr {
|
|
|
292
265
|
* ```ts
|
|
293
266
|
* const parseNum = (s: string): Maybe<number> => {
|
|
294
267
|
* const n = Number(s);
|
|
295
|
-
* return isNaN(n) ? Maybe.none() : Maybe.some(n);
|
|
268
|
+
* return isNaN(n) ? Maybe.make.none() : Maybe.make.some(n);
|
|
296
269
|
* };
|
|
297
270
|
*
|
|
298
271
|
* pipe(["1", "abc", "3"], Arr.filterMap(parseNum)); // [1, 3]
|
|
299
272
|
* ```
|
|
300
273
|
*/
|
|
301
|
-
const filterMap: <A, B>(f: (a: A) => Maybe<B>) => (data: readonly A[]) => readonly B[];
|
|
274
|
+
export const filterMap: <A, B>(f: (a: A) => Maybe<B>) => (data: readonly A[]) => readonly B[];
|
|
302
275
|
/**
|
|
303
276
|
* Splits an array into two groups based on a predicate.
|
|
304
277
|
* First group contains elements that satisfy the predicate,
|
|
@@ -309,27 +282,27 @@ declare namespace Arr {
|
|
|
309
282
|
* pipe([1, 2, 3, 4], Arr.partition(n => n % 2 === 0)); // [[2, 4], [1, 3]]
|
|
310
283
|
* ```
|
|
311
284
|
*/
|
|
312
|
-
const partition: <A>(predicate: (a: A) => boolean) => (data: readonly A[]) => readonly [readonly A[], readonly A[]];
|
|
285
|
+
export const partition: <A>(predicate: (a: A) => boolean) => (data: readonly A[]) => readonly [readonly A[], readonly A[]];
|
|
313
286
|
/**
|
|
314
287
|
* Narrows a list of Maybe values down to a list of their underlying values,
|
|
315
288
|
* discarding all None instances.
|
|
316
289
|
*
|
|
317
290
|
* @example
|
|
318
291
|
* ```ts
|
|
319
|
-
* Arr.compact([Maybe.some(1), Maybe.none(), Maybe.some(3)]); // [1, 3]
|
|
292
|
+
* Arr.compact([Maybe.make.some(1), Maybe.make.none(), Maybe.make.some(3)]); // [1, 3]
|
|
320
293
|
* ```
|
|
321
294
|
*/
|
|
322
|
-
const compact: <A>(data: readonly Maybe<A>[]) => readonly A[];
|
|
295
|
+
export const compact: <A>(data: readonly Maybe<A>[]) => readonly A[];
|
|
323
296
|
/**
|
|
324
297
|
* Separates an array of Result values into two separate lists of errors and successes.
|
|
325
298
|
* Returns a tuple containing `[errors, successes]`.
|
|
326
299
|
*
|
|
327
300
|
* @example
|
|
328
301
|
* ```ts
|
|
329
|
-
* Arr.separate([Result.ok(1), Result.err("bad"), Result.ok(3)]); // [["bad"], [1, 3]]
|
|
302
|
+
* Arr.separate([Result.make.ok(1), Result.make.err("bad"), Result.make.ok(3)]); // [["bad"], [1, 3]]
|
|
330
303
|
* ```
|
|
331
304
|
*/
|
|
332
|
-
const separate: <E, A>(data: readonly Result<E, A>[]) => readonly [readonly E[], readonly A[]];
|
|
305
|
+
export const separate: <E, A>(data: readonly Result<E, A>[]) => readonly [readonly E[], readonly A[]];
|
|
333
306
|
/**
|
|
334
307
|
* Maps each element to a Result, and separates the results into a tuple of failures and successes.
|
|
335
308
|
*
|
|
@@ -337,11 +310,11 @@ declare namespace Arr {
|
|
|
337
310
|
* ```ts
|
|
338
311
|
* pipe(
|
|
339
312
|
* [1, 2, 3, 4],
|
|
340
|
-
* Arr.partitionMap(n => n % 2 === 0 ? Result.ok(n) : Result.err(`odd: ${n}`))
|
|
313
|
+
* Arr.partitionMap(n => n % 2 === 0 ? Result.make.ok(n) : Result.make.err(`odd: ${n}`))
|
|
341
314
|
* ); // [["odd: 1", "odd: 3"], [2, 4]]
|
|
342
315
|
* ```
|
|
343
316
|
*/
|
|
344
|
-
const partitionMap: <A, E, B>(f: (a: A) => Result<E, B>) => (data: readonly A[]) => readonly [readonly E[], readonly B[]];
|
|
317
|
+
export const partitionMap: <A, E, B>(f: (a: A) => Result<E, B>) => (data: readonly A[]) => readonly [readonly E[], readonly B[]];
|
|
345
318
|
/**
|
|
346
319
|
* Groups elements by a key function.
|
|
347
320
|
*
|
|
@@ -353,7 +326,7 @@ declare namespace Arr {
|
|
|
353
326
|
* ); // { a: ["apple", "avocado"], b: ["banana"] }
|
|
354
327
|
* ```
|
|
355
328
|
*/
|
|
356
|
-
const groupBy: <A>(f: (a: A) => string) => (data: readonly A[]) => Record<string, NonEmptyArr<A>>;
|
|
329
|
+
export const groupBy: <A>(f: (a: A) => string) => (data: readonly A[]) => Record<string, NonEmptyArr<A>>;
|
|
357
330
|
/**
|
|
358
331
|
* Removes duplicate elements using strict equality.
|
|
359
332
|
*
|
|
@@ -362,7 +335,7 @@ declare namespace Arr {
|
|
|
362
335
|
* Arr.uniq([1, 2, 2, 3, 1]); // [1, 2, 3]
|
|
363
336
|
* ```
|
|
364
337
|
*/
|
|
365
|
-
const uniq: <A>(data: readonly A[]) => readonly A[];
|
|
338
|
+
export const uniq: <A>(data: readonly A[]) => readonly A[];
|
|
366
339
|
/**
|
|
367
340
|
* Removes duplicate elements by comparing the result of a key function.
|
|
368
341
|
*
|
|
@@ -374,7 +347,7 @@ declare namespace Arr {
|
|
|
374
347
|
* ); // [{id: 1, name: "a"}, {id: 2, name: "c"}]
|
|
375
348
|
* ```
|
|
376
349
|
*/
|
|
377
|
-
const uniqBy: <A, B>(f: (a: A) => B) => (data: readonly A[]) => readonly A[];
|
|
350
|
+
export const uniqBy: <A, B>(f: (a: A) => B) => (data: readonly A[]) => readonly A[];
|
|
378
351
|
/**
|
|
379
352
|
* Removes duplicate elements using a custom equality check.
|
|
380
353
|
* Preserves the order of first occurrences. Complements `uniq` (reference equality)
|
|
@@ -391,7 +364,7 @@ declare namespace Arr {
|
|
|
391
364
|
* ); // [{ x: 1, y: 1 }, { x: 2, y: 2 }]
|
|
392
365
|
* ```
|
|
393
366
|
*/
|
|
394
|
-
const uniqWith: <A>(eq: Equality<A>) => (data: readonly A[]) => readonly A[];
|
|
367
|
+
export const uniqWith: <A>(eq: Equality<A>) => (data: readonly A[]) => readonly A[];
|
|
395
368
|
/**
|
|
396
369
|
* Sorts an array using a comparison function. Returns a new array.
|
|
397
370
|
* To sort with a typed `Ordering<A>`, prefer `Arr.sortWith`.
|
|
@@ -401,7 +374,7 @@ declare namespace Arr {
|
|
|
401
374
|
* pipe([3, 1, 2], Arr.sortBy((a, b) => a - b)); // [1, 2, 3]
|
|
402
375
|
* ```
|
|
403
376
|
*/
|
|
404
|
-
const sortBy: <A>(compare: (a: A, b: A) => number) => (data: readonly A[]) => readonly A[];
|
|
377
|
+
export const sortBy: <A>(compare: (a: A, b: A) => number) => (data: readonly A[]) => readonly A[];
|
|
405
378
|
/**
|
|
406
379
|
* Sorts an array using an `Ordering<A>`. Returns a new array without mutating the original.
|
|
407
380
|
* Use this over `sortBy` when you have a typed `Ordering<A>` from the `Ordering` module.
|
|
@@ -414,7 +387,7 @@ declare namespace Arr {
|
|
|
414
387
|
* pipe(products, Arr.sortWith(byPrice));
|
|
415
388
|
* ```
|
|
416
389
|
*/
|
|
417
|
-
const sortWith: <A>(ord: Ordering<A>) => (data: readonly A[]) => readonly A[];
|
|
390
|
+
export const sortWith: <A>(ord: Ordering<A>) => (data: readonly A[]) => readonly A[];
|
|
418
391
|
/**
|
|
419
392
|
* Pairs up elements from two arrays. Stops at the shorter array.
|
|
420
393
|
*
|
|
@@ -423,7 +396,7 @@ declare namespace Arr {
|
|
|
423
396
|
* pipe([1, 2, 3], Arr.zip(["a", "b"])); // [[1, "a"], [2, "b"]]
|
|
424
397
|
* ```
|
|
425
398
|
*/
|
|
426
|
-
const zip: <B>(other: readonly B[]) => <A>(data: readonly A[]) => readonly (readonly [A, B])[];
|
|
399
|
+
export const zip: <B>(other: readonly B[]) => <A>(data: readonly A[]) => readonly (readonly [A, B])[];
|
|
427
400
|
/**
|
|
428
401
|
* Combines elements from two arrays using a function. Stops at the shorter array.
|
|
429
402
|
*
|
|
@@ -432,7 +405,7 @@ declare namespace Arr {
|
|
|
432
405
|
* pipe([1, 2], Arr.zipWith((a, b) => a + b, ["a", "b"])); // ["1a", "2b"]
|
|
433
406
|
* ```
|
|
434
407
|
*/
|
|
435
|
-
const zipWith: <A, B, C>(f: (a: A, b: B) => C) => (other: readonly B[]) => (data: readonly A[]) => readonly C[];
|
|
408
|
+
export const zipWith: <A, B, C>(f: (a: A, b: B) => C) => (other: readonly B[]) => (data: readonly A[]) => readonly C[];
|
|
436
409
|
/**
|
|
437
410
|
* Inserts a separator between every element.
|
|
438
411
|
*
|
|
@@ -441,23 +414,16 @@ declare namespace Arr {
|
|
|
441
414
|
* pipe([1, 2, 3], Arr.intersperse(0)); // [1, 0, 2, 0, 3]
|
|
442
415
|
* ```
|
|
443
416
|
*/
|
|
444
|
-
const intersperse: <A>(sep: A) =>
|
|
445
|
-
(data: NonEmpty<A>): NonEmpty<A>;
|
|
446
|
-
(data: readonly A[]): readonly A[];
|
|
447
|
-
};
|
|
417
|
+
export const intersperse: <A>(sep: A) => (data: readonly A[]) => readonly A[];
|
|
448
418
|
/**
|
|
449
|
-
* Concatenates a standard array
|
|
450
|
-
* If the first array is a NonEmptyArr, the result is guaranteed to be a NonEmptyArr.
|
|
419
|
+
* Concatenates a standard array with another array.
|
|
451
420
|
*
|
|
452
421
|
* @example
|
|
453
422
|
* ```ts
|
|
454
423
|
* pipe([1, 2], Arr.concat([3, 4])); // [1, 2, 3, 4]
|
|
455
424
|
* ```
|
|
456
425
|
*/
|
|
457
|
-
const concat: <A>(other: readonly A[]) =>
|
|
458
|
-
(data: NonEmpty<A>): NonEmpty<A>;
|
|
459
|
-
(data: readonly A[]): readonly A[];
|
|
460
|
-
};
|
|
426
|
+
export const concat: <A>(other: readonly A[]) => (data: readonly A[]) => readonly A[];
|
|
461
427
|
/**
|
|
462
428
|
* Splits an array into chunks of the given size.
|
|
463
429
|
*
|
|
@@ -466,7 +432,7 @@ declare namespace Arr {
|
|
|
466
432
|
* pipe([1, 2, 3, 4, 5], Arr.chunksOf(2)); // [[1, 2], [3, 4], [5]]
|
|
467
433
|
* ```
|
|
468
434
|
*/
|
|
469
|
-
const chunksOf: (n: number) => <A>(data: readonly A[]) => readonly (readonly A[])[];
|
|
435
|
+
export const chunksOf: (n: number) => <A>(data: readonly A[]) => readonly (readonly A[])[];
|
|
470
436
|
/**
|
|
471
437
|
* Flattens a nested array by one level.
|
|
472
438
|
*
|
|
@@ -475,7 +441,7 @@ declare namespace Arr {
|
|
|
475
441
|
* Arr.flatten([[1, 2], [3], [4, 5]]); // [1, 2, 3, 4, 5]
|
|
476
442
|
* ```
|
|
477
443
|
*/
|
|
478
|
-
const flatten: <A>(data: readonly (readonly A[])[]) => readonly A[];
|
|
444
|
+
export const flatten: <A>(data: readonly (readonly A[])[]) => readonly A[];
|
|
479
445
|
/**
|
|
480
446
|
* Maps each element to an array and flattens the result.
|
|
481
447
|
*
|
|
@@ -484,7 +450,7 @@ declare namespace Arr {
|
|
|
484
450
|
* pipe([1, 2, 3], Arr.flatMap(n => [n, n * 10])); // [1, 10, 2, 20, 3, 30]
|
|
485
451
|
* ```
|
|
486
452
|
*/
|
|
487
|
-
const flatMap: <A, B>(f: (a: A) => readonly B[]) => (data: readonly A[]) => readonly B[];
|
|
453
|
+
export const flatMap: <A, B>(f: (a: A) => readonly B[]) => (data: readonly A[]) => readonly B[];
|
|
488
454
|
/**
|
|
489
455
|
* Reduces an array from the left.
|
|
490
456
|
*
|
|
@@ -493,14 +459,35 @@ declare namespace Arr {
|
|
|
493
459
|
* pipe([1, 2, 3], Arr.reduce(0, (acc, n) => acc + n)); // 6
|
|
494
460
|
* ```
|
|
495
461
|
*/
|
|
496
|
-
const reduce: <A, B>(initial: B, f: (acc: B, a: A) => B) => (data: readonly A[]) => B;
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
462
|
+
export const reduce: <A, B>(initial: B, f: (acc: B, a: A) => B) => (data: readonly A[]) => B;
|
|
463
|
+
interface TaskTraverse {
|
|
464
|
+
<A, B>(f: (a: A) => Task<B>): (data: readonly A[]) => Task<readonly B[]>;
|
|
465
|
+
Result: typeof ArrTaskResult.traverse;
|
|
466
|
+
}
|
|
467
|
+
interface TaskSequence {
|
|
468
|
+
<A>(data: readonly Task<A>[]): Task<readonly A[]>;
|
|
469
|
+
Result: typeof ArrTaskResult.sequence;
|
|
470
|
+
}
|
|
471
|
+
export namespace traverse {
|
|
472
|
+
const Maybe: <A, B>(f: (a: A) => Maybe<B>) => (data: readonly A[]) => Maybe<readonly B[]>;
|
|
473
|
+
const Result: <E, A, B>(f: (a: A) => Result<E, B>) => (data: readonly A[]) => Result<E, readonly B[]>;
|
|
474
|
+
const Task: TaskTraverse;
|
|
475
|
+
}
|
|
476
|
+
export namespace sequence {
|
|
477
|
+
const Maybe: <A>(data: readonly Maybe<A>[]) => Maybe<readonly A[]>;
|
|
478
|
+
const Result: <E, A>(data: readonly Result<E, A>[]) => Result<E, readonly A[]>;
|
|
479
|
+
const Task: TaskSequence;
|
|
480
|
+
}
|
|
481
|
+
export namespace is {
|
|
482
|
+
/**
|
|
483
|
+
* Returns true if the array is empty.
|
|
484
|
+
*/
|
|
485
|
+
const empty: <A>(data: readonly A[]) => data is readonly [];
|
|
486
|
+
/**
|
|
487
|
+
* Returns true if the array is non-empty (type guard).
|
|
488
|
+
*/
|
|
489
|
+
const nonEmpty: <A>(data: readonly A[]) => data is NonEmpty<A>;
|
|
490
|
+
}
|
|
504
491
|
/**
|
|
505
492
|
* Prepends a value to the beginning of an array, returning a NonEmptyArr.
|
|
506
493
|
*
|
|
@@ -509,7 +496,7 @@ declare namespace Arr {
|
|
|
509
496
|
* pipe([1, 2], Arr.prepend(0)); // [0, 1, 2]
|
|
510
497
|
* ```
|
|
511
498
|
*/
|
|
512
|
-
const prepend: <A>(value: A) => (data: readonly A[]) => NonEmpty<A>;
|
|
499
|
+
export const prepend: <A>(value: A) => (data: readonly A[]) => NonEmpty<A>;
|
|
513
500
|
/**
|
|
514
501
|
* Appends a value to the end of an array, returning a NonEmptyArr.
|
|
515
502
|
*
|
|
@@ -518,11 +505,11 @@ declare namespace Arr {
|
|
|
518
505
|
* pipe([1, 2], Arr.append(3)); // [1, 2, 3]
|
|
519
506
|
* ```
|
|
520
507
|
*/
|
|
521
|
-
const append: <A>(value: A) => (data: readonly A[]) => NonEmpty<A>;
|
|
508
|
+
export const append: <A>(value: A) => (data: readonly A[]) => NonEmpty<A>;
|
|
522
509
|
/**
|
|
523
510
|
* Returns the length of an array.
|
|
524
511
|
*/
|
|
525
|
-
const size: <A>(data: readonly A[]) => number;
|
|
512
|
+
export const size: <A>(data: readonly A[]) => number;
|
|
526
513
|
/**
|
|
527
514
|
* Returns true if any element satisfies the predicate.
|
|
528
515
|
*
|
|
@@ -531,7 +518,7 @@ declare namespace Arr {
|
|
|
531
518
|
* pipe([1, 2, 3], Arr.some(n => n > 2)); // true
|
|
532
519
|
* ```
|
|
533
520
|
*/
|
|
534
|
-
const some: <A>(predicate: (a: A) => boolean) => (data: readonly A[]) => boolean;
|
|
521
|
+
export const some: <A>(predicate: (a: A) => boolean) => (data: readonly A[]) => boolean;
|
|
535
522
|
/**
|
|
536
523
|
* Returns true if all elements satisfy the predicate.
|
|
537
524
|
*
|
|
@@ -540,7 +527,7 @@ declare namespace Arr {
|
|
|
540
527
|
* pipe([1, 2, 3], Arr.every(n => n > 0)); // true
|
|
541
528
|
* ```
|
|
542
529
|
*/
|
|
543
|
-
const every: <A>(predicate: (a: A) => boolean) => (data: readonly A[]) => boolean;
|
|
530
|
+
export const every: <A>(predicate: (a: A) => boolean) => (data: readonly A[]) => boolean;
|
|
544
531
|
/**
|
|
545
532
|
* Reverses an array. Returns a new array.
|
|
546
533
|
*
|
|
@@ -549,10 +536,7 @@ declare namespace Arr {
|
|
|
549
536
|
* Arr.reverse([1, 2, 3]); // [3, 2, 1]
|
|
550
537
|
* ```
|
|
551
538
|
*/
|
|
552
|
-
const reverse:
|
|
553
|
-
<A>(data: NonEmpty<A>): NonEmpty<A>;
|
|
554
|
-
<A>(data: readonly A[]): readonly A[];
|
|
555
|
-
};
|
|
539
|
+
export const reverse: <A>(data: readonly A[]) => readonly A[];
|
|
556
540
|
/**
|
|
557
541
|
* Returns a new array with `item` inserted before the element at `index`.
|
|
558
542
|
* Negative indices are clamped to 0; indices beyond the array length append to the end.
|
|
@@ -564,7 +548,7 @@ declare namespace Arr {
|
|
|
564
548
|
* pipe([1, 2, 3], Arr.insertAt(3, 99)); // [1, 2, 3, 99]
|
|
565
549
|
* ```
|
|
566
550
|
*/
|
|
567
|
-
const insertAt: <A>(index: number, item: A) => (data: readonly A[]) => readonly A[];
|
|
551
|
+
export const insertAt: <A>(index: number, item: A) => (data: readonly A[]) => readonly A[];
|
|
568
552
|
/**
|
|
569
553
|
* Returns a new array with the element at `index` removed.
|
|
570
554
|
* Returns the original array unchanged if `index` is out of bounds.
|
|
@@ -576,7 +560,7 @@ declare namespace Arr {
|
|
|
576
560
|
* pipe([1, 2, 3], Arr.removeAt(5)); // [1, 2, 3]
|
|
577
561
|
* ```
|
|
578
562
|
*/
|
|
579
|
-
const removeAt: (index: number) => <A>(data: readonly A[]) => readonly A[];
|
|
563
|
+
export const removeAt: (index: number) => <A>(data: readonly A[]) => readonly A[];
|
|
580
564
|
/**
|
|
581
565
|
* Takes the first n elements from an array.
|
|
582
566
|
*
|
|
@@ -585,7 +569,7 @@ declare namespace Arr {
|
|
|
585
569
|
* pipe([1, 2, 3, 4], Arr.take(2)); // [1, 2]
|
|
586
570
|
* ```
|
|
587
571
|
*/
|
|
588
|
-
const take: (n: number) => <A>(data: readonly A[]) => readonly A[];
|
|
572
|
+
export const take: (n: number) => <A>(data: readonly A[]) => readonly A[];
|
|
589
573
|
/**
|
|
590
574
|
* Drops the first n elements from an array.
|
|
591
575
|
*
|
|
@@ -594,7 +578,7 @@ declare namespace Arr {
|
|
|
594
578
|
* pipe([1, 2, 3, 4], Arr.drop(2)); // [3, 4]
|
|
595
579
|
* ```
|
|
596
580
|
*/
|
|
597
|
-
const drop: (n: number) => <A>(data: readonly A[]) => readonly A[];
|
|
581
|
+
export const drop: (n: number) => <A>(data: readonly A[]) => readonly A[];
|
|
598
582
|
/**
|
|
599
583
|
* Takes elements from the start while the predicate holds.
|
|
600
584
|
*
|
|
@@ -603,7 +587,7 @@ declare namespace Arr {
|
|
|
603
587
|
* pipe([1, 2, 3, 1], Arr.takeWhile(n => n < 3)); // [1, 2]
|
|
604
588
|
* ```
|
|
605
589
|
*/
|
|
606
|
-
const takeWhile: <A>(predicate: (a: A) => boolean) => (data: readonly A[]) => readonly A[];
|
|
590
|
+
export const takeWhile: <A>(predicate: (a: A) => boolean) => (data: readonly A[]) => readonly A[];
|
|
607
591
|
/**
|
|
608
592
|
* Drops elements from the start while the predicate holds.
|
|
609
593
|
*
|
|
@@ -612,7 +596,7 @@ declare namespace Arr {
|
|
|
612
596
|
* pipe([1, 2, 3, 1], Arr.dropWhile(n => n < 3)); // [3, 1]
|
|
613
597
|
* ```
|
|
614
598
|
*/
|
|
615
|
-
const dropWhile: <A>(predicate: (a: A) => boolean) => (data: readonly A[]) => readonly A[];
|
|
599
|
+
export const dropWhile: <A>(predicate: (a: A) => boolean) => (data: readonly A[]) => readonly A[];
|
|
616
600
|
/**
|
|
617
601
|
* Like `reduce`, but returns every intermediate accumulator as an array.
|
|
618
602
|
* The initial value is not included — the output has the same length as the input.
|
|
@@ -622,7 +606,7 @@ declare namespace Arr {
|
|
|
622
606
|
* pipe([1, 2, 3], Arr.scan(0, (acc, n) => acc + n)); // [1, 3, 6]
|
|
623
607
|
* ```
|
|
624
608
|
*/
|
|
625
|
-
const scan: <A, B>(initial: B, f: (acc: B, a: A) => B) => (data: readonly A[]) => readonly B[];
|
|
609
|
+
export const scan: <A, B>(initial: B, f: (acc: B, a: A) => B) => (data: readonly A[]) => readonly B[];
|
|
626
610
|
/**
|
|
627
611
|
* Splits an array at an index into a `[before, after]` tuple.
|
|
628
612
|
* Negative indices clamp to 0; indices beyond the array length clamp to the end.
|
|
@@ -634,10 +618,15 @@ declare namespace Arr {
|
|
|
634
618
|
* pipe([1, 2, 3], Arr.splitAt(10)); // [[1, 2, 3], []]
|
|
635
619
|
* ```
|
|
636
620
|
*/
|
|
637
|
-
const splitAt: (index: number) => <A>(data: readonly A[]) => readonly [readonly A[], readonly A[]];
|
|
638
|
-
const NonEmpty: typeof ArrNonEmpty;
|
|
621
|
+
export const splitAt: (index: number) => <A>(data: readonly A[]) => readonly [readonly A[], readonly A[]];
|
|
622
|
+
export const NonEmpty: typeof ArrNonEmpty;
|
|
623
|
+
export { };
|
|
639
624
|
}
|
|
640
625
|
|
|
626
|
+
/**
|
|
627
|
+
* A branded type representing a key-value dictionary with at least one entry.
|
|
628
|
+
*/
|
|
629
|
+
type NonEmptyMap<K, V> = Brand<NonEmpty<"Dict">, ReadonlyMap<K, V>>;
|
|
641
630
|
/**
|
|
642
631
|
* Functional utilities for key-value dictionaries (`ReadonlyMap<K, V>`). All functions are pure
|
|
643
632
|
* and data-last — they compose naturally with `pipe`.
|
|
@@ -651,50 +640,150 @@ declare namespace Arr {
|
|
|
651
640
|
* import { pipe } from "@nlozgachev/pipelined/composition";
|
|
652
641
|
*
|
|
653
642
|
* const scores = pipe(
|
|
654
|
-
* Dict.
|
|
643
|
+
* Dict.from.entries([["alice", 10], ["bob", 8], ["carol", 10]] as const),
|
|
655
644
|
* Dict.filter(n => n >= 10),
|
|
656
645
|
* Dict.map(n => `${n} points`),
|
|
657
646
|
* );
|
|
658
647
|
* // ReadonlyMap { "alice" => "10 points", "carol" => "10 points" }
|
|
659
648
|
* ```
|
|
660
649
|
*/
|
|
661
|
-
declare namespace
|
|
650
|
+
declare namespace DictNonEmpty {
|
|
662
651
|
/**
|
|
663
|
-
* Creates
|
|
652
|
+
* Creates a NonEmptyMap containing a single key-value entry.
|
|
664
653
|
*
|
|
665
654
|
* @example
|
|
666
655
|
* ```ts
|
|
667
|
-
* Dict.
|
|
656
|
+
* Dict.NonEmpty.singleton("name", "Alice"); // ReadonlyMap { "name" => "Alice" }
|
|
668
657
|
* ```
|
|
669
658
|
*/
|
|
670
|
-
const
|
|
659
|
+
const singleton: <K, V>(key: K, value: V) => NonEmptyMap<K, V>;
|
|
660
|
+
namespace from {
|
|
661
|
+
/**
|
|
662
|
+
* Returns Some containing NonEmptyMap if the map is not empty, None otherwise.
|
|
663
|
+
*
|
|
664
|
+
* @example
|
|
665
|
+
* ```ts
|
|
666
|
+
* Dict.NonEmpty.from.Map(Dict.from.entries([["a", 1]])); // Some(ReadonlyMap { "a" => 1 })
|
|
667
|
+
* Dict.NonEmpty.from.Map(Dict.empty()); // None
|
|
668
|
+
* ```
|
|
669
|
+
*/
|
|
670
|
+
const Map: <K, V>(m: ReadonlyMap<K, V>) => Maybe<NonEmptyMap<K, V>>;
|
|
671
|
+
}
|
|
671
672
|
/**
|
|
672
|
-
*
|
|
673
|
+
* Returns a non-empty array of keys, in insertion order.
|
|
673
674
|
*
|
|
674
675
|
* @example
|
|
675
676
|
* ```ts
|
|
676
|
-
* Dict.singleton("
|
|
677
|
+
* Dict.NonEmpty.keys(Dict.NonEmpty.singleton("a", 1)); // ["a"]
|
|
677
678
|
* ```
|
|
678
679
|
*/
|
|
679
|
-
const
|
|
680
|
+
const keys: <K, V>(m: NonEmptyMap<K, V>) => NonEmptyArr<K>;
|
|
681
|
+
/**
|
|
682
|
+
* Returns a non-empty array of values, in insertion order.
|
|
683
|
+
*
|
|
684
|
+
* @example
|
|
685
|
+
* ```ts
|
|
686
|
+
* Dict.NonEmpty.values(Dict.NonEmpty.singleton("a", 1)); // [1]
|
|
687
|
+
* ```
|
|
688
|
+
*/
|
|
689
|
+
const values: <K, V>(m: NonEmptyMap<K, V>) => NonEmptyArr<V>;
|
|
690
|
+
/**
|
|
691
|
+
* Returns a non-empty array of entry tuples, in insertion order.
|
|
692
|
+
*
|
|
693
|
+
* @example
|
|
694
|
+
* ```ts
|
|
695
|
+
* Dict.NonEmpty.entries(Dict.NonEmpty.singleton("a", 1)); // [["a", 1]]
|
|
696
|
+
* ```
|
|
697
|
+
*/
|
|
698
|
+
const entries: <K, V>(m: NonEmptyMap<K, V>) => NonEmptyArr<readonly [K, V]>;
|
|
699
|
+
/**
|
|
700
|
+
* Reduces a NonEmptyMap's values from the left without an initial seed value.
|
|
701
|
+
*
|
|
702
|
+
* @example
|
|
703
|
+
* ```ts
|
|
704
|
+
* pipe(Dict.NonEmpty.singleton("a", 1), Dict.NonEmpty.reduce((a, b) => a + b)); // 1
|
|
705
|
+
* ```
|
|
706
|
+
*/
|
|
707
|
+
const reduce: <V>(f: (acc: V, value: V) => V) => <K>(m: NonEmptyMap<K, V>) => V;
|
|
708
|
+
/**
|
|
709
|
+
* Transforms each value in the non-empty dictionary.
|
|
710
|
+
*
|
|
711
|
+
* @example
|
|
712
|
+
* ```ts
|
|
713
|
+
* pipe(Dict.NonEmpty.singleton("a", 1), Dict.NonEmpty.map(n => n * 2));
|
|
714
|
+
* // ReadonlyMap { "a" => 2 }
|
|
715
|
+
* ```
|
|
716
|
+
*/
|
|
717
|
+
const map: <A, B>(f: (a: A) => B) => <K>(m: NonEmptyMap<K, A>) => NonEmptyMap<K, B>;
|
|
718
|
+
/**
|
|
719
|
+
* Transforms each value in the non-empty dictionary, also receiving the key.
|
|
720
|
+
*
|
|
721
|
+
* @example
|
|
722
|
+
* ```ts
|
|
723
|
+
* pipe(Dict.NonEmpty.singleton("a", 1), Dict.NonEmpty.mapWithKey((k, v) => `${k}:${v}`));
|
|
724
|
+
* // ReadonlyMap { "a" => "a:1" }
|
|
725
|
+
* ```
|
|
726
|
+
*/
|
|
727
|
+
const mapWithKey: <K, A, B>(f: (key: K, a: A) => B) => (m: NonEmptyMap<K, A>) => NonEmptyMap<K, B>;
|
|
728
|
+
}
|
|
729
|
+
declare namespace Dict {
|
|
730
|
+
/**
|
|
731
|
+
* A branded type representing a key-value dictionary with at least one entry.
|
|
732
|
+
*/
|
|
733
|
+
type NonEmpty<K, V> = NonEmptyMap<K, V>;
|
|
734
|
+
namespace is {
|
|
735
|
+
/**
|
|
736
|
+
* Returns `true` if the dictionary has no entries.
|
|
737
|
+
*
|
|
738
|
+
* @example
|
|
739
|
+
* ```ts
|
|
740
|
+
* Dict.is.empty(Dict.empty()); // true
|
|
741
|
+
* ```
|
|
742
|
+
*/
|
|
743
|
+
const empty: <K, V>(m: ReadonlyMap<K, V>) => boolean;
|
|
744
|
+
/**
|
|
745
|
+
* Type guard to check if a dictionary is non-empty.
|
|
746
|
+
*/
|
|
747
|
+
const nonEmpty: <K, V>(m: ReadonlyMap<K, V>) => m is NonEmpty<K, V>;
|
|
748
|
+
}
|
|
680
749
|
/**
|
|
681
|
-
* Creates
|
|
750
|
+
* Creates an empty dictionary.
|
|
682
751
|
*
|
|
683
752
|
* @example
|
|
684
753
|
* ```ts
|
|
685
|
-
* Dict.
|
|
754
|
+
* Dict.empty<string, number>(); // ReadonlyMap {}
|
|
686
755
|
* ```
|
|
687
756
|
*/
|
|
688
|
-
const
|
|
757
|
+
const empty: <K, V>() => ReadonlyMap<K, V>;
|
|
689
758
|
/**
|
|
690
|
-
* Creates a dictionary
|
|
759
|
+
* Creates a dictionary with a single entry.
|
|
691
760
|
*
|
|
692
761
|
* @example
|
|
693
762
|
* ```ts
|
|
694
|
-
* Dict.
|
|
763
|
+
* Dict.singleton("name", "Alice"); // ReadonlyMap { "name" => "Alice" }
|
|
695
764
|
* ```
|
|
696
765
|
*/
|
|
697
|
-
const
|
|
766
|
+
const singleton: <K, V>(key: K, value: V) => ReadonlyMap<K, V>;
|
|
767
|
+
namespace from {
|
|
768
|
+
/**
|
|
769
|
+
* Creates a dictionary from an array of key-value pairs.
|
|
770
|
+
*
|
|
771
|
+
* @example
|
|
772
|
+
* ```ts
|
|
773
|
+
* Dict.from.entries([["a", 1], ["b", 2]]); // ReadonlyMap { "a" => 1, "b" => 2 }
|
|
774
|
+
* ```
|
|
775
|
+
*/
|
|
776
|
+
const entries: <K, V>(entries: readonly (readonly [K, V])[]) => ReadonlyMap<K, V>;
|
|
777
|
+
/**
|
|
778
|
+
* Creates a dictionary from a plain object. Keys are always strings.
|
|
779
|
+
*
|
|
780
|
+
* @example
|
|
781
|
+
* ```ts
|
|
782
|
+
* Dict.from.Record({ a: 1, b: 2 }); // ReadonlyMap { "a" => 1, "b" => 2 }
|
|
783
|
+
* ```
|
|
784
|
+
*/
|
|
785
|
+
const Record: <V>(rec: Readonly<Record<string, V>>) => ReadonlyMap<string, V>;
|
|
786
|
+
}
|
|
698
787
|
/**
|
|
699
788
|
* Groups elements of an array into a dictionary keyed by the result of `keyFn`. Each key maps
|
|
700
789
|
* to the array of elements that produced it, in insertion order. Uses the native `Map.groupBy`
|
|
@@ -715,8 +804,8 @@ declare namespace Dict {
|
|
|
715
804
|
*
|
|
716
805
|
* @example
|
|
717
806
|
* ```ts
|
|
718
|
-
* pipe(Dict.
|
|
719
|
-
* pipe(Dict.
|
|
807
|
+
* pipe(Dict.from.Entries([["a", 1]]), Dict.has("a")); // true
|
|
808
|
+
* pipe(Dict.from.Entries([["a", 1]]), Dict.has("b")); // false
|
|
720
809
|
* ```
|
|
721
810
|
*/
|
|
722
811
|
const has: <K>(key: K) => <V>(m: ReadonlyMap<K, V>) => boolean;
|
|
@@ -725,8 +814,8 @@ declare namespace Dict {
|
|
|
725
814
|
*
|
|
726
815
|
* @example
|
|
727
816
|
* ```ts
|
|
728
|
-
* pipe(Dict.
|
|
729
|
-
* pipe(Dict.
|
|
817
|
+
* pipe(Dict.from.Entries([["a", 1]]), Dict.lookup("a")); // Some(1)
|
|
818
|
+
* pipe(Dict.from.Entries([["a", 1]]), Dict.lookup("b")); // None
|
|
730
819
|
* ```
|
|
731
820
|
*/
|
|
732
821
|
const lookup: <K>(key: K) => <V>(m: ReadonlyMap<K, V>) => Maybe<V>;
|
|
@@ -735,25 +824,16 @@ declare namespace Dict {
|
|
|
735
824
|
*
|
|
736
825
|
* @example
|
|
737
826
|
* ```ts
|
|
738
|
-
* Dict.size(Dict.
|
|
827
|
+
* Dict.size(Dict.from.Entries([["a", 1], ["b", 2]])); // 2
|
|
739
828
|
* ```
|
|
740
829
|
*/
|
|
741
830
|
const size: <K, V>(m: ReadonlyMap<K, V>) => number;
|
|
742
|
-
/**
|
|
743
|
-
* Returns `true` if the dictionary has no entries.
|
|
744
|
-
*
|
|
745
|
-
* @example
|
|
746
|
-
* ```ts
|
|
747
|
-
* Dict.isEmpty(Dict.empty()); // true
|
|
748
|
-
* ```
|
|
749
|
-
*/
|
|
750
|
-
const isEmpty: <K, V>(m: ReadonlyMap<K, V>) => boolean;
|
|
751
831
|
/**
|
|
752
832
|
* Returns all keys as a readonly array, in insertion order.
|
|
753
833
|
*
|
|
754
834
|
* @example
|
|
755
835
|
* ```ts
|
|
756
|
-
* Dict.keys(Dict.
|
|
836
|
+
* Dict.keys(Dict.from.Entries([["a", 1], ["b", 2]])); // ["a", "b"]
|
|
757
837
|
* ```
|
|
758
838
|
*/
|
|
759
839
|
const keys: <K, V>(m: ReadonlyMap<K, V>) => readonly K[];
|
|
@@ -762,7 +842,7 @@ declare namespace Dict {
|
|
|
762
842
|
*
|
|
763
843
|
* @example
|
|
764
844
|
* ```ts
|
|
765
|
-
* Dict.values(Dict.
|
|
845
|
+
* Dict.values(Dict.from.Entries([["a", 1], ["b", 2]])); // [1, 2]
|
|
766
846
|
* ```
|
|
767
847
|
*/
|
|
768
848
|
const values: <K, V>(m: ReadonlyMap<K, V>) => readonly V[];
|
|
@@ -771,7 +851,7 @@ declare namespace Dict {
|
|
|
771
851
|
*
|
|
772
852
|
* @example
|
|
773
853
|
* ```ts
|
|
774
|
-
* Dict.entries(Dict.
|
|
854
|
+
* Dict.entries(Dict.from.Entries([["a", 1], ["b", 2]])); // [["a", 1], ["b", 2]]
|
|
775
855
|
* ```
|
|
776
856
|
*/
|
|
777
857
|
const entries: <K, V>(m: ReadonlyMap<K, V>) => readonly (readonly [K, V])[];
|
|
@@ -781,7 +861,7 @@ declare namespace Dict {
|
|
|
781
861
|
*
|
|
782
862
|
* @example
|
|
783
863
|
* ```ts
|
|
784
|
-
* pipe(Dict.
|
|
864
|
+
* pipe(Dict.from.Entries([["a", 1]]), Dict.insert("b", 2));
|
|
785
865
|
* // ReadonlyMap { "a" => 1, "b" => 2 }
|
|
786
866
|
* ```
|
|
787
867
|
*/
|
|
@@ -792,7 +872,7 @@ declare namespace Dict {
|
|
|
792
872
|
*
|
|
793
873
|
* @example
|
|
794
874
|
* ```ts
|
|
795
|
-
* pipe(Dict.
|
|
875
|
+
* pipe(Dict.from.Entries([["a", 1], ["b", 2]]), Dict.remove("a"));
|
|
796
876
|
* // ReadonlyMap { "b" => 2 }
|
|
797
877
|
* ```
|
|
798
878
|
*/
|
|
@@ -808,8 +888,8 @@ declare namespace Dict {
|
|
|
808
888
|
* import { Maybe } from "@nlozgachev/pipelined/core";
|
|
809
889
|
*
|
|
810
890
|
* const increment = (opt: Maybe<number>) => Maybe.getOrElse(() => 0)(opt) + 1;
|
|
811
|
-
* pipe(Dict.
|
|
812
|
-
* pipe(Dict.
|
|
891
|
+
* pipe(Dict.from.Entries([["views", 5]]), Dict.upsert("views", increment)); // { views: 6 }
|
|
892
|
+
* pipe(Dict.from.Entries([["views", 5]]), Dict.upsert("likes", increment)); // { views: 5, likes: 1 }
|
|
813
893
|
* ```
|
|
814
894
|
*/
|
|
815
895
|
const upsert: <K, V>(key: K, f: (existing: Maybe<V>) => V) => (m: ReadonlyMap<K, V>) => ReadonlyMap<K, V>;
|
|
@@ -818,7 +898,7 @@ declare namespace Dict {
|
|
|
818
898
|
*
|
|
819
899
|
* @example
|
|
820
900
|
* ```ts
|
|
821
|
-
* pipe(Dict.
|
|
901
|
+
* pipe(Dict.from.Entries([["a", 1], ["b", 2]]), Dict.map(n => n * 2));
|
|
822
902
|
* // ReadonlyMap { "a" => 2, "b" => 4 }
|
|
823
903
|
* ```
|
|
824
904
|
*/
|
|
@@ -828,7 +908,7 @@ declare namespace Dict {
|
|
|
828
908
|
*
|
|
829
909
|
* @example
|
|
830
910
|
* ```ts
|
|
831
|
-
* pipe(Dict.
|
|
911
|
+
* pipe(Dict.from.Entries([["a", 1], ["b", 2]]), Dict.mapWithKey((k, v) => `${k}:${v}`));
|
|
832
912
|
* // ReadonlyMap { "a" => "a:1", "b" => "b:2" }
|
|
833
913
|
* ```
|
|
834
914
|
*/
|
|
@@ -838,7 +918,7 @@ declare namespace Dict {
|
|
|
838
918
|
*
|
|
839
919
|
* @example
|
|
840
920
|
* ```ts
|
|
841
|
-
* pipe(Dict.
|
|
921
|
+
* pipe(Dict.from.Entries([["a", 1], ["b", 3], ["c", 0]]), Dict.filter(n => n > 0));
|
|
842
922
|
* // ReadonlyMap { "a" => 1, "b" => 3 }
|
|
843
923
|
* ```
|
|
844
924
|
*/
|
|
@@ -849,7 +929,7 @@ declare namespace Dict {
|
|
|
849
929
|
*
|
|
850
930
|
* @example
|
|
851
931
|
* ```ts
|
|
852
|
-
* pipe(Dict.
|
|
932
|
+
* pipe(Dict.from.Entries([["a", 1], ["b", 2]]), Dict.filterWithKey((k, v) => k !== "a" && v > 0));
|
|
853
933
|
* // ReadonlyMap { "b" => 2 }
|
|
854
934
|
* ```
|
|
855
935
|
*/
|
|
@@ -862,10 +942,10 @@ declare namespace Dict {
|
|
|
862
942
|
* ```ts
|
|
863
943
|
* import { Maybe } from "@nlozgachev/pipelined/core";
|
|
864
944
|
*
|
|
865
|
-
* Dict.compact(Dict.
|
|
866
|
-
* ["a", Maybe.some(1)],
|
|
867
|
-
* ["b", Maybe.none()],
|
|
868
|
-
* ["c", Maybe.some(3)],
|
|
945
|
+
* Dict.compact(Dict.from.Entries([
|
|
946
|
+
* ["a", Maybe.make.some(1)],
|
|
947
|
+
* ["b", Maybe.make.none()],
|
|
948
|
+
* ["c", Maybe.make.some(3)],
|
|
869
949
|
* ]));
|
|
870
950
|
* // ReadonlyMap { "a" => 1, "c" => 3 }
|
|
871
951
|
* ```
|
|
@@ -879,9 +959,9 @@ declare namespace Dict {
|
|
|
879
959
|
* ```ts
|
|
880
960
|
* const parse = (s: string): Maybe<number> => {
|
|
881
961
|
* const n = Number(s);
|
|
882
|
-
* return isNaN(n) ? Maybe.none() : Maybe.some(n);
|
|
962
|
+
* return isNaN(n) ? Maybe.make.none() : Maybe.make.some(n);
|
|
883
963
|
* };
|
|
884
|
-
* Dict.filterMap(parse)(Dict.
|
|
964
|
+
* Dict.filterMap(parse)(Dict.from.Record({ a: "1", b: "two", c: "3" }));
|
|
885
965
|
* // ReadonlyMap { "a" => 1, "c" => 3 }
|
|
886
966
|
* ```
|
|
887
967
|
*/
|
|
@@ -893,8 +973,8 @@ declare namespace Dict {
|
|
|
893
973
|
* @example
|
|
894
974
|
* ```ts
|
|
895
975
|
* pipe(
|
|
896
|
-
* Dict.
|
|
897
|
-
* Dict.union(Dict.
|
|
976
|
+
* Dict.from.Entries([["a", 1], ["b", 2]]),
|
|
977
|
+
* Dict.union(Dict.from.Entries([["b", 3], ["c", 4]])),
|
|
898
978
|
* );
|
|
899
979
|
* // ReadonlyMap { "a" => 1, "b" => 3, "c" => 4 }
|
|
900
980
|
* ```
|
|
@@ -907,8 +987,8 @@ declare namespace Dict {
|
|
|
907
987
|
* @example
|
|
908
988
|
* ```ts
|
|
909
989
|
* pipe(
|
|
910
|
-
* Dict.
|
|
911
|
-
* Dict.intersection(Dict.
|
|
990
|
+
* Dict.from.Entries([["a", 1], ["b", 2], ["c", 3]]),
|
|
991
|
+
* Dict.intersection(Dict.from.Entries([["b", 99], ["c", 0]])),
|
|
912
992
|
* );
|
|
913
993
|
* // ReadonlyMap { "b" => 2, "c" => 3 }
|
|
914
994
|
* ```
|
|
@@ -920,8 +1000,8 @@ declare namespace Dict {
|
|
|
920
1000
|
* @example
|
|
921
1001
|
* ```ts
|
|
922
1002
|
* pipe(
|
|
923
|
-
* Dict.
|
|
924
|
-
* Dict.difference(Dict.
|
|
1003
|
+
* Dict.from.Entries([["a", 1], ["b", 2], ["c", 3]]),
|
|
1004
|
+
* Dict.difference(Dict.from.Entries([["b", 0]])),
|
|
925
1005
|
* );
|
|
926
1006
|
* // ReadonlyMap { "a" => 1, "c" => 3 }
|
|
927
1007
|
* ```
|
|
@@ -934,7 +1014,7 @@ declare namespace Dict {
|
|
|
934
1014
|
* @example
|
|
935
1015
|
* ```ts
|
|
936
1016
|
* Dict.reduce(0, (acc, value) => acc + value)(
|
|
937
|
-
* Dict.
|
|
1017
|
+
* Dict.from.Entries([["a", 1], ["b", 2], ["c", 3]])
|
|
938
1018
|
* ); // 6
|
|
939
1019
|
* ```
|
|
940
1020
|
*/
|
|
@@ -946,20 +1026,23 @@ declare namespace Dict {
|
|
|
946
1026
|
* @example
|
|
947
1027
|
* ```ts
|
|
948
1028
|
* Dict.reduceWithKey("", (acc, value, key) => acc + key + ":" + value + " ")(
|
|
949
|
-
* Dict.
|
|
1029
|
+
* Dict.from.Entries([["a", 1], ["b", 2]])
|
|
950
1030
|
* ); // "a:1 b:2 "
|
|
951
1031
|
* ```
|
|
952
1032
|
*/
|
|
953
1033
|
const reduceWithKey: <K, A, B>(init: B, f: (acc: B, value: A, key: K) => B) => (m: ReadonlyMap<K, A>) => B;
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
1034
|
+
namespace to {
|
|
1035
|
+
/**
|
|
1036
|
+
* Converts a `ReadonlyMap<string, V>` to a plain object. Only meaningful when keys are strings.
|
|
1037
|
+
*
|
|
1038
|
+
* @example
|
|
1039
|
+
* ```ts
|
|
1040
|
+
* Dict.to.Record(Dict.from.Entries([["a", 1], ["b", 2]])); // { a: 1, b: 2 }
|
|
1041
|
+
* ```
|
|
1042
|
+
*/
|
|
1043
|
+
const Record: <V>(m: ReadonlyMap<string, V>) => Readonly<Record<string, V>>;
|
|
1044
|
+
}
|
|
1045
|
+
const NonEmpty: typeof DictNonEmpty;
|
|
963
1046
|
}
|
|
964
1047
|
|
|
965
1048
|
/**
|
|
@@ -1185,121 +1268,86 @@ declare namespace Num {
|
|
|
1185
1268
|
const max: (ns: readonly number[]) => Maybe<number>;
|
|
1186
1269
|
}
|
|
1187
1270
|
|
|
1188
|
-
declare const _nonEmptyRecord: unique symbol;
|
|
1189
1271
|
/**
|
|
1190
1272
|
* A branded type representing a record with at least one key-value pair.
|
|
1191
1273
|
*/
|
|
1192
|
-
type NonEmptyRecord<A> = Readonly<Record<
|
|
1193
|
-
|
|
1194
|
-
};
|
|
1195
|
-
declare namespace RecMaybe {
|
|
1196
|
-
/**
|
|
1197
|
-
* Map a function that returns a `Maybe` over each value of a record,
|
|
1198
|
-
* and combine the results into a single `Maybe` containing the updated record.
|
|
1199
|
-
* If any value results in `None`, the entire operation returns `None` (short-circuits).
|
|
1200
|
-
*
|
|
1201
|
-
* @example
|
|
1202
|
-
* ```ts
|
|
1203
|
-
* const parseNum = (s: string) => s === "NaN" ? Maybe.none() : Maybe.some(Number(s));
|
|
1204
|
-
* pipe({ a: "1", b: "2" }, Rec.Maybe.traverse(parseNum)); // Some({ a: 1, b: 2 })
|
|
1205
|
-
* pipe({ a: "1", b: "NaN" }, Rec.Maybe.traverse(parseNum)); // None
|
|
1206
|
-
* ```
|
|
1207
|
-
*/
|
|
1208
|
-
const traverse: <A, B>(f: (a: A) => Maybe<B>) => (data: Readonly<Record<string, A>>) => Maybe<Readonly<Record<string, B>>>;
|
|
1209
|
-
/**
|
|
1210
|
-
* Sequence a record of `Maybe` values into a `Maybe` of a record.
|
|
1211
|
-
* If any key contains `None`, the entire operation returns `None`.
|
|
1212
|
-
*
|
|
1213
|
-
* @example
|
|
1214
|
-
* ```ts
|
|
1215
|
-
* Rec.Maybe.sequence({ a: Maybe.some(1), b: Maybe.some(2) }); // Some({ a: 1, b: 2 })
|
|
1216
|
-
* Rec.Maybe.sequence({ a: Maybe.some(1), b: Maybe.none() }); // None
|
|
1217
|
-
* ```
|
|
1218
|
-
*/
|
|
1219
|
-
const sequence: <A>(data: Readonly<Record<string, Maybe<A>>>) => Maybe<Readonly<Record<string, A>>>;
|
|
1220
|
-
}
|
|
1221
|
-
declare namespace RecResult {
|
|
1222
|
-
/**
|
|
1223
|
-
* Map a function that returns a `Result` over each value of a record,
|
|
1224
|
-
* and combine the results into a single `Result` containing the updated record.
|
|
1225
|
-
* If any value results in an `Err`, the entire operation returns that `Err` (short-circuits).
|
|
1226
|
-
*
|
|
1227
|
-
* @example
|
|
1228
|
-
* ```ts
|
|
1229
|
-
* const checkPositive = (n: number) => n < 0 ? Result.err("negative") : Result.ok(n);
|
|
1230
|
-
* pipe({ a: 1, b: 2 }, Rec.Result.traverse(checkPositive)); // Ok({ a: 1, b: 2 })
|
|
1231
|
-
* pipe({ a: 1, b: -2 }, Rec.Result.traverse(checkPositive)); // Err("negative")
|
|
1232
|
-
* ```
|
|
1233
|
-
*/
|
|
1234
|
-
const traverse: <E, A, B>(f: (a: A) => Result<E, B>) => (data: Readonly<Record<string, A>>) => Result<E, Readonly<Record<string, B>>>;
|
|
1274
|
+
type NonEmptyRecord<A, K extends string = string> = Brand<NonEmpty<"Rec">, Readonly<Record<K, A>>>;
|
|
1275
|
+
declare namespace RecNonEmpty {
|
|
1235
1276
|
/**
|
|
1236
|
-
*
|
|
1237
|
-
* If any key contains an `Err`, the entire operation returns that `Err`.
|
|
1277
|
+
* Creates a NonEmpty record from a single key-value pair.
|
|
1238
1278
|
*
|
|
1239
1279
|
* @example
|
|
1240
1280
|
* ```ts
|
|
1241
|
-
* Rec.
|
|
1242
|
-
* Rec.Result.sequence({ a: Result.ok(1), b: Result.err("oops") }); // Err("oops")
|
|
1281
|
+
* Rec.NonEmpty.singleton("a", 1); // { a: 1 }
|
|
1243
1282
|
* ```
|
|
1244
1283
|
*/
|
|
1245
|
-
const
|
|
1246
|
-
|
|
1247
|
-
|
|
1284
|
+
const singleton: <K extends string, A>(key: K, value: A) => NonEmptyRecord<A, K>;
|
|
1285
|
+
namespace from {
|
|
1286
|
+
/**
|
|
1287
|
+
* Creates a NonEmpty record from a standard record if it is not empty.
|
|
1288
|
+
*
|
|
1289
|
+
* @example
|
|
1290
|
+
* ```ts
|
|
1291
|
+
* Rec.NonEmpty.from.Record({ a: 1 }); // Some({ a: 1 })
|
|
1292
|
+
* Rec.NonEmpty.from.Record({}); // None
|
|
1293
|
+
* ```
|
|
1294
|
+
*/
|
|
1295
|
+
const Record: <K extends string, A>(data: Readonly<Record<K, A>>) => Maybe<NonEmptyRecord<A, K>>;
|
|
1296
|
+
}
|
|
1248
1297
|
/**
|
|
1249
|
-
*
|
|
1298
|
+
* Returns a non-empty array of keys for a NonEmpty record.
|
|
1250
1299
|
*
|
|
1251
1300
|
* @example
|
|
1252
1301
|
* ```ts
|
|
1253
|
-
* Rec.NonEmpty.singleton("a", 1); //
|
|
1302
|
+
* Rec.NonEmpty.keys(Rec.NonEmpty.singleton("a", 1)); // ["a"]
|
|
1254
1303
|
* ```
|
|
1255
1304
|
*/
|
|
1256
|
-
const
|
|
1305
|
+
const keys: <K extends string, A>(data: NonEmptyRecord<A, K>) => NonEmptyArr<K>;
|
|
1257
1306
|
/**
|
|
1258
|
-
*
|
|
1307
|
+
* Returns a non-empty array of values for a NonEmpty record.
|
|
1259
1308
|
*
|
|
1260
1309
|
* @example
|
|
1261
1310
|
* ```ts
|
|
1262
|
-
* Rec.NonEmpty.
|
|
1263
|
-
* Rec.NonEmpty.fromRecord({}); // None
|
|
1311
|
+
* Rec.NonEmpty.values(Rec.NonEmpty.singleton("a", 1)); // [1]
|
|
1264
1312
|
* ```
|
|
1265
1313
|
*/
|
|
1266
|
-
const
|
|
1314
|
+
const values: <K extends string, A>(data: NonEmptyRecord<A, K>) => NonEmptyArr<A>;
|
|
1267
1315
|
/**
|
|
1268
|
-
* Returns a non-empty array of
|
|
1316
|
+
* Returns a non-empty array of entry tuples for a NonEmpty record.
|
|
1269
1317
|
*
|
|
1270
1318
|
* @example
|
|
1271
1319
|
* ```ts
|
|
1272
|
-
* Rec.NonEmpty.
|
|
1320
|
+
* Rec.NonEmpty.entries(Rec.NonEmpty.singleton("a", 1)); // [["a", 1]]
|
|
1273
1321
|
* ```
|
|
1274
1322
|
*/
|
|
1275
|
-
const
|
|
1323
|
+
const entries: <K extends string, A>(data: NonEmptyRecord<A, K>) => NonEmptyArr<readonly [K, A]>;
|
|
1276
1324
|
/**
|
|
1277
|
-
*
|
|
1325
|
+
* Reduces a NonEmpty record's values from the left without an initial value.
|
|
1278
1326
|
*
|
|
1279
1327
|
* @example
|
|
1280
1328
|
* ```ts
|
|
1281
|
-
*
|
|
1329
|
+
* pipe(Rec.NonEmpty.singleton("a", 1), Rec.NonEmpty.reduce((a, b) => a + b)); // 1
|
|
1282
1330
|
* ```
|
|
1283
1331
|
*/
|
|
1284
|
-
const
|
|
1332
|
+
const reduce: <A>(f: (acc: A, a: A) => A) => <K extends string>(data: NonEmptyRecord<A, K>) => A;
|
|
1285
1333
|
/**
|
|
1286
|
-
*
|
|
1334
|
+
* Transforms each value of a NonEmpty record.
|
|
1287
1335
|
*
|
|
1288
1336
|
* @example
|
|
1289
1337
|
* ```ts
|
|
1290
|
-
*
|
|
1338
|
+
* pipe(Rec.NonEmpty.singleton("a", 1), Rec.NonEmpty.map(n => n * 2)); // { a: 2 }
|
|
1291
1339
|
* ```
|
|
1292
1340
|
*/
|
|
1293
|
-
const
|
|
1341
|
+
const map: <A, B>(f: (a: A) => B) => <K extends string>(data: NonEmptyRecord<A, K>) => NonEmptyRecord<B, K>;
|
|
1294
1342
|
/**
|
|
1295
|
-
*
|
|
1343
|
+
* Transforms each value of a NonEmpty record, also receiving the key.
|
|
1296
1344
|
*
|
|
1297
1345
|
* @example
|
|
1298
1346
|
* ```ts
|
|
1299
|
-
* pipe(Rec.NonEmpty.singleton("a", 1), Rec.NonEmpty.
|
|
1347
|
+
* pipe(Rec.NonEmpty.singleton("a", 1), Rec.NonEmpty.mapWithKey((k, v) => `${k}:${v}`)); // { a: "a:1" }
|
|
1300
1348
|
* ```
|
|
1301
1349
|
*/
|
|
1302
|
-
const
|
|
1350
|
+
const mapWithKey: <A, B>(f: (key: string, a: A) => B) => <K extends string>(data: NonEmptyRecord<A, K>) => NonEmptyRecord<B, K>;
|
|
1303
1351
|
}
|
|
1304
1352
|
/**
|
|
1305
1353
|
* Functional record/object utilities that compose well with pipe.
|
|
@@ -1318,11 +1366,17 @@ declare namespace Rec {
|
|
|
1318
1366
|
/**
|
|
1319
1367
|
* A branded type representing a record with at least one key-value pair.
|
|
1320
1368
|
*/
|
|
1321
|
-
type NonEmpty<A> = NonEmptyRecord<A>;
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1369
|
+
type NonEmpty<A, K extends string = string> = NonEmptyRecord<A, K>;
|
|
1370
|
+
namespace is {
|
|
1371
|
+
/**
|
|
1372
|
+
* Returns true if the record has no keys.
|
|
1373
|
+
*/
|
|
1374
|
+
const empty: <A>(data: Readonly<Record<string, A>>) => boolean;
|
|
1375
|
+
/**
|
|
1376
|
+
* Type guard to check if a record is non-empty.
|
|
1377
|
+
*/
|
|
1378
|
+
const nonEmpty: <A, K extends string>(data: Readonly<Record<K, A>>) => data is NonEmptyRecord<A, K>;
|
|
1379
|
+
}
|
|
1326
1380
|
/**
|
|
1327
1381
|
* Transforms each value in a record.
|
|
1328
1382
|
*
|
|
@@ -1331,10 +1385,7 @@ declare namespace Rec {
|
|
|
1331
1385
|
* pipe({ a: 1, b: 2 }, Rec.map(n => n * 2)); // { a: 2, b: 4 }
|
|
1332
1386
|
* ```
|
|
1333
1387
|
*/
|
|
1334
|
-
const map: <A, B>(f: (a: A) => B) =>
|
|
1335
|
-
(data: NonEmpty<A>): NonEmpty<B>;
|
|
1336
|
-
(data: Readonly<Record<string, A>>): Readonly<Record<string, B>>;
|
|
1337
|
-
};
|
|
1388
|
+
const map: <A, B>(f: (a: A) => B) => <K extends string>(data: Readonly<Record<K, A>>) => Readonly<Record<K, B>>;
|
|
1338
1389
|
const filterMap: <A, B>(f: (a: A) => Maybe<B>) => (data: Readonly<Record<string, A>>) => Readonly<Record<string, B>>;
|
|
1339
1390
|
/**
|
|
1340
1391
|
* Transforms each value in a record, also receiving the key.
|
|
@@ -1345,10 +1396,7 @@ declare namespace Rec {
|
|
|
1345
1396
|
* // { a: "a:1", b: "b:2" }
|
|
1346
1397
|
* ```
|
|
1347
1398
|
*/
|
|
1348
|
-
const mapWithKey: <A, B>(f: (key: string, a: A) => B) =>
|
|
1349
|
-
(data: NonEmpty<A>): NonEmpty<B>;
|
|
1350
|
-
(data: Readonly<Record<string, A>>): Readonly<Record<string, B>>;
|
|
1351
|
-
};
|
|
1399
|
+
const mapWithKey: <A, B>(f: (key: string, a: A) => B) => <K extends string>(data: Readonly<Record<K, A>>) => Readonly<Record<K, B>>;
|
|
1352
1400
|
/**
|
|
1353
1401
|
* Filters values in a record by a predicate.
|
|
1354
1402
|
*
|
|
@@ -1390,15 +1438,17 @@ declare namespace Rec {
|
|
|
1390
1438
|
* Returns all key-value pairs of a record.
|
|
1391
1439
|
*/
|
|
1392
1440
|
const entries: <T extends Record<string, unknown>>(data: T) => readonly (readonly [keyof T, T[keyof T]])[];
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1441
|
+
namespace from {
|
|
1442
|
+
/**
|
|
1443
|
+
* Creates a record from key-value pairs.
|
|
1444
|
+
*
|
|
1445
|
+
* @example
|
|
1446
|
+
* ```ts
|
|
1447
|
+
* Rec.from.entries([["a", 1], ["b", 2]]); // { a: 1, b: 2 }
|
|
1448
|
+
* ```
|
|
1449
|
+
*/
|
|
1450
|
+
const entries: <A>(data: readonly (readonly [string, A])[]) => Readonly<Record<string, A>>;
|
|
1451
|
+
}
|
|
1402
1452
|
/**
|
|
1403
1453
|
* Groups elements of an array into a record keyed by the result of `keyFn`. Each key maps to
|
|
1404
1454
|
* the array of elements that produced it, in insertion order.
|
|
@@ -1442,10 +1492,6 @@ declare namespace Rec {
|
|
|
1442
1492
|
* ```
|
|
1443
1493
|
*/
|
|
1444
1494
|
const merge: <A>(other: Readonly<Record<string, A>>) => (data: Readonly<Record<string, A>>) => Readonly<Record<string, A>>;
|
|
1445
|
-
/**
|
|
1446
|
-
* Returns true if the record has no keys.
|
|
1447
|
-
*/
|
|
1448
|
-
const isEmpty: <A>(data: Readonly<Record<string, A>>) => boolean;
|
|
1449
1495
|
/**
|
|
1450
1496
|
* Returns the number of keys in a record.
|
|
1451
1497
|
*/
|
|
@@ -1467,16 +1513,26 @@ declare namespace Rec {
|
|
|
1467
1513
|
*
|
|
1468
1514
|
* @example
|
|
1469
1515
|
* ```ts
|
|
1470
|
-
* Rec.compact({ a: Maybe.some(1), b: Maybe.none(), c: Maybe.some(3) });
|
|
1516
|
+
* Rec.compact({ a: Maybe.make.some(1), b: Maybe.make.none(), c: Maybe.make.some(3) });
|
|
1471
1517
|
* // { a: 1, c: 3 }
|
|
1472
1518
|
* ```
|
|
1473
1519
|
*/
|
|
1474
1520
|
const compact: <A>(data: Readonly<Record<string, Maybe<A>>>) => Readonly<Record<string, A>>;
|
|
1475
|
-
|
|
1476
|
-
|
|
1521
|
+
namespace traverse {
|
|
1522
|
+
const Maybe: <A, B>(f: (a: A) => Maybe<B>) => (data: Readonly<Record<string, A>>) => Maybe<Readonly<Record<string, B>>>;
|
|
1523
|
+
const Result: <E, A, B>(f: (a: A) => Result<E, B>) => (data: Readonly<Record<string, A>>) => Result<E, Readonly<Record<string, B>>>;
|
|
1524
|
+
}
|
|
1525
|
+
namespace sequence {
|
|
1526
|
+
const Maybe: <A>(data: Readonly<Record<string, Maybe<A>>>) => Maybe<Readonly<Record<string, A>>>;
|
|
1527
|
+
const Result: <E, A>(data: Readonly<Record<string, Result<E, A>>>) => Result<E, Readonly<Record<string, A>>>;
|
|
1528
|
+
}
|
|
1477
1529
|
const NonEmpty: typeof RecNonEmpty;
|
|
1478
1530
|
}
|
|
1479
1531
|
|
|
1532
|
+
/**
|
|
1533
|
+
* A branded type representing a string with at least one character.
|
|
1534
|
+
*/
|
|
1535
|
+
type NonEmptyString = Brand<NonEmpty<"Str">, string>;
|
|
1480
1536
|
/**
|
|
1481
1537
|
* String utilities. All transformation functions are data-last and curried so they
|
|
1482
1538
|
* compose naturally with `pipe`. Safe parsers return `Maybe` instead of `NaN`.
|
|
@@ -1489,7 +1545,41 @@ declare namespace Rec {
|
|
|
1489
1545
|
* pipe(" Hello, World! ", Str.trim, Str.toLowerCase); // "hello, world!"
|
|
1490
1546
|
* ```
|
|
1491
1547
|
*/
|
|
1548
|
+
declare namespace StrNonEmpty {
|
|
1549
|
+
namespace from {
|
|
1550
|
+
/**
|
|
1551
|
+
* Returns Some containing NonEmptyString if the string is not empty, None otherwise.
|
|
1552
|
+
*
|
|
1553
|
+
* @example
|
|
1554
|
+
* ```ts
|
|
1555
|
+
* Str.NonEmpty.from.String("hello"); // Some("hello")
|
|
1556
|
+
* Str.NonEmpty.from.String(""); // None
|
|
1557
|
+
* ```
|
|
1558
|
+
*/
|
|
1559
|
+
const String: (s: string) => Maybe<NonEmptyString>;
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1492
1562
|
declare namespace Str {
|
|
1563
|
+
/**
|
|
1564
|
+
* A branded type representing a string with at least one character.
|
|
1565
|
+
*/
|
|
1566
|
+
type NonEmpty = NonEmptyString;
|
|
1567
|
+
namespace is {
|
|
1568
|
+
/**
|
|
1569
|
+
* Returns `true` when the string is empty.
|
|
1570
|
+
*
|
|
1571
|
+
* @example
|
|
1572
|
+
* ```ts
|
|
1573
|
+
* pipe("", Str.is.empty); // true
|
|
1574
|
+
* pipe("hi", Str.is.empty); // false
|
|
1575
|
+
* ```
|
|
1576
|
+
*/
|
|
1577
|
+
const empty: (s: string) => boolean;
|
|
1578
|
+
/**
|
|
1579
|
+
* Type guard to check if a string is non-empty.
|
|
1580
|
+
*/
|
|
1581
|
+
const nonEmpty: (s: string) => s is NonEmpty;
|
|
1582
|
+
}
|
|
1493
1583
|
/**
|
|
1494
1584
|
* Splits a string by a separator. Data-last: use in `pipe`.
|
|
1495
1585
|
*
|
|
@@ -1604,16 +1694,6 @@ declare namespace Str {
|
|
|
1604
1694
|
* ```
|
|
1605
1695
|
*/
|
|
1606
1696
|
const words: (s: string) => readonly string[];
|
|
1607
|
-
/**
|
|
1608
|
-
* Returns `true` when the string is empty.
|
|
1609
|
-
*
|
|
1610
|
-
* @example
|
|
1611
|
-
* ```ts
|
|
1612
|
-
* pipe("", Str.isEmpty); // true
|
|
1613
|
-
* pipe("hi", Str.isEmpty); // false
|
|
1614
|
-
* ```
|
|
1615
|
-
*/
|
|
1616
|
-
const isEmpty: (s: string) => boolean;
|
|
1617
1697
|
/**
|
|
1618
1698
|
* Returns `true` when the string is empty or contains only whitespace.
|
|
1619
1699
|
*
|
|
@@ -1701,8 +1781,13 @@ declare namespace Str {
|
|
|
1701
1781
|
* ```
|
|
1702
1782
|
*/
|
|
1703
1783
|
const parseJson: (s: string) => Result<SyntaxError, unknown>;
|
|
1784
|
+
const NonEmpty: typeof StrNonEmpty;
|
|
1704
1785
|
}
|
|
1705
1786
|
|
|
1787
|
+
/**
|
|
1788
|
+
* A branded type representing a unique collection with at least one element.
|
|
1789
|
+
*/
|
|
1790
|
+
type NonEmptySet<A> = Brand<NonEmpty<"Uniq">, ReadonlySet<A>>;
|
|
1706
1791
|
/**
|
|
1707
1792
|
* Functional utilities for unique-value collections (`ReadonlySet<A>`). All functions are pure
|
|
1708
1793
|
* and data-last — they compose naturally with `pipe`.
|
|
@@ -1715,78 +1800,142 @@ declare namespace Str {
|
|
|
1715
1800
|
* import { pipe } from "@nlozgachev/pipelined/composition";
|
|
1716
1801
|
*
|
|
1717
1802
|
* const active = pipe(
|
|
1718
|
-
* Uniq.
|
|
1803
|
+
* Uniq.from.Array(["alice", "bob", "alice", "carol"]),
|
|
1719
1804
|
* Uniq.remove("bob"),
|
|
1720
1805
|
* Uniq.map(name => name.toUpperCase()),
|
|
1721
1806
|
* );
|
|
1722
1807
|
* // ReadonlySet { "ALICE", "CAROL" }
|
|
1723
1808
|
* ```
|
|
1724
1809
|
*/
|
|
1725
|
-
declare namespace
|
|
1810
|
+
declare namespace UniqNonEmpty {
|
|
1726
1811
|
/**
|
|
1727
|
-
* Creates
|
|
1812
|
+
* Creates a single-element unique collection.
|
|
1728
1813
|
*
|
|
1729
1814
|
* @example
|
|
1730
1815
|
* ```ts
|
|
1731
|
-
* Uniq.
|
|
1816
|
+
* Uniq.NonEmpty.singleton(42); // ReadonlySet { 42 }
|
|
1732
1817
|
* ```
|
|
1733
1818
|
*/
|
|
1734
|
-
const
|
|
1819
|
+
const singleton: <A>(item: A) => NonEmptySet<A>;
|
|
1820
|
+
namespace from {
|
|
1821
|
+
/**
|
|
1822
|
+
* Returns Some containing NonEmptySet if the set is not empty, None otherwise.
|
|
1823
|
+
*
|
|
1824
|
+
* @example
|
|
1825
|
+
* ```ts
|
|
1826
|
+
* Uniq.NonEmpty.from.Set(Uniq.from.Array([1, 2])); // Some(ReadonlySet { 1, 2 })
|
|
1827
|
+
* Uniq.NonEmpty.from.Set(Uniq.empty()); // None
|
|
1828
|
+
* ```
|
|
1829
|
+
*/
|
|
1830
|
+
const Set: <A>(s: ReadonlySet<A>) => Maybe<NonEmptySet<A>>;
|
|
1831
|
+
}
|
|
1735
1832
|
/**
|
|
1736
|
-
*
|
|
1833
|
+
* Folds the collection into a single value without an initial seed value.
|
|
1737
1834
|
*
|
|
1738
1835
|
* @example
|
|
1739
1836
|
* ```ts
|
|
1740
|
-
* Uniq.singleton(42); //
|
|
1837
|
+
* pipe(Uniq.NonEmpty.singleton(42), Uniq.NonEmpty.reduce((a, b) => a + b)); // 42
|
|
1741
1838
|
* ```
|
|
1742
1839
|
*/
|
|
1743
|
-
const
|
|
1840
|
+
const reduce: <A>(f: (acc: A, a: A) => A) => (s: NonEmptySet<A>) => A;
|
|
1744
1841
|
/**
|
|
1745
|
-
*
|
|
1842
|
+
* Transforms each item in the non-empty unique collection.
|
|
1746
1843
|
*
|
|
1747
1844
|
* @example
|
|
1748
1845
|
* ```ts
|
|
1749
|
-
* Uniq.
|
|
1750
|
-
* Uniq.fromArray([]); // ReadonlySet {}
|
|
1846
|
+
* pipe(Uniq.NonEmpty.singleton(1), Uniq.NonEmpty.map(n => n * 2)); // ReadonlySet { 2 }
|
|
1751
1847
|
* ```
|
|
1752
1848
|
*/
|
|
1753
|
-
const
|
|
1849
|
+
const map: <A, B>(f: (a: A) => B) => (s: NonEmptySet<A>) => NonEmptySet<B>;
|
|
1850
|
+
namespace to {
|
|
1851
|
+
/**
|
|
1852
|
+
* Converts the collection to a non-empty readonly array in insertion order.
|
|
1853
|
+
*
|
|
1854
|
+
* @example
|
|
1855
|
+
* ```ts
|
|
1856
|
+
* Uniq.NonEmpty.to.Array(Uniq.NonEmpty.singleton(42)); // [42]
|
|
1857
|
+
* ```
|
|
1858
|
+
*/
|
|
1859
|
+
const Array: <A>(s: NonEmptySet<A>) => NonEmptyArr<A>;
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
declare namespace Uniq {
|
|
1754
1863
|
/**
|
|
1755
|
-
*
|
|
1864
|
+
* A branded type representing a unique collection with at least one element.
|
|
1865
|
+
*/
|
|
1866
|
+
type NonEmpty<A> = NonEmptySet<A>;
|
|
1867
|
+
namespace is {
|
|
1868
|
+
/**
|
|
1869
|
+
* Returns `true` if the collection has no items.
|
|
1870
|
+
*
|
|
1871
|
+
* @example
|
|
1872
|
+
* ```ts
|
|
1873
|
+
* Uniq.is.empty(Uniq.empty()); // true
|
|
1874
|
+
* ```
|
|
1875
|
+
*/
|
|
1876
|
+
const empty: <A>(s: ReadonlySet<A>) => boolean;
|
|
1877
|
+
/**
|
|
1878
|
+
* Type guard to check if a unique collection is non-empty.
|
|
1879
|
+
*/
|
|
1880
|
+
const nonEmpty: <A>(s: ReadonlySet<A>) => s is NonEmpty<A>;
|
|
1881
|
+
}
|
|
1882
|
+
/**
|
|
1883
|
+
* Creates an empty unique collection.
|
|
1756
1884
|
*
|
|
1757
1885
|
* @example
|
|
1758
1886
|
* ```ts
|
|
1759
|
-
*
|
|
1760
|
-
* pipe(Uniq.fromArray([1, 2, 3]), Uniq.has(4)); // false
|
|
1887
|
+
* Uniq.empty<number>(); // ReadonlySet {}
|
|
1761
1888
|
* ```
|
|
1762
1889
|
*/
|
|
1763
|
-
const
|
|
1890
|
+
const empty: <A>() => ReadonlySet<A>;
|
|
1764
1891
|
/**
|
|
1765
|
-
*
|
|
1892
|
+
* Creates a unique collection containing a single item.
|
|
1766
1893
|
*
|
|
1767
1894
|
* @example
|
|
1768
1895
|
* ```ts
|
|
1769
|
-
* Uniq.
|
|
1896
|
+
* Uniq.singleton(42); // ReadonlySet { 42 }
|
|
1770
1897
|
* ```
|
|
1771
1898
|
*/
|
|
1772
|
-
const
|
|
1899
|
+
const singleton: <A>(item: A) => ReadonlySet<A>;
|
|
1900
|
+
namespace from {
|
|
1901
|
+
/**
|
|
1902
|
+
* Creates a unique collection from an array, automatically discarding duplicates.
|
|
1903
|
+
*
|
|
1904
|
+
* @example
|
|
1905
|
+
* ```ts
|
|
1906
|
+
* Uniq.from.Array([1, 2, 2, 3, 3, 3]); // ReadonlySet { 1, 2, 3 }
|
|
1907
|
+
* Uniq.from.Array([]); // ReadonlySet {}
|
|
1908
|
+
* ```
|
|
1909
|
+
*/
|
|
1910
|
+
const Array: <A>(arr: readonly A[]) => ReadonlySet<A>;
|
|
1911
|
+
}
|
|
1773
1912
|
/**
|
|
1774
|
-
* Returns `true` if the collection
|
|
1913
|
+
* Returns `true` if the collection contains the given item.
|
|
1775
1914
|
*
|
|
1776
1915
|
* @example
|
|
1777
1916
|
* ```ts
|
|
1778
|
-
* Uniq.
|
|
1917
|
+
* pipe(Uniq.from.Array([1, 2, 3]), Uniq.has(2)); // true
|
|
1918
|
+
* pipe(Uniq.from.Array([1, 2, 3]), Uniq.has(4)); // false
|
|
1779
1919
|
* ```
|
|
1780
1920
|
*/
|
|
1781
|
-
const
|
|
1921
|
+
const has: <A>(item: A) => (s: ReadonlySet<A>) => boolean;
|
|
1922
|
+
/**
|
|
1923
|
+
* Returns the number of items in the collection.
|
|
1924
|
+
*
|
|
1925
|
+
* @example
|
|
1926
|
+
* ```ts
|
|
1927
|
+
* Uniq.size(Uniq.from.Array([1, 2, 3])); // 3
|
|
1928
|
+
* ```
|
|
1929
|
+
*/
|
|
1930
|
+
const size: <A>(s: ReadonlySet<A>) => number;
|
|
1782
1931
|
/**
|
|
1783
1932
|
* Returns `true` if every item in `set` also exists in `other`.
|
|
1784
1933
|
*
|
|
1785
1934
|
* @example
|
|
1786
1935
|
* ```ts
|
|
1787
|
-
* pipe(Uniq.
|
|
1788
|
-
* pipe(Uniq.
|
|
1789
|
-
* pipe(Uniq.empty<number>(), Uniq.isSubsetOf(Uniq.
|
|
1936
|
+
* pipe(Uniq.from.Array([1, 2]), Uniq.isSubsetOf(Uniq.from.Array([1, 2, 3]))); // true
|
|
1937
|
+
* pipe(Uniq.from.Array([1, 4]), Uniq.isSubsetOf(Uniq.from.Array([1, 2, 3]))); // false
|
|
1938
|
+
* pipe(Uniq.empty<number>(), Uniq.isSubsetOf(Uniq.from.Array([1, 2, 3]))); // true
|
|
1790
1939
|
* ```
|
|
1791
1940
|
*/
|
|
1792
1941
|
const isSubsetOf: <A>(other: ReadonlySet<A>) => (s: ReadonlySet<A>) => boolean;
|
|
@@ -1796,8 +1945,8 @@ declare namespace Uniq {
|
|
|
1796
1945
|
*
|
|
1797
1946
|
* @example
|
|
1798
1947
|
* ```ts
|
|
1799
|
-
* pipe(Uniq.
|
|
1800
|
-
* pipe(Uniq.
|
|
1948
|
+
* pipe(Uniq.from.Array([1, 2]), Uniq.insert(3)); // ReadonlySet { 1, 2, 3 }
|
|
1949
|
+
* pipe(Uniq.from.Array([1, 2]), Uniq.insert(2)); // ReadonlySet { 1, 2 } — unchanged
|
|
1801
1950
|
* ```
|
|
1802
1951
|
*/
|
|
1803
1952
|
const insert: <A>(item: A) => (s: ReadonlySet<A>) => ReadonlySet<A>;
|
|
@@ -1807,8 +1956,8 @@ declare namespace Uniq {
|
|
|
1807
1956
|
*
|
|
1808
1957
|
* @example
|
|
1809
1958
|
* ```ts
|
|
1810
|
-
* pipe(Uniq.
|
|
1811
|
-
* pipe(Uniq.
|
|
1959
|
+
* pipe(Uniq.from.Array([1, 2, 3]), Uniq.remove(2)); // ReadonlySet { 1, 3 }
|
|
1960
|
+
* pipe(Uniq.from.Array([1, 2, 3]), Uniq.remove(4)); // ReadonlySet { 1, 2, 3 } — unchanged
|
|
1812
1961
|
* ```
|
|
1813
1962
|
*/
|
|
1814
1963
|
const remove: <A>(item: A) => (s: ReadonlySet<A>) => ReadonlySet<A>;
|
|
@@ -1818,7 +1967,7 @@ declare namespace Uniq {
|
|
|
1818
1967
|
*
|
|
1819
1968
|
* @example
|
|
1820
1969
|
* ```ts
|
|
1821
|
-
* pipe(Uniq.
|
|
1970
|
+
* pipe(Uniq.from.Array([1, 2, 3, 4]), Uniq.map(n => n % 3)); // ReadonlySet { 1, 2, 0 }
|
|
1822
1971
|
* ```
|
|
1823
1972
|
*/
|
|
1824
1973
|
const map: <A, B>(f: (a: A) => B) => (s: ReadonlySet<A>) => ReadonlySet<B>;
|
|
@@ -1827,7 +1976,7 @@ declare namespace Uniq {
|
|
|
1827
1976
|
*
|
|
1828
1977
|
* @example
|
|
1829
1978
|
* ```ts
|
|
1830
|
-
* pipe(Uniq.
|
|
1979
|
+
* pipe(Uniq.from.Array([1, 2, 3, 4, 5]), Uniq.filter(n => n % 2 === 0));
|
|
1831
1980
|
* // ReadonlySet { 2, 4 }
|
|
1832
1981
|
* ```
|
|
1833
1982
|
*/
|
|
@@ -1837,7 +1986,7 @@ declare namespace Uniq {
|
|
|
1837
1986
|
*
|
|
1838
1987
|
* @example
|
|
1839
1988
|
* ```ts
|
|
1840
|
-
* pipe(Uniq.
|
|
1989
|
+
* pipe(Uniq.from.Array([1, 2, 3]), Uniq.union(Uniq.from.Array([2, 3, 4])));
|
|
1841
1990
|
* // ReadonlySet { 1, 2, 3, 4 }
|
|
1842
1991
|
* ```
|
|
1843
1992
|
*/
|
|
@@ -1847,7 +1996,7 @@ declare namespace Uniq {
|
|
|
1847
1996
|
*
|
|
1848
1997
|
* @example
|
|
1849
1998
|
* ```ts
|
|
1850
|
-
* pipe(Uniq.
|
|
1999
|
+
* pipe(Uniq.from.Array([1, 2, 3]), Uniq.intersection(Uniq.from.Array([2, 3, 4])));
|
|
1851
2000
|
* // ReadonlySet { 2, 3 }
|
|
1852
2001
|
* ```
|
|
1853
2002
|
*/
|
|
@@ -1857,7 +2006,7 @@ declare namespace Uniq {
|
|
|
1857
2006
|
*
|
|
1858
2007
|
* @example
|
|
1859
2008
|
* ```ts
|
|
1860
|
-
* pipe(Uniq.
|
|
2009
|
+
* pipe(Uniq.from.Array([1, 2, 3, 4]), Uniq.difference(Uniq.from.Array([2, 4])));
|
|
1861
2010
|
* // ReadonlySet { 1, 3 }
|
|
1862
2011
|
* ```
|
|
1863
2012
|
*/
|
|
@@ -1867,19 +2016,22 @@ declare namespace Uniq {
|
|
|
1867
2016
|
*
|
|
1868
2017
|
* @example
|
|
1869
2018
|
* ```ts
|
|
1870
|
-
* Uniq.reduce(0, (acc, n) => acc + n)(Uniq.
|
|
2019
|
+
* Uniq.reduce(0, (acc, n) => acc + n)(Uniq.from.Array([1, 2, 3])); // 6
|
|
1871
2020
|
* ```
|
|
1872
2021
|
*/
|
|
1873
2022
|
const reduce: <A, B>(init: B, f: (acc: B, a: A) => B) => (s: ReadonlySet<A>) => B;
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
2023
|
+
namespace to {
|
|
2024
|
+
/**
|
|
2025
|
+
* Converts the collection to a readonly array in insertion order.
|
|
2026
|
+
*
|
|
2027
|
+
* @example
|
|
2028
|
+
* ```ts
|
|
2029
|
+
* Uniq.to.Array(Uniq.from.Array([3, 1, 2])); // [3, 1, 2]
|
|
2030
|
+
* ```
|
|
2031
|
+
*/
|
|
2032
|
+
const Array: <A>(s: ReadonlySet<A>) => readonly A[];
|
|
2033
|
+
}
|
|
2034
|
+
const NonEmpty: typeof UniqNonEmpty;
|
|
1883
2035
|
}
|
|
1884
2036
|
|
|
1885
|
-
export { Arr, Dict, type NonEmptyRecord, Num, Rec, Str, Uniq };
|
|
2037
|
+
export { Arr, Dict, type NonEmptyMap, type NonEmptyRecord, type NonEmptySet, type NonEmptyString, Num, Rec, Str, Uniq };
|