@nlozgachev/pipelined 0.42.0 → 0.43.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/InternalTypes-DsCqxWZm.d.mts +118 -0
- package/dist/InternalTypes-DuzMFAfJ.d.ts +118 -0
- package/dist/{Task-BprUabHP.d.mts → Validation-BOPLiDqa.d.ts} +875 -111
- package/dist/{Task-Dt3ZMen6.d.ts → Validation-Do6uWLLZ.d.mts} +875 -111
- package/dist/{chunk-GBB6LVLI.mjs → chunk-74JKKJ4R.mjs} +0 -4
- package/dist/{chunk-OAP765G3.mjs → chunk-CHRXZIJU.mjs} +177 -135
- package/dist/{chunk-6VYLZTAM.mjs → chunk-W6RWKBDX.mjs} +157 -69
- package/dist/{chunk-F6SBU7GB.mjs → chunk-X6XQX3OZ.mjs} +3 -3
- package/dist/composition.d.mts +45 -44
- package/dist/composition.d.ts +45 -44
- package/dist/composition.js +2 -2
- package/dist/composition.mjs +2 -2
- package/dist/core.d.mts +10 -812
- package/dist/core.d.ts +10 -812
- package/dist/core.js +175 -137
- package/dist/core.mjs +2 -8
- package/dist/index.d.mts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +331 -208
- package/dist/index.mjs +5 -13
- package/dist/types.d.mts +112 -17
- package/dist/types.d.ts +112 -17
- package/dist/types.js +2 -7
- package/dist/types.mjs +3 -5
- package/dist/utils.d.mts +345 -89
- package/dist/utils.d.ts +345 -89
- package/dist/utils.js +429 -107
- package/dist/utils.mjs +3 -3
- package/package.json +2 -2
- package/dist/Duration-BTeT9D-q.d.mts +0 -127
- package/dist/Duration-BTeT9D-q.d.ts +0 -127
package/dist/utils.d.mts
CHANGED
|
@@ -1,7 +1,160 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import './
|
|
1
|
+
import { N as NonEmptyArr } from './InternalTypes-DsCqxWZm.mjs';
|
|
2
|
+
import { M as Maybe, R as Result, E as Equality, b as Ordering, T as Task } from './Validation-Do6uWLLZ.mjs';
|
|
3
|
+
import './types.mjs';
|
|
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
|
+
declare namespace ArrTaskResult {
|
|
55
|
+
/**
|
|
56
|
+
* Maps each element to a TaskResult and runs them sequentially.
|
|
57
|
+
* Returns the first Err encountered, or Ok of all results if all succeed.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* const validate = (n: number): Task.Result<string, number> =>
|
|
62
|
+
* n > 0 ? Task.Result.ok(n) : Task.Result.err("non-positive");
|
|
63
|
+
*
|
|
64
|
+
* pipe(
|
|
65
|
+
* [1, 2, 3],
|
|
66
|
+
* Arr.Task.Result.traverse(validate)
|
|
67
|
+
* )(); // Deferred<Ok([1, 2, 3])>
|
|
68
|
+
*
|
|
69
|
+
* pipe(
|
|
70
|
+
* [1, -1, 3],
|
|
71
|
+
* Arr.Task.Result.traverse(validate)
|
|
72
|
+
* )(); // Deferred<Err("non-positive")>
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
const traverse: <E, A, B>(f: (a: A) => Task<Result<E, B>>) => (data: readonly A[]) => Task<Result<E, readonly B[]>>;
|
|
76
|
+
/**
|
|
77
|
+
* Collects an array of TaskResults into a TaskResult of array.
|
|
78
|
+
* Returns the first Err if any element is Err, runs sequentially.
|
|
79
|
+
*/
|
|
80
|
+
const sequence: <E, A>(data: readonly Task<Result<E, A>>[]) => Task<Result<E, readonly A[]>>;
|
|
81
|
+
}
|
|
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
|
+
declare namespace ArrNonEmpty {
|
|
102
|
+
/**
|
|
103
|
+
* Creates a single-element list.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* Arr.NonEmpty.singleton(42); // [42]
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
const singleton: <A>(value: A) => NonEmptyArr<A>;
|
|
111
|
+
/**
|
|
112
|
+
* Returns Some if the array is non-empty, None otherwise.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```ts
|
|
116
|
+
* Arr.NonEmpty.fromArray([1, 2]); // Some([1, 2])
|
|
117
|
+
* Arr.NonEmpty.fromArray([]); // None
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
const fromArray: <A>(data: readonly A[]) => Maybe<NonEmptyArr<A>>;
|
|
121
|
+
/**
|
|
122
|
+
* Returns the first element of a NonEmptyArr.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* Arr.NonEmpty.head([1, 2, 3]); // 1
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
const head: <A>(data: NonEmptyArr<A>) => A;
|
|
130
|
+
/**
|
|
131
|
+
* Returns the last element of a NonEmptyArr.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* Arr.NonEmpty.last([1, 2, 3]); // 3
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
const last: <A>(data: NonEmptyArr<A>) => A;
|
|
139
|
+
/**
|
|
140
|
+
* Returns all elements except the first.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* Arr.NonEmpty.tail([1, 2, 3]); // [2, 3]
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
const tail: <A>(data: NonEmptyArr<A>) => readonly A[];
|
|
148
|
+
/**
|
|
149
|
+
* Reduces a NonEmptyArr from the left without an initial value.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```ts
|
|
153
|
+
* pipe([1, 2, 3, 4] as NonEmptyArr<number>, Arr.NonEmpty.reduce((a, b) => a + b)); // 10
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
const reduce: <A>(f: (acc: A, a: A) => A) => (data: NonEmptyArr<A>) => A;
|
|
157
|
+
}
|
|
5
158
|
/**
|
|
6
159
|
* Functional array utilities that compose well with pipe.
|
|
7
160
|
* All functions are data-last and curried where applicable.
|
|
@@ -18,6 +171,16 @@ import './Duration-BTeT9D-q.mjs';
|
|
|
18
171
|
* ```
|
|
19
172
|
*/
|
|
20
173
|
declare namespace Arr {
|
|
174
|
+
/**
|
|
175
|
+
* A type alias representing an array that is guaranteed to contain at least one element.
|
|
176
|
+
* Under the hood, this is a read-only tuple structure: `readonly [A, ...A[]]`.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```ts
|
|
180
|
+
* const list: Arr.NonEmpty<number> = [1, 2, 3];
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
type NonEmpty<A> = NonEmptyArr<A>;
|
|
21
184
|
/**
|
|
22
185
|
* Returns the first element of an array, or None if the array is empty.
|
|
23
186
|
*
|
|
@@ -93,7 +256,10 @@ declare namespace Arr {
|
|
|
93
256
|
* pipe([1, 2, 3], Arr.map(n => n * 2)); // [2, 4, 6]
|
|
94
257
|
* ```
|
|
95
258
|
*/
|
|
96
|
-
const map: <A, B>(f: (a: A) => B) =>
|
|
259
|
+
const map: <A, B>(f: (a: A) => B) => {
|
|
260
|
+
(data: NonEmpty<A>): NonEmpty<B>;
|
|
261
|
+
(data: readonly A[]): readonly B[];
|
|
262
|
+
};
|
|
97
263
|
/**
|
|
98
264
|
* Transforms each element using both its value and its zero-based index.
|
|
99
265
|
*
|
|
@@ -105,7 +271,10 @@ declare namespace Arr {
|
|
|
105
271
|
* ); // [{ position: 1, value: "a" }, { position: 2, value: "b" }, { position: 3, value: "c" }]
|
|
106
272
|
* ```
|
|
107
273
|
*/
|
|
108
|
-
const mapWithIndex: <A, B>(f: (i: number, a: A) => B) =>
|
|
274
|
+
const mapWithIndex: <A, B>(f: (i: number, a: A) => B) => {
|
|
275
|
+
(data: NonEmpty<A>): NonEmpty<B>;
|
|
276
|
+
(data: readonly A[]): readonly B[];
|
|
277
|
+
};
|
|
109
278
|
/**
|
|
110
279
|
* Filters elements that satisfy the predicate.
|
|
111
280
|
*
|
|
@@ -184,7 +353,7 @@ declare namespace Arr {
|
|
|
184
353
|
* ); // { a: ["apple", "avocado"], b: ["banana"] }
|
|
185
354
|
* ```
|
|
186
355
|
*/
|
|
187
|
-
const groupBy: <A>(f: (a: A) => string) => (data: readonly A[]) => Record<string,
|
|
356
|
+
const groupBy: <A>(f: (a: A) => string) => (data: readonly A[]) => Record<string, NonEmptyArr<A>>;
|
|
188
357
|
/**
|
|
189
358
|
* Removes duplicate elements using strict equality.
|
|
190
359
|
*
|
|
@@ -272,7 +441,23 @@ declare namespace Arr {
|
|
|
272
441
|
* pipe([1, 2, 3], Arr.intersperse(0)); // [1, 0, 2, 0, 3]
|
|
273
442
|
* ```
|
|
274
443
|
*/
|
|
275
|
-
const intersperse: <A>(sep: A) =>
|
|
444
|
+
const intersperse: <A>(sep: A) => {
|
|
445
|
+
(data: NonEmpty<A>): NonEmpty<A>;
|
|
446
|
+
(data: readonly A[]): readonly A[];
|
|
447
|
+
};
|
|
448
|
+
/**
|
|
449
|
+
* Concatenates a standard array or NonEmptyArr with another array.
|
|
450
|
+
* If the first array is a NonEmptyArr, the result is guaranteed to be a NonEmptyArr.
|
|
451
|
+
*
|
|
452
|
+
* @example
|
|
453
|
+
* ```ts
|
|
454
|
+
* pipe([1, 2], Arr.concat([3, 4])); // [1, 2, 3, 4]
|
|
455
|
+
* ```
|
|
456
|
+
*/
|
|
457
|
+
const concat: <A>(other: readonly A[]) => {
|
|
458
|
+
(data: NonEmpty<A>): NonEmpty<A>;
|
|
459
|
+
(data: readonly A[]): readonly A[];
|
|
460
|
+
};
|
|
276
461
|
/**
|
|
277
462
|
* Splits an array into chunks of the given size.
|
|
278
463
|
*
|
|
@@ -309,97 +494,31 @@ declare namespace Arr {
|
|
|
309
494
|
* ```
|
|
310
495
|
*/
|
|
311
496
|
const reduce: <A, B>(initial: B, f: (acc: B, a: A) => B) => (data: readonly A[]) => B;
|
|
497
|
+
const Maybe: typeof ArrMaybe;
|
|
498
|
+
const Result: typeof ArrResult;
|
|
499
|
+
const Task: typeof ArrTask;
|
|
312
500
|
/**
|
|
313
|
-
*
|
|
314
|
-
* Returns None if any mapping returns None.
|
|
315
|
-
*
|
|
316
|
-
* @example
|
|
317
|
-
* ```ts
|
|
318
|
-
* const parseNum = (s: string): Maybe<number> => {
|
|
319
|
-
* const n = Number(s);
|
|
320
|
-
* return isNaN(n) ? Maybe.none() : Maybe.some(n);
|
|
321
|
-
* };
|
|
322
|
-
*
|
|
323
|
-
* pipe(["1", "2", "3"], Arr.traverse(parseNum)); // Some([1, 2, 3])
|
|
324
|
-
* pipe(["1", "x", "3"], Arr.traverse(parseNum)); // None
|
|
325
|
-
* ```
|
|
326
|
-
*/
|
|
327
|
-
const traverse: <A, B>(f: (a: A) => Maybe<B>) => (data: readonly A[]) => Maybe<readonly B[]>;
|
|
328
|
-
/**
|
|
329
|
-
* Maps each element to a Result and collects the results.
|
|
330
|
-
* Returns the first Err if any mapping fails.
|
|
331
|
-
*
|
|
332
|
-
* @example
|
|
333
|
-
* ```ts
|
|
334
|
-
* pipe(
|
|
335
|
-
* [1, 2, 3],
|
|
336
|
-
* Arr.traverseResult(n => n > 0 ? Result.ok(n) : Result.err("negative"))
|
|
337
|
-
* ); // Ok([1, 2, 3])
|
|
338
|
-
* ```
|
|
501
|
+
* Returns true if the array is non-empty (type guard).
|
|
339
502
|
*/
|
|
340
|
-
const
|
|
503
|
+
const isNonEmpty: <A>(data: readonly A[]) => data is NonEmpty<A>;
|
|
341
504
|
/**
|
|
342
|
-
*
|
|
505
|
+
* Prepends a value to the beginning of an array, returning a NonEmptyArr.
|
|
343
506
|
*
|
|
344
507
|
* @example
|
|
345
508
|
* ```ts
|
|
346
|
-
* pipe(
|
|
347
|
-
* [1, 2, 3],
|
|
348
|
-
* Arr.traverseTask(n => Task.resolve(n * 2))
|
|
349
|
-
* )(); // Promise<[2, 4, 6]>
|
|
509
|
+
* pipe([1, 2], Arr.prepend(0)); // [0, 1, 2]
|
|
350
510
|
* ```
|
|
351
511
|
*/
|
|
352
|
-
const
|
|
512
|
+
const prepend: <A>(value: A) => (data: readonly A[]) => NonEmpty<A>;
|
|
353
513
|
/**
|
|
354
|
-
*
|
|
355
|
-
* Returns None if any element is None.
|
|
514
|
+
* Appends a value to the end of an array, returning a NonEmptyArr.
|
|
356
515
|
*
|
|
357
516
|
* @example
|
|
358
517
|
* ```ts
|
|
359
|
-
*
|
|
360
|
-
* Arr.sequence([Maybe.some(1), Maybe.none()]); // None
|
|
518
|
+
* pipe([1, 2], Arr.append(3)); // [1, 2, 3]
|
|
361
519
|
* ```
|
|
362
520
|
*/
|
|
363
|
-
const
|
|
364
|
-
/**
|
|
365
|
-
* Collects an array of Results into a Result of array.
|
|
366
|
-
* Returns the first Err if any element is Err.
|
|
367
|
-
*/
|
|
368
|
-
const sequenceResult: <E, A>(data: readonly Result<E, A>[]) => Result<E, readonly A[]>;
|
|
369
|
-
/**
|
|
370
|
-
* Collects an array of Tasks into a Task of array. Runs in parallel.
|
|
371
|
-
*/
|
|
372
|
-
const sequenceTask: <A>(data: readonly Task<A>[]) => Task<readonly A[]>;
|
|
373
|
-
/**
|
|
374
|
-
* Maps each element to a TaskResult and runs them sequentially.
|
|
375
|
-
* Returns the first Err encountered, or Ok of all results if all succeed.
|
|
376
|
-
*
|
|
377
|
-
* @example
|
|
378
|
-
* ```ts
|
|
379
|
-
* const validate = (n: number): TaskResult<string, number> =>
|
|
380
|
-
* n > 0 ? TaskResult.ok(n) : TaskResult.err("non-positive");
|
|
381
|
-
*
|
|
382
|
-
* pipe(
|
|
383
|
-
* [1, 2, 3],
|
|
384
|
-
* Arr.traverseTaskResult(validate)
|
|
385
|
-
* )(); // Deferred<Ok([1, 2, 3])>
|
|
386
|
-
*
|
|
387
|
-
* pipe(
|
|
388
|
-
* [1, -1, 3],
|
|
389
|
-
* Arr.traverseTaskResult(validate)
|
|
390
|
-
* )(); // Deferred<Err("non-positive")>
|
|
391
|
-
* ```
|
|
392
|
-
*/
|
|
393
|
-
const traverseTaskResult: <E, A, B>(f: (a: A) => Task<Result<E, B>>) => (data: readonly A[]) => Task<Result<E, readonly B[]>>;
|
|
394
|
-
/**
|
|
395
|
-
* Collects an array of TaskResults into a TaskResult of array.
|
|
396
|
-
* Returns the first Err if any element is Err, runs sequentially.
|
|
397
|
-
*/
|
|
398
|
-
const sequenceTaskResult: <E, A>(data: readonly Task<Result<E, A>>[]) => Task<Result<E, readonly A[]>>;
|
|
399
|
-
/**
|
|
400
|
-
* Returns true if the array is non-empty (type guard).
|
|
401
|
-
*/
|
|
402
|
-
const isNonEmpty: <A>(data: readonly A[]) => data is NonEmptyList<A>;
|
|
521
|
+
const append: <A>(value: A) => (data: readonly A[]) => NonEmpty<A>;
|
|
403
522
|
/**
|
|
404
523
|
* Returns the length of an array.
|
|
405
524
|
*/
|
|
@@ -430,7 +549,10 @@ declare namespace Arr {
|
|
|
430
549
|
* Arr.reverse([1, 2, 3]); // [3, 2, 1]
|
|
431
550
|
* ```
|
|
432
551
|
*/
|
|
433
|
-
const reverse:
|
|
552
|
+
const reverse: {
|
|
553
|
+
<A>(data: NonEmpty<A>): NonEmpty<A>;
|
|
554
|
+
<A>(data: readonly A[]): readonly A[];
|
|
555
|
+
};
|
|
434
556
|
/**
|
|
435
557
|
* Returns a new array with `item` inserted before the element at `index`.
|
|
436
558
|
* Negative indices are clamped to 0; indices beyond the array length append to the end.
|
|
@@ -513,6 +635,7 @@ declare namespace Arr {
|
|
|
513
635
|
* ```
|
|
514
636
|
*/
|
|
515
637
|
const splitAt: (index: number) => <A>(data: readonly A[]) => readonly [readonly A[], readonly A[]];
|
|
638
|
+
const NonEmpty: typeof ArrNonEmpty;
|
|
516
639
|
}
|
|
517
640
|
|
|
518
641
|
/**
|
|
@@ -1062,6 +1185,122 @@ declare namespace Num {
|
|
|
1062
1185
|
const max: (ns: readonly number[]) => Maybe<number>;
|
|
1063
1186
|
}
|
|
1064
1187
|
|
|
1188
|
+
declare const _nonEmptyRecord: unique symbol;
|
|
1189
|
+
/**
|
|
1190
|
+
* A branded type representing a record with at least one key-value pair.
|
|
1191
|
+
*/
|
|
1192
|
+
type NonEmptyRecord<A> = Readonly<Record<string, A>> & {
|
|
1193
|
+
readonly [_nonEmptyRecord]: true;
|
|
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>>>;
|
|
1235
|
+
/**
|
|
1236
|
+
* Sequence a record of `Result` values into a `Result` of a record.
|
|
1237
|
+
* If any key contains an `Err`, the entire operation returns that `Err`.
|
|
1238
|
+
*
|
|
1239
|
+
* @example
|
|
1240
|
+
* ```ts
|
|
1241
|
+
* Rec.Result.sequence({ a: Result.ok(1), b: Result.ok(2) }); // Ok({ a: 1, b: 2 })
|
|
1242
|
+
* Rec.Result.sequence({ a: Result.ok(1), b: Result.err("oops") }); // Err("oops")
|
|
1243
|
+
* ```
|
|
1244
|
+
*/
|
|
1245
|
+
const sequence: <E, A>(data: Readonly<Record<string, Result<E, A>>>) => Result<E, Readonly<Record<string, A>>>;
|
|
1246
|
+
}
|
|
1247
|
+
declare namespace RecNonEmpty {
|
|
1248
|
+
/**
|
|
1249
|
+
* Creates a NonEmpty record from a single key-value pair.
|
|
1250
|
+
*
|
|
1251
|
+
* @example
|
|
1252
|
+
* ```ts
|
|
1253
|
+
* Rec.NonEmpty.singleton("a", 1); // { a: 1 }
|
|
1254
|
+
* ```
|
|
1255
|
+
*/
|
|
1256
|
+
const singleton: <A>(key: string, value: A) => NonEmptyRecord<A>;
|
|
1257
|
+
/**
|
|
1258
|
+
* Creates a NonEmpty record from a standard record if it is not empty.
|
|
1259
|
+
*
|
|
1260
|
+
* @example
|
|
1261
|
+
* ```ts
|
|
1262
|
+
* Rec.NonEmpty.fromRecord({ a: 1 }); // Some({ a: 1 })
|
|
1263
|
+
* Rec.NonEmpty.fromRecord({}); // None
|
|
1264
|
+
* ```
|
|
1265
|
+
*/
|
|
1266
|
+
const fromRecord: <A>(data: Readonly<Record<string, A>>) => Maybe<NonEmptyRecord<A>>;
|
|
1267
|
+
/**
|
|
1268
|
+
* Returns a non-empty array of keys for a NonEmpty record.
|
|
1269
|
+
*
|
|
1270
|
+
* @example
|
|
1271
|
+
* ```ts
|
|
1272
|
+
* Rec.NonEmpty.keys(Rec.NonEmpty.singleton("a", 1)); // ["a"]
|
|
1273
|
+
* ```
|
|
1274
|
+
*/
|
|
1275
|
+
const keys: <A>(data: NonEmptyRecord<A>) => NonEmptyArr<string>;
|
|
1276
|
+
/**
|
|
1277
|
+
* Returns a non-empty array of values for a NonEmpty record.
|
|
1278
|
+
*
|
|
1279
|
+
* @example
|
|
1280
|
+
* ```ts
|
|
1281
|
+
* Rec.NonEmpty.values(Rec.NonEmpty.singleton("a", 1)); // [1]
|
|
1282
|
+
* ```
|
|
1283
|
+
*/
|
|
1284
|
+
const values: <A>(data: NonEmptyRecord<A>) => NonEmptyArr<A>;
|
|
1285
|
+
/**
|
|
1286
|
+
* Returns a non-empty array of entry tuples for a NonEmpty record.
|
|
1287
|
+
*
|
|
1288
|
+
* @example
|
|
1289
|
+
* ```ts
|
|
1290
|
+
* Rec.NonEmpty.entries(Rec.NonEmpty.singleton("a", 1)); // [["a", 1]]
|
|
1291
|
+
* ```
|
|
1292
|
+
*/
|
|
1293
|
+
const entries: <A>(data: NonEmptyRecord<A>) => NonEmptyArr<readonly [string, A]>;
|
|
1294
|
+
/**
|
|
1295
|
+
* Reduces a NonEmpty record's values from the left without an initial value.
|
|
1296
|
+
*
|
|
1297
|
+
* @example
|
|
1298
|
+
* ```ts
|
|
1299
|
+
* pipe(Rec.NonEmpty.singleton("a", 1), Rec.NonEmpty.reduce((a, b) => a + b)); // 1
|
|
1300
|
+
* ```
|
|
1301
|
+
*/
|
|
1302
|
+
const reduce: <A>(f: (acc: A, a: A) => A) => (data: NonEmptyRecord<A>) => A;
|
|
1303
|
+
}
|
|
1065
1304
|
/**
|
|
1066
1305
|
* Functional record/object utilities that compose well with pipe.
|
|
1067
1306
|
* All functions are data-last and curried where applicable.
|
|
@@ -1076,6 +1315,14 @@ declare namespace Num {
|
|
|
1076
1315
|
* ```
|
|
1077
1316
|
*/
|
|
1078
1317
|
declare namespace Rec {
|
|
1318
|
+
/**
|
|
1319
|
+
* A branded type representing a record with at least one key-value pair.
|
|
1320
|
+
*/
|
|
1321
|
+
type NonEmpty<A> = NonEmptyRecord<A>;
|
|
1322
|
+
/**
|
|
1323
|
+
* Type guard to check if a record is non-empty.
|
|
1324
|
+
*/
|
|
1325
|
+
const isNonEmpty: <A>(data: Readonly<Record<string, A>>) => data is NonEmptyRecord<A>;
|
|
1079
1326
|
/**
|
|
1080
1327
|
* Transforms each value in a record.
|
|
1081
1328
|
*
|
|
@@ -1084,7 +1331,10 @@ declare namespace Rec {
|
|
|
1084
1331
|
* pipe({ a: 1, b: 2 }, Rec.map(n => n * 2)); // { a: 2, b: 4 }
|
|
1085
1332
|
* ```
|
|
1086
1333
|
*/
|
|
1087
|
-
const map: <A, B>(f: (a: A) => B) =>
|
|
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
|
+
};
|
|
1088
1338
|
const filterMap: <A, B>(f: (a: A) => Maybe<B>) => (data: Readonly<Record<string, A>>) => Readonly<Record<string, B>>;
|
|
1089
1339
|
/**
|
|
1090
1340
|
* Transforms each value in a record, also receiving the key.
|
|
@@ -1095,7 +1345,10 @@ declare namespace Rec {
|
|
|
1095
1345
|
* // { a: "a:1", b: "b:2" }
|
|
1096
1346
|
* ```
|
|
1097
1347
|
*/
|
|
1098
|
-
const mapWithKey: <A, B>(f: (key: string, a: A) => B) =>
|
|
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
|
+
};
|
|
1099
1352
|
/**
|
|
1100
1353
|
* Filters values in a record by a predicate.
|
|
1101
1354
|
*
|
|
@@ -1110,7 +1363,7 @@ declare namespace Rec {
|
|
|
1110
1363
|
*
|
|
1111
1364
|
* @example
|
|
1112
1365
|
* ```ts
|
|
1113
|
-
* pipe({ a: 1, b: 2 }, Rec.filterWithKey((k, v) => k !== "a" && v > 0));
|
|
1366
|
+
* pipe({ a: 1, b: 2, c: 3 }, Rec.filterWithKey((k, v) => k !== "a" && v > 0));
|
|
1114
1367
|
* // { b: 2 }
|
|
1115
1368
|
* ```
|
|
1116
1369
|
*/
|
|
@@ -1219,6 +1472,9 @@ declare namespace Rec {
|
|
|
1219
1472
|
* ```
|
|
1220
1473
|
*/
|
|
1221
1474
|
const compact: <A>(data: Readonly<Record<string, Maybe<A>>>) => Readonly<Record<string, A>>;
|
|
1475
|
+
const Maybe: typeof RecMaybe;
|
|
1476
|
+
const Result: typeof RecResult;
|
|
1477
|
+
const NonEmpty: typeof RecNonEmpty;
|
|
1222
1478
|
}
|
|
1223
1479
|
|
|
1224
1480
|
/**
|
|
@@ -1626,4 +1882,4 @@ declare namespace Uniq {
|
|
|
1626
1882
|
const toArray: <A>(s: ReadonlySet<A>) => readonly A[];
|
|
1627
1883
|
}
|
|
1628
1884
|
|
|
1629
|
-
export { Arr, Dict, Num, Rec, Str, Uniq };
|
|
1885
|
+
export { Arr, Dict, type NonEmptyRecord, Num, Rec, Str, Uniq };
|