@nlozgachev/pipelined 0.11.0 → 0.12.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/esm/src/Core/Tuple.js +112 -0
- package/esm/src/Core/index.js +4 -3
- package/esm/src/Utils/Dict.js +421 -0
- package/esm/src/Utils/Rec.js +26 -0
- package/esm/src/Utils/Uniq.js +265 -0
- package/esm/src/Utils/index.js +2 -0
- package/package.json +1 -1
- package/script/src/Core/Tuple.js +115 -0
- package/script/src/Core/index.js +4 -3
- package/script/src/Utils/Dict.js +424 -0
- package/script/src/Utils/Rec.js +26 -0
- package/script/src/Utils/Uniq.js +268 -0
- package/script/src/Utils/index.js +2 -0
- package/types/src/Core/Tuple.d.ts +129 -0
- package/types/src/Core/Tuple.d.ts.map +1 -0
- package/types/src/Core/index.d.ts +4 -3
- package/types/src/Core/index.d.ts.map +1 -1
- package/types/src/Utils/Dict.d.ts +310 -0
- package/types/src/Utils/Dict.d.ts.map +1 -0
- package/types/src/Utils/Rec.d.ts +16 -0
- package/types/src/Utils/Rec.d.ts.map +1 -1
- package/types/src/Utils/Uniq.d.ts +179 -0
- package/types/src/Utils/Uniq.d.ts.map +1 -0
- package/types/src/Utils/index.d.ts +2 -0
- package/types/src/Utils/index.d.ts.map +1 -1
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { Option } from "../Core/Option.js";
|
|
2
|
+
/**
|
|
3
|
+
* Functional utilities for key-value dictionaries (`ReadonlyMap<K, V>`). All functions are pure
|
|
4
|
+
* and data-last — they compose naturally with `pipe`.
|
|
5
|
+
*
|
|
6
|
+
* Unlike plain objects (`Rec`), dictionaries support any key type, preserve insertion order, and
|
|
7
|
+
* make membership checks explicit via `lookup` returning `Option`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { Dict } from "@nlozgachev/pipelined/utils";
|
|
12
|
+
* import { pipe } from "@nlozgachev/pipelined/composition";
|
|
13
|
+
*
|
|
14
|
+
* const scores = pipe(
|
|
15
|
+
* Dict.fromEntries([["alice", 10], ["bob", 8], ["carol", 10]] as const),
|
|
16
|
+
* Dict.filter(n => n >= 10),
|
|
17
|
+
* Dict.map(n => `${n} points`),
|
|
18
|
+
* );
|
|
19
|
+
* // ReadonlyMap { "alice" => "10 points", "carol" => "10 points" }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare namespace Dict {
|
|
23
|
+
/**
|
|
24
|
+
* Creates an empty dictionary.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* Dict.empty<string, number>(); // ReadonlyMap {}
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
const empty: <K, V>() => ReadonlyMap<K, V>;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a dictionary with a single entry.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* Dict.singleton("name", "Alice"); // ReadonlyMap { "name" => "Alice" }
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
const singleton: <K, V>(key: K, value: V) => ReadonlyMap<K, V>;
|
|
41
|
+
/**
|
|
42
|
+
* Creates a dictionary from an array of key-value pairs.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* Dict.fromEntries([["a", 1], ["b", 2]]); // ReadonlyMap { "a" => 1, "b" => 2 }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
const fromEntries: <K, V>(entries: readonly (readonly [K, V])[]) => ReadonlyMap<K, V>;
|
|
50
|
+
/**
|
|
51
|
+
* Creates a dictionary from a plain object. Keys are always strings.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* Dict.fromRecord({ a: 1, b: 2 }); // ReadonlyMap { "a" => 1, "b" => 2 }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
const fromRecord: <V>(rec: Readonly<Record<string, V>>) => ReadonlyMap<string, V>;
|
|
59
|
+
/**
|
|
60
|
+
* Groups elements of an array into a dictionary keyed by the result of `keyFn`. Each key maps
|
|
61
|
+
* to the array of elements that produced it, in insertion order. Uses the native `Map.groupBy`
|
|
62
|
+
* when available, falling back to a manual loop in older environments.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* pipe(
|
|
67
|
+
* [{ name: "alice", role: "admin" }, { name: "bob", role: "viewer" }, { name: "carol", role: "admin" }],
|
|
68
|
+
* Dict.groupBy(user => user.role),
|
|
69
|
+
* );
|
|
70
|
+
* // ReadonlyMap { "admin" => [alice, carol], "viewer" => [bob] }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
const groupBy: <K, A>(keyFn: (a: A) => K) => (items: readonly A[]) => ReadonlyMap<K, readonly A[]>;
|
|
74
|
+
/**
|
|
75
|
+
* Returns `true` if the dictionary contains the given key.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* pipe(Dict.fromEntries([["a", 1]]), Dict.has("a")); // true
|
|
80
|
+
* pipe(Dict.fromEntries([["a", 1]]), Dict.has("b")); // false
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
const has: <K>(key: K) => <V>(m: ReadonlyMap<K, V>) => boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Looks up a value by key, returning `Some(value)` if found and `None` if not.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* pipe(Dict.fromEntries([["a", 1]]), Dict.lookup("a")); // Some(1)
|
|
90
|
+
* pipe(Dict.fromEntries([["a", 1]]), Dict.lookup("b")); // None
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
const lookup: <K>(key: K) => <V>(m: ReadonlyMap<K, V>) => Option<V>;
|
|
94
|
+
/**
|
|
95
|
+
* Returns the number of entries in the dictionary.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* Dict.size(Dict.fromEntries([["a", 1], ["b", 2]])); // 2
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
const size: <K, V>(m: ReadonlyMap<K, V>) => number;
|
|
103
|
+
/**
|
|
104
|
+
* Returns `true` if the dictionary has no entries.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* Dict.isEmpty(Dict.empty()); // true
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
const isEmpty: <K, V>(m: ReadonlyMap<K, V>) => boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Returns all keys as a readonly array, in insertion order.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* Dict.keys(Dict.fromEntries([["a", 1], ["b", 2]])); // ["a", "b"]
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
const keys: <K, V>(m: ReadonlyMap<K, V>) => readonly K[];
|
|
121
|
+
/**
|
|
122
|
+
* Returns all values as a readonly array, in insertion order.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* Dict.values(Dict.fromEntries([["a", 1], ["b", 2]])); // [1, 2]
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
const values: <K, V>(m: ReadonlyMap<K, V>) => readonly V[];
|
|
130
|
+
/**
|
|
131
|
+
* Returns all key-value pairs as a readonly array of tuples, in insertion order.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* Dict.entries(Dict.fromEntries([["a", 1], ["b", 2]])); // [["a", 1], ["b", 2]]
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
const entries: <K, V>(m: ReadonlyMap<K, V>) => readonly (readonly [K, V])[];
|
|
139
|
+
/**
|
|
140
|
+
* Returns a new dictionary with the given key set to the given value.
|
|
141
|
+
* If the key already exists, its value is replaced.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* pipe(Dict.fromEntries([["a", 1]]), Dict.insert("b", 2));
|
|
146
|
+
* // ReadonlyMap { "a" => 1, "b" => 2 }
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
const insert: <K, V>(key: K, value: V) => (m: ReadonlyMap<K, V>) => ReadonlyMap<K, V>;
|
|
150
|
+
/**
|
|
151
|
+
* Returns a new dictionary with the given key removed.
|
|
152
|
+
* If the key does not exist, the dictionary is returned unchanged.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```ts
|
|
156
|
+
* pipe(Dict.fromEntries([["a", 1], ["b", 2]]), Dict.remove("a"));
|
|
157
|
+
* // ReadonlyMap { "b" => 2 }
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
const remove: <K, V>(key: K) => (m: ReadonlyMap<K, V>) => ReadonlyMap<K, V>;
|
|
161
|
+
/**
|
|
162
|
+
* Returns a new dictionary with the value at `key` set by `f`. If the key does not exist,
|
|
163
|
+
* `f` receives `None`. If the key exists, `f` receives `Some(currentValue)`.
|
|
164
|
+
*
|
|
165
|
+
* Useful for incrementing counters, initialising defaults, or conditional updates.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* ```ts
|
|
169
|
+
* import { Option } from "@nlozgachev/pipelined/core";
|
|
170
|
+
*
|
|
171
|
+
* const increment = (opt: Option<number>) => Option.getOrElse(() => 0)(opt) + 1;
|
|
172
|
+
* pipe(Dict.fromEntries([["views", 5]]), Dict.upsert("views", increment)); // { views: 6 }
|
|
173
|
+
* pipe(Dict.fromEntries([["views", 5]]), Dict.upsert("likes", increment)); // { views: 5, likes: 1 }
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
const upsert: <K, V>(key: K, f: (existing: Option<V>) => V) => (m: ReadonlyMap<K, V>) => ReadonlyMap<K, V>;
|
|
177
|
+
/**
|
|
178
|
+
* Transforms each value in the dictionary.
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```ts
|
|
182
|
+
* pipe(Dict.fromEntries([["a", 1], ["b", 2]]), Dict.map(n => n * 2));
|
|
183
|
+
* // ReadonlyMap { "a" => 2, "b" => 4 }
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
const map: <A, B>(f: (a: A) => B) => <K>(m: ReadonlyMap<K, A>) => ReadonlyMap<K, B>;
|
|
187
|
+
/**
|
|
188
|
+
* Transforms each value in the dictionary, also receiving the key.
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```ts
|
|
192
|
+
* pipe(Dict.fromEntries([["a", 1], ["b", 2]]), Dict.mapWithKey((k, v) => `${k}:${v}`));
|
|
193
|
+
* // ReadonlyMap { "a" => "a:1", "b" => "b:2" }
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
const mapWithKey: <K, A, B>(f: (key: K, a: A) => B) => (m: ReadonlyMap<K, A>) => ReadonlyMap<K, B>;
|
|
197
|
+
/**
|
|
198
|
+
* Returns a new dictionary containing only the entries for which the predicate returns `true`.
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```ts
|
|
202
|
+
* pipe(Dict.fromEntries([["a", 1], ["b", 3], ["c", 0]]), Dict.filter(n => n > 0));
|
|
203
|
+
* // ReadonlyMap { "a" => 1, "b" => 3 }
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
const filter: <A>(predicate: (a: A) => boolean) => <K>(m: ReadonlyMap<K, A>) => ReadonlyMap<K, A>;
|
|
207
|
+
/**
|
|
208
|
+
* Returns a new dictionary containing only the entries for which the predicate returns `true`.
|
|
209
|
+
* The predicate also receives the key.
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```ts
|
|
213
|
+
* pipe(Dict.fromEntries([["a", 1], ["b", 2]]), Dict.filterWithKey((k, v) => k !== "a" && v > 0));
|
|
214
|
+
* // ReadonlyMap { "b" => 2 }
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
const filterWithKey: <K, A>(predicate: (key: K, a: A) => boolean) => (m: ReadonlyMap<K, A>) => ReadonlyMap<K, A>;
|
|
218
|
+
/**
|
|
219
|
+
* Removes all `None` values from a `ReadonlyMap<K, Option<A>>`, returning a plain
|
|
220
|
+
* `ReadonlyMap<K, A>`. Useful when building dictionaries from fallible lookups.
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```ts
|
|
224
|
+
* import { Option } from "@nlozgachev/pipelined/core";
|
|
225
|
+
*
|
|
226
|
+
* Dict.compact(Dict.fromEntries([
|
|
227
|
+
* ["a", Option.some(1)],
|
|
228
|
+
* ["b", Option.none()],
|
|
229
|
+
* ["c", Option.some(3)],
|
|
230
|
+
* ]));
|
|
231
|
+
* // ReadonlyMap { "a" => 1, "c" => 3 }
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
const compact: <K, A>(m: ReadonlyMap<K, Option<A>>) => ReadonlyMap<K, A>;
|
|
235
|
+
/**
|
|
236
|
+
* Merges two dictionaries. When both contain the same key, the value from `other` takes
|
|
237
|
+
* precedence.
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```ts
|
|
241
|
+
* pipe(
|
|
242
|
+
* Dict.fromEntries([["a", 1], ["b", 2]]),
|
|
243
|
+
* Dict.union(Dict.fromEntries([["b", 3], ["c", 4]])),
|
|
244
|
+
* );
|
|
245
|
+
* // ReadonlyMap { "a" => 1, "b" => 3, "c" => 4 }
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
const union: <K, V>(other: ReadonlyMap<K, V>) => (m: ReadonlyMap<K, V>) => ReadonlyMap<K, V>;
|
|
249
|
+
/**
|
|
250
|
+
* Returns a new dictionary containing only the entries whose keys appear in both dictionaries.
|
|
251
|
+
* Values are taken from the left (base) dictionary.
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* ```ts
|
|
255
|
+
* pipe(
|
|
256
|
+
* Dict.fromEntries([["a", 1], ["b", 2], ["c", 3]]),
|
|
257
|
+
* Dict.intersection(Dict.fromEntries([["b", 99], ["c", 0]])),
|
|
258
|
+
* );
|
|
259
|
+
* // ReadonlyMap { "b" => 2, "c" => 3 }
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
const intersection: <K, V>(other: ReadonlyMap<K, unknown>) => (m: ReadonlyMap<K, V>) => ReadonlyMap<K, V>;
|
|
263
|
+
/**
|
|
264
|
+
* Returns a new dictionary containing only the entries whose keys do not appear in `other`.
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* ```ts
|
|
268
|
+
* pipe(
|
|
269
|
+
* Dict.fromEntries([["a", 1], ["b", 2], ["c", 3]]),
|
|
270
|
+
* Dict.difference(Dict.fromEntries([["b", 0]])),
|
|
271
|
+
* );
|
|
272
|
+
* // ReadonlyMap { "a" => 1, "c" => 3 }
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
const difference: <K, V>(other: ReadonlyMap<K, unknown>) => (m: ReadonlyMap<K, V>) => ReadonlyMap<K, V>;
|
|
276
|
+
/**
|
|
277
|
+
* Folds the dictionary into a single value by applying `f` to each value in insertion order.
|
|
278
|
+
* When you also need the key, use `reduceWithKey`.
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* ```ts
|
|
282
|
+
* Dict.reduce(0, (acc, value) => acc + value)(
|
|
283
|
+
* Dict.fromEntries([["a", 1], ["b", 2], ["c", 3]])
|
|
284
|
+
* ); // 6
|
|
285
|
+
* ```
|
|
286
|
+
*/
|
|
287
|
+
const reduce: <A, B>(init: B, f: (acc: B, value: A) => B) => <K>(m: ReadonlyMap<K, A>) => B;
|
|
288
|
+
/**
|
|
289
|
+
* Folds the dictionary into a single value by applying `f` to each key-value pair in insertion
|
|
290
|
+
* order.
|
|
291
|
+
*
|
|
292
|
+
* @example
|
|
293
|
+
* ```ts
|
|
294
|
+
* Dict.reduceWithKey("", (acc, value, key) => acc + key + ":" + value + " ")(
|
|
295
|
+
* Dict.fromEntries([["a", 1], ["b", 2]])
|
|
296
|
+
* ); // "a:1 b:2 "
|
|
297
|
+
* ```
|
|
298
|
+
*/
|
|
299
|
+
const reduceWithKey: <K, A, B>(init: B, f: (acc: B, value: A, key: K) => B) => (m: ReadonlyMap<K, A>) => B;
|
|
300
|
+
/**
|
|
301
|
+
* Converts a `ReadonlyMap<string, V>` to a plain object. Only meaningful when keys are strings.
|
|
302
|
+
*
|
|
303
|
+
* @example
|
|
304
|
+
* ```ts
|
|
305
|
+
* Dict.toRecord(Dict.fromEntries([["a", 1], ["b", 2]])); // { a: 1, b: 2 }
|
|
306
|
+
* ```
|
|
307
|
+
*/
|
|
308
|
+
const toRecord: <V>(m: ReadonlyMap<string, V>) => Readonly<Record<string, V>>;
|
|
309
|
+
}
|
|
310
|
+
//# sourceMappingURL=Dict.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Dict.d.ts","sourceRoot":"","sources":["../../../src/src/Utils/Dict.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,yBAAiB,IAAI,CAAC;IAKrB;;;;;;;OAOG;IACI,MAAM,KAAK,GAAI,CAAC,EAAE,CAAC,OAAK,WAAW,CAAC,CAAC,EAAE,CAAC,CAA+B,CAAC;IAE/E;;;;;;;OAOG;IACI,MAAM,SAAS,GAAI,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,OAAO,CAAC,KAAG,WAAW,CAAC,CAAC,EAAE,CAAC,CAA6C,CAAC;IAEjH;;;;;;;OAOG;IACI,MAAM,WAAW,GAAI,CAAC,EAAE,CAAC,EAAE,SAAS,SAAS,CAAC,SAAS,CAAC,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AO,WAAW,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,GAAG,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,WAAW,CAAC,CAAC,EAAE,CAAC,CAM3G,CAAC;IAMF;;;;;;;;;;OAUG;IACI,MAAM,MAAM,GAAI,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,GAAG,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,CAM/F,CAAC;IAEF;;;;;;;;;;OAUG;IACI,MAAM,aAAa,GAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,KAAG,CAM9G,CAAC;IAMF;;;;;;;OAOG;IACI,MAAM,QAAQ,GAAI,CAAC,EAAE,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,KAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAA0B,CAAC;CAC7G"}
|
package/types/src/Utils/Rec.d.ts
CHANGED
|
@@ -82,6 +82,22 @@ export declare namespace Rec {
|
|
|
82
82
|
* ```
|
|
83
83
|
*/
|
|
84
84
|
const fromEntries: <A>(data: readonly (readonly [string, A])[]) => Readonly<Record<string, A>>;
|
|
85
|
+
/**
|
|
86
|
+
* Groups elements of an array into a record keyed by the result of `keyFn`. Each key maps to
|
|
87
|
+
* the array of elements that produced it, in insertion order.
|
|
88
|
+
*
|
|
89
|
+
* Unlike `Dict.groupBy`, keys are always strings. Use `Dict.groupBy` when you need non-string
|
|
90
|
+
* keys or want to avoid the plain-object prototype chain.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* pipe(
|
|
95
|
+
* ["apple", "avocado", "banana", "blueberry"],
|
|
96
|
+
* Rec.groupBy(s => s[0]),
|
|
97
|
+
* ); // { a: ["apple", "avocado"], b: ["banana", "blueberry"] }
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
const groupBy: <A>(keyFn: (a: A) => string) => (items: readonly A[]) => Readonly<Record<string, readonly A[]>>;
|
|
85
101
|
/**
|
|
86
102
|
* Picks specific keys from a record.
|
|
87
103
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Rec.d.ts","sourceRoot":"","sources":["../../../src/src/Utils/Rec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C;;;;;;;;;;;;GAYG;AACH,yBAAiB,GAAG,CAAC;IACpB;;;;;;;OAOG;IACI,MAAM,GAAG,GAAI,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,MAAM,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,KAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAQ3G,CAAC;IAEF;;;;;;;;OAQG;IACI,MAAM,UAAU,GACrB,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,MAAM,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,KAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAQrG,CAAC;IAEH;;;;;;;OAOG;IACI,MAAM,MAAM,GACjB,CAAC,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,KAAK,OAAO,MAAM,MAAM,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,KAAG,QAAQ,CAAC,MAAM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
|
1
|
+
/**
|
|
2
|
+
* Functional utilities for unique-value collections (`ReadonlySet<A>`). All functions are pure
|
|
3
|
+
* and data-last — they compose naturally with `pipe`.
|
|
4
|
+
*
|
|
5
|
+
* Every "mutating" operation returns a new set; the original is never changed.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { Uniq } from "@nlozgachev/pipelined/utils";
|
|
10
|
+
* import { pipe } from "@nlozgachev/pipelined/composition";
|
|
11
|
+
*
|
|
12
|
+
* const active = pipe(
|
|
13
|
+
* Uniq.fromArray(["alice", "bob", "alice", "carol"]),
|
|
14
|
+
* Uniq.remove("bob"),
|
|
15
|
+
* Uniq.map(name => name.toUpperCase()),
|
|
16
|
+
* );
|
|
17
|
+
* // ReadonlySet { "ALICE", "CAROL" }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare namespace Uniq {
|
|
21
|
+
/**
|
|
22
|
+
* Creates an empty unique collection.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* Uniq.empty<number>(); // ReadonlySet {}
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
const empty: <A>() => ReadonlySet<A>;
|
|
30
|
+
/**
|
|
31
|
+
* Creates a unique collection containing a single item.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* Uniq.singleton(42); // ReadonlySet { 42 }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
const singleton: <A>(item: A) => ReadonlySet<A>;
|
|
39
|
+
/**
|
|
40
|
+
* Creates a unique collection from an array, automatically discarding duplicates.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* Uniq.fromArray([1, 2, 2, 3, 3, 3]); // ReadonlySet { 1, 2, 3 }
|
|
45
|
+
* Uniq.fromArray([]); // ReadonlySet {}
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
const fromArray: <A>(arr: readonly A[]) => ReadonlySet<A>;
|
|
49
|
+
/**
|
|
50
|
+
* Returns `true` if the collection contains the given item.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* pipe(Uniq.fromArray([1, 2, 3]), Uniq.has(2)); // true
|
|
55
|
+
* pipe(Uniq.fromArray([1, 2, 3]), Uniq.has(4)); // false
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
const has: <A>(item: A) => (s: ReadonlySet<A>) => boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Returns the number of items in the collection.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* Uniq.size(Uniq.fromArray([1, 2, 3])); // 3
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
const size: <A>(s: ReadonlySet<A>) => number;
|
|
68
|
+
/**
|
|
69
|
+
* Returns `true` if the collection has no items.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* Uniq.isEmpty(Uniq.empty()); // true
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
const isEmpty: <A>(s: ReadonlySet<A>) => boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Returns `true` if every item in `set` also exists in `other`.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* pipe(Uniq.fromArray([1, 2]), Uniq.isSubsetOf(Uniq.fromArray([1, 2, 3]))); // true
|
|
83
|
+
* pipe(Uniq.fromArray([1, 4]), Uniq.isSubsetOf(Uniq.fromArray([1, 2, 3]))); // false
|
|
84
|
+
* pipe(Uniq.empty<number>(), Uniq.isSubsetOf(Uniq.fromArray([1, 2, 3]))); // true
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
const isSubsetOf: <A>(other: ReadonlySet<A>) => (s: ReadonlySet<A>) => boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Returns a new collection with the item added. If the item is already present, returns the
|
|
90
|
+
* original collection unchanged.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* pipe(Uniq.fromArray([1, 2]), Uniq.insert(3)); // ReadonlySet { 1, 2, 3 }
|
|
95
|
+
* pipe(Uniq.fromArray([1, 2]), Uniq.insert(2)); // ReadonlySet { 1, 2 } — unchanged
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
const insert: <A>(item: A) => (s: ReadonlySet<A>) => ReadonlySet<A>;
|
|
99
|
+
/**
|
|
100
|
+
* Returns a new collection with the item removed. If the item is not present, returns the
|
|
101
|
+
* original collection unchanged.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* pipe(Uniq.fromArray([1, 2, 3]), Uniq.remove(2)); // ReadonlySet { 1, 3 }
|
|
106
|
+
* pipe(Uniq.fromArray([1, 2, 3]), Uniq.remove(4)); // ReadonlySet { 1, 2, 3 } — unchanged
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
const remove: <A>(item: A) => (s: ReadonlySet<A>) => ReadonlySet<A>;
|
|
110
|
+
/**
|
|
111
|
+
* Applies `f` to each item, returning a new collection of the results. Duplicate results are
|
|
112
|
+
* automatically merged.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```ts
|
|
116
|
+
* pipe(Uniq.fromArray([1, 2, 3, 4]), Uniq.map(n => n % 3)); // ReadonlySet { 1, 2, 0 }
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
const map: <A, B>(f: (a: A) => B) => (s: ReadonlySet<A>) => ReadonlySet<B>;
|
|
120
|
+
/**
|
|
121
|
+
* Returns a new collection containing only the items for which the predicate returns `true`.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```ts
|
|
125
|
+
* pipe(Uniq.fromArray([1, 2, 3, 4, 5]), Uniq.filter(n => n % 2 === 0));
|
|
126
|
+
* // ReadonlySet { 2, 4 }
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
const filter: <A>(predicate: (a: A) => boolean) => (s: ReadonlySet<A>) => ReadonlySet<A>;
|
|
130
|
+
/**
|
|
131
|
+
* Returns a new collection containing all items from both collections.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* pipe(Uniq.fromArray([1, 2, 3]), Uniq.union(Uniq.fromArray([2, 3, 4])));
|
|
136
|
+
* // ReadonlySet { 1, 2, 3, 4 }
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
const union: <A>(other: ReadonlySet<A>) => (s: ReadonlySet<A>) => ReadonlySet<A>;
|
|
140
|
+
/**
|
|
141
|
+
* Returns a new collection containing only the items that appear in both collections.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* pipe(Uniq.fromArray([1, 2, 3]), Uniq.intersection(Uniq.fromArray([2, 3, 4])));
|
|
146
|
+
* // ReadonlySet { 2, 3 }
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
const intersection: <A>(other: ReadonlySet<A>) => (s: ReadonlySet<A>) => ReadonlySet<A>;
|
|
150
|
+
/**
|
|
151
|
+
* Returns a new collection containing only the items from `set` that do not appear in `other`.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```ts
|
|
155
|
+
* pipe(Uniq.fromArray([1, 2, 3, 4]), Uniq.difference(Uniq.fromArray([2, 4])));
|
|
156
|
+
* // ReadonlySet { 1, 3 }
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
const difference: <A>(other: ReadonlySet<A>) => (s: ReadonlySet<A>) => ReadonlySet<A>;
|
|
160
|
+
/**
|
|
161
|
+
* Folds the collection into a single value by applying `f` to each item in insertion order.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```ts
|
|
165
|
+
* Uniq.reduce(0, (acc, n) => acc + n)(Uniq.fromArray([1, 2, 3])); // 6
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
const reduce: <A, B>(init: B, f: (acc: B, a: A) => B) => (s: ReadonlySet<A>) => B;
|
|
169
|
+
/**
|
|
170
|
+
* Converts the collection to a readonly array in insertion order.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```ts
|
|
174
|
+
* Uniq.toArray(Uniq.fromArray([3, 1, 2])); // [3, 1, 2]
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
const toArray: <A>(s: ReadonlySet<A>) => readonly A[];
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=Uniq.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Uniq.d.ts","sourceRoot":"","sources":["../../../src/src/Utils/Uniq.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,yBAAiB,IAAI,CAAC;IAKrB;;;;;;;OAOG;IACI,MAAM,KAAK,GAAI,CAAC,OAAK,WAAW,CAAC,CAAC,CAA4B,CAAC;IAEtE;;;;;;;OAOG;IACI,MAAM,SAAS,GAAI,CAAC,EAAE,MAAM,CAAC,KAAG,WAAW,CAAC,CAAC,CAA+B,CAAC;IAEpF;;;;;;;;OAQG;IACI,MAAM,SAAS,GAAI,CAAC,EAAE,KAAK,SAAS,CAAC,EAAE,KAAG,WAAW,CAAC,CAAC,CAA4B,CAAC;IAM3F;;;;;;;;OAQG;IACI,MAAM,GAAG,GAAI,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,KAAG,OAAsB,CAAC;IAE/E;;;;;;;OAOG;IACI,MAAM,IAAI,GAAI,CAAC,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC,KAAG,MAAgB,CAAC;IAE7D;;;;;;;OAOG;IACI,MAAM,OAAO,GAA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CAAC,CAAC,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,KAAG,WAAW,CAAC,CAAC,CAMzF,CAAC;IAMF;;;;;;;OAOG;IACI,MAAM,MAAM,GAAI,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,KAAG,CAMrF,CAAC;IAMF;;;;;;;OAOG;IACI,MAAM,OAAO,GAAI,CAAC,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC,KAAG,SAAS,CAAC,EAAY,CAAC;CACtE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/Utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/Utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC"}
|