UNPKG

30.8 kBTypeScriptView Raw
1import { MapFunction as MapFunction$1 } from 'extra-iterable';
2
3/**
4 * Entries is a list of key-value pairs, with unique keys.
5 * [📘](https://github.com/nodef/extra-map/wiki/Entries)
6 */
7type Entries<K, V> = Iterable<[K, V]>;
8/**
9 * Lists is a pair of key list and value list, with unique keys.
10 * [📘](https://github.com/nodef/extra-map/wiki/Lists)
11 */
12type Lists<K, V> = [Iterable<K>, Iterable<V>];
13/**
14 * Handle reading of a single value.
15 * [📘](https://github.com/nodef/extra-map/wiki/ReadFunction)
16 * @returns value
17 */
18type ReadFunction<V> = () => V;
19/**
20 * Handle combining of two values.
21 * [📘](https://github.com/nodef/extra-map/wiki/CombineFunction)
22 * @param a a value
23 * @param b another value
24 * @returns combined value
25 */
26type CombineFunction<V> = (a: V, b: V) => V;
27/**
28 * Handle comparison of two values.
29 * [📘](https://github.com/nodef/extra-map/wiki/CompareFunction)
30 * @param a a value
31 * @param b another value
32 * @returns a<b: -ve, a=b: 0, a>b: +ve
33 */
34type CompareFunction<V> = (a: V, b: V) => number;
35/**
36 * Handle processing of values in a map.
37 * [📘](https://github.com/nodef/extra-map/wiki/ProcessFunction)
38 * @param v value in map
39 * @param k key of value in map
40 * @param x map containing the value
41 */
42type ProcessFunction<K, V> = (v: V, k: K, x: Map<K, V>) => void;
43/**
44 * Handle selection of values in a map.
45 * [📘](https://github.com/nodef/extra-map/wiki/TestFunction)
46 * @param v value in map
47 * @param k key of value in map
48 * @param x map containing the value
49 * @returns selected?
50 */
51type TestFunction<K, V> = (v: V, k: K, x: Map<K, V>) => boolean;
52/**
53 * Handle transformation of a value to another.
54 * [📘](https://github.com/nodef/extra-map/wiki/MapFunction)
55 * @param v value in map
56 * @param k key of value in map
57 * @param x map containing the value
58 * @returns transformed value
59 */
60type MapFunction<K, V, W> = (v: V, k: K, x: Map<K, V>) => W;
61/**
62 * Handle reduction of multiple values into a single value.
63 * [📘](https://github.com/nodef/extra-map/wiki/ReduceFunction)
64 * @param acc accumulator (temporary result)
65 * @param v value in map
66 * @param k key of value in map
67 * @param x map containing the value
68 * @returns reduced value
69 */
70type ReduceFunction<K, V, W> = (acc: W, v: V, k: K, x: Map<K, V>) => W;
71/**
72 * Handle ending of a combined map.
73 * [📘](https://github.com/nodef/extra-map/wiki/EndFunction)
74 * @param dones iᵗʰ map done?
75 * @returns combined map done?
76 */
77type EndFunction = (dones: boolean[]) => boolean;
78/**
79 * Check if value is a map.
80 * [📘](https://github.com/nodef/extra-map/wiki/is)
81 * @param v value
82 * @returns v is a map?
83 */
84declare function is(v: any): v is Map<any, any>;
85/**
86 * List all keys.
87 * [📘](https://github.com/nodef/extra-map/wiki/keys)
88 * @param x a map
89 * @returns k₀, k₁, ... | [kᵢ, vᵢ] ∈ x
90 */
91declare function keys<K, V>(x: Map<K, V>): IterableIterator<K>;
92/**
93 * List all values.
94 * [📘](https://github.com/nodef/extra-map/wiki/values)
95 * @param x a map
96 * @returns v₀, v₁, ... | [kᵢ, vᵢ] ∈ x
97 */
98declare function values<K, V>(x: Map<K, V>): IterableIterator<V>;
99/**
100 * List all key-value pairs.
101 * [📘](https://github.com/nodef/extra-map/wiki/entries)
102 * @param x a map
103 * @returns [k₀, v₀], [k₁, v₁], ... | [kᵢ, vᵢ] ∈ x
104 */
105declare function entries<K, V>(x: Map<K, V>): IterableIterator<[K, V]>;
106/**
107 * Convert entries to map.
108 * [📘](https://github.com/nodef/extra-map/wiki/from)
109 * @param x entries
110 * @returns x as map
111 */
112declare function from<K, V>(x: Entries<K, V>): Map<K, V>;
113
114/**
115 * Convert entries to map.
116 * [📘](https://github.com/nodef/extra-map/wiki/from$)
117 * @param x entries (updateable is map!)
118 * @returns x as map
119 */
120declare function from$<K, V>(x: Entries<K, V>): Map<K, V>;
121
122/**
123 * Convert lists to map.
124 * [📘](https://github.com/nodef/extra-map/wiki/fromLists)
125 * @param x lists, i.e. [keys, values]
126 * @returns x as map
127 */
128declare function fromLists<K, V>(x: Lists<K, V>): Map<K, V>;
129/**
130 * Create a map from keys.
131 * [📘](https://github.com/nodef/extra-map/wiki/fromKeys)
132 * @param x keys
133 * @param fm map function for values (v, i, x)
134 * @returns x as map
135 */
136declare function fromKeys<K, V = K>(x: Iterable<K>, fm?: MapFunction$1<K, K | V> | null): Map<K, K | V>;
137/**
138 * Create a map from values.
139 * [📘](https://github.com/nodef/extra-map/wiki/fromValues)
140 * @param x values
141 * @param fm map function for keys (v, i, x)
142 * @returns x as map
143 */
144declare function fromValues<V, K = V>(x: Iterable<V>, fm?: MapFunction$1<V, V | K> | null): Map<V | K, V>;
145/**
146 * Compare two maps.
147 * [📘](https://github.com/nodef/extra-map/wiki/compare)
148 * @param x a map
149 * @param y another map
150 * @param fc compare function (a, b)
151 * @param fm map function (v, k, x)
152 * @returns x=y: 0, otherwise: -ve/+ve
153 */
154declare function compare<K, V, W = V>(x: Map<K, V>, y: Map<K, V>, fc?: CompareFunction<V | W> | null, fm?: MapFunction<K, V, V | W> | null): number;
155/**
156 * Check if two maps are equal.
157 * [📘](https://github.com/nodef/extra-map/wiki/isEqual)
158 * @param x a map
159 * @param y another map
160 * @param fc compare function (a, b)
161 * @param fm map function (v, k, x)
162 * @returns x = y?
163 */
164declare function isEqual<K, V, W = V>(x: Map<K, V>, y: Map<K, V>, fc?: CompareFunction<V | W> | null, fm?: MapFunction<K, V, V | W> | null): boolean;
165/**
166 * Find the size of a map.
167 * [📘](https://github.com/nodef/extra-map/wiki/size)
168 * @param x a map
169 * @returns |x|
170 */
171declare function size<K, V>(x: Map<K, V>): number;
172
173/**
174 * Check if a map is empty.
175 * [📘](https://github.com/nodef/extra-map/wiki/isEmpty)
176 * @param x a map
177 * @returns |x| = 0?
178 */
179declare function isEmpty<K, V>(x: Map<K, V>): boolean;
180/**
181 * Get value at key.
182 * [📘](https://github.com/nodef/extra-map/wiki/get)
183 * @param x a map
184 * @param k key
185 * @returns x[k]
186 */
187declare function get<K, V>(x: Map<K, V>, k: K): V;
188/**
189 * Get values at keys.
190 * [📘](https://github.com/nodef/extra-map/wiki/getAll)
191 * @param x a map
192 * @param ks keys
193 * @returns [x[k₀], x[k₁], ...] | [k₀, k₁, ...] = ks
194 */
195declare function getAll<K, V>(x: Map<K, V>, ks: K[]): V[];
196/**
197 * Get value at path in a nested map.
198 * [📘](https://github.com/nodef/extra-map/wiki/getPath)
199 * @param x a nested map
200 * @param p path
201 * @returns x[k₀][k₁][...] | [k₀, k₁, ...] = p
202 */
203declare function getPath<K>(x: Map<K, any>, p: K[]): any;
204/**
205 * Check if nested map has a path.
206 * [📘](https://github.com/nodef/extra-map/wiki/hasPath)
207 * @param x a nested map
208 * @param p path
209 * @returns x[k₀][k₁][...] exists? | [k₀, k₁, ...] = p
210 */
211declare function hasPath<K>(x: Map<K, any>, p: K[]): boolean;
212/**
213 * Set value at key.
214 * [📘](https://github.com/nodef/extra-map/wiki/set)
215 * @param x a map
216 * @param k key
217 * @param v value
218 * @returns x' | x' = x; x'[k] = v
219 */
220declare function set<K, V>(x: Entries<K, V>, k: K, v: V): Map<K, V>;
221/**
222 * Set value at key.
223 * [📘](https://github.com/nodef/extra-map/wiki/set$)
224 * @param x a map (updated)
225 * @param k key
226 * @param v value
227 * @returns x | x[k] = v
228 */
229declare function set$<K, V>(x: Map<K, V>, k: K, v: V): Map<K, V>;
230/**
231 * Set value at path in a nested map.
232 * [📘](https://github.com/nodef/extra-map/wiki/setPath$)
233 * @param x a nested map (updated)
234 * @param p path
235 * @param v value
236 * @returns x | x[k₀][k₁][...] = v; [k₀, k₁, ...] = p
237 */
238declare function setPath$<K>(x: Map<K, any>, p: K[], v: any): Map<K, any>;
239/**
240 * Exchange two values.
241 * [📘](https://github.com/nodef/extra-map/wiki/swap)
242 * @param x a map
243 * @param k a key
244 * @param l another key
245 * @returns x' | x' = x; x'[k] = x[l]; x'[l] = x[k]
246 */
247declare function swap<K, V>(x: Entries<K, V>, k: K, l: K): Map<K, V>;
248/**
249 * Exchange two values.
250 * [📘](https://github.com/nodef/extra-map/wiki/swap$)
251 * @param x a map (updated)
252 * @param k a key
253 * @param l another key
254 * @returns x | x[i] ↔ x[j]
255 */
256declare function swap$<K, V>(x: Map<K, V>, k: K, l: K): Map<K, V>;
257/**
258 * Remove value at key.
259 * [📘](https://github.com/nodef/extra-map/wiki/remove)
260 * @param x a map
261 * @param k key
262 * @returns x \\: [k]
263 */
264declare function remove<K, V>(x: Entries<K, V>, k: K): Map<K, V>;
265/**
266 * Remove value at key.
267 * [📘](https://github.com/nodef/extra-map/wiki/remove$)
268 * @param x a map (updated)
269 * @param k key
270 * @returns x = x \\: [k]
271 */
272declare function remove$<K, V>(x: Map<K, V>, k: K): Map<K, V>;
273/**
274 * Remove value at path in a nested map.
275 * [📘](https://github.com/nodef/extra-map/wiki/removePath$)
276 * @param x a nested map (updated)
277 * @param p path
278 * @returns x = x \\: [k₀][k₁][...] | [k₀, k₁, ...] = p
279 */
280declare function removePath$<K>(x: Map<K, any>, p: K[]): Map<K, any>;
281/**
282 * Count values which satisfy a test.
283 * [📘](https://github.com/nodef/extra-map/wiki/count)
284 * @param x a map
285 * @param ft test function (v, k, x)
286 * @returns Σtᵢ | tᵢ = 1 if ft(vᵢ) else 0; [kᵢ, vᵢ] ∈ x
287 */
288declare function count<K, V>(x: Map<K, V>, ft: TestFunction<K, V>): number;
289/**
290 * Count occurrences of values.
291 * [📘](https://github.com/nodef/extra-map/wiki/countAs)
292 * @param x a map
293 * @param fm map function (v, k, x)
294 * @returns Map \{value ⇒ count\}
295 */
296declare function countAs<K, V, W = V>(x: Map<K, V>, fm?: MapFunction<K, V, V | W> | null): Map<V | W, number>;
297/**
298 * Find smallest value.
299 * [📘](https://github.com/nodef/extra-map/wiki/min)
300 * @param x a map
301 * @param fc compare function (a, b)
302 * @param fm map function (v, k, x)
303 * @returns v | v ≤ vᵢ; [kᵢ, vᵢ] ∈ x
304 */
305declare function min<K, V, W = V>(x: Map<K, V>, fc?: CompareFunction<V | W> | null, fm?: MapFunction<K, V, V | W> | null): V;
306/**
307 * Find smallest entry.
308 * [📘](https://github.com/nodef/extra-map/wiki/minEntry)
309 * @param x a map
310 * @param fc compare function (a, b)
311 * @param fm map function (v, k, x)
312 * @returns [min_key, min_value]
313 */
314declare function minEntry<K, V, W = V>(x: Map<K, V>, fc?: CompareFunction<V | W> | null, fm?: MapFunction<K, V, V | W> | null): [K, V];
315/**
316 * Find largest value.
317 * [📘](https://github.com/nodef/extra-map/wiki/max)
318 * @param x a map
319 * @param fc compare function (a, b)
320 * @param fm map function (v, k, x)
321 * @returns v | v ≥ vᵢ; [kᵢ, vᵢ] ∈ x
322 */
323declare function max<K, V, W = V>(x: Map<K, V>, fc?: CompareFunction<V | W> | null, fm?: MapFunction<K, V, V | W> | null): V;
324/**
325 * Find largest entry.
326 * [📘](https://github.com/nodef/extra-map/wiki/maxEntry)
327 * @param x a map
328 * @param fc compare function (a, b)
329 * @param fm map function (v, k, x)
330 * @returns [max_key, max_value]
331 */
332declare function maxEntry<K, V, W = V>(x: Map<K, V>, fc?: CompareFunction<V | W> | null, fm?: MapFunction<K, V, V | W> | null): [K, V];
333/**
334 * Find smallest and largest values.
335 * [📘](https://github.com/nodef/extra-map/wiki/range)
336 * @param x a map
337 * @param fc compare function (a, b)
338 * @param fm map function (v, k, x)
339 * @returns [min_value, max_value]
340 */
341declare function range<K, V, W = V>(x: Map<K, V>, fc?: CompareFunction<V | W> | null, fm?: MapFunction<K, V, V | W> | null): [V, V];
342/**
343 * Find smallest and largest entries.
344 * [📘](https://github.com/nodef/extra-map/wiki/rangeEntries)
345 * @param x a map
346 * @param fc compare function (a, b)
347 * @param fm map function (v, k, x)
348 * @returns [min_entry, max_entry]
349 */
350declare function rangeEntries<K, V, W = V>(x: Map<K, V>, fc?: CompareFunction<V | W> | null, fm?: MapFunction<K, V, V | W> | null): [[K, V], [K, V]];
351/**
352 * Get first entry from map (default order).
353 * [📘](https://github.com/nodef/extra-map/wiki/head)
354 * @param x a map
355 * @param ed default entry
356 * @returns [k₀, v₀] if x ≠ Φ else ed | [k₀, v₀] ∈ x
357 */
358declare function head<K, V>(x: Entries<K, V>, ed?: [K, V]): [K, V];
359/**
360 * Get a map without its first entry (default order).
361 * [📘](https://github.com/nodef/extra-map/wiki/tail)
362 * @param x a map
363 * @returns x \\ \{[k₀, v₀]\} if x ≠ Φ else x | [k₀, v₀] ∈ x
364 */
365declare function tail<K, V>(x: Map<K, V>): Map<K, V>;
366/**
367 * Keep first n entries only (default order).
368 * [📘](https://github.com/nodef/extra-map/wiki/take)
369 * @param x a map
370 * @param n number of entries [1]
371 * @returns \{[k₀, v₀], [k₁, v₁], ...\} | [kᵢ, vᵢ] ∈ x and |\{[k₀, v₀], [k₁, v₁], ...\}| ≤ n
372 */
373declare function take<K, V>(x: Map<K, V>, n?: number): Map<K, V>;
374/**
375 * Keep first n entries only (default order).
376 * [📘](https://github.com/nodef/extra-map/wiki/take$)
377 * @param x a map (updated)
378 * @param n number of entries [1]
379 * @returns x = \{[k₀, v₀], [k₁, v₁], ...\} | [kᵢ, vᵢ] ∈ x and |\{[k₀, v₀], [k₁, v₁], ...\}| ≤ n
380 */
381declare function take$<K, V>(x: Map<K, V>, n?: number): Map<K, V>;
382/**
383 * Remove first n entries (default order).
384 * [📘](https://github.com/nodef/extra-map/wiki/drop)
385 * @param x a map
386 * @param n number of entries [1]
387 * @returns \{[kₙ, vₙ], [kₙ₊₁, vₙ₊₁], ...\} | [kᵢ, vᵢ] ∈ x and |\{[kₙ, vₙ], [kₙ₊₁, vₙ₊₁], ...\}| ≤ max(|x| - n, 0)
388 */
389declare function drop<K, V>(x: Map<K, V>, n?: number): Map<K, V>;
390/**
391 * Remove first n entries (default order).
392 * [📘](https://github.com/nodef/extra-map/wiki/drop$)
393 * @param x a map (updated)
394 * @param n number of entries [1]
395 * @returns x = \{[kₙ, vₙ], [kₙ₊₁, vₙ₊₁], ...\} | [kᵢ, vᵢ] ∈ x and |\{[kₙ, vₙ], [kₙ₊₁, vₙ₊₁], ...\}| ≤ max(|x| - n, 0)
396 */
397declare function drop$<K, V>(x: Map<K, V>, n?: number): Map<K, V>;
398/**
399 * List all possible subsets.
400 * [📘](https://github.com/nodef/extra-map/wiki/subsets)
401 * @param x a map
402 * @param n number of entries [-1 ⇒ any]
403 * @returns entries selected by bit from 0..2^|x| if n<0; only of length n otherwise
404 */
405declare function subsets<K, V>(x: Map<K, V>, n?: number): IterableIterator<Map<K, V>>;
406/**
407 * Pick an arbitrary key.
408 * [📘](https://github.com/nodef/extra-map/wiki/randomKey)
409 * @param x a map
410 * @param fr random number generator ([0, 1))
411 * @returns kᵢ | [kᵢ, vᵢ] ∈ x
412 */
413declare function randomKey<K, V>(x: Map<K, V>, fr?: ReadFunction<number>): K;
414
415/**
416 * Pick an arbitrary entry.
417 * [📘](https://github.com/nodef/extra-map/wiki/randomEntry)
418 * @param x a map
419 * @param fr random number generator ([0, 1))
420 * @returns [kᵢ, vᵢ] | [kᵢ, vᵢ] ∈ x
421 */
422declare function randomEntry<K, V>(x: Entries<K, V>, fr?: ReadFunction<number>): [K, V];
423
424/**
425 * Pick an arbitrary subset.
426 * [📘](https://github.com/nodef/extra-map/wiki/randomSubset)
427 * @param x a map
428 * @param n number of entries [-1 ⇒ any]
429 * @param fr random number generator ([0, 1))
430 * @returns \{[kᵢ, vᵢ], [kⱼ, vⱼ], ...\} | [kᵢ, vᵢ], [kⱼ, vⱼ], ... ∈ x; |\{[kᵢ, vᵢ], [kⱼ, vⱼ], ...\}| = |x| if n<0 else n
431 */
432declare function randomSubset<K, V>(x: Map<K, V>, n?: number, fr?: ReadFunction<number> | null): Map<K, V>;
433
434/**
435 * Check if map has a key.
436 * [📘](https://github.com/nodef/extra-map/wiki/has)
437 * @param x a map
438 * @param k search key
439 * @returns [k, *] ∈ x?
440 */
441declare function has<K, V>(x: Map<K, V>, k: K): boolean;
442
443/**
444 * Check if map has a value.
445 * [📘](https://github.com/nodef/extra-map/wiki/hasValue)
446 * @param x a map
447 * @param v search value
448 * @param fc compare function (a, b)
449 * @param fm map function (v, k, x)
450 * @returns [*, v] ∈ x?
451 */
452declare function hasValue<K, V, W = V>(x: Map<K, V>, v: V, fc?: CompareFunction<V | W> | null, fm?: MapFunction<K, V, V | W> | null): boolean;
453/**
454 * Check if map has an entry.
455 * [📘](https://github.com/nodef/extra-map/wiki/hasEntry)
456 * @param x a map
457 * @param e search entry ([k, v])
458 * @param fc compare function (a, b)
459 * @param fm map function (v, k, x)
460 * @returns [k, v] ∈ x? | [k, v] = e
461 */
462declare function hasEntry<K, V, W = V>(x: Map<K, V>, e: [K, V], fc?: CompareFunction<V | W> | null, fm?: MapFunction<K, V, V | W> | null): boolean;
463/**
464 * Check if map has a subset.
465 * [📘](https://github.com/nodef/extra-map/wiki/hasSubset)
466 * @param x a map
467 * @param y search subset
468 * @param fc compare function (a, b)
469 * @param fm map function (v, k, x)
470 * @returns y ⊆ x?
471 */
472declare function hasSubset<K, V, W = V>(x: Map<K, V>, y: Map<K, V>, fc?: CompareFunction<V | W> | null, fm?: MapFunction<K, V, V | W> | null): boolean;
473/**
474 * Find first value passing a test (default order).
475 * [📘](https://github.com/nodef/extra-map/wiki/find)
476 * @param x a map
477 * @param ft test function (v, k, x)
478 * @returns first v | ft(v) = true; [k, v] ∈ x
479 */
480declare function find<K, V>(x: Map<K, V>, ft: TestFunction<K, V>): V;
481/**
482 * Find values passing a test.
483 * [📘](https://github.com/nodef/extra-map/wiki/findAll)
484 * @param x a map
485 * @param ft test function (v, k, x)
486 * @returns [v₀, v₁, ...] | ft(vᵢ) = true; [kᵢ, vᵢ] ∈ x
487 */
488declare function findAll<K, V>(x: Map<K, V>, ft: TestFunction<K, V>): V[];
489/**
490 * Find key of an entry passing a test.
491 * [📘](https://github.com/nodef/extra-map/wiki/search)
492 * @param x a map
493 * @param ft test function (v, k, x)
494 * @returns key of entry
495 */
496declare function search<K, V>(x: Map<K, V>, ft: TestFunction<K, V>): K;
497/**
498 * Find keys of entries passing a test.
499 * [📘](https://github.com/nodef/extra-map/wiki/searchAll)
500 * @param x a map
501 * @param ft test function (v, k, x)
502 * @returns keys of entries
503 */
504declare function searchAll<K, V>(x: Map<K, V>, ft: TestFunction<K, V>): K[];
505/**
506 * Find a key with given value.
507 * [📘](https://github.com/nodef/extra-map/wiki/searchValue)
508 * @param x a map
509 * @param v search value
510 * @param fc compare function (a, b)
511 * @param fm map function (v, k, x)
512 * @returns key of value
513 */
514declare function searchValue<K, V, W = V>(x: Map<K, V>, v: V, fc?: CompareFunction<V | W> | null, fm?: MapFunction<K, V, V | W> | null): K;
515/**
516 * Find keys with given value.
517 * [📘](https://github.com/nodef/extra-map/wiki/searchValueAll)
518 * @param x a map
519 * @param v search value
520 * @param fc compare function (a, b)
521 * @param fm map function (v, k, x)
522 * @returns keys of value
523 */
524declare function searchValueAll<K, V, W = V>(x: Map<K, V>, v: V, fc?: CompareFunction<V | W> | null, fm?: MapFunction<K, V, V | W> | null): K[];
525/**
526 * Call a function for each value.
527 * [📘](https://github.com/nodef/extra-map/wiki/forEach)
528 * @param x a map
529 * @param fp process function (v, k, x)
530 */
531declare function forEach<K, V>(x: Map<K, V>, fp: ProcessFunction<K, V>): void;
532/**
533 * Check if any value satisfies a test.
534 * [📘](https://github.com/nodef/extra-map/wiki/some)
535 * @param x a map
536 * @param ft test function (v, k, x)
537 * @returns true if ft(vᵢ) = true for some [kᵢ, vᵢ] ∈ x
538 */
539declare function some<K, V>(x: Map<K, V>, ft: TestFunction<K, V>): boolean;
540/**
541 * Check if all values satisfy a test.
542 * [📘](https://github.com/nodef/extra-map/wiki/every)
543 * @param x a map
544 * @param ft test function (v, k, x)
545 * @returns true if ft(vᵢ) = true for all [kᵢ, vᵢ] ∈ x
546 */
547declare function every<K, V>(x: Map<K, V>, ft: TestFunction<K, V>): boolean;
548/**
549 * Transform values of a map.
550 * [📘](https://github.com/nodef/extra-map/wiki/map)
551 * @param x a map
552 * @param fm map function (v, k, x)
553 * @returns \{[k₀, fm(v₀)], [k₁, fm(v₁)], ...\} | [kᵢ, vᵢ] ∈ x
554 */
555declare function map<K, V, W = V>(x: Map<K, V>, fm: MapFunction<K, V, V | W>): Map<K, V | W>;
556/**
557 * Transform values of a map.
558 * [📘](https://github.com/nodef/extra-map/wiki/map$)
559 * @param x a map (updated)
560 * @param fm map function (v, k, x)
561 * @returns x = \{[k₀, fm(v₀)], [k₁, fm(v₁)], ...\} | [kᵢ, vᵢ] ∈ x
562 */
563declare function map$<K, V>(x: Map<K, V>, fm: MapFunction<K, V, V>): Map<K, V>;
564/**
565 * Reduce values of set to a single value.
566 * [📘](https://github.com/nodef/extra-map/wiki/reduce)
567 * @param x a map
568 * @param fr reduce function (acc, v, k, x)
569 * @param acc initial value
570 * @returns fr(fr(acc, v₀), v₁)... | fr(acc, v₀) = v₀ if acc not given
571 */
572declare function reduce<K, V, W = V>(x: Map<K, V>, fr: ReduceFunction<K, V, V | W>, acc?: V | W): V | W;
573/**
574 * Keep entries which pass a test.
575 * [📘](https://github.com/nodef/extra-map/wiki/filter)
576 * @param x a map
577 * @param ft test function (v, k, x)
578 * @returns \{[k₀, v₀], [k₁, v₁], ...\} | ft(vᵢ) = true; [kᵢ, vᵢ] ∈ x
579 */
580declare function filter<K, V>(x: Map<K, V>, ft: TestFunction<K, V>): Map<K, V>;
581/**
582 * Keep entries which pass a test.
583 * [📘](https://github.com/nodef/extra-map/wiki/filter$)
584 * @param x an map (updated)
585 * @param ft test function (v, k, x)
586 * @returns x = \{[k₀, v₀], [k₁, v₁], ...\} | ft(vᵢ) = true; [kᵢ, vᵢ] ∈ x
587 */
588declare function filter$<K, V>(x: Map<K, V>, ft: TestFunction<K, V>): Map<K, V>;
589/**
590 * Keep values at given keys.
591 * [📘](https://github.com/nodef/extra-map/wiki/filterAt)
592 * @param x a map
593 * @param ks keys
594 * @returns \{[k₀, v₀], [k₁, v₁], ...\} | kᵢ ∈ ks; [kᵢ, vᵢ] ∈ x
595 */
596declare function filterAt<K, V>(x: Map<K, V>, ks: K[]): Map<K, V>;
597/**
598 * Keep values at given keys.
599 * [📘](https://github.com/nodef/extra-map/wiki/filterAt$)
600 * @param x a map (updated)
601 * @param ks keys
602 * @returns x = \{[k₀, v₀], [k₁, v₁], ...\} | kᵢ ∈ ks; [kᵢ, vᵢ] ∈ x
603 */
604declare function filterAt$<K, V>(x: Map<K, V>, ks: K[]): Map<K, V>;
605/**
606 * Discard entries which pass a test.
607 * [📘](https://github.com/nodef/extra-map/wiki/reject)
608 * @param x a map
609 * @param ft test function (v, k, x)
610 * @returns \{[k₀, v₀], [k₁, v₁], ...\} | ft(vᵢ) = false; [kᵢ, vᵢ] ∈ x
611 */
612declare function reject<K, V>(x: Map<K, V>, ft: TestFunction<K, V>): Map<K, V>;
613/**
614 * Discard entries which pass a test.
615 * [📘](https://github.com/nodef/extra-map/wiki/reject$)
616 * @param x a map (updated)
617 * @param ft test function (v, k, x)
618 * @returns x = \{[k₀, v₀], [k₁, v₁], ...\} | ft(vᵢ) = false; [kᵢ, vᵢ] ∈ x
619 */
620declare function reject$<K, V>(x: Map<K, V>, ft: TestFunction<K, V>): Map<K, V>;
621/**
622 * Discard values at given keys.
623 * [📘](https://github.com/nodef/extra-map/wiki/rejectAt)
624 * @param x a map
625 * @param ks keys
626 * @returns \{[k₀, v₀], [k₁, v₁], ...\} | kᵢ ∉ ks; [kᵢ, vᵢ] ∈ x
627 */
628declare function rejectAt<K, V>(x: Map<K, V>, ks: K[]): Map<K, V>;
629/**
630 * Discard values at given keys.
631 * [📘](https://github.com/nodef/extra-map/wiki/rejectAt$)
632 * @param x a map (updated)
633 * @param ks keys
634 * @returns x = \{[k₀, v₀], [k₁, v₁], ...\} | kᵢ ∉ ks; [kᵢ, vᵢ] ∈ x
635 */
636declare function rejectAt$<K, V>(x: Map<K, V>, ks: K[]): Map<K, V>;
637/**
638 * Flatten nested map to given depth.
639 * [📘](https://github.com/nodef/extra-map/wiki/flat)
640 * @param x a nested map
641 * @param n maximum depth [-1 ⇒ all]
642 * @param fm map function (v, k, x)
643 * @param ft test function for flatten (v, k, x) [is]
644 * @returns flat map
645 */
646declare function flat<K>(x: Map<K, any>, n?: number, fm?: MapFunction<K, any, any> | null, ft?: TestFunction<K, any> | null): Map<K, any>;
647/**
648 * Flatten nested map, based on map function.
649 * [📘](https://github.com/nodef/extra-map/wiki/flatMap)
650 * @param x a nested map
651 * @param fm map function (v, k, x)
652 * @param ft test function for flatten (v, k, x) [is]
653 * @returns flat map
654 */
655declare function flatMap<K>(x: Map<K, any>, fm?: MapFunction<K, any, any> | null, ft?: TestFunction<K, any> | null): Map<K, any>;
656/**
657 * Combine matching entries from maps.
658 * [📘](https://github.com/nodef/extra-map/wiki/zip)
659 * @param xs maps
660 * @param fm map function (vs, k)
661 * @param fe end function (dones) [array.some]
662 * @param vd default value
663 * @returns [fm([x₀[k₀], x₁[k₀], ...]), fm([x₀[k₁], x₁[k₁], ...]), ...]
664 */
665declare function zip<K, V, W = V>(xs: Map<K, V>[], fm?: MapFunction<K, V[], V[] | W> | null, fe?: EndFunction, vd?: V): Map<K, V[] | W>;
666/**
667 * Segregate entries by test result.
668 * [📘](https://github.com/nodef/extra-map/wiki/partition)
669 * @param x a map
670 * @param ft test function (v, k, x)
671 * @returns [satisfies, doesnt]
672 */
673declare function partition<K, V>(x: Map<K, V>, ft: TestFunction<K, V>): [Map<K, V>, Map<K, V>];
674/**
675 * Segregate entries by similarity.
676 * [📘](https://github.com/nodef/extra-map/wiki/partitionAs)
677 * @param x a map
678 * @param fm map function (v, k, x)
679 * @returns Map \{key ⇒ values\}
680 */
681declare function partitionAs<K, V, W = V>(x: Map<K, V>, fm: MapFunction<K, V, V | W>): Map<V | W, Map<K, V>>;
682/**
683 * Break map into chunks of given size.
684 * [📘](https://github.com/nodef/extra-map/wiki/chunk)
685 * @param x a map
686 * @param n chunk size [1]
687 * @param s chunk step [n]
688 * @returns [x[0..n], x[s..s+n], x[2s..2s+n], ...]
689 */
690declare function chunk<K, V>(x: Map<K, V>, n?: number, s?: number): Map<K, V>[];
691/**
692 * Append entries from maps, preferring last.
693 * [📘](https://github.com/nodef/extra-map/wiki/concat)
694 * @param xs maps
695 * @returns x₀ ∪ x₁ ∪ ... | [x₀, x₁, ...] = xs
696 */
697declare function concat<K, V>(...xs: Entries<K, V>[]): Map<K, V>;
698/**
699 * Append entries from maps, preferring last.
700 * [📘](https://github.com/nodef/extra-map/wiki/concat$)
701 * @param x a map (updated)
702 * @param ys other maps
703 * @returns x = x ∪ y₀ ∪ y₁ ∪ ... | [y₀, y₁, ...] = ys
704 */
705declare function concat$<K, V>(x: Map<K, V>, ...ys: Entries<K, V>[]): Map<K, V>;
706/**
707 * Join entries together into a string.
708 * [📘](https://github.com/nodef/extra-map/wiki/join)
709 * @param x a map
710 * @param sep separator [,]
711 * @param asc associator [=]
712 * @returns "$\{k₀\}=$\{v₀\},$\{k₁\}=$\{v₁\}..." | [kᵢ, vᵢ] ∈ x
713 */
714declare function join<K, V>(x: Entries<K, V>, sep?: string, asc?: string): string;
715/**
716 * Check if maps have no common keys.
717 * [📘](https://github.com/nodef/extra-map/wiki/isDisjoint)
718 * @param x a map
719 * @param y another map
720 * @returns x ∩ y = Φ?
721 */
722declare function isDisjoint<K, V>(x: Map<K, V>, y: Entries<K, V>): boolean;
723/**
724 * Obtain keys present in any map.
725 * [📘](https://github.com/nodef/extra-map/wiki/unionKeys)
726 * @param xs maps
727 * @returns [k₀, k₁, ...] | [kᵢ, vᵢ] ∈ x₀ ∪ x₁, ...; [x₀, x₁, ...] = xs
728 */
729declare function unionKeys<K, V>(...xs: Entries<K, V>[]): Set<K>;
730/**
731 * Obtain entries present in any map.
732 * [📘](https://github.com/nodef/extra-map/wiki/union)
733 * @param x a map
734 * @param y another map
735 * @param fc combine function (a, b)
736 * @returns x ∪ y = \{[kᵢ, vᵢ] | [kᵢ, vᵢ] ∈ x or [kᵢ, vᵢ] ∈ y\}
737 */
738declare function union<K, V>(x: Entries<K, V>, y: Entries<K, V>, fc?: CombineFunction<V> | null): Map<K, V>;
739/**
740 * Obtain entries present in any map.
741 * [📘](https://github.com/nodef/extra-map/wiki/union$)
742 * @param x a map (updated)
743 * @param y another map
744 * @param fc combine function (a, b)
745 * @returns x = x ∪ y = \{[kᵢ, vᵢ] | [kᵢ, vᵢ] ∈ x or [kᵢ, vᵢ] ∈ y\}
746 */
747declare function union$<K, V>(x: Map<K, V>, y: Entries<K, V>, fc?: CombineFunction<V> | null): Map<K, V>;
748/**
749 * Obtain keys present in all maps.
750 * [📘](https://github.com/nodef/extra-map/wiki/intersectionKeys)
751 * @param xs maps
752 * @returns [k₀, k₁, ...] | [kᵢ, vᵢ] ∈ x₀ ∩ x₁, ...; [x₀, x₁, ...] = xs
753 */
754declare function intersectionKeys<K, V>(...xs: Map<K, V>[]): Set<K>;
755/**
756 * Obtain entries present in both maps.
757 * [📘](https://github.com/nodef/extra-map/wiki/intersection)
758 * @param x a map
759 * @param y another map
760 * @param fc combine function (a, b)
761 * @returns x ∩ y = \{[kᵢ, vᵢ] | [kᵢ, vᵢ] ∈ x and [kᵢ, vᵢ] ∈ y\}
762 */
763declare function intersection<K, V>(x: Map<K, V>, y: Entries<K, V>, fc?: CombineFunction<V> | null): Map<K, V>;
764/**
765 * Obtain entries present in both maps.
766 * [📘](https://github.com/nodef/extra-map/wiki/intersection$)
767 * @param x a map (updated)
768 * @param y another map
769 * @param fc combine function (a, b)
770 * @returns x = x ∩ y = \{[kᵢ, vᵢ] | [kᵢ, vᵢ] ∈ x and [kᵢ, vᵢ] ∈ y\}
771 */
772declare function intersection$<K, V>(x: Map<K, V>, y: Map<K, V>, fc?: CombineFunction<V> | null): Map<K, V>;
773/**
774 * Obtain entries not present in another map.
775 * [📘](https://github.com/nodef/extra-map/wiki/difference)
776 * @param x a map
777 * @param y another map
778 * @returns x - y = \{[kᵢ, vᵢ] | [kᵢ, vᵢ] ∈ x, [kᵢ, *] ∉ y\}
779 */
780declare function difference<K, V>(x: Entries<K, V>, y: Entries<K, V>): Map<K, V>;
781/**
782 * Obtain entries not present in another map.
783 * [📘](https://github.com/nodef/extra-map/wiki/difference$)
784 * @param x a map (updated)
785 * @param y another map
786 * @returns x = x - y = \{[kᵢ, vᵢ] | [kᵢ, vᵢ] ∈ x, [kᵢ, *] ∉ y\}
787 */
788declare function difference$<K, V>(x: Map<K, V>, y: Entries<K, V>): Map<K, V>;
789/**
790 * Obtain entries not present in both maps.
791 * [📘](https://github.com/nodef/extra-map/wiki/symmetricDifference)
792 * @param x a map
793 * @param y another map
794 * @returns x-y ∪ y-x
795 */
796declare function symmetricDifference<K, V>(x: Entries<K, V>, y: Entries<K, V>): Map<K, V>;
797/**
798 * Obtain entries not present in both maps.
799 * [📘](https://github.com/nodef/extra-map/wiki/symmetricDifference$)
800 * @param x a map (updated)
801 * @param y another map
802 * @returns x = x-y ∪ y-x
803 */
804declare function symmetricDifference$<K, V>(x: Map<K, V>, y: Entries<K, V>): Map<K, V>;
805/**
806 * List cartesian product of maps.
807 * [📘](https://github.com/nodef/extra-map/wiki/cartesianProduct)
808 * @param xs maps
809 * @param fm map function (vs, i)
810 * @returns x₀ × x₁ × ... = \{\{[k₀, v₀], [k₁, v₁], ...\} | [k₀, v₀] ∈ x₀, [k₁, v₁] ∈ x₁, ...]\}
811 */
812declare function cartesianProduct<K, V, W = Map<K, V>>(xs: Map<K, V>[], fm?: MapFunction<number, Map<K, V>, Map<K, V> | W> | null): IterableIterator<Map<K, V> | W>;
813
814export { type CombineFunction, type CompareFunction, type EndFunction, type Entries, type Lists, type MapFunction, type ProcessFunction, type ReadFunction, type ReduceFunction, type TestFunction, cartesianProduct, chunk, compare, concat, concat$, count, countAs, difference, difference$, drop, drop$, entries, randomEntry as entry, every, filter, filter$, filterAt, filterAt$, find, findAll, flat, flatMap, forEach, from, from$, from as fromEntries, from$ as fromEntries$, fromKeys, fromLists, fromValues, get, getAll, getPath, has, hasEntry, has as hasKey, hasPath, hasSubset, hasValue, head, intersection, intersection$, intersectionKeys, is, isDisjoint, isEmpty, isEqual, join, randomKey as key, keys, size as length, map, map$, max, maxEntry, min, minEntry, partition, partitionAs, randomEntry, randomKey, randomSubset, range, rangeEntries, reduce, reject, reject$, rejectAt, rejectAt$, remove, remove$, removePath$, search, searchAll, searchValue, searchValueAll, set, set$, setPath$, size, some, randomSubset as subset, subsets, swap, swap$, symmetricDifference, symmetricDifference$, tail, take, take$, union, union$, unionKeys, values, zip };