1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 | declare namespace Immutable {
|
96 |
|
97 | type OnlyObject<T> = Extract<T, object>;
|
98 |
|
99 |
|
100 | type ContainObject<T> = OnlyObject<T> extends object
|
101 | ? OnlyObject<T> extends never
|
102 | ? false
|
103 | : true
|
104 | : false;
|
105 |
|
106 | |
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 | export type DeepCopy<T> = T extends Record<infer R>
|
113 | ?
|
114 | {
|
115 | [key in keyof R]: ContainObject<R[key]> extends true ? unknown : R[key];
|
116 | }
|
117 | : T extends MapOf<infer R>
|
118 | ?
|
119 | {
|
120 | [key in keyof R]: ContainObject<R[key]> extends true ? unknown : R[key];
|
121 | }
|
122 | : T extends Collection.Keyed<infer KeyedKey, infer V>
|
123 | ?
|
124 | {
|
125 | [key in KeyedKey extends string | number | symbol
|
126 | ? KeyedKey
|
127 | : string]: V extends object ? unknown : V;
|
128 | }
|
129 | :
|
130 |
|
131 | T extends Collection<infer _, infer V>
|
132 | ? Array<DeepCopy<V>>
|
133 | : T extends string | number
|
134 | ? T
|
135 | : T extends Iterable<infer V>
|
136 | ? Array<DeepCopy<V>>
|
137 | : T extends object
|
138 | ? {
|
139 | [ObjectKey in keyof T]: ContainObject<T[ObjectKey]> extends true
|
140 | ? unknown
|
141 | : T[ObjectKey];
|
142 | }
|
143 | :
|
144 | T;
|
145 |
|
146 | |
147 |
|
148 |
|
149 |
|
150 |
|
151 | export enum PairSorting {
|
152 | LeftThenRight = -1,
|
153 | RightThenLeft = +1,
|
154 | }
|
155 |
|
156 | |
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 | export type Comparator<T> = (left: T, right: T) => PairSorting | number;
|
166 |
|
167 | |
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 | namespace List {
|
182 | |
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 | function isList(maybeList: unknown): maybeList is List<unknown>;
|
193 |
|
194 | |
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 |
|
203 |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 | function of<T>(...values: Array<T>): List<T>;
|
214 | }
|
215 |
|
216 | |
217 |
|
218 |
|
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 | function List<T>(collection?: Iterable<T> | ArrayLike<T>): List<T>;
|
248 |
|
249 | interface List<T> extends Collection.Indexed<T> {
|
250 | |
251 |
|
252 |
|
253 | readonly size: number;
|
254 |
|
255 |
|
256 |
|
257 | |
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 |
|
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 |
|
285 |
|
286 | set(index: number, value: T): List<T>;
|
287 |
|
288 | |
289 |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 |
|
304 |
|
305 |
|
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 |
|
315 | delete(index: number): List<T>;
|
316 | remove(index: number): List<T>;
|
317 |
|
318 | |
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 |
|
329 |
|
330 |
|
331 |
|
332 |
|
333 |
|
334 |
|
335 |
|
336 |
|
337 | insert(index: number, value: T): List<T>;
|
338 |
|
339 | |
340 |
|
341 |
|
342 |
|
343 |
|
344 |
|
345 |
|
346 |
|
347 |
|
348 |
|
349 |
|
350 |
|
351 |
|
352 | clear(): List<T>;
|
353 |
|
354 | |
355 |
|
356 |
|
357 |
|
358 |
|
359 |
|
360 |
|
361 |
|
362 |
|
363 |
|
364 |
|
365 |
|
366 |
|
367 |
|
368 | push(...values: Array<T>): List<T>;
|
369 |
|
370 | |
371 |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 |
|
377 |
|
378 |
|
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 |
|
385 | pop(): List<T>;
|
386 |
|
387 | |
388 |
|
389 |
|
390 |
|
391 |
|
392 |
|
393 |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 |
|
399 |
|
400 |
|
401 | unshift(...values: Array<T>): List<T>;
|
402 |
|
403 | |
404 |
|
405 |
|
406 |
|
407 |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 |
|
417 |
|
418 |
|
419 |
|
420 |
|
421 | shift(): List<T>;
|
422 |
|
423 | |
424 |
|
425 |
|
426 |
|
427 |
|
428 |
|
429 |
|
430 |
|
431 |
|
432 |
|
433 |
|
434 |
|
435 |
|
436 |
|
437 |
|
438 |
|
439 |
|
440 |
|
441 |
|
442 |
|
443 |
|
444 |
|
445 |
|
446 |
|
447 |
|
448 |
|
449 |
|
450 |
|
451 |
|
452 |
|
453 |
|
454 |
|
455 |
|
456 |
|
457 |
|
458 |
|
459 |
|
460 |
|
461 |
|
462 |
|
463 |
|
464 |
|
465 | update(index: number, notSetValue: T, updater: (value: T) => T): this;
|
466 | update(
|
467 | index: number,
|
468 | updater: (value: T | undefined) => T | undefined
|
469 | ): this;
|
470 | update<R>(updater: (value: this) => R): R;
|
471 |
|
472 | /**
|
473 | * Returns a new List with size `size`. If `size` is less than this
|
474 | * List's size, the new List will exclude values at the higher indices.
|
475 | * If `size` is greater than this List's size, the new List will have
|
476 | * undefined values for the newly available indices.
|
477 | *
|
478 | * When building a new List and the final size is known up front, `setSize`
|
479 | * used in conjunction with `withMutations` may result in the more
|
480 | * performant construction.
|
481 | */
|
482 | setSize(size: number): List<T>;
|
483 |
|
484 | // Deep persistent changes
|
485 |
|
486 | /**
|
487 | * Returns a new List having set `value` at this `keyPath`. If any keys in
|
488 | * `keyPath` do not exist, a new immutable Map will be created at that key.
|
489 | *
|
490 | * Index numbers are used as keys to determine the path to follow in
|
491 | * the List.
|
492 | *
|
493 | * <!-- runkit:activate -->
|
494 | * ```js
|
495 | * const { List } = require('immutable')
|
496 | * const list = List([ 0, 1, 2, List([ 3, 4 ])])
|
497 | * list.setIn([3, 0], 999);
|
498 | * // List [ 0, 1, 2, List [ 999, 4 ] ]
|
499 | * ```
|
500 | *
|
501 | * Plain JavaScript Object or Arrays may be nested within an Immutable.js
|
502 | * Collection, and setIn() can update those values as well, treating them
|
503 | * immutably by creating new copies of those values with the changes applied.
|
504 | *
|
505 | * <!-- runkit:activate -->
|
506 | * ```js
|
507 | * const { List } = require('immutable')
|
508 | * const list = List([ 0, 1, 2, { plain: 'object' }])
|
509 | * list.setIn([3, 'plain'], 'value');
|
510 | * // List([ 0, 1, 2, { plain: 'value' }])
|
511 | * ```
|
512 | *
|
513 | * Note: `setIn` can be used in `withMutations`.
|
514 | */
|
515 | setIn(keyPath: Iterable<unknown>, value: unknown): this;
|
516 |
|
517 | /**
|
518 | * Returns a new List having removed the value at this `keyPath`. If any
|
519 | * keys in `keyPath` do not exist, no change will occur.
|
520 | *
|
521 | * <!-- runkit:activate -->
|
522 | * ```js
|
523 | * const { List } = require('immutable')
|
524 | * const list = List([ 0, 1, 2, List([ 3, 4 ])])
|
525 | * list.deleteIn([3, 0]);
|
526 | * // List [ 0, 1, 2, List [ 4 ] ]
|
527 | * ```
|
528 | *
|
529 | * Plain JavaScript Object or Arrays may be nested within an Immutable.js
|
530 | * Collection, and removeIn() can update those values as well, treating them
|
531 | * immutably by creating new copies of those values with the changes applied.
|
532 | *
|
533 | * <!-- runkit:activate -->
|
534 | * ```js
|
535 | * const { List } = require('immutable')
|
536 | * const list = List([ 0, 1, 2, { plain: 'object' }])
|
537 | * list.removeIn([3, 'plain']);
|
538 | * // List([ 0, 1, 2, {}])
|
539 | * ```
|
540 | *
|
541 | * Note: `deleteIn` *cannot* be safely used in `withMutations`.
|
542 | *
|
543 | * @alias removeIn
|
544 | */
|
545 | deleteIn(keyPath: Iterable<unknown>): this;
|
546 | removeIn(keyPath: Iterable<unknown>): this;
|
547 |
|
548 | /**
|
549 | * Note: `updateIn` can be used in `withMutations`.
|
550 | *
|
551 | * @see `Map#updateIn`
|
552 | */
|
553 | updateIn(
|
554 | keyPath: Iterable<unknown>,
|
555 | notSetValue: unknown,
|
556 | updater: (value: unknown) => unknown
|
557 | ): this;
|
558 | updateIn(
|
559 | keyPath: Iterable<unknown>,
|
560 | updater: (value: unknown) => unknown
|
561 | ): this;
|
562 |
|
563 | /**
|
564 | * Note: `mergeIn` can be used in `withMutations`.
|
565 | *
|
566 | * @see `Map#mergeIn`
|
567 | */
|
568 | mergeIn(keyPath: Iterable<unknown>, ...collections: Array<unknown>): this;
|
569 |
|
570 | /**
|
571 | * Note: `mergeDeepIn` can be used in `withMutations`.
|
572 | *
|
573 | * @see `Map#mergeDeepIn`
|
574 | */
|
575 | mergeDeepIn(
|
576 | keyPath: Iterable<unknown>,
|
577 | ...collections: Array<unknown>
|
578 | ): this;
|
579 |
|
580 | // Transient changes
|
581 |
|
582 | /**
|
583 | * Note: Not all methods can be safely used on a mutable collection or within
|
584 | * `withMutations`! Check the documentation for each method to see if it
|
585 | * allows being used in `withMutations`.
|
586 | *
|
587 | * @see `Map#withMutations`
|
588 | */
|
589 | withMutations(mutator: (mutable: this) => unknown): this;
|
590 |
|
591 | /**
|
592 | * An alternative API for withMutations()
|
593 | *
|
594 | * Note: Not all methods can be safely used on a mutable collection or within
|
595 | * `withMutations`! Check the documentation for each method to see if it
|
596 | * allows being used in `withMutations`.
|
597 | *
|
598 | * @see `Map#asMutable`
|
599 | */
|
600 | asMutable(): this;
|
601 |
|
602 | /**
|
603 | * @see `Map#wasAltered`
|
604 | */
|
605 | wasAltered(): boolean;
|
606 |
|
607 | /**
|
608 | * @see `Map#asImmutable`
|
609 | */
|
610 | asImmutable(): this;
|
611 |
|
612 | // Sequence algorithms
|
613 |
|
614 | /**
|
615 | * Returns a new List with other values or collections concatenated to this one.
|
616 | *
|
617 | * Note: `concat` can be used in `withMutations`.
|
618 | *
|
619 | * @alias merge
|
620 | */
|
621 | concat<C>(...valuesOrCollections: Array<Iterable<C> | C>): List<T | C>;
|
622 | merge<C>(...collections: Array<Iterable<C>>): List<T | C>;
|
623 |
|
624 | /**
|
625 | * Returns a new List with values passed through a
|
626 | * `mapper` function.
|
627 | *
|
628 | * <!-- runkit:activate
|
629 | * { "preamble": "const { List } = require('immutable');" }
|
630 | * -->
|
631 | * ```js
|
632 | * List([ 1, 2 ]).map(x => 10 * x)
|
633 | * // List [ 10, 20 ]
|
634 | * ```
|
635 | */
|
636 | map<M>(
|
637 | mapper: (value: T, key: number, iter: this) => M,
|
638 | context?: unknown
|
639 | ): List<M>;
|
640 |
|
641 | /**
|
642 | * Flat-maps the List, returning a new List.
|
643 | *
|
644 | * Similar to `list.map(...).flatten(true)`.
|
645 | */
|
646 | flatMap<M>(
|
647 | mapper: (value: T, key: number, iter: this) => Iterable<M>,
|
648 | context?: unknown
|
649 | ): List<M>;
|
650 |
|
651 | /**
|
652 | * Returns a new List with only the values for which the `predicate`
|
653 | * function returns true.
|
654 | *
|
655 | * Note: `filter()` always returns a new instance, even if it results in
|
656 | * not filtering out any values.
|
657 | */
|
658 | filter<F extends T>(
|
659 | predicate: (value: T, index: number, iter: this) => value is F,
|
660 | context?: unknown
|
661 | ): List<F>;
|
662 | filter(
|
663 | predicate: (value: T, index: number, iter: this) => unknown,
|
664 | context?: unknown
|
665 | ): this;
|
666 |
|
667 | /**
|
668 | * Returns a new List with the values for which the `predicate`
|
669 | * function returns false and another for which is returns true.
|
670 | */
|
671 | partition<F extends T, C>(
|
672 | predicate: (this: C, value: T, index: number, iter: this) => value is F,
|
673 | context?: C
|
674 | ): [List<T>, List<F>];
|
675 | partition<C>(
|
676 | predicate: (this: C, value: T, index: number, iter: this) => unknown,
|
677 | context?: C
|
678 | ): [this, this];
|
679 |
|
680 | /**
|
681 | * Returns a List "zipped" with the provided collection.
|
682 | *
|
683 | * Like `zipWith`, but using the default `zipper`: creating an `Array`.
|
684 | *
|
685 | * <!-- runkit:activate
|
686 | * { "preamble": "const { List } = require('immutable');" }
|
687 | * -->
|
688 | * ```js
|
689 | * const a = List([ 1, 2, 3 ]);
|
690 | * const b = List([ 4, 5, 6 ]);
|
691 | * const c = a.zip(b); // List [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]
|
692 | * ```
|
693 | */
|
694 | zip<U>(other: Collection<unknown, U>): List<[T, U]>;
|
695 | zip<U, V>(
|
696 | other: Collection<unknown, U>,
|
697 | other2: Collection<unknown, V>
|
698 | ): List<[T, U, V]>;
|
699 | zip(...collections: Array<Collection<unknown, unknown>>): List<unknown>;
|
700 |
|
701 | /**
|
702 | * Returns a List "zipped" with the provided collections.
|
703 | *
|
704 | * Unlike `zip`, `zipAll` continues zipping until the longest collection is
|
705 | * exhausted. Missing values from shorter collections are filled with `undefined`.
|
706 | *
|
707 | * <!-- runkit:activate
|
708 | * { "preamble": "const { List } = require('immutable');" }
|
709 | * -->
|
710 | * ```js
|
711 | * const a = List([ 1, 2 ]);
|
712 | * const b = List([ 3, 4, 5 ]);
|
713 | * const c = a.zipAll(b); // List [ [ 1, 3 ], [ 2, 4 ], [ undefined, 5 ] ]
|
714 | * ```
|
715 | *
|
716 | * Note: Since zipAll will return a collection as large as the largest
|
717 | * input, some results may contain undefined values. TypeScript cannot
|
718 | * account for these without cases (as of v2.5).
|
719 | */
|
720 | zipAll<U>(other: Collection<unknown, U>): List<[T, U]>;
|
721 | zipAll<U, V>(
|
722 | other: Collection<unknown, U>,
|
723 | other2: Collection<unknown, V>
|
724 | ): List<[T, U, V]>;
|
725 | zipAll(...collections: Array<Collection<unknown, unknown>>): List<unknown>;
|
726 |
|
727 | /**
|
728 | * Returns a List "zipped" with the provided collections by using a
|
729 | * custom `zipper` function.
|
730 | *
|
731 | * <!-- runkit:activate
|
732 | * { "preamble": "const { List } = require('immutable');" }
|
733 | * -->
|
734 | * ```js
|
735 | * const a = List([ 1, 2, 3 ]);
|
736 | * const b = List([ 4, 5, 6 ]);
|
737 | * const c = a.zipWith((a, b) => a + b, b);
|
738 | * // List [ 5, 7, 9 ]
|
739 | * ```
|
740 | */
|
741 | zipWith<U, Z>(
|
742 | zipper: (value: T, otherValue: U) => Z,
|
743 | otherCollection: Collection<unknown, U>
|
744 | ): List<Z>;
|
745 | zipWith<U, V, Z>(
|
746 | zipper: (value: T, otherValue: U, thirdValue: V) => Z,
|
747 | otherCollection: Collection<unknown, U>,
|
748 | thirdCollection: Collection<unknown, V>
|
749 | ): List<Z>;
|
750 | zipWith<Z>(
|
751 | zipper: (...values: Array<unknown>) => Z,
|
752 | ...collections: Array<Collection<unknown, unknown>>
|
753 | ): List<Z>;
|
754 | }
|
755 |
|
756 | /**
|
757 | * Immutable Map is an unordered Collection.Keyed of (key, value) pairs with
|
758 | * `O(log32 N)` gets and `O(log32 N)` persistent sets.
|
759 | *
|
760 | * Iteration order of a Map is undefined, however is stable. Multiple
|
761 | * iterations of the same Map will iterate in the same order.
|
762 | *
|
763 | * Map's keys can be of any type, and use `Immutable.is` to determine key
|
764 | * equality. This allows the use of any value (including NaN) as a key.
|
765 | *
|
766 | * Because `Immutable.is` returns equality based on value semantics, and
|
767 | * Immutable collections are treated as values, any Immutable collection may
|
768 | * be used as a key.
|
769 | *
|
770 | * <!-- runkit:activate -->
|
771 | * ```js
|
772 | * const { Map, List } = require('immutable');
|
773 | * Map().set(List([ 1 ]), 'listofone').get(List([ 1 ]));
|
774 | * // 'listofone'
|
775 | * ```
|
776 | *
|
777 | * Any JavaScript object may be used as a key, however strict identity is used
|
778 | * to evaluate key equality. Two similar looking objects will represent two
|
779 | * different keys.
|
780 | *
|
781 | * Implemented by a hash-array mapped trie.
|
782 | */
|
783 | namespace Map {
|
784 | /**
|
785 | * True if the provided value is a Map
|
786 | *
|
787 | * <!-- runkit:activate -->
|
788 | * ```js
|
789 | * const { Map } = require('immutable')
|
790 | * Map.isMap({}) // false
|
791 | * Map.isMap(Map()) // true
|
792 | * ```
|
793 | */
|
794 | function isMap(maybeMap: unknown): maybeMap is Map<unknown, unknown>;
|
795 | }
|
796 |
|
797 | /**
|
798 | * Creates a new Immutable Map.
|
799 | *
|
800 | * Created with the same key value pairs as the provided Collection.Keyed or
|
801 | * JavaScript Object or expects a Collection of [K, V] tuple entries.
|
802 | *
|
803 | * Note: `Map` is a factory function and not a class, and does not use the
|
804 | * `new` keyword during construction.
|
805 | *
|
806 | * <!-- runkit:activate -->
|
807 | * ```js
|
808 | * const { Map } = require('immutable')
|
809 | * Map({ key: "value" })
|
810 | * Map([ [ "key", "value" ] ])
|
811 | * ```
|
812 | *
|
813 | * Keep in mind, when using JS objects to construct Immutable Maps, that
|
814 | * JavaScript Object properties are always strings, even if written in a
|
815 | * quote-less shorthand, while Immutable Maps accept keys of any type.
|
816 | *
|
817 | * <!-- runkit:activate
|
818 | * { "preamble": "const { Map } = require('immutable');" }
|
819 | * -->
|
820 | * ```js
|
821 | * let obj = { 1: "one" }
|
822 | * Object.keys(obj) // [ "1" ]
|
823 | * assert.equal(obj["1"], obj[1]) // "one" === "one"
|
824 | *
|
825 | * let map = Map(obj)
|
826 | * assert.notEqual(map.get("1"), map.get(1)) // "one" !== undefined
|
827 | * ```
|
828 | *
|
829 | * Property access for JavaScript Objects first converts the key to a string,
|
830 | * but since Immutable Map keys can be of any type the argument to `get()` is
|
831 | * not altered.
|
832 | */
|
833 | function Map<K, V>(collection?: Iterable<[K, V]>): Map<K, V>;
|
834 | function Map<R extends { [key in string | number | symbol]: unknown }>(
|
835 | obj: R
|
836 | ): MapOf<R>;
|
837 | function Map<V>(obj: { [key: string]: V }): Map<string, V>;
|
838 | function Map<K extends string | symbol, V>(obj: { [P in K]?: V }): Map<K, V>;
|
839 |
|
840 | /**
|
841 | * Represent a Map constructed by an object
|
842 | *
|
843 | * @ignore
|
844 | */
|
845 | interface MapOf<R extends { [key in string | number | symbol]: unknown }>
|
846 | extends Map<keyof R, R[keyof R]> {
|
847 | /**
|
848 | * Returns the value associated with the provided key, or notSetValue if
|
849 | * the Collection does not contain this key.
|
850 | *
|
851 | * Note: it is possible a key may be associated with an `undefined` value,
|
852 | * so if `notSetValue` is not provided and this method returns `undefined`,
|
853 | * that does not guarantee the key was not found.
|
854 | */
|
855 | get<K extends keyof R>(key: K, notSetValue?: unknown): R[K];
|
856 | get<NSV>(key: any, notSetValue: NSV): NSV;
|
857 |
|
858 | // TODO `<const P extends ...>` can be used after dropping support for TypeScript 4.x
|
859 | // reference: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-0.html#const-type-parameters
|
860 | // after this change, `as const` assertions can be remove from the type tests
|
861 | getIn<P extends ReadonlyArray<string | number | symbol>>(
|
862 | searchKeyPath: [...P],
|
863 | notSetValue?: unknown
|
864 | ): RetrievePath<R, P>;
|
865 |
|
866 | set<K extends keyof R>(key: K, value: R[K]): this;
|
867 |
|
868 | update(updater: (value: this) => this): this;
|
869 | update<K extends keyof R>(key: K, updater: (value: R[K]) => R[K]): this;
|
870 | update<K extends keyof R, NSV extends R[K]>(
|
871 | key: K,
|
872 | notSetValue: NSV,
|
873 | updater: (value: R[K]) => R[K]
|
874 | ): this;
|
875 |
|
876 | // Possible best type is MapOf<Omit<R, K>> but Omit seems to broke other function calls
|
877 | // and generate recursion error with other methods (update, merge, etc.) until those functions are defined in MapOf
|
878 | delete<K extends keyof R>(
|
879 | key: K
|
880 | ): Extract<R[K], undefined> extends never ? never : this;
|
881 | remove<K extends keyof R>(
|
882 | key: K
|
883 | ): Extract<R[K], undefined> extends never ? never : this;
|
884 |
|
885 | toJS(): { [K in keyof R]: DeepCopy<R[K]> };
|
886 |
|
887 | toJSON(): { [K in keyof R]: R[K] };
|
888 | }
|
889 |
|
890 | // Loosely based off of this work.
|
891 | // https://github.com/immutable-js/immutable-js/issues/1462#issuecomment-584123268
|
892 |
|
893 | /** @ignore */
|
894 | type GetMapType<S> = S extends MapOf<infer T> ? T : S;
|
895 |
|
896 | /** @ignore */
|
897 | type Head<T extends ReadonlyArray<any>> = T extends [
|
898 | infer H,
|
899 | ...Array<unknown>
|
900 | ]
|
901 | ? H
|
902 | : never;
|
903 |
|
904 | /** @ignore */
|
905 | type Tail<T extends ReadonlyArray<any>> = T extends [unknown, ...infer I]
|
906 | ? I
|
907 | : Array<never>;
|
908 |
|
909 | /** @ignore */
|
910 | type RetrievePathReducer<
|
911 | T,
|
912 | C,
|
913 | L extends ReadonlyArray<any>
|
914 | > = C extends keyof GetMapType<T>
|
915 | ? L extends []
|
916 | ? GetMapType<T>[C]
|
917 | : RetrievePathReducer<GetMapType<T>[C], Head<L>, Tail<L>>
|
918 | : never;
|
919 |
|
920 | /** @ignore */
|
921 | type RetrievePath<
|
922 | R,
|
923 | P extends ReadonlyArray<string | number | symbol>
|
924 | > = P extends [] ? P : RetrievePathReducer<R, Head<P>, Tail<P>>;
|
925 |
|
926 | interface Map<K, V> extends Collection.Keyed<K, V> {
|
927 | /**
|
928 | * The number of entries in this Map.
|
929 | */
|
930 | readonly size: number;
|
931 |
|
932 | // Persistent changes
|
933 |
|
934 | /**
|
935 | * Returns a new Map also containing the new key, value pair. If an equivalent
|
936 | * key already exists in this Map, it will be replaced.
|
937 | *
|
938 | * <!-- runkit:activate -->
|
939 | * ```js
|
940 | * const { Map } = require('immutable')
|
941 | * const originalMap = Map()
|
942 | * const newerMap = originalMap.set('key', 'value')
|
943 | * const newestMap = newerMap.set('key', 'newer value')
|
944 | *
|
945 | * originalMap
|
946 | * // Map {}
|
947 | * newerMap
|
948 | * // Map { "key": "value" }
|
949 | * newestMap
|
950 | * // Map { "key": "newer value" }
|
951 | * ```
|
952 | *
|
953 | * Note: `set` can be used in `withMutations`.
|
954 | */
|
955 | set(key: K, value: V): this;
|
956 |
|
957 | /**
|
958 | * Returns a new Map which excludes this `key`.
|
959 | *
|
960 | * Note: `delete` cannot be safely used in IE8, but is provided to mirror
|
961 | * the ES6 collection API.
|
962 | *
|
963 | * <!-- runkit:activate -->
|
964 | * ```js
|
965 | * const { Map } = require('immutable')
|
966 | * const originalMap = Map({
|
967 | * key: 'value',
|
968 | * otherKey: 'other value'
|
969 | * })
|
970 | * // Map { "key": "value", "otherKey": "other value" }
|
971 | * originalMap.delete('otherKey')
|
972 | * // Map { "key": "value" }
|
973 | * ```
|
974 | *
|
975 | * Note: `delete` can be used in `withMutations`.
|
976 | *
|
977 | * @alias remove
|
978 | */
|
979 | delete(key: K): this;
|
980 | remove(key: K): this;
|
981 |
|
982 | /**
|
983 | * Returns a new Map which excludes the provided `keys`.
|
984 | *
|
985 | * <!-- runkit:activate -->
|
986 | * ```js
|
987 | * const { Map } = require('immutable')
|
988 | * const names = Map({ a: "Aaron", b: "Barry", c: "Connor" })
|
989 | * names.deleteAll([ 'a', 'c' ])
|
990 | * // Map { "b": "Barry" }
|
991 | * ```
|
992 | *
|
993 | * Note: `deleteAll` can be used in `withMutations`.
|
994 | *
|
995 | * @alias removeAll
|
996 | */
|
997 | deleteAll(keys: Iterable<K>): this;
|
998 | removeAll(keys: Iterable<K>): this;
|
999 |
|
1000 | /**
|
1001 | * Returns a new Map containing no keys or values.
|
1002 | *
|
1003 | * <!-- runkit:activate -->
|
1004 | * ```js
|
1005 | * const { Map } = require('immutable')
|
1006 | * Map({ key: 'value' }).clear()
|
1007 | * // Map {}
|
1008 | * ```
|
1009 | *
|
1010 | * Note: `clear` can be used in `withMutations`.
|
1011 | */
|
1012 | clear(): this;
|
1013 |
|
1014 | /**
|
1015 | * Returns a new Map having updated the value at this `key` with the return
|
1016 | * value of calling `updater` with the existing value.
|
1017 | *
|
1018 | * Similar to: `map.set(key, updater(map.get(key)))`.
|
1019 | *
|
1020 | * <!-- runkit:activate -->
|
1021 | * ```js
|
1022 | * const { Map } = require('immutable')
|
1023 | * const aMap = Map({ key: 'value' })
|
1024 | * const newMap = aMap.update('key', value => value + value)
|
1025 | * // Map { "key": "valuevalue" }
|
1026 | * ```
|
1027 | *
|
1028 | * This is most commonly used to call methods on collections within a
|
1029 | * structure of data. For example, in order to `.push()` onto a nested `List`,
|
1030 | * `update` and `push` can be used together:
|
1031 | *
|
1032 | * <!-- runkit:activate
|
1033 | * { "preamble": "const { Map, List } = require('immutable');" }
|
1034 | * -->
|
1035 | * ```js
|
1036 | * const aMap = Map({ nestedList: List([ 1, 2, 3 ]) })
|
1037 | * const newMap = aMap.update('nestedList', list => list.push(4))
|
1038 | * // Map { "nestedList": List [ 1, 2, 3, 4 ] }
|
1039 | * ```
|
1040 | *
|
1041 | * When a `notSetValue` is provided, it is provided to the `updater`
|
1042 | * function when the value at the key does not exist in the Map.
|
1043 | *
|
1044 | * <!-- runkit:activate
|
1045 | * { "preamble": "const { Map } = require('immutable');" }
|
1046 | * -->
|
1047 | * ```js
|
1048 | * const aMap = Map({ key: 'value' })
|
1049 | * const newMap = aMap.update('noKey', 'no value', value => value + value)
|
1050 | * // Map { "key": "value", "noKey": "no valueno value" }
|
1051 | * ```
|
1052 | *
|
1053 | * However, if the `updater` function returns the same value it was called
|
1054 | * with, then no change will occur. This is still true if `notSetValue`
|
1055 | * is provided.
|
1056 | *
|
1057 | * <!-- runkit:activate
|
1058 | * { "preamble": "const { Map } = require('immutable');" }
|
1059 | * -->
|
1060 | * ```js
|
1061 | * const aMap = Map({ apples: 10 })
|
1062 | * const newMap = aMap.update('oranges', 0, val => val)
|
1063 | * // Map { "apples": 10 }
|
1064 | * assert.strictEqual(newMap, map);
|
1065 | * ```
|
1066 | *
|
1067 | * For code using ES2015 or later, using `notSetValue` is discourged in
|
1068 | * favor of function parameter default values. This helps to avoid any
|
1069 | * potential confusion with identify functions as described above.
|
1070 | *
|
1071 | * The previous example behaves differently when written with default values:
|
1072 | *
|
1073 | * <!-- runkit:activate
|
1074 | * { "preamble": "const { Map } = require('immutable');" }
|
1075 | * -->
|
1076 | * ```js
|
1077 | * const aMap = Map({ apples: 10 })
|
1078 | * const newMap = aMap.update('oranges', (val = 0) => val)
|
1079 | * // Map { "apples": 10, "oranges": 0 }
|
1080 | * ```
|
1081 | *
|
1082 | * If no key is provided, then the `updater` function return value is
|
1083 | * returned as well.
|
1084 | *
|
1085 | * <!-- runkit:activate
|
1086 | * { "preamble": "const { Map } = require('immutable');" }
|
1087 | * -->
|
1088 | * ```js
|
1089 | * const aMap = Map({ key: 'value' })
|
1090 | * const result = aMap.update(aMap => aMap.get('key'))
|
1091 | * // "value"
|
1092 | * ```
|
1093 | *
|
1094 | * This can be very useful as a way to "chain" a normal function into a
|
1095 | * sequence of methods. RxJS calls this "let" and lodash calls it "thru".
|
1096 | *
|
1097 | * For example, to sum the values in a Map
|
1098 | *
|
1099 | * <!-- runkit:activate
|
1100 | * { "preamble": "const { Map } = require('immutable');" }
|
1101 | * -->
|
1102 | * ```js
|
1103 | * function sum(collection) {
|
1104 | * return collection.reduce((sum, x) => sum + x, 0)
|
1105 | * }
|
1106 | *
|
1107 | * Map({ x: 1, y: 2, z: 3 })
|
1108 | * .map(x => x + 1)
|
1109 | * .filter(x => x % 2 === 0)
|
1110 | * .update(sum)
|
1111 | * // 6
|
1112 | * ```
|
1113 | *
|
1114 | * Note: `update(key)` can be used in `withMutations`.
|
1115 | */
|
1116 | update(key: K, notSetValue: V, updater: (value: V) => V): this;
|
1117 | update(key: K, updater: (value: V | undefined) => V | undefined): this;
|
1118 | update<R>(updater: (value: this) => R): R;
|
1119 |
|
1120 | /**
|
1121 | * Returns a new Map resulting from merging the provided Collections
|
1122 | * (or JS objects) into this Map. In other words, this takes each entry of
|
1123 | * each collection and sets it on this Map.
|
1124 | *
|
1125 | * Note: Values provided to `merge` are shallowly converted before being
|
1126 | * merged. No nested values are altered.
|
1127 | *
|
1128 | * <!-- runkit:activate -->
|
1129 | * ```js
|
1130 | * const { Map } = require('immutable')
|
1131 | * const one = Map({ a: 10, b: 20, c: 30 })
|
1132 | * const two = Map({ b: 40, a: 50, d: 60 })
|
1133 | * one.merge(two) // Map { "a": 50, "b": 40, "c": 30, "d": 60 }
|
1134 | * two.merge(one) // Map { "b": 20, "a": 10, "d": 60, "c": 30 }
|
1135 | * ```
|
1136 | *
|
1137 | * Note: `merge` can be used in `withMutations`.
|
1138 | *
|
1139 | * @alias concat
|
1140 | */
|
1141 | merge<KC, VC>(
|
1142 | ...collections: Array<Iterable<[KC, VC]>>
|
1143 | ): Map<K | KC, Exclude<V, VC> | VC>;
|
1144 | merge<C>(
|
1145 | ...collections: Array<{ [key: string]: C }>
|
1146 | ): Map<K | string, Exclude<V, C> | C>;
|
1147 |
|
1148 | concat<KC, VC>(
|
1149 | ...collections: Array<Iterable<[KC, VC]>>
|
1150 | ): Map<K | KC, Exclude<V, VC> | VC>;
|
1151 | concat<C>(
|
1152 | ...collections: Array<{ [key: string]: C }>
|
1153 | ): Map<K | string, Exclude<V, C> | C>;
|
1154 |
|
1155 | /**
|
1156 | * Like `merge()`, `mergeWith()` returns a new Map resulting from merging
|
1157 | * the provided Collections (or JS objects) into this Map, but uses the
|
1158 | * `merger` function for dealing with conflicts.
|
1159 | *
|
1160 | * <!-- runkit:activate -->
|
1161 | * ```js
|
1162 | * const { Map } = require('immutable')
|
1163 | * const one = Map({ a: 10, b: 20, c: 30 })
|
1164 | * const two = Map({ b: 40, a: 50, d: 60 })
|
1165 | * one.mergeWith((oldVal, newVal) => oldVal / newVal, two)
|
1166 | * // { "a": 0.2, "b": 0.5, "c": 30, "d": 60 }
|
1167 | * two.mergeWith((oldVal, newVal) => oldVal / newVal, one)
|
1168 | * // { "b": 2, "a": 5, "d": 60, "c": 30 }
|
1169 | * ```
|
1170 | *
|
1171 | * Note: `mergeWith` can be used in `withMutations`.
|
1172 | */
|
1173 | mergeWith<KC, VC, VCC>(
|
1174 | merger: (oldVal: V, newVal: VC, key: K) => VCC,
|
1175 | ...collections: Array<Iterable<[KC, VC]>>
|
1176 | ): Map<K | KC, V | VC | VCC>;
|
1177 | mergeWith<C, CC>(
|
1178 | merger: (oldVal: V, newVal: C, key: string) => CC,
|
1179 | ...collections: Array<{ [key: string]: C }>
|
1180 | ): Map<K | string, V | C | CC>;
|
1181 |
|
1182 | /**
|
1183 | * Like `merge()`, but when two compatible collections are encountered with
|
1184 | * the same key, it merges them as well, recursing deeply through the nested
|
1185 | * data. Two collections are considered to be compatible (and thus will be
|
1186 | * merged together) if they both fall into one of three categories: keyed
|
1187 | * (e.g., `Map`s, `Record`s, and objects), indexed (e.g., `List`s and
|
1188 | * arrays), or set-like (e.g., `Set`s). If they fall into separate
|
1189 | * categories, `mergeDeep` will replace the existing collection with the
|
1190 | * collection being merged in. This behavior can be customized by using
|
1191 | * `mergeDeepWith()`.
|
1192 | *
|
1193 | * Note: Indexed and set-like collections are merged using
|
1194 | * `concat()`/`union()` and therefore do not recurse.
|
1195 | *
|
1196 | * <!-- runkit:activate -->
|
1197 | * ```js
|
1198 | * const { Map } = require('immutable')
|
1199 | * const one = Map({ a: Map({ x: 10, y: 10 }), b: Map({ x: 20, y: 50 }) })
|
1200 | * const two = Map({ a: Map({ x: 2 }), b: Map({ y: 5 }), c: Map({ z: 3 }) })
|
1201 | * one.mergeDeep(two)
|
1202 | * // Map {
|
1203 | * // "a": Map { "x": 2, "y": 10 },
|
1204 | * // "b": Map { "x": 20, "y": 5 },
|
1205 | * // "c": Map { "z": 3 }
|
1206 | * // }
|
1207 | * ```
|
1208 | *
|
1209 | * Note: `mergeDeep` can be used in `withMutations`.
|
1210 | */
|
1211 | mergeDeep<KC, VC>(
|
1212 | ...collections: Array<Iterable<[KC, VC]>>
|
1213 | ): Map<K | KC, V | VC>;
|
1214 | mergeDeep<C>(
|
1215 | ...collections: Array<{ [key: string]: C }>
|
1216 | ): Map<K | string, V | C>;
|
1217 |
|
1218 | /**
|
1219 | * Like `mergeDeep()`, but when two non-collections or incompatible
|
1220 | * collections are encountered at the same key, it uses the `merger`
|
1221 | * function to determine the resulting value. Collections are considered
|
1222 | * incompatible if they fall into separate categories between keyed,
|
1223 | * indexed, and set-like.
|
1224 | *
|
1225 | * <!-- runkit:activate -->
|
1226 | * ```js
|
1227 | * const { Map } = require('immutable')
|
1228 | * const one = Map({ a: Map({ x: 10, y: 10 }), b: Map({ x: 20, y: 50 }) })
|
1229 | * const two = Map({ a: Map({ x: 2 }), b: Map({ y: 5 }), c: Map({ z: 3 }) })
|
1230 | * one.mergeDeepWith((oldVal, newVal) => oldVal / newVal, two)
|
1231 | * // Map {
|
1232 | * // "a": Map { "x": 5, "y": 10 },
|
1233 | * // "b": Map { "x": 20, "y": 10 },
|
1234 | * // "c": Map { "z": 3 }
|
1235 | * // }
|
1236 | * ```
|
1237 | *
|
1238 | * Note: `mergeDeepWith` can be used in `withMutations`.
|
1239 | */
|
1240 | mergeDeepWith(
|
1241 | merger: (oldVal: unknown, newVal: unknown, key: unknown) => unknown,
|
1242 | ...collections: Array<Iterable<[K, V]> | { [key: string]: V }>
|
1243 | ): this;
|
1244 |
|
1245 | // Deep persistent changes
|
1246 |
|
1247 | /**
|
1248 | * Returns a new Map having set `value` at this `keyPath`. If any keys in
|
1249 | * `keyPath` do not exist, a new immutable Map will be created at that key.
|
1250 | *
|
1251 | * <!-- runkit:activate -->
|
1252 | * ```js
|
1253 | * const { Map } = require('immutable')
|
1254 | * const originalMap = Map({
|
1255 | * subObject: Map({
|
1256 | * subKey: 'subvalue',
|
1257 | * subSubObject: Map({
|
1258 | * subSubKey: 'subSubValue'
|
1259 | * })
|
1260 | * })
|
1261 | * })
|
1262 | *
|
1263 | * const newMap = originalMap.setIn(['subObject', 'subKey'], 'ha ha!')
|
1264 | * // Map {
|
1265 | * // "subObject": Map {
|
1266 | * // "subKey": "ha ha!",
|
1267 | * // "subSubObject": Map { "subSubKey": "subSubValue" }
|
1268 | * // }
|
1269 | * // }
|
1270 | *
|
1271 | * const newerMap = originalMap.setIn(
|
1272 | * ['subObject', 'subSubObject', 'subSubKey'],
|
1273 | * 'ha ha ha!'
|
1274 | * )
|
1275 | * // Map {
|
1276 | * // "subObject": Map {
|
1277 | * // "subKey": "subvalue",
|
1278 | * // "subSubObject": Map { "subSubKey": "ha ha ha!" }
|
1279 | * // }
|
1280 | * // }
|
1281 | * ```
|
1282 | *
|
1283 | * Plain JavaScript Object or Arrays may be nested within an Immutable.js
|
1284 | * Collection, and setIn() can update those values as well, treating them
|
1285 | * immutably by creating new copies of those values with the changes applied.
|
1286 | *
|
1287 | * <!-- runkit:activate -->
|
1288 | * ```js
|
1289 | * const { Map } = require('immutable')
|
1290 | * const originalMap = Map({
|
1291 | * subObject: {
|
1292 | * subKey: 'subvalue',
|
1293 | * subSubObject: {
|
1294 | * subSubKey: 'subSubValue'
|
1295 | * }
|
1296 | * }
|
1297 | * })
|
1298 | *
|
1299 | * originalMap.setIn(['subObject', 'subKey'], 'ha ha!')
|
1300 | * // Map {
|
1301 | * // "subObject": {
|
1302 | * // subKey: "ha ha!",
|
1303 | * // subSubObject: { subSubKey: "subSubValue" }
|
1304 | * // }
|
1305 | * // }
|
1306 | * ```
|
1307 | *
|
1308 | * If any key in the path exists but cannot be updated (such as a primitive
|
1309 | * like number or a custom Object like Date), an error will be thrown.
|
1310 | *
|
1311 | * Note: `setIn` can be used in `withMutations`.
|
1312 | */
|
1313 | setIn(keyPath: Iterable<unknown>, value: unknown): this;
|
1314 |
|
1315 | /**
|
1316 | * Returns a new Map having removed the value at this `keyPath`. If any keys
|
1317 | * in `keyPath` do not exist, no change will occur.
|
1318 | *
|
1319 | * Note: `deleteIn` can be used in `withMutations`.
|
1320 | *
|
1321 | * @alias removeIn
|
1322 | */
|
1323 | deleteIn(keyPath: Iterable<unknown>): this;
|
1324 | removeIn(keyPath: Iterable<unknown>): this;
|
1325 |
|
1326 | /**
|
1327 | * Returns a new Map having applied the `updater` to the entry found at the
|
1328 | * keyPath.
|
1329 | *
|
1330 | * This is most commonly used to call methods on collections nested within a
|
1331 | * structure of data. For example, in order to `.push()` onto a nested `List`,
|
1332 | * `updateIn` and `push` can be used together:
|
1333 | *
|
1334 | * <!-- runkit:activate -->
|
1335 | * ```js
|
1336 | * const { Map, List } = require('immutable')
|
1337 | * const map = Map({ inMap: Map({ inList: List([ 1, 2, 3 ]) }) })
|
1338 | * const newMap = map.updateIn(['inMap', 'inList'], list => list.push(4))
|
1339 | * // Map { "inMap": Map { "inList": List [ 1, 2, 3, 4 ] } }
|
1340 | * ```
|
1341 | *
|
1342 | * If any keys in `keyPath` do not exist, new Immutable `Map`s will
|
1343 | * be created at those keys. If the `keyPath` does not already contain a
|
1344 | * value, the `updater` function will be called with `notSetValue`, if
|
1345 | * provided, otherwise `undefined`.
|
1346 | *
|
1347 | * <!-- runkit:activate
|
1348 | * { "preamble": "const { Map } = require('immutable')" }
|
1349 | * -->
|
1350 | * ```js
|
1351 | * const map = Map({ a: Map({ b: Map({ c: 10 }) }) })
|
1352 | * const newMap = map.updateIn(['a', 'b', 'c'], val => val * 2)
|
1353 | * // Map { "a": Map { "b": Map { "c": 20 } } }
|
1354 | * ```
|
1355 | *
|
1356 | * If the `updater` function returns the same value it was called with, then
|
1357 | * no change will occur. This is still true if `notSetValue` is provided.
|
1358 | *
|
1359 | * <!-- runkit:activate
|
1360 | * { "preamble": "const { Map } = require('immutable')" }
|
1361 | * -->
|
1362 | * ```js
|
1363 | * const map = Map({ a: Map({ b: Map({ c: 10 }) }) })
|
1364 | * const newMap = map.updateIn(['a', 'b', 'x'], 100, val => val)
|
1365 | * // Map { "a": Map { "b": Map { "c": 10 } } }
|
1366 | * assert.strictEqual(newMap, aMap)
|
1367 | * ```
|
1368 | *
|
1369 | * For code using ES2015 or later, using `notSetValue` is discourged in
|
1370 | * favor of function parameter default values. This helps to avoid any
|
1371 | * potential confusion with identify functions as described above.
|
1372 | *
|
1373 | * The previous example behaves differently when written with default values:
|
1374 | *
|
1375 | * <!-- runkit:activate
|
1376 | * { "preamble": "const { Map } = require('immutable')" }
|
1377 | * -->
|
1378 | * ```js
|
1379 | * const map = Map({ a: Map({ b: Map({ c: 10 }) }) })
|
1380 | * const newMap = map.updateIn(['a', 'b', 'x'], (val = 100) => val)
|
1381 | * // Map { "a": Map { "b": Map { "c": 10, "x": 100 } } }
|
1382 | * ```
|
1383 | *
|
1384 | * Plain JavaScript Object or Arrays may be nested within an Immutable.js
|
1385 | * Collection, and updateIn() can update those values as well, treating them
|
1386 | * immutably by creating new copies of those values with the changes applied.
|
1387 | *
|
1388 | * <!-- runkit:activate
|
1389 | * { "preamble": "const { Map } = require('immutable')" }
|
1390 | * -->
|
1391 | * ```js
|
1392 | * const map = Map({ a: { b: { c: 10 } } })
|
1393 | * const newMap = map.updateIn(['a', 'b', 'c'], val => val * 2)
|
1394 | * // Map { "a": { b: { c: 20 } } }
|
1395 | * ```
|
1396 | *
|
1397 | * If any key in the path exists but cannot be updated (such as a primitive
|
1398 | * like number or a custom Object like Date), an error will be thrown.
|
1399 | *
|
1400 | * Note: `updateIn` can be used in `withMutations`.
|
1401 | */
|
1402 | updateIn(
|
1403 | keyPath: Iterable<unknown>,
|
1404 | notSetValue: unknown,
|
1405 | updater: (value: unknown) => unknown
|
1406 | ): this;
|
1407 | updateIn(
|
1408 | keyPath: Iterable<unknown>,
|
1409 | updater: (value: unknown) => unknown
|
1410 | ): this;
|
1411 |
|
1412 | /**
|
1413 | * A combination of `updateIn` and `merge`, returning a new Map, but
|
1414 | * performing the merge at a point arrived at by following the keyPath.
|
1415 | * In other words, these two lines are equivalent:
|
1416 | *
|
1417 | * ```js
|
1418 | * map.updateIn(['a', 'b', 'c'], abc => abc.merge(y))
|
1419 | * map.mergeIn(['a', 'b', 'c'], y)
|
1420 | * ```
|
1421 | *
|
1422 | * Note: `mergeIn` can be used in `withMutations`.
|
1423 | */
|
1424 | mergeIn(keyPath: Iterable<unknown>, ...collections: Array<unknown>): this;
|
1425 |
|
1426 | /**
|
1427 | * A combination of `updateIn` and `mergeDeep`, returning a new Map, but
|
1428 | * performing the deep merge at a point arrived at by following the keyPath.
|
1429 | * In other words, these two lines are equivalent:
|
1430 | *
|
1431 | * ```js
|
1432 | * map.updateIn(['a', 'b', 'c'], abc => abc.mergeDeep(y))
|
1433 | * map.mergeDeepIn(['a', 'b', 'c'], y)
|
1434 | * ```
|
1435 | *
|
1436 | * Note: `mergeDeepIn` can be used in `withMutations`.
|
1437 | */
|
1438 | mergeDeepIn(
|
1439 | keyPath: Iterable<unknown>,
|
1440 | ...collections: Array<unknown>
|
1441 | ): this;
|
1442 |
|
1443 | // Transient changes
|
1444 |
|
1445 | /**
|
1446 | * Every time you call one of the above functions, a new immutable Map is
|
1447 | * created. If a pure function calls a number of these to produce a final
|
1448 | * return value, then a penalty on performance and memory has been paid by
|
1449 | * creating all of the intermediate immutable Maps.
|
1450 | *
|
1451 | * If you need to apply a series of mutations to produce a new immutable
|
1452 | * Map, `withMutations()` creates a temporary mutable copy of the Map which
|
1453 | * can apply mutations in a highly performant manner. In fact, this is
|
1454 | * exactly how complex mutations like `merge` are done.
|
1455 | *
|
1456 | * As an example, this results in the creation of 2, not 4, new Maps:
|
1457 | *
|
1458 | * <!-- runkit:activate -->
|
1459 | * ```js
|
1460 | * const { Map } = require('immutable')
|
1461 | * const map1 = Map()
|
1462 | * const map2 = map1.withMutations(map => {
|
1463 | * map.set('a', 1).set('b', 2).set('c', 3)
|
1464 | * })
|
1465 | * assert.equal(map1.size, 0)
|
1466 | * assert.equal(map2.size, 3)
|
1467 | * ```
|
1468 | *
|
1469 | * Note: Not all methods can be used on a mutable collection or within
|
1470 | * `withMutations`! Read the documentation for each method to see if it
|
1471 | * is safe to use in `withMutations`.
|
1472 | */
|
1473 | withMutations(mutator: (mutable: this) => unknown): this;
|
1474 |
|
1475 | /**
|
1476 | * Another way to avoid creation of intermediate Immutable maps is to create
|
1477 | * a mutable copy of this collection. Mutable copies *always* return `this`,
|
1478 | * and thus shouldn't be used for equality. Your function should never return
|
1479 | * a mutable copy of a collection, only use it internally to create a new
|
1480 | * collection.
|
1481 | *
|
1482 | * If possible, use `withMutations` to work with temporary mutable copies as
|
1483 | * it provides an easier to use API and considers many common optimizations.
|
1484 | *
|
1485 | * Note: if the collection is already mutable, `asMutable` returns itself.
|
1486 | *
|
1487 | * Note: Not all methods can be used on a mutable collection or within
|
1488 | * `withMutations`! Read the documentation for each method to see if it
|
1489 | * is safe to use in `withMutations`.
|
1490 | *
|
1491 | * @see `Map#asImmutable`
|
1492 | */
|
1493 | asMutable(): this;
|
1494 |
|
1495 | /**
|
1496 | * Returns true if this is a mutable copy (see `asMutable()`) and mutative
|
1497 | * alterations have been applied.
|
1498 | *
|
1499 | * @see `Map#asMutable`
|
1500 | */
|
1501 | wasAltered(): boolean;
|
1502 |
|
1503 | /**
|
1504 | * The yin to `asMutable`'s yang. Because it applies to mutable collections,
|
1505 | * this operation is *mutable* and may return itself (though may not
|
1506 | * return itself, i.e. if the result is an empty collection). Once
|
1507 | * performed, the original mutable copy must no longer be mutated since it
|
1508 | * may be the immutable result.
|
1509 | *
|
1510 | * If possible, use `withMutations` to work with temporary mutable copies as
|
1511 | * it provides an easier to use API and considers many common optimizations.
|
1512 | *
|
1513 | * @see `Map#asMutable`
|
1514 | */
|
1515 | asImmutable(): this;
|
1516 |
|
1517 | // Sequence algorithms
|
1518 |
|
1519 | /**
|
1520 | * Returns a new Map with values passed through a
|
1521 | * `mapper` function.
|
1522 | *
|
1523 | * Map({ a: 1, b: 2 }).map(x => 10 * x)
|
1524 | * // Map { a: 10, b: 20 }
|
1525 | */
|
1526 | map<M>(
|
1527 | mapper: (value: V, key: K, iter: this) => M,
|
1528 | context?: unknown
|
1529 | ): Map<K, M>;
|
1530 |
|
1531 | /**
|
1532 | * @see Collection.Keyed.mapKeys
|
1533 | */
|
1534 | mapKeys<M>(
|
1535 | mapper: (key: K, value: V, iter: this) => M,
|
1536 | context?: unknown
|
1537 | ): Map<M, V>;
|
1538 |
|
1539 | /**
|
1540 | * @see Collection.Keyed.mapEntries
|
1541 | */
|
1542 | mapEntries<KM, VM>(
|
1543 | mapper: (
|
1544 | entry: [K, V],
|
1545 | index: number,
|
1546 | iter: this
|
1547 | ) => [KM, VM] | undefined,
|
1548 | context?: unknown
|
1549 | ): Map<KM, VM>;
|
1550 |
|
1551 | /**
|
1552 | * Flat-maps the Map, returning a new Map.
|
1553 | *
|
1554 | * Similar to `data.map(...).flatten(true)`.
|
1555 | */
|
1556 | flatMap<KM, VM>(
|
1557 | mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>,
|
1558 | context?: unknown
|
1559 | ): Map<KM, VM>;
|
1560 |
|
1561 | /**
|
1562 | * Returns a new Map with only the entries for which the `predicate`
|
1563 | * function returns true.
|
1564 | *
|
1565 | * Note: `filter()` always returns a new instance, even if it results in
|
1566 | * not filtering out any values.
|
1567 | */
|
1568 | filter<F extends V>(
|
1569 | predicate: (value: V, key: K, iter: this) => value is F,
|
1570 | context?: unknown
|
1571 | ): Map<K, F>;
|
1572 | filter(
|
1573 | predicate: (value: V, key: K, iter: this) => unknown,
|
1574 | context?: unknown
|
1575 | ): this;
|
1576 |
|
1577 | /**
|
1578 | * Returns a new Map with the values for which the `predicate`
|
1579 | * function returns false and another for which is returns true.
|
1580 | */
|
1581 | partition<F extends V, C>(
|
1582 | predicate: (this: C, value: V, key: K, iter: this) => value is F,
|
1583 | context?: C
|
1584 | ): [Map<K, V>, Map<K, F>];
|
1585 | partition<C>(
|
1586 | predicate: (this: C, value: V, key: K, iter: this) => unknown,
|
1587 | context?: C
|
1588 | ): [this, this];
|
1589 |
|
1590 | /**
|
1591 | * @see Collection.Keyed.flip
|
1592 | */
|
1593 | flip(): Map<V, K>;
|
1594 |
|
1595 | /**
|
1596 | * Returns an OrderedMap of the same type which includes the same entries,
|
1597 | * stably sorted by using a `comparator`.
|
1598 | *
|
1599 | * If a `comparator` is not provided, a default comparator uses `<` and `>`.
|
1600 | *
|
1601 | * `comparator(valueA, valueB)`:
|
1602 | *
|
1603 | * * Returns `0` if the elements should not be swapped.
|
1604 | * * Returns `-1` (or any negative number) if `valueA` comes before `valueB`
|
1605 | * * Returns `1` (or any positive number) if `valueA` comes after `valueB`
|
1606 | * * Alternatively, can return a value of the `PairSorting` enum type
|
1607 | * * Is pure, i.e. it must always return the same value for the same pair
|
1608 | * of values.
|
1609 | *
|
1610 | * <!-- runkit:activate -->
|
1611 | * ```js
|
1612 | * const { Map } = require('immutable')
|
1613 | * Map({ "c": 3, "a": 1, "b": 2 }).sort((a, b) => {
|
1614 | * if (a < b) { return -1; }
|
1615 | * if (a > b) { return 1; }
|
1616 | * if (a === b) { return 0; }
|
1617 | * });
|
1618 | * // OrderedMap { "a": 1, "b": 2, "c": 3 }
|
1619 | * ```
|
1620 | *
|
1621 | * Note: `sort()` Always returns a new instance, even if the original was
|
1622 | * already sorted.
|
1623 | *
|
1624 | * Note: This is always an eager operation.
|
1625 | */
|
1626 | sort(comparator?: Comparator<V>): this & OrderedMap<K, V>;
|
1627 |
|
1628 | /**
|
1629 | * Like `sort`, but also accepts a `comparatorValueMapper` which allows for
|
1630 | * sorting by more sophisticated means:
|
1631 | *
|
1632 | * <!-- runkit:activate -->
|
1633 | * ```js
|
1634 | * const { Map } = require('immutable')
|
1635 | * const beattles = Map({
|
1636 | * John: { name: "Lennon" },
|
1637 | * Paul: { name: "McCartney" },
|
1638 | * George: { name: "Harrison" },
|
1639 | * Ringo: { name: "Starr" },
|
1640 | * });
|
1641 | * beattles.sortBy(member => member.name);
|
1642 | * ```
|
1643 | *
|
1644 | * Note: `sortBy()` Always returns a new instance, even if the original was
|
1645 | * already sorted.
|
1646 | *
|
1647 | * Note: This is always an eager operation.
|
1648 | */
|
1649 | sortBy<C>(
|
1650 | comparatorValueMapper: (value: V, key: K, iter: this) => C,
|
1651 | comparator?: (valueA: C, valueB: C) => number
|
1652 | ): this & OrderedMap<K, V>;
|
1653 | }
|
1654 |
|
1655 | /**
|
1656 | * A type of Map that has the additional guarantee that the iteration order of
|
1657 | * entries will be the order in which they were set().
|
1658 | *
|
1659 | * The iteration behavior of OrderedMap is the same as native ES6 Map and
|
1660 | * JavaScript Object.
|
1661 | *
|
1662 | * Note that `OrderedMap` are more expensive than non-ordered `Map` and may
|
1663 | * consume more memory. `OrderedMap#set` is amortized O(log32 N), but not
|
1664 | * stable.
|
1665 | */
|
1666 | namespace OrderedMap {
|
1667 | /**
|
1668 | * True if the provided value is an OrderedMap.
|
1669 | */
|
1670 | function isOrderedMap(
|
1671 | maybeOrderedMap: unknown
|
1672 | ): maybeOrderedMap is OrderedMap<unknown, unknown>;
|
1673 | }
|
1674 |
|
1675 | /**
|
1676 | * Creates a new Immutable OrderedMap.
|
1677 | *
|
1678 | * Created with the same key value pairs as the provided Collection.Keyed or
|
1679 | * JavaScript Object or expects a Collection of [K, V] tuple entries.
|
1680 | *
|
1681 | * The iteration order of key-value pairs provided to this constructor will
|
1682 | * be preserved in the OrderedMap.
|
1683 | *
|
1684 | * let newOrderedMap = OrderedMap({key: "value"})
|
1685 | * let newOrderedMap = OrderedMap([["key", "value"]])
|
1686 | *
|
1687 | * Note: `OrderedMap` is a factory function and not a class, and does not use
|
1688 | * the `new` keyword during construction.
|
1689 | */
|
1690 | function OrderedMap<K, V>(collection?: Iterable<[K, V]>): OrderedMap<K, V>;
|
1691 | function OrderedMap<V>(obj: { [key: string]: V }): OrderedMap<string, V>;
|
1692 |
|
1693 | interface OrderedMap<K, V> extends Map<K, V> {
|
1694 | /**
|
1695 | * The number of entries in this OrderedMap.
|
1696 | */
|
1697 | readonly size: number;
|
1698 |
|
1699 | /**
|
1700 | * Returns a new OrderedMap also containing the new key, value pair. If an
|
1701 | * equivalent key already exists in this OrderedMap, it will be replaced
|
1702 | * while maintaining the existing order.
|
1703 | *
|
1704 | * <!-- runkit:activate -->
|
1705 | * ```js
|
1706 | * const { OrderedMap } = require('immutable')
|
1707 | * const originalMap = OrderedMap({a:1, b:1, c:1})
|
1708 | * const updatedMap = originalMap.set('b', 2)
|
1709 | *
|
1710 | * originalMap
|
1711 | * // OrderedMap {a: 1, b: 1, c: 1}
|
1712 | * updatedMap
|
1713 | * // OrderedMap {a: 1, b: 2, c: 1}
|
1714 | * ```
|
1715 | *
|
1716 | * Note: `set` can be used in `withMutations`.
|
1717 | */
|
1718 | set(key: K, value: V): this;
|
1719 |
|
1720 | /**
|
1721 | * Returns a new OrderedMap resulting from merging the provided Collections
|
1722 | * (or JS objects) into this OrderedMap. In other words, this takes each
|
1723 | * entry of each collection and sets it on this OrderedMap.
|
1724 | *
|
1725 | * Note: Values provided to `merge` are shallowly converted before being
|
1726 | * merged. No nested values are altered.
|
1727 | *
|
1728 | * <!-- runkit:activate -->
|
1729 | * ```js
|
1730 | * const { OrderedMap } = require('immutable')
|
1731 | * const one = OrderedMap({ a: 10, b: 20, c: 30 })
|
1732 | * const two = OrderedMap({ b: 40, a: 50, d: 60 })
|
1733 | * one.merge(two) // OrderedMap { "a": 50, "b": 40, "c": 30, "d": 60 }
|
1734 | * two.merge(one) // OrderedMap { "b": 20, "a": 10, "d": 60, "c": 30 }
|
1735 | * ```
|
1736 | *
|
1737 | * Note: `merge` can be used in `withMutations`.
|
1738 | *
|
1739 | * @alias concat
|
1740 | */
|
1741 | merge<KC, VC>(
|
1742 | ...collections: Array<Iterable<[KC, VC]>>
|
1743 | ): OrderedMap<K | KC, Exclude<V, VC> | VC>;
|
1744 | merge<C>(
|
1745 | ...collections: Array<{ [key: string]: C }>
|
1746 | ): OrderedMap<K | string, Exclude<V, C> | C>;
|
1747 |
|
1748 | concat<KC, VC>(
|
1749 | ...collections: Array<Iterable<[KC, VC]>>
|
1750 | ): OrderedMap<K | KC, Exclude<V, VC> | VC>;
|
1751 | concat<C>(
|
1752 | ...collections: Array<{ [key: string]: C }>
|
1753 | ): OrderedMap<K | string, Exclude<V, C> | C>;
|
1754 |
|
1755 | mergeWith<KC, VC, VCC>(
|
1756 | merger: (oldVal: V, newVal: VC, key: K) => VCC,
|
1757 | ...collections: Array<Iterable<[KC, VC]>>
|
1758 | ): OrderedMap<K | KC, V | VC | VCC>;
|
1759 | mergeWith<C, CC>(
|
1760 | merger: (oldVal: V, newVal: C, key: string) => CC,
|
1761 | ...collections: Array<{ [key: string]: C }>
|
1762 | ): OrderedMap<K | string, V | C | CC>;
|
1763 |
|
1764 | mergeDeep<KC, VC>(
|
1765 | ...collections: Array<Iterable<[KC, VC]>>
|
1766 | ): OrderedMap<K | KC, V | VC>;
|
1767 | mergeDeep<C>(
|
1768 | ...collections: Array<{ [key: string]: C }>
|
1769 | ): OrderedMap<K | string, V | C>;
|
1770 |
|
1771 | // Sequence algorithms
|
1772 |
|
1773 | /**
|
1774 | * Returns a new OrderedMap with values passed through a
|
1775 | * `mapper` function.
|
1776 | *
|
1777 | * OrderedMap({ a: 1, b: 2 }).map(x => 10 * x)
|
1778 | * // OrderedMap { "a": 10, "b": 20 }
|
1779 | *
|
1780 | * Note: `map()` always returns a new instance, even if it produced the same
|
1781 | * value at every step.
|
1782 | */
|
1783 | map<M>(
|
1784 | mapper: (value: V, key: K, iter: this) => M,
|
1785 | context?: unknown
|
1786 | ): OrderedMap<K, M>;
|
1787 |
|
1788 | /**
|
1789 | * @see Collection.Keyed.mapKeys
|
1790 | */
|
1791 | mapKeys<M>(
|
1792 | mapper: (key: K, value: V, iter: this) => M,
|
1793 | context?: unknown
|
1794 | ): OrderedMap<M, V>;
|
1795 |
|
1796 | /**
|
1797 | * @see Collection.Keyed.mapEntries
|
1798 | */
|
1799 | mapEntries<KM, VM>(
|
1800 | mapper: (
|
1801 | entry: [K, V],
|
1802 | index: number,
|
1803 | iter: this
|
1804 | ) => [KM, VM] | undefined,
|
1805 | context?: unknown
|
1806 | ): OrderedMap<KM, VM>;
|
1807 |
|
1808 | /**
|
1809 | * Flat-maps the OrderedMap, returning a new OrderedMap.
|
1810 | *
|
1811 | * Similar to `data.map(...).flatten(true)`.
|
1812 | */
|
1813 | flatMap<KM, VM>(
|
1814 | mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>,
|
1815 | context?: unknown
|
1816 | ): OrderedMap<KM, VM>;
|
1817 |
|
1818 | /**
|
1819 | * Returns a new OrderedMap with only the entries for which the `predicate`
|
1820 | * function returns true.
|
1821 | *
|
1822 | * Note: `filter()` always returns a new instance, even if it results in
|
1823 | * not filtering out any values.
|
1824 | */
|
1825 | filter<F extends V>(
|
1826 | predicate: (value: V, key: K, iter: this) => value is F,
|
1827 | context?: unknown
|
1828 | ): OrderedMap<K, F>;
|
1829 | filter(
|
1830 | predicate: (value: V, key: K, iter: this) => unknown,
|
1831 | context?: unknown
|
1832 | ): this;
|
1833 |
|
1834 | /**
|
1835 | * Returns a new OrderedMap with the values for which the `predicate`
|
1836 | * function returns false and another for which is returns true.
|
1837 | */
|
1838 | partition<F extends V, C>(
|
1839 | predicate: (this: C, value: V, key: K, iter: this) => value is F,
|
1840 | context?: C
|
1841 | ): [OrderedMap<K, V>, OrderedMap<K, F>];
|
1842 | partition<C>(
|
1843 | predicate: (this: C, value: V, key: K, iter: this) => unknown,
|
1844 | context?: C
|
1845 | ): [this, this];
|
1846 |
|
1847 | /**
|
1848 | * @see Collection.Keyed.flip
|
1849 | */
|
1850 | flip(): OrderedMap<V, K>;
|
1851 | }
|
1852 |
|
1853 | /**
|
1854 | * A Collection of unique values with `O(log32 N)` adds and has.
|
1855 | *
|
1856 | * When iterating a Set, the entries will be (value, value) pairs. Iteration
|
1857 | * order of a Set is undefined, however is stable. Multiple iterations of the
|
1858 | * same Set will iterate in the same order.
|
1859 | *
|
1860 | * Set values, like Map keys, may be of any type. Equality is determined using
|
1861 | * `Immutable.is`, enabling Sets to uniquely include other Immutable
|
1862 | * collections, custom value types, and NaN.
|
1863 | */
|
1864 | namespace Set {
|
1865 | /**
|
1866 | * True if the provided value is a Set
|
1867 | */
|
1868 | function isSet(maybeSet: unknown): maybeSet is Set<unknown>;
|
1869 |
|
1870 | /**
|
1871 | * Creates a new Set containing `values`.
|
1872 | */
|
1873 | function of<T>(...values: Array<T>): Set<T>;
|
1874 |
|
1875 | /**
|
1876 | * `Set.fromKeys()` creates a new immutable Set containing the keys from
|
1877 | * this Collection or JavaScript Object.
|
1878 | */
|
1879 | function fromKeys<T>(iter: Collection.Keyed<T, unknown>): Set<T>;
|
1880 | function fromKeys<T>(iter: Collection<T, unknown>): Set<T>;
|
1881 | function fromKeys(obj: { [key: string]: unknown }): Set<string>;
|
1882 |
|
1883 | /**
|
1884 | * `Set.intersect()` creates a new immutable Set that is the intersection of
|
1885 | * a collection of other sets.
|
1886 | *
|
1887 | * ```js
|
1888 | * const { Set } = require('immutable')
|
1889 | * const intersected = Set.intersect([
|
1890 | * Set([ 'a', 'b', 'c' ])
|
1891 | * Set([ 'c', 'a', 't' ])
|
1892 | * ])
|
1893 | * // Set [ "a", "c" ]
|
1894 | * ```
|
1895 | */
|
1896 | function intersect<T>(sets: Iterable<Iterable<T>>): Set<T>;
|
1897 |
|
1898 | /**
|
1899 | * `Set.union()` creates a new immutable Set that is the union of a
|
1900 | * collection of other sets.
|
1901 | *
|
1902 | * ```js
|
1903 | * const { Set } = require('immutable')
|
1904 | * const unioned = Set.union([
|
1905 | * Set([ 'a', 'b', 'c' ])
|
1906 | * Set([ 'c', 'a', 't' ])
|
1907 | * ])
|
1908 | * // Set [ "a", "b", "c", "t" ]
|
1909 | * ```
|
1910 | */
|
1911 | function union<T>(sets: Iterable<Iterable<T>>): Set<T>;
|
1912 | }
|
1913 |
|
1914 | /**
|
1915 | * Create a new immutable Set containing the values of the provided
|
1916 | * collection-like.
|
1917 | *
|
1918 | * Note: `Set` is a factory function and not a class, and does not use the
|
1919 | * `new` keyword during construction.
|
1920 | */
|
1921 | function Set<T>(collection?: Iterable<T> | ArrayLike<T>): Set<T>;
|
1922 |
|
1923 | interface Set<T> extends Collection.Set<T> {
|
1924 | /**
|
1925 | * The number of items in this Set.
|
1926 | */
|
1927 | readonly size: number;
|
1928 |
|
1929 | // Persistent changes
|
1930 |
|
1931 | /**
|
1932 | * Returns a new Set which also includes this value.
|
1933 | *
|
1934 | * Note: `add` can be used in `withMutations`.
|
1935 | */
|
1936 | add(value: T): this;
|
1937 |
|
1938 | /**
|
1939 | * Returns a new Set which excludes this value.
|
1940 | *
|
1941 | * Note: `delete` can be used in `withMutations`.
|
1942 | *
|
1943 | * Note: `delete` **cannot** be safely used in IE8, use `remove` if
|
1944 | * supporting old browsers.
|
1945 | *
|
1946 | * @alias remove
|
1947 | */
|
1948 | delete(value: T): this;
|
1949 | remove(value: T): this;
|
1950 |
|
1951 | /**
|
1952 | * Returns a new Set containing no values.
|
1953 | *
|
1954 | * Note: `clear` can be used in `withMutations`.
|
1955 | */
|
1956 | clear(): this;
|
1957 |
|
1958 | /**
|
1959 | * Returns a Set including any value from `collections` that does not already
|
1960 | * exist in this Set.
|
1961 | *
|
1962 | * Note: `union` can be used in `withMutations`.
|
1963 | * @alias merge
|
1964 | * @alias concat
|
1965 | */
|
1966 | union<C>(...collections: Array<Iterable<C>>): Set<T | C>;
|
1967 | merge<C>(...collections: Array<Iterable<C>>): Set<T | C>;
|
1968 | concat<C>(...collections: Array<Iterable<C>>): Set<T | C>;
|
1969 |
|
1970 | /**
|
1971 | * Returns a Set which has removed any values not also contained
|
1972 | * within `collections`.
|
1973 | *
|
1974 | * Note: `intersect` can be used in `withMutations`.
|
1975 | */
|
1976 | intersect(...collections: Array<Iterable<T>>): this;
|
1977 |
|
1978 | /**
|
1979 | * Returns a Set excluding any values contained within `collections`.
|
1980 | *
|
1981 | * <!-- runkit:activate -->
|
1982 | * ```js
|
1983 | * const { OrderedSet } = require('immutable')
|
1984 | * OrderedSet([ 1, 2, 3 ]).subtract([1, 3])
|
1985 | * // OrderedSet [2]
|
1986 | * ```
|
1987 | *
|
1988 | * Note: `subtract` can be used in `withMutations`.
|
1989 | */
|
1990 | subtract(...collections: Array<Iterable<T>>): this;
|
1991 |
|
1992 | // Transient changes
|
1993 |
|
1994 | /**
|
1995 | * Note: Not all methods can be used on a mutable collection or within
|
1996 | * `withMutations`! Check the documentation for each method to see if it
|
1997 | * mentions being safe to use in `withMutations`.
|
1998 | *
|
1999 | * @see `Map#withMutations`
|
2000 | */
|
2001 | withMutations(mutator: (mutable: this) => unknown): this;
|
2002 |
|
2003 | /**
|
2004 | * Note: Not all methods can be used on a mutable collection or within
|
2005 | * `withMutations`! Check the documentation for each method to see if it
|
2006 | * mentions being safe to use in `withMutations`.
|
2007 | *
|
2008 | * @see `Map#asMutable`
|
2009 | */
|
2010 | asMutable(): this;
|
2011 |
|
2012 | /**
|
2013 | * @see `Map#wasAltered`
|
2014 | */
|
2015 | wasAltered(): boolean;
|
2016 |
|
2017 | /**
|
2018 | * @see `Map#asImmutable`
|
2019 | */
|
2020 | asImmutable(): this;
|
2021 |
|
2022 | // Sequence algorithms
|
2023 |
|
2024 | /**
|
2025 | * Returns a new Set with values passed through a
|
2026 | * `mapper` function.
|
2027 | *
|
2028 | * Set([1,2]).map(x => 10 * x)
|
2029 | * // Set [10,20]
|
2030 | */
|
2031 | map<M>(
|
2032 | mapper: (value: T, key: T, iter: this) => M,
|
2033 | context?: unknown
|
2034 | ): Set<M>;
|
2035 |
|
2036 | /**
|
2037 | * Flat-maps the Set, returning a new Set.
|
2038 | *
|
2039 | * Similar to `set.map(...).flatten(true)`.
|
2040 | */
|
2041 | flatMap<M>(
|
2042 | mapper: (value: T, key: T, iter: this) => Iterable<M>,
|
2043 | context?: unknown
|
2044 | ): Set<M>;
|
2045 |
|
2046 | /**
|
2047 | * Returns a new Set with only the values for which the `predicate`
|
2048 | * function returns true.
|
2049 | *
|
2050 | * Note: `filter()` always returns a new instance, even if it results in
|
2051 | * not filtering out any values.
|
2052 | */
|
2053 | filter<F extends T>(
|
2054 | predicate: (value: T, key: T, iter: this) => value is F,
|
2055 | context?: unknown
|
2056 | ): Set<F>;
|
2057 | filter(
|
2058 | predicate: (value: T, key: T, iter: this) => unknown,
|
2059 | context?: unknown
|
2060 | ): this;
|
2061 |
|
2062 | /**
|
2063 | * Returns a new Set with the values for which the `predicate` function
|
2064 | * returns false and another for which is returns true.
|
2065 | */
|
2066 | partition<F extends T, C>(
|
2067 | predicate: (this: C, value: T, key: T, iter: this) => value is F,
|
2068 | context?: C
|
2069 | ): [Set<T>, Set<F>];
|
2070 | partition<C>(
|
2071 | predicate: (this: C, value: T, key: T, iter: this) => unknown,
|
2072 | context?: C
|
2073 | ): [this, this];
|
2074 |
|
2075 | /**
|
2076 | * Returns an OrderedSet of the same type which includes the same entries,
|
2077 | * stably sorted by using a `comparator`.
|
2078 | *
|
2079 | * If a `comparator` is not provided, a default comparator uses `<` and `>`.
|
2080 | *
|
2081 | * `comparator(valueA, valueB)`:
|
2082 | *
|
2083 | * * Returns `0` if the elements should not be swapped.
|
2084 | * * Returns `-1` (or any negative number) if `valueA` comes before `valueB`
|
2085 | * * Returns `1` (or any positive number) if `valueA` comes after `valueB`
|
2086 | * * Alternatively, can return a value of the `PairSorting` enum type
|
2087 | * * Is pure, i.e. it must always return the same value for the same pair
|
2088 | * of values.
|
2089 | *
|
2090 | * <!-- runkit:activate -->
|
2091 | * ```js
|
2092 | * const { Set } = require('immutable')
|
2093 | * Set(['b', 'a', 'c']).sort((a, b) => {
|
2094 | * if (a < b) { return -1; }
|
2095 | * if (a > b) { return 1; }
|
2096 | * if (a === b) { return 0; }
|
2097 | * });
|
2098 | * // OrderedSet { "a":, "b", "c" }
|
2099 | * ```
|
2100 | *
|
2101 | * Note: `sort()` Always returns a new instance, even if the original was
|
2102 | * already sorted.
|
2103 | *
|
2104 | * Note: This is always an eager operation.
|
2105 | */
|
2106 | sort(comparator?: Comparator<T>): this & OrderedSet<T>;
|
2107 |
|
2108 | /**
|
2109 | * Like `sort`, but also accepts a `comparatorValueMapper` which allows for
|
2110 | * sorting by more sophisticated means:
|
2111 | *
|
2112 | * <!-- runkit:activate -->
|
2113 | * ```js
|
2114 | * const { Set } = require('immutable')
|
2115 | * const beattles = Set([
|
2116 | * { name: "Lennon" },
|
2117 | * { name: "McCartney" },
|
2118 | * { name: "Harrison" },
|
2119 | * { name: "Starr" },
|
2120 | * ]);
|
2121 | * beattles.sortBy(member => member.name);
|
2122 | * ```
|
2123 | *
|
2124 | * Note: `sortBy()` Always returns a new instance, even if the original was
|
2125 | * already sorted.
|
2126 | *
|
2127 | * Note: This is always an eager operation.
|
2128 | */
|
2129 | sortBy<C>(
|
2130 | comparatorValueMapper: (value: T, key: T, iter: this) => C,
|
2131 | comparator?: (valueA: C, valueB: C) => number
|
2132 | ): this & OrderedSet<T>;
|
2133 | }
|
2134 |
|
2135 | /**
|
2136 | * A type of Set that has the additional guarantee that the iteration order of
|
2137 | * values will be the order in which they were `add`ed.
|
2138 | *
|
2139 | * The iteration behavior of OrderedSet is the same as native ES6 Set.
|
2140 | *
|
2141 | * Note that `OrderedSet` are more expensive than non-ordered `Set` and may
|
2142 | * consume more memory. `OrderedSet#add` is amortized O(log32 N), but not
|
2143 | * stable.
|
2144 | */
|
2145 | namespace OrderedSet {
|
2146 | /**
|
2147 | * True if the provided value is an OrderedSet.
|
2148 | */
|
2149 | function isOrderedSet(
|
2150 | maybeOrderedSet: unknown
|
2151 | ): maybeOrderedSet is OrderedSet<unknown>;
|
2152 |
|
2153 | /**
|
2154 | * Creates a new OrderedSet containing `values`.
|
2155 | */
|
2156 | function of<T>(...values: Array<T>): OrderedSet<T>;
|
2157 |
|
2158 | /**
|
2159 | * `OrderedSet.fromKeys()` creates a new immutable OrderedSet containing
|
2160 | * the keys from this Collection or JavaScript Object.
|
2161 | */
|
2162 | function fromKeys<T>(iter: Collection.Keyed<T, unknown>): OrderedSet<T>;
|
2163 | function fromKeys<T>(iter: Collection<T, unknown>): OrderedSet<T>;
|
2164 | function fromKeys(obj: { [key: string]: unknown }): OrderedSet<string>;
|
2165 | }
|
2166 |
|
2167 | /**
|
2168 | * Create a new immutable OrderedSet containing the values of the provided
|
2169 | * collection-like.
|
2170 | *
|
2171 | * Note: `OrderedSet` is a factory function and not a class, and does not use
|
2172 | * the `new` keyword during construction.
|
2173 | */
|
2174 | function OrderedSet<T>(
|
2175 | collection?: Iterable<T> | ArrayLike<T>
|
2176 | ): OrderedSet<T>;
|
2177 |
|
2178 | interface OrderedSet<T> extends Set<T> {
|
2179 | /**
|
2180 | * The number of items in this OrderedSet.
|
2181 | */
|
2182 | readonly size: number;
|
2183 |
|
2184 | /**
|
2185 | * Returns an OrderedSet including any value from `collections` that does
|
2186 | * not already exist in this OrderedSet.
|
2187 | *
|
2188 | * Note: `union` can be used in `withMutations`.
|
2189 | * @alias merge
|
2190 | * @alias concat
|
2191 | */
|
2192 | union<C>(...collections: Array<Iterable<C>>): OrderedSet<T | C>;
|
2193 | merge<C>(...collections: Array<Iterable<C>>): OrderedSet<T | C>;
|
2194 | concat<C>(...collections: Array<Iterable<C>>): OrderedSet<T | C>;
|
2195 |
|
2196 | // Sequence algorithms
|
2197 |
|
2198 | /**
|
2199 | * Returns a new Set with values passed through a
|
2200 | * `mapper` function.
|
2201 | *
|
2202 | * OrderedSet([ 1, 2 ]).map(x => 10 * x)
|
2203 | * // OrderedSet [10, 20]
|
2204 | */
|
2205 | map<M>(
|
2206 | mapper: (value: T, key: T, iter: this) => M,
|
2207 | context?: unknown
|
2208 | ): OrderedSet<M>;
|
2209 |
|
2210 | /**
|
2211 | * Flat-maps the OrderedSet, returning a new OrderedSet.
|
2212 | *
|
2213 | * Similar to `set.map(...).flatten(true)`.
|
2214 | */
|
2215 | flatMap<M>(
|
2216 | mapper: (value: T, key: T, iter: this) => Iterable<M>,
|
2217 | context?: unknown
|
2218 | ): OrderedSet<M>;
|
2219 |
|
2220 | /**
|
2221 | * Returns a new OrderedSet with only the values for which the `predicate`
|
2222 | * function returns true.
|
2223 | *
|
2224 | * Note: `filter()` always returns a new instance, even if it results in
|
2225 | * not filtering out any values.
|
2226 | */
|
2227 | filter<F extends T>(
|
2228 | predicate: (value: T, key: T, iter: this) => value is F,
|
2229 | context?: unknown
|
2230 | ): OrderedSet<F>;
|
2231 | filter(
|
2232 | predicate: (value: T, key: T, iter: this) => unknown,
|
2233 | context?: unknown
|
2234 | ): this;
|
2235 |
|
2236 | /**
|
2237 | * Returns a new OrderedSet with the values for which the `predicate`
|
2238 | * function returns false and another for which is returns true.
|
2239 | */
|
2240 | partition<F extends T, C>(
|
2241 | predicate: (this: C, value: T, key: T, iter: this) => value is F,
|
2242 | context?: C
|
2243 | ): [OrderedSet<T>, OrderedSet<F>];
|
2244 | partition<C>(
|
2245 | predicate: (this: C, value: T, key: T, iter: this) => unknown,
|
2246 | context?: C
|
2247 | ): [this, this];
|
2248 |
|
2249 | /**
|
2250 | * Returns an OrderedSet of the same type "zipped" with the provided
|
2251 | * collections.
|
2252 | *
|
2253 | * Like `zipWith`, but using the default `zipper`: creating an `Array`.
|
2254 | *
|
2255 | * ```js
|
2256 | * const a = OrderedSet([ 1, 2, 3 ])
|
2257 | * const b = OrderedSet([ 4, 5, 6 ])
|
2258 | * const c = a.zip(b)
|
2259 | * // OrderedSet [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]
|
2260 | * ```
|
2261 | */
|
2262 | zip<U>(other: Collection<unknown, U>): OrderedSet<[T, U]>;
|
2263 | zip<U, V>(
|
2264 | other1: Collection<unknown, U>,
|
2265 | other2: Collection<unknown, V>
|
2266 | ): OrderedSet<[T, U, V]>;
|
2267 | zip(
|
2268 | ...collections: Array<Collection<unknown, unknown>>
|
2269 | ): OrderedSet<unknown>;
|
2270 |
|
2271 | /**
|
2272 | * Returns a OrderedSet of the same type "zipped" with the provided
|
2273 | * collections.
|
2274 | *
|
2275 | * Unlike `zip`, `zipAll` continues zipping until the longest collection is
|
2276 | * exhausted. Missing values from shorter collections are filled with `undefined`.
|
2277 | *
|
2278 | * ```js
|
2279 | * const a = OrderedSet([ 1, 2 ]);
|
2280 | * const b = OrderedSet([ 3, 4, 5 ]);
|
2281 | * const c = a.zipAll(b); // OrderedSet [ [ 1, 3 ], [ 2, 4 ], [ undefined, 5 ] ]
|
2282 | * ```
|
2283 | *
|
2284 | * Note: Since zipAll will return a collection as large as the largest
|
2285 | * input, some results may contain undefined values. TypeScript cannot
|
2286 | * account for these without cases (as of v2.5).
|
2287 | */
|
2288 | zipAll<U>(other: Collection<unknown, U>): OrderedSet<[T, U]>;
|
2289 | zipAll<U, V>(
|
2290 | other1: Collection<unknown, U>,
|
2291 | other2: Collection<unknown, V>
|
2292 | ): OrderedSet<[T, U, V]>;
|
2293 | zipAll(
|
2294 | ...collections: Array<Collection<unknown, unknown>>
|
2295 | ): OrderedSet<unknown>;
|
2296 |
|
2297 | /**
|
2298 | * Returns an OrderedSet of the same type "zipped" with the provided
|
2299 | * collections by using a custom `zipper` function.
|
2300 | *
|
2301 | * @see Seq.Indexed.zipWith
|
2302 | */
|
2303 | zipWith<U, Z>(
|
2304 | zipper: (value: T, otherValue: U) => Z,
|
2305 | otherCollection: Collection<unknown, U>
|
2306 | ): OrderedSet<Z>;
|
2307 | zipWith<U, V, Z>(
|
2308 | zipper: (value: T, otherValue: U, thirdValue: V) => Z,
|
2309 | otherCollection: Collection<unknown, U>,
|
2310 | thirdCollection: Collection<unknown, V>
|
2311 | ): OrderedSet<Z>;
|
2312 | zipWith<Z>(
|
2313 | zipper: (...values: Array<unknown>) => Z,
|
2314 | ...collections: Array<Collection<unknown, unknown>>
|
2315 | ): OrderedSet<Z>;
|
2316 | }
|
2317 |
|
2318 | /**
|
2319 | * Stacks are indexed collections which support very efficient O(1) addition
|
2320 | * and removal from the front using `unshift(v)` and `shift()`.
|
2321 | *
|
2322 | * For familiarity, Stack also provides `push(v)`, `pop()`, and `peek()`, but
|
2323 | * be aware that they also operate on the front of the list, unlike List or
|
2324 | * a JavaScript Array.
|
2325 | *
|
2326 | * Note: `reverse()` or any inherent reverse traversal (`reduceRight`,
|
2327 | * `lastIndexOf`, etc.) is not efficient with a Stack.
|
2328 | *
|
2329 | * Stack is implemented with a Single-Linked List.
|
2330 | */
|
2331 | namespace Stack {
|
2332 | /**
|
2333 | * True if the provided value is a Stack
|
2334 | */
|
2335 | function isStack(maybeStack: unknown): maybeStack is Stack<unknown>;
|
2336 |
|
2337 | /**
|
2338 | * Creates a new Stack containing `values`.
|
2339 | */
|
2340 | function of<T>(...values: Array<T>): Stack<T>;
|
2341 | }
|
2342 |
|
2343 | /**
|
2344 | * Create a new immutable Stack containing the values of the provided
|
2345 | * collection-like.
|
2346 | *
|
2347 | * The iteration order of the provided collection is preserved in the
|
2348 | * resulting `Stack`.
|
2349 | *
|
2350 | * Note: `Stack` is a factory function and not a class, and does not use the
|
2351 | * `new` keyword during construction.
|
2352 | */
|
2353 | function Stack<T>(collection?: Iterable<T> | ArrayLike<T>): Stack<T>;
|
2354 |
|
2355 | interface Stack<T> extends Collection.Indexed<T> {
|
2356 | /**
|
2357 | * The number of items in this Stack.
|
2358 | */
|
2359 | readonly size: number;
|
2360 |
|
2361 | // Reading values
|
2362 |
|
2363 | /**
|
2364 | * Alias for `Stack.first()`.
|
2365 | */
|
2366 | peek(): T | undefined;
|
2367 |
|
2368 | // Persistent changes
|
2369 |
|
2370 | /**
|
2371 | * Returns a new Stack with 0 size and no values.
|
2372 | *
|
2373 | * Note: `clear` can be used in `withMutations`.
|
2374 | */
|
2375 | clear(): Stack<T>;
|
2376 |
|
2377 | /**
|
2378 | * Returns a new Stack with the provided `values` prepended, shifting other
|
2379 | * values ahead to higher indices.
|
2380 | *
|
2381 | * This is very efficient for Stack.
|
2382 | *
|
2383 | * Note: `unshift` can be used in `withMutations`.
|
2384 | */
|
2385 | unshift(...values: Array<T>): Stack<T>;
|
2386 |
|
2387 | /**
|
2388 | * Like `Stack#unshift`, but accepts a collection rather than varargs.
|
2389 | *
|
2390 | * Note: `unshiftAll` can be used in `withMutations`.
|
2391 | */
|
2392 | unshiftAll(iter: Iterable<T>): Stack<T>;
|
2393 |
|
2394 | /**
|
2395 | * Returns a new Stack with a size ones less than this Stack, excluding
|
2396 | * the first item in this Stack, shifting all other values to a lower index.
|
2397 | *
|
2398 | * Note: this differs from `Array#shift` because it returns a new
|
2399 | * Stack rather than the removed value. Use `first()` or `peek()` to get the
|
2400 | * first value in this Stack.
|
2401 | *
|
2402 | * Note: `shift` can be used in `withMutations`.
|
2403 | */
|
2404 | shift(): Stack<T>;
|
2405 |
|
2406 | /**
|
2407 | * Alias for `Stack#unshift` and is not equivalent to `List#push`.
|
2408 | */
|
2409 | push(...values: Array<T>): Stack<T>;
|
2410 |
|
2411 | /**
|
2412 | * Alias for `Stack#unshiftAll`.
|
2413 | */
|
2414 | pushAll(iter: Iterable<T>): Stack<T>;
|
2415 |
|
2416 | /**
|
2417 | * Alias for `Stack#shift` and is not equivalent to `List#pop`.
|
2418 | */
|
2419 | pop(): Stack<T>;
|
2420 |
|
2421 | // Transient changes
|
2422 |
|
2423 | /**
|
2424 | * Note: Not all methods can be used on a mutable collection or within
|
2425 | * `withMutations`! Check the documentation for each method to see if it
|
2426 | * mentions being safe to use in `withMutations`.
|
2427 | *
|
2428 | * @see `Map#withMutations`
|
2429 | */
|
2430 | withMutations(mutator: (mutable: this) => unknown): this;
|
2431 |
|
2432 | /**
|
2433 | * Note: Not all methods can be used on a mutable collection or within
|
2434 | * `withMutations`! Check the documentation for each method to see if it
|
2435 | * mentions being safe to use in `withMutations`.
|
2436 | *
|
2437 | * @see `Map#asMutable`
|
2438 | */
|
2439 | asMutable(): this;
|
2440 |
|
2441 | /**
|
2442 | * @see `Map#wasAltered`
|
2443 | */
|
2444 | wasAltered(): boolean;
|
2445 |
|
2446 | /**
|
2447 | * @see `Map#asImmutable`
|
2448 | */
|
2449 | asImmutable(): this;
|
2450 |
|
2451 | // Sequence algorithms
|
2452 |
|
2453 | /**
|
2454 | * Returns a new Stack with other collections concatenated to this one.
|
2455 | */
|
2456 | concat<C>(...valuesOrCollections: Array<Iterable<C> | C>): Stack<T | C>;
|
2457 |
|
2458 | /**
|
2459 | * Returns a new Stack with values passed through a
|
2460 | * `mapper` function.
|
2461 | *
|
2462 | * Stack([ 1, 2 ]).map(x => 10 * x)
|
2463 | * // Stack [ 10, 20 ]
|
2464 | *
|
2465 | * Note: `map()` always returns a new instance, even if it produced the same
|
2466 | * value at every step.
|
2467 | */
|
2468 | map<M>(
|
2469 | mapper: (value: T, key: number, iter: this) => M,
|
2470 | context?: unknown
|
2471 | ): Stack<M>;
|
2472 |
|
2473 | /**
|
2474 | * Flat-maps the Stack, returning a new Stack.
|
2475 | *
|
2476 | * Similar to `stack.map(...).flatten(true)`.
|
2477 | */
|
2478 | flatMap<M>(
|
2479 | mapper: (value: T, key: number, iter: this) => Iterable<M>,
|
2480 | context?: unknown
|
2481 | ): Stack<M>;
|
2482 |
|
2483 | /**
|
2484 | * Returns a new Set with only the values for which the `predicate`
|
2485 | * function returns true.
|
2486 | *
|
2487 | * Note: `filter()` always returns a new instance, even if it results in
|
2488 | * not filtering out any values.
|
2489 | */
|
2490 | filter<F extends T>(
|
2491 | predicate: (value: T, index: number, iter: this) => value is F,
|
2492 | context?: unknown
|
2493 | ): Set<F>;
|
2494 | filter(
|
2495 | predicate: (value: T, index: number, iter: this) => unknown,
|
2496 | context?: unknown
|
2497 | ): this;
|
2498 |
|
2499 | /**
|
2500 | * Returns a Stack "zipped" with the provided collections.
|
2501 | *
|
2502 | * Like `zipWith`, but using the default `zipper`: creating an `Array`.
|
2503 | *
|
2504 | * ```js
|
2505 | * const a = Stack([ 1, 2, 3 ]);
|
2506 | * const b = Stack([ 4, 5, 6 ]);
|
2507 | * const c = a.zip(b); // Stack [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]
|
2508 | * ```
|
2509 | */
|
2510 | zip<U>(other: Collection<unknown, U>): Stack<[T, U]>;
|
2511 | zip<U, V>(
|
2512 | other: Collection<unknown, U>,
|
2513 | other2: Collection<unknown, V>
|
2514 | ): Stack<[T, U, V]>;
|
2515 | zip(...collections: Array<Collection<unknown, unknown>>): Stack<unknown>;
|
2516 |
|
2517 | /**
|
2518 | * Returns a Stack "zipped" with the provided collections.
|
2519 | *
|
2520 | * Unlike `zip`, `zipAll` continues zipping until the longest collection is
|
2521 | * exhausted. Missing values from shorter collections are filled with `undefined`.
|
2522 | *
|
2523 | * ```js
|
2524 | * const a = Stack([ 1, 2 ]);
|
2525 | * const b = Stack([ 3, 4, 5 ]);
|
2526 | * const c = a.zipAll(b); // Stack [ [ 1, 3 ], [ 2, 4 ], [ undefined, 5 ] ]
|
2527 | * ```
|
2528 | *
|
2529 | * Note: Since zipAll will return a collection as large as the largest
|
2530 | * input, some results may contain undefined values. TypeScript cannot
|
2531 | * account for these without cases (as of v2.5).
|
2532 | */
|
2533 | zipAll<U>(other: Collection<unknown, U>): Stack<[T, U]>;
|
2534 | zipAll<U, V>(
|
2535 | other: Collection<unknown, U>,
|
2536 | other2: Collection<unknown, V>
|
2537 | ): Stack<[T, U, V]>;
|
2538 | zipAll(...collections: Array<Collection<unknown, unknown>>): Stack<unknown>;
|
2539 |
|
2540 | /**
|
2541 | * Returns a Stack "zipped" with the provided collections by using a
|
2542 | * custom `zipper` function.
|
2543 | *
|
2544 | * ```js
|
2545 | * const a = Stack([ 1, 2, 3 ]);
|
2546 | * const b = Stack([ 4, 5, 6 ]);
|
2547 | * const c = a.zipWith((a, b) => a + b, b);
|
2548 | * // Stack [ 5, 7, 9 ]
|
2549 | * ```
|
2550 | */
|
2551 | zipWith<U, Z>(
|
2552 | zipper: (value: T, otherValue: U) => Z,
|
2553 | otherCollection: Collection<unknown, U>
|
2554 | ): Stack<Z>;
|
2555 | zipWith<U, V, Z>(
|
2556 | zipper: (value: T, otherValue: U, thirdValue: V) => Z,
|
2557 | otherCollection: Collection<unknown, U>,
|
2558 | thirdCollection: Collection<unknown, V>
|
2559 | ): Stack<Z>;
|
2560 | zipWith<Z>(
|
2561 | zipper: (...values: Array<unknown>) => Z,
|
2562 | ...collections: Array<Collection<unknown, unknown>>
|
2563 | ): Stack<Z>;
|
2564 | }
|
2565 |
|
2566 | /**
|
2567 | * Returns a Seq.Indexed of numbers from `start` (inclusive) to `end`
|
2568 | * (exclusive), by `step`, where `start` defaults to 0, `step` to 1, and `end` to
|
2569 | * infinity. When `start` is equal to `end`, returns empty range.
|
2570 | *
|
2571 | * Note: `Range` is a factory function and not a class, and does not use the
|
2572 | * `new` keyword during construction.
|
2573 | *
|
2574 | * ```js
|
2575 | * const { Range } = require('immutable')
|
2576 | * Range() // [ 0, 1, 2, 3, ... ]
|
2577 | * Range(10) // [ 10, 11, 12, 13, ... ]
|
2578 | * Range(10, 15) // [ 10, 11, 12, 13, 14 ]
|
2579 | * Range(10, 30, 5) // [ 10, 15, 20, 25 ]
|
2580 | * Range(30, 10, 5) // [ 30, 25, 20, 15 ]
|
2581 | * Range(30, 30, 5) // []
|
2582 | * ```
|
2583 | */
|
2584 | function Range(
|
2585 | start: number,
|
2586 | end: number,
|
2587 | step?: number
|
2588 | ): Seq.Indexed<number>;
|
2589 |
|
2590 | /**
|
2591 | * Returns a Seq.Indexed of `value` repeated `times` times. When `times` is
|
2592 | * not defined, returns an infinite `Seq` of `value`.
|
2593 | *
|
2594 | * Note: `Repeat` is a factory function and not a class, and does not use the
|
2595 | * `new` keyword during construction.
|
2596 | *
|
2597 | * ```js
|
2598 | * const { Repeat } = require('immutable')
|
2599 | * Repeat('foo') // [ 'foo', 'foo', 'foo', ... ]
|
2600 | * Repeat('bar', 4) // [ 'bar', 'bar', 'bar', 'bar' ]
|
2601 | * ```
|
2602 | */
|
2603 | function Repeat<T>(value: T, times?: number): Seq.Indexed<T>;
|
2604 |
|
2605 | /**
|
2606 | * A record is similar to a JS object, but enforces a specific set of allowed
|
2607 | * string keys, and has default values.
|
2608 | *
|
2609 | * The `Record()` function produces new Record Factories, which when called
|
2610 | * create Record instances.
|
2611 | *
|
2612 | * ```js
|
2613 | * const { Record } = require('immutable')
|
2614 | * const ABRecord = Record({ a: 1, b: 2 })
|
2615 | * const myRecord = ABRecord({ b: 3 })
|
2616 | * ```
|
2617 | *
|
2618 | * Records always have a value for the keys they define. `remove`ing a key
|
2619 | * from a record simply resets it to the default value for that key.
|
2620 | *
|
2621 | * ```js
|
2622 | * myRecord.get('a') // 1
|
2623 | * myRecord.get('b') // 3
|
2624 | * const myRecordWithoutB = myRecord.remove('b')
|
2625 | * myRecordWithoutB.get('b') // 2
|
2626 | * ```
|
2627 | *
|
2628 | * Values provided to the constructor not found in the Record type will
|
2629 | * be ignored. For example, in this case, ABRecord is provided a key "x" even
|
2630 | * though only "a" and "b" have been defined. The value for "x" will be
|
2631 | * ignored for this record.
|
2632 | *
|
2633 | * ```js
|
2634 | * const myRecord = ABRecord({ b: 3, x: 10 })
|
2635 | * myRecord.get('x') // undefined
|
2636 | * ```
|
2637 | *
|
2638 | * Because Records have a known set of string keys, property get access works
|
2639 | * as expected, however property sets will throw an Error.
|
2640 | *
|
2641 | * Note: IE8 does not support property access. Only use `get()` when
|
2642 | * supporting IE8.
|
2643 | *
|
2644 | * ```js
|
2645 | * myRecord.b // 3
|
2646 | * myRecord.b = 5 // throws Error
|
2647 | * ```
|
2648 | *
|
2649 | * Record Types can be extended as well, allowing for custom methods on your
|
2650 | * Record. This is not a common pattern in functional environments, but is in
|
2651 | * many JS programs.
|
2652 | *
|
2653 | * However Record Types are more restricted than typical JavaScript classes.
|
2654 | * They do not use a class constructor, which also means they cannot use
|
2655 | * class properties (since those are technically part of a constructor).
|
2656 | *
|
2657 | * While Record Types can be syntactically created with the JavaScript `class`
|
2658 | * form, the resulting Record function is actually a factory function, not a
|
2659 | * class constructor. Even though Record Types are not classes, JavaScript
|
2660 | * currently requires the use of `new` when creating new Record instances if
|
2661 | * they are defined as a `class`.
|
2662 | *
|
2663 | * ```
|
2664 | * class ABRecord extends Record({ a: 1, b: 2 }) {
|
2665 | * getAB() {
|
2666 | * return this.a + this.b;
|
2667 | * }
|
2668 | * }
|
2669 | *
|
2670 | * var myRecord = new ABRecord({b: 3})
|
2671 | * myRecord.getAB() // 4
|
2672 | * ```
|
2673 | *
|
2674 | *
|
2675 | * **Flow Typing Records:**
|
2676 | *
|
2677 | * Immutable.js exports two Flow types designed to make it easier to use
|
2678 | * Records with flow typed code, `RecordOf<TProps>` and `RecordFactory<TProps>`.
|
2679 | *
|
2680 | * When defining a new kind of Record factory function, use a flow type that
|
2681 | * describes the values the record contains along with `RecordFactory<TProps>`.
|
2682 | * To type instances of the Record (which the factory function returns),
|
2683 | * use `RecordOf<TProps>`.
|
2684 | *
|
2685 | * Typically, new Record definitions will export both the Record factory
|
2686 | * function as well as the Record instance type for use in other code.
|
2687 | *
|
2688 | * ```js
|
2689 | * import type { RecordFactory, RecordOf } from 'immutable';
|
2690 | *
|
2691 | * // Use RecordFactory<TProps> for defining new Record factory functions.
|
2692 | * type Point3DProps = { x: number, y: number, z: number };
|
2693 | * const defaultValues: Point3DProps = { x: 0, y: 0, z: 0 };
|
2694 | * const makePoint3D: RecordFactory<Point3DProps> = Record(defaultValues);
|
2695 | * export makePoint3D;
|
2696 | *
|
2697 | * // Use RecordOf<T> for defining new instances of that Record.
|
2698 | * export type Point3D = RecordOf<Point3DProps>;
|
2699 | * const some3DPoint: Point3D = makePoint3D({ x: 10, y: 20, z: 30 });
|
2700 | * ```
|
2701 | *
|
2702 | * **Flow Typing Record Subclasses:**
|
2703 | *
|
2704 | * Records can be subclassed as a means to add additional methods to Record
|
2705 | * instances. This is generally discouraged in favor of a more functional API,
|
2706 | * since Subclasses have some minor overhead. However the ability to create
|
2707 | * a rich API on Record types can be quite valuable.
|
2708 | *
|
2709 | * When using Flow to type Subclasses, do not use `RecordFactory<TProps>`,
|
2710 | * instead apply the props type when subclassing:
|
2711 | *
|
2712 | * ```js
|
2713 | * type PersonProps = {name: string, age: number};
|
2714 | * const defaultValues: PersonProps = {name: 'Aristotle', age: 2400};
|
2715 | * const PersonRecord = Record(defaultValues);
|
2716 | * class Person extends PersonRecord<PersonProps> {
|
2717 | * getName(): string {
|
2718 | * return this.get('name')
|
2719 | * }
|
2720 | *
|
2721 | * setName(name: string): this {
|
2722 | * return this.set('name', name);
|
2723 | * }
|
2724 | * }
|
2725 | * ```
|
2726 | *
|
2727 | * **Choosing Records vs plain JavaScript objects**
|
2728 | *
|
2729 | * Records offer a persistently immutable alternative to plain JavaScript
|
2730 | * objects, however they're not required to be used within Immutable.js
|
2731 | * collections. In fact, the deep-access and deep-updating functions
|
2732 | * like `getIn()` and `setIn()` work with plain JavaScript Objects as well.
|
2733 | *
|
2734 | * Deciding to use Records or Objects in your application should be informed
|
2735 | * by the tradeoffs and relative benefits of each:
|
2736 | *
|
2737 | * - *Runtime immutability*: plain JS objects may be carefully treated as
|
2738 | * immutable, however Record instances will *throw* if attempted to be
|
2739 | * mutated directly. Records provide this additional guarantee, however at
|
2740 | * some marginal runtime cost. While JS objects are mutable by nature, the
|
2741 | * use of type-checking tools like [Flow](https:
|
2742 | * can help gain confidence in code written to favor immutability.
|
2743 | *
|
2744 | * - *Value equality*: Records use value equality when compared with `is()`
|
2745 | * or `record.equals()`. That is, two Records with the same keys and values
|
2746 | * are equal. Plain objects use *reference equality*. Two objects with the
|
2747 | * same keys and values are not equal since they are different objects.
|
2748 | * This is important to consider when using objects as keys in a `Map` or
|
2749 | * values in a `Set`, which use equality when retrieving values.
|
2750 | *
|
2751 | * - *API methods*: Records have a full featured API, with methods like
|
2752 | * `.getIn()`, and `.equals()`. These can make working with these values
|
2753 | * easier, but comes at the cost of not allowing keys with those names.
|
2754 | *
|
2755 | * - *Default values*: Records provide default values for every key, which
|
2756 | * can be useful when constructing Records with often unchanging values.
|
2757 | * However default values can make using Flow and TypeScript more laborious.
|
2758 | *
|
2759 | * - *Serialization*: Records use a custom internal representation to
|
2760 | * efficiently store and update their values. Converting to and from this
|
2761 | * form isn't free. If converting Records to plain objects is common,
|
2762 | * consider sticking with plain objects to begin with.
|
2763 | */
|
2764 | namespace Record {
|
2765 | |
2766 |
|
2767 |
|
2768 | function isRecord(maybeRecord: unknown): maybeRecord is Record<{}>;
|
2769 |
|
2770 | |
2771 |
|
2772 |
|
2773 |
|
2774 |
|
2775 |
|
2776 |
|
2777 |
|
2778 |
|
2779 |
|
2780 |
|
2781 |
|
2782 |
|
2783 |
|
2784 |
|
2785 |
|
2786 |
|
2787 | function getDescriptiveName(record: Record<any>): string;
|
2788 |
|
2789 | |
2790 |
|
2791 |
|
2792 |
|
2793 |
|
2794 |
|
2795 |
|
2796 |
|
2797 |
|
2798 |
|
2799 |
|
2800 |
|
2801 |
|
2802 |
|
2803 |
|
2804 |
|
2805 |
|
2806 |
|
2807 |
|
2808 |
|
2809 |
|
2810 |
|
2811 |
|
2812 |
|
2813 |
|
2814 |
|
2815 |
|
2816 |
|
2817 |
|
2818 |
|
2819 |
|
2820 |
|
2821 |
|
2822 |
|
2823 |
|
2824 |
|
2825 |
|
2826 |
|
2827 |
|
2828 |
|
2829 |
|
2830 |
|
2831 |
|
2832 |
|
2833 |
|
2834 |
|
2835 |
|
2836 |
|
2837 | namespace Factory {}
|
2838 |
|
2839 | interface Factory<TProps extends object> {
|
2840 | (values?: Partial<TProps> | Iterable<[string, unknown]>): Record<TProps> &
|
2841 | Readonly<TProps>;
|
2842 | new (
|
2843 | values?: Partial<TProps> | Iterable<[string, unknown]>
|
2844 | ): Record<TProps> & Readonly<TProps>;
|
2845 |
|
2846 | |
2847 |
|
2848 |
|
2849 |
|
2850 | displayName: string;
|
2851 | }
|
2852 |
|
2853 | function Factory<TProps extends object>(
|
2854 | values?: Partial<TProps> | Iterable<[string, unknown]>
|
2855 | ): Record<TProps> & Readonly<TProps>;
|
2856 | }
|
2857 |
|
2858 | |
2859 |
|
2860 |
|
2861 |
|
2862 |
|
2863 |
|
2864 |
|
2865 |
|
2866 |
|
2867 | function Record<TProps extends object>(
|
2868 | defaultValues: TProps,
|
2869 | name?: string
|
2870 | ): Record.Factory<TProps>;
|
2871 |
|
2872 | interface Record<TProps extends object> {
|
2873 |
|
2874 |
|
2875 | has(key: string): key is keyof TProps & string;
|
2876 |
|
2877 | |
2878 |
|
2879 |
|
2880 |
|
2881 |
|
2882 |
|
2883 |
|
2884 |
|
2885 | get<K extends keyof TProps>(key: K, notSetValue?: unknown): TProps[K];
|
2886 | get<T>(key: string, notSetValue: T): T;
|
2887 |
|
2888 |
|
2889 |
|
2890 | hasIn(keyPath: Iterable<unknown>): boolean;
|
2891 | getIn(keyPath: Iterable<unknown>): unknown;
|
2892 |
|
2893 |
|
2894 |
|
2895 | equals(other: unknown): boolean;
|
2896 | hashCode(): number;
|
2897 |
|
2898 |
|
2899 |
|
2900 | set<K extends keyof TProps>(key: K, value: TProps[K]): this;
|
2901 | update<K extends keyof TProps>(
|
2902 | key: K,
|
2903 | updater: (value: TProps[K]) => TProps[K]
|
2904 | ): this;
|
2905 | merge(
|
2906 | ...collections: Array<Partial<TProps> | Iterable<[string, unknown]>>
|
2907 | ): this;
|
2908 | mergeDeep(
|
2909 | ...collections: Array<Partial<TProps> | Iterable<[string, unknown]>>
|
2910 | ): this;
|
2911 |
|
2912 | mergeWith(
|
2913 | merger: (oldVal: unknown, newVal: unknown, key: keyof TProps) => unknown,
|
2914 | ...collections: Array<Partial<TProps> | Iterable<[string, unknown]>>
|
2915 | ): this;
|
2916 | mergeDeepWith(
|
2917 | merger: (oldVal: unknown, newVal: unknown, key: unknown) => unknown,
|
2918 | ...collections: Array<Partial<TProps> | Iterable<[string, unknown]>>
|
2919 | ): this;
|
2920 |
|
2921 | |
2922 |
|
2923 |
|
2924 |
|
2925 |
|
2926 |
|
2927 | delete<K extends keyof TProps>(key: K): this;
|
2928 | remove<K extends keyof TProps>(key: K): this;
|
2929 |
|
2930 | |
2931 |
|
2932 |
|
2933 |
|
2934 | clear(): this;
|
2935 |
|
2936 |
|
2937 |
|
2938 | setIn(keyPath: Iterable<unknown>, value: unknown): this;
|
2939 | updateIn(
|
2940 | keyPath: Iterable<unknown>,
|
2941 | updater: (value: unknown) => unknown
|
2942 | ): this;
|
2943 | mergeIn(keyPath: Iterable<unknown>, ...collections: Array<unknown>): this;
|
2944 | mergeDeepIn(
|
2945 | keyPath: Iterable<unknown>,
|
2946 | ...collections: Array<unknown>
|
2947 | ): this;
|
2948 |
|
2949 | |
2950 |
|
2951 |
|
2952 | deleteIn(keyPath: Iterable<unknown>): this;
|
2953 | removeIn(keyPath: Iterable<unknown>): this;
|
2954 |
|
2955 |
|
2956 |
|
2957 | |
2958 |
|
2959 |
|
2960 |
|
2961 |
|
2962 |
|
2963 | toJS(): DeepCopy<TProps>;
|
2964 |
|
2965 | |
2966 |
|
2967 |
|
2968 | toJSON(): TProps;
|
2969 |
|
2970 | |
2971 |
|
2972 |
|
2973 | toObject(): TProps;
|
2974 |
|
2975 |
|
2976 |
|
2977 | |
2978 |
|
2979 |
|
2980 |
|
2981 |
|
2982 |
|
2983 | withMutations(mutator: (mutable: this) => unknown): this;
|
2984 |
|
2985 | |
2986 |
|
2987 |
|
2988 | asMutable(): this;
|
2989 |
|
2990 | |
2991 |
|
2992 |
|
2993 | wasAltered(): boolean;
|
2994 |
|
2995 | |
2996 |
|
2997 |
|
2998 | asImmutable(): this;
|
2999 |
|
3000 |
|
3001 |
|
3002 | toSeq(): Seq.Keyed<keyof TProps, TProps[keyof TProps]>;
|
3003 |
|
3004 | [Symbol.iterator](): IterableIterator<[keyof TProps, TProps[keyof TProps]]>;
|
3005 | }
|
3006 |
|
3007 | |
3008 |
|
3009 |
|
3010 |
|
3011 |
|
3012 |
|
3013 | type RecordOf<TProps extends object> = Record<TProps> & Readonly<TProps>;
|
3014 |
|
3015 | |
3016 |
|
3017 |
|
3018 |
|
3019 |
|
3020 |
|
3021 |
|
3022 |
|
3023 |
|
3024 |
|
3025 |
|
3026 |
|
3027 |
|
3028 |
|
3029 |
|
3030 |
|
3031 |
|
3032 |
|
3033 |
|
3034 |
|
3035 |
|
3036 |
|
3037 |
|
3038 |
|
3039 |
|
3040 |
|
3041 |
|
3042 |
|
3043 |
|
3044 |
|
3045 |
|
3046 |
|
3047 |
|
3048 |
|
3049 |
|
3050 |
|
3051 |
|
3052 |
|
3053 |
|
3054 |
|
3055 |
|
3056 |
|
3057 |
|
3058 |
|
3059 |
|
3060 |
|
3061 |
|
3062 |
|
3063 |
|
3064 |
|
3065 |
|
3066 |
|
3067 |
|
3068 |
|
3069 |
|
3070 |
|
3071 |
|
3072 |
|
3073 |
|
3074 |
|
3075 |
|
3076 |
|
3077 |
|
3078 |
|
3079 |
|
3080 |
|
3081 |
|
3082 |
|
3083 |
|
3084 |
|
3085 |
|
3086 |
|
3087 |
|
3088 |
|
3089 |
|
3090 | namespace Seq {
|
3091 | |
3092 |
|
3093 |
|
3094 |
|
3095 | function isSeq(
|
3096 | maybeSeq: unknown
|
3097 | ): maybeSeq is
|
3098 | | Seq.Indexed<unknown>
|
3099 | | Seq.Keyed<unknown, unknown>
|
3100 | | Seq.Set<unknown>;
|
3101 |
|
3102 | |
3103 |
|
3104 |
|
3105 | namespace Keyed {}
|
3106 |
|
3107 | |
3108 |
|
3109 |
|
3110 |
|
3111 |
|
3112 |
|
3113 |
|
3114 | function Keyed<K, V>(collection?: Iterable<[K, V]>): Seq.Keyed<K, V>;
|
3115 | function Keyed<V>(obj: { [key: string]: V }): Seq.Keyed<string, V>;
|
3116 |
|
3117 | interface Keyed<K, V> extends Seq<K, V>, Collection.Keyed<K, V> {
|
3118 | |
3119 |
|
3120 |
|
3121 |
|
3122 |
|
3123 | toJS(): { [key in string | number | symbol]: DeepCopy<V> };
|
3124 |
|
3125 | |
3126 |
|
3127 |
|
3128 |
|
3129 |
|
3130 | toJSON(): { [key in string | number | symbol]: V };
|
3131 |
|
3132 | |
3133 |
|
3134 |
|
3135 | toArray(): Array<[K, V]>;
|
3136 |
|
3137 | |
3138 |
|
3139 |
|
3140 | toSeq(): this;
|
3141 |
|
3142 | |
3143 |
|
3144 |
|
3145 |
|
3146 |
|
3147 |
|
3148 | concat<KC, VC>(
|
3149 | ...collections: Array<Iterable<[KC, VC]>>
|
3150 | ): Seq.Keyed<K | KC, V | VC>;
|
3151 | concat<C>(
|
3152 | ...collections: Array<{ [key: string]: C }>
|
3153 | ): Seq.Keyed<K | string, V | C>;
|
3154 |
|
3155 | |
3156 |
|
3157 |
|
3158 |
|
3159 |
|
3160 |
|
3161 |
|
3162 |
|
3163 |
|
3164 |
|
3165 |
|
3166 |
|
3167 |
|
3168 | map<M>(
|
3169 | mapper: (value: V, key: K, iter: this) => M,
|
3170 | context?: unknown
|
3171 | ): Seq.Keyed<K, M>;
|
3172 |
|
3173 | |
3174 |
|
3175 |
|
3176 | mapKeys<M>(
|
3177 | mapper: (key: K, value: V, iter: this) => M,
|
3178 | context?: unknown
|
3179 | ): Seq.Keyed<M, V>;
|
3180 |
|
3181 | |
3182 |
|
3183 |
|
3184 | mapEntries<KM, VM>(
|
3185 | mapper: (
|
3186 | entry: [K, V],
|
3187 | index: number,
|
3188 | iter: this
|
3189 | ) => [KM, VM] | undefined,
|
3190 | context?: unknown
|
3191 | ): Seq.Keyed<KM, VM>;
|
3192 |
|
3193 | |
3194 |
|
3195 |
|
3196 |
|
3197 |
|
3198 | flatMap<KM, VM>(
|
3199 | mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>,
|
3200 | context?: unknown
|
3201 | ): Seq.Keyed<KM, VM>;
|
3202 |
|
3203 | |
3204 |
|
3205 |
|
3206 |
|
3207 |
|
3208 |
|
3209 |
|
3210 | filter<F extends V>(
|
3211 | predicate: (value: V, key: K, iter: this) => value is F,
|
3212 | context?: unknown
|
3213 | ): Seq.Keyed<K, F>;
|
3214 | filter(
|
3215 | predicate: (value: V, key: K, iter: this) => unknown,
|
3216 | context?: unknown
|
3217 | ): this;
|
3218 |
|
3219 | |
3220 |
|
3221 |
|
3222 |
|
3223 | partition<F extends V, C>(
|
3224 | predicate: (this: C, value: V, key: K, iter: this) => value is F,
|
3225 | context?: C
|
3226 | ): [Seq.Keyed<K, V>, Seq.Keyed<K, F>];
|
3227 | partition<C>(
|
3228 | predicate: (this: C, value: V, key: K, iter: this) => unknown,
|
3229 | context?: C
|
3230 | ): [this, this];
|
3231 |
|
3232 | |
3233 |
|
3234 |
|
3235 | flip(): Seq.Keyed<V, K>;
|
3236 |
|
3237 | [Symbol.iterator](): IterableIterator<[K, V]>;
|
3238 | }
|
3239 |
|
3240 | |
3241 |
|
3242 |
|
3243 | namespace Indexed {
|
3244 | |
3245 |
|
3246 |
|
3247 | function of<T>(...values: Array<T>): Seq.Indexed<T>;
|
3248 | }
|
3249 |
|
3250 | |
3251 |
|
3252 |
|
3253 |
|
3254 |
|
3255 |
|
3256 |
|
3257 | function Indexed<T>(
|
3258 | collection?: Iterable<T> | ArrayLike<T>
|
3259 | ): Seq.Indexed<T>;
|
3260 |
|
3261 | interface Indexed<T> extends Seq<number, T>, Collection.Indexed<T> {
|
3262 | |
3263 |
|
3264 |
|
3265 | toJS(): Array<DeepCopy<T>>;
|
3266 |
|
3267 | |
3268 |
|
3269 |
|
3270 | toJSON(): Array<T>;
|
3271 |
|
3272 | |
3273 |
|
3274 |
|
3275 | toArray(): Array<T>;
|
3276 |
|
3277 | |
3278 |
|
3279 |
|
3280 | toSeq(): this;
|
3281 |
|
3282 | |
3283 |
|
3284 |
|
3285 | concat<C>(
|
3286 | ...valuesOrCollections: Array<Iterable<C> | C>
|
3287 | ): Seq.Indexed<T | C>;
|
3288 |
|
3289 | |
3290 |
|
3291 |
|
3292 |
|
3293 |
|
3294 |
|
3295 |
|
3296 |
|
3297 |
|
3298 |
|
3299 |
|
3300 |
|
3301 |
|
3302 | map<M>(
|
3303 | mapper: (value: T, key: number, iter: this) => M,
|
3304 | context?: unknown
|
3305 | ): Seq.Indexed<M>;
|
3306 |
|
3307 | |
3308 |
|
3309 |
|
3310 |
|
3311 |
|
3312 | flatMap<M>(
|
3313 | mapper: (value: T, key: number, iter: this) => Iterable<M>,
|
3314 | context?: unknown
|
3315 | ): Seq.Indexed<M>;
|
3316 |
|
3317 | |
3318 |
|
3319 |
|
3320 |
|
3321 |
|
3322 |
|
3323 |
|
3324 | filter<F extends T>(
|
3325 | predicate: (value: T, index: number, iter: this) => value is F,
|
3326 | context?: unknown
|
3327 | ): Seq.Indexed<F>;
|
3328 | filter(
|
3329 | predicate: (value: T, index: number, iter: this) => unknown,
|
3330 | context?: unknown
|
3331 | ): this;
|
3332 |
|
3333 | |
3334 |
|
3335 |
|
3336 |
|
3337 | partition<F extends T, C>(
|
3338 | predicate: (this: C, value: T, index: number, iter: this) => value is F,
|
3339 | context?: C
|
3340 | ): [Seq.Indexed<T>, Seq.Indexed<F>];
|
3341 | partition<C>(
|
3342 | predicate: (this: C, value: T, index: number, iter: this) => unknown,
|
3343 | context?: C
|
3344 | ): [this, this];
|
3345 |
|
3346 | |
3347 |
|
3348 |
|
3349 |
|
3350 |
|
3351 |
|
3352 |
|
3353 |
|
3354 |
|
3355 |
|
3356 |
|
3357 | zip<U>(other: Collection<unknown, U>): Seq.Indexed<[T, U]>;
|
3358 | zip<U, V>(
|
3359 | other: Collection<unknown, U>,
|
3360 | other2: Collection<unknown, V>
|
3361 | ): Seq.Indexed<[T, U, V]>;
|
3362 | zip(
|
3363 | ...collections: Array<Collection<unknown, unknown>>
|
3364 | ): Seq.Indexed<unknown>;
|
3365 |
|
3366 | |
3367 |
|
3368 |
|
3369 |
|
3370 |
|
3371 |
|
3372 |
|
3373 |
|
3374 |
|
3375 |
|
3376 |
|
3377 |
|
3378 | zipAll<U>(other: Collection<unknown, U>): Seq.Indexed<[T, U]>;
|
3379 | zipAll<U, V>(
|
3380 | other: Collection<unknown, U>,
|
3381 | other2: Collection<unknown, V>
|
3382 | ): Seq.Indexed<[T, U, V]>;
|
3383 | zipAll(
|
3384 | ...collections: Array<Collection<unknown, unknown>>
|
3385 | ): Seq.Indexed<unknown>;
|
3386 |
|
3387 | |
3388 |
|
3389 |
|
3390 |
|
3391 |
|
3392 |
|
3393 |
|
3394 |
|
3395 |
|
3396 |
|
3397 |
|
3398 | zipWith<U, Z>(
|
3399 | zipper: (value: T, otherValue: U) => Z,
|
3400 | otherCollection: Collection<unknown, U>
|
3401 | ): Seq.Indexed<Z>;
|
3402 | zipWith<U, V, Z>(
|
3403 | zipper: (value: T, otherValue: U, thirdValue: V) => Z,
|
3404 | otherCollection: Collection<unknown, U>,
|
3405 | thirdCollection: Collection<unknown, V>
|
3406 | ): Seq.Indexed<Z>;
|
3407 | zipWith<Z>(
|
3408 | zipper: (...values: Array<unknown>) => Z,
|
3409 | ...collections: Array<Collection<unknown, unknown>>
|
3410 | ): Seq.Indexed<Z>;
|
3411 |
|
3412 | [Symbol.iterator](): IterableIterator<T>;
|
3413 | }
|
3414 |
|
3415 | |
3416 |
|
3417 |
|
3418 |
|
3419 |
|
3420 |
|
3421 | namespace Set {
|
3422 | |
3423 |
|
3424 |
|
3425 | function of<T>(...values: Array<T>): Seq.Set<T>;
|
3426 | }
|
3427 |
|
3428 | |
3429 |
|
3430 |
|
3431 |
|
3432 |
|
3433 |
|
3434 | function Set<T>(collection?: Iterable<T> | ArrayLike<T>): Seq.Set<T>;
|
3435 |
|
3436 | interface Set<T> extends Seq<T, T>, Collection.Set<T> {
|
3437 | |
3438 |
|
3439 |
|
3440 | toJS(): Array<DeepCopy<T>>;
|
3441 |
|
3442 | |
3443 |
|
3444 |
|
3445 | toJSON(): Array<T>;
|
3446 |
|
3447 | |
3448 |
|
3449 |
|
3450 | toArray(): Array<T>;
|
3451 |
|
3452 | |
3453 |
|
3454 |
|
3455 | toSeq(): this;
|
3456 |
|
3457 | |
3458 |
|
3459 |
|
3460 |
|
3461 |
|
3462 |
|
3463 | concat<U>(...collections: Array<Iterable<U>>): Seq.Set<T | U>;
|
3464 |
|
3465 | |
3466 |
|
3467 |
|
3468 |
|
3469 |
|
3470 |
|
3471 |
|
3472 |
|
3473 |
|
3474 |
|
3475 |
|
3476 |
|
3477 | map<M>(
|
3478 | mapper: (value: T, key: T, iter: this) => M,
|
3479 | context?: unknown
|
3480 | ): Seq.Set<M>;
|
3481 |
|
3482 | |
3483 |
|
3484 |
|
3485 |
|
3486 |
|
3487 | flatMap<M>(
|
3488 | mapper: (value: T, key: T, iter: this) => Iterable<M>,
|
3489 | context?: unknown
|
3490 | ): Seq.Set<M>;
|
3491 |
|
3492 | |
3493 |
|
3494 |
|
3495 |
|
3496 |
|
3497 |
|
3498 |
|
3499 | filter<F extends T>(
|
3500 | predicate: (value: T, key: T, iter: this) => value is F,
|
3501 | context?: unknown
|
3502 | ): Seq.Set<F>;
|
3503 | filter(
|
3504 | predicate: (value: T, key: T, iter: this) => unknown,
|
3505 | context?: unknown
|
3506 | ): this;
|
3507 |
|
3508 | |
3509 |
|
3510 |
|
3511 |
|
3512 | partition<F extends T, C>(
|
3513 | predicate: (this: C, value: T, key: T, iter: this) => value is F,
|
3514 | context?: C
|
3515 | ): [Seq.Set<T>, Seq.Set<F>];
|
3516 | partition<C>(
|
3517 | predicate: (this: C, value: T, key: T, iter: this) => unknown,
|
3518 | context?: C
|
3519 | ): [this, this];
|
3520 |
|
3521 | [Symbol.iterator](): IterableIterator<T>;
|
3522 | }
|
3523 | }
|
3524 |
|
3525 | |
3526 |
|
3527 |
|
3528 |
|
3529 |
|
3530 |
|
3531 |
|
3532 |
|
3533 |
|
3534 |
|
3535 |
|
3536 |
|
3537 |
|
3538 |
|
3539 |
|
3540 |
|
3541 |
|
3542 |
|
3543 |
|
3544 | function Seq<S extends Seq<unknown, unknown>>(seq: S): S;
|
3545 | function Seq<K, V>(collection: Collection.Keyed<K, V>): Seq.Keyed<K, V>;
|
3546 | function Seq<T>(collection: Collection.Set<T>): Seq.Set<T>;
|
3547 | function Seq<T>(
|
3548 | collection: Collection.Indexed<T> | Iterable<T> | ArrayLike<T>
|
3549 | ): Seq.Indexed<T>;
|
3550 | function Seq<V>(obj: { [key: string]: V }): Seq.Keyed<string, V>;
|
3551 | function Seq<K = unknown, V = unknown>(): Seq<K, V>;
|
3552 |
|
3553 | interface Seq<K, V> extends Collection<K, V> {
|
3554 | |
3555 |
|
3556 |
|
3557 |
|
3558 |
|
3559 |
|
3560 |
|
3561 |
|
3562 |
|
3563 |
|
3564 | readonly size: number | undefined;
|
3565 |
|
3566 |
|
3567 |
|
3568 | |
3569 |
|
3570 |
|
3571 |
|
3572 |
|
3573 |
|
3574 |
|
3575 |
|
3576 |
|
3577 |
|
3578 |
|
3579 |
|
3580 |
|
3581 |
|
3582 |
|
3583 |
|
3584 |
|
3585 |
|
3586 |
|
3587 |
|
3588 | cacheResult(): this;
|
3589 |
|
3590 |
|
3591 |
|
3592 | |
3593 |
|
3594 |
|
3595 |
|
3596 |
|
3597 |
|
3598 |
|
3599 |
|
3600 |
|
3601 |
|
3602 |
|
3603 |
|
3604 |
|
3605 | map<M>(
|
3606 | mapper: (value: V, key: K, iter: this) => M,
|
3607 | context?: unknown
|
3608 | ): Seq<K, M>;
|
3609 |
|
3610 | |
3611 |
|
3612 |
|
3613 |
|
3614 |
|
3615 |
|
3616 |
|
3617 |
|
3618 |
|
3619 |
|
3620 |
|
3621 |
|
3622 |
|
3623 |
|
3624 | map<M>(
|
3625 | mapper: (value: V, key: K, iter: this) => M,
|
3626 | context?: unknown
|
3627 | ): Seq<M, M>;
|
3628 |
|
3629 | |
3630 |
|
3631 |
|
3632 |
|
3633 |
|
3634 | flatMap<M>(
|
3635 | mapper: (value: V, key: K, iter: this) => Iterable<M>,
|
3636 | context?: unknown
|
3637 | ): Seq<K, M>;
|
3638 |
|
3639 | |
3640 |
|
3641 |
|
3642 |
|
3643 |
|
3644 |
|
3645 | flatMap<M>(
|
3646 | mapper: (value: V, key: K, iter: this) => Iterable<M>,
|
3647 | context?: unknown
|
3648 | ): Seq<M, M>;
|
3649 |
|
3650 | |
3651 |
|
3652 |
|
3653 |
|
3654 |
|
3655 |
|
3656 |
|
3657 | filter<F extends V>(
|
3658 | predicate: (value: V, key: K, iter: this) => value is F,
|
3659 | context?: unknown
|
3660 | ): Seq<K, F>;
|
3661 | filter(
|
3662 | predicate: (value: V, key: K, iter: this) => unknown,
|
3663 | context?: unknown
|
3664 | ): this;
|
3665 |
|
3666 | |
3667 |
|
3668 |
|
3669 |
|
3670 | partition<F extends V, C>(
|
3671 | predicate: (this: C, value: V, key: K, iter: this) => value is F,
|
3672 | context?: C
|
3673 | ): [Seq<K, V>, Seq<K, F>];
|
3674 | partition<C>(
|
3675 | predicate: (this: C, value: V, key: K, iter: this) => unknown,
|
3676 | context?: C
|
3677 | ): [this, this];
|
3678 | }
|
3679 |
|
3680 | |
3681 |
|
3682 |
|
3683 |
|
3684 |
|
3685 |
|
3686 |
|
3687 |
|
3688 |
|
3689 |
|
3690 |
|
3691 |
|
3692 |
|
3693 |
|
3694 | namespace Collection {
|
3695 | |
3696 |
|
3697 |
|
3698 |
|
3699 |
|
3700 |
|
3701 |
|
3702 | namespace Keyed {}
|
3703 |
|
3704 | |
3705 |
|
3706 |
|
3707 |
|
3708 |
|
3709 |
|
3710 |
|
3711 |
|
3712 |
|
3713 | function Keyed<K, V>(collection?: Iterable<[K, V]>): Collection.Keyed<K, V>;
|
3714 | function Keyed<V>(obj: { [key: string]: V }): Collection.Keyed<string, V>;
|
3715 |
|
3716 | interface Keyed<K, V> extends Collection<K, V> {
|
3717 | |
3718 |
|
3719 |
|
3720 |
|
3721 |
|
3722 | toJS(): { [key in string | number | symbol]: DeepCopy<V> };
|
3723 |
|
3724 | |
3725 |
|
3726 |
|
3727 |
|
3728 |
|
3729 | toJSON(): { [key in string | number | symbol]: V };
|
3730 |
|
3731 | |
3732 |
|
3733 |
|
3734 | toArray(): Array<[K, V]>;
|
3735 |
|
3736 | |
3737 |
|
3738 |
|
3739 |
|
3740 | toSeq(): Seq.Keyed<K, V>;
|
3741 |
|
3742 |
|
3743 |
|
3744 | |
3745 |
|
3746 |
|
3747 |
|
3748 |
|
3749 |
|
3750 |
|
3751 |
|
3752 |
|
3753 |
|
3754 |
|
3755 | flip(): Collection.Keyed<V, K>;
|
3756 |
|
3757 | |
3758 |
|
3759 |
|
3760 | concat<KC, VC>(
|
3761 | ...collections: Array<Iterable<[KC, VC]>>
|
3762 | ): Collection.Keyed<K | KC, V | VC>;
|
3763 | concat<C>(
|
3764 | ...collections: Array<{ [key: string]: C }>
|
3765 | ): Collection.Keyed<K | string, V | C>;
|
3766 |
|
3767 | |
3768 |
|
3769 |
|
3770 |
|
3771 |
|
3772 |
|
3773 |
|
3774 |
|
3775 |
|
3776 |
|
3777 |
|
3778 |
|
3779 |
|
3780 | map<M>(
|
3781 | mapper: (value: V, key: K, iter: this) => M,
|
3782 | context?: unknown
|
3783 | ): Collection.Keyed<K, M>;
|
3784 |
|
3785 | |
3786 |
|
3787 |
|
3788 |
|
3789 |
|
3790 |
|
3791 |
|
3792 |
|
3793 |
|
3794 |
|
3795 |
|
3796 |
|
3797 |
|
3798 |
|
3799 | mapKeys<M>(
|
3800 | mapper: (key: K, value: V, iter: this) => M,
|
3801 | context?: unknown
|
3802 | ): Collection.Keyed<M, V>;
|
3803 |
|
3804 | |
3805 |
|
3806 |
|
3807 |
|
3808 |
|
3809 |
|
3810 |
|
3811 |
|
3812 |
|
3813 |
|
3814 |
|
3815 |
|
3816 |
|
3817 |
|
3818 |
|
3819 |
|
3820 |
|
3821 | mapEntries<KM, VM>(
|
3822 | mapper: (
|
3823 | entry: [K, V],
|
3824 | index: number,
|
3825 | iter: this
|
3826 | ) => [KM, VM] | undefined,
|
3827 | context?: unknown
|
3828 | ): Collection.Keyed<KM, VM>;
|
3829 |
|
3830 | |
3831 |
|
3832 |
|
3833 |
|
3834 |
|
3835 | flatMap<KM, VM>(
|
3836 | mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>,
|
3837 | context?: unknown
|
3838 | ): Collection.Keyed<KM, VM>;
|
3839 |
|
3840 | |
3841 |
|
3842 |
|
3843 |
|
3844 |
|
3845 |
|
3846 |
|
3847 | filter<F extends V>(
|
3848 | predicate: (value: V, key: K, iter: this) => value is F,
|
3849 | context?: unknown
|
3850 | ): Collection.Keyed<K, F>;
|
3851 | filter(
|
3852 | predicate: (value: V, key: K, iter: this) => unknown,
|
3853 | context?: unknown
|
3854 | ): this;
|
3855 |
|
3856 | |
3857 |
|
3858 |
|
3859 |
|
3860 |
|
3861 | partition<F extends V, C>(
|
3862 | predicate: (this: C, value: V, key: K, iter: this) => value is F,
|
3863 | context?: C
|
3864 | ): [Collection.Keyed<K, V>, Collection.Keyed<K, F>];
|
3865 | partition<C>(
|
3866 | predicate: (this: C, value: V, key: K, iter: this) => unknown,
|
3867 | context?: C
|
3868 | ): [this, this];
|
3869 |
|
3870 | [Symbol.iterator](): IterableIterator<[K, V]>;
|
3871 | }
|
3872 |
|
3873 | |
3874 |
|
3875 |
|
3876 |
|
3877 |
|
3878 |
|
3879 |
|
3880 |
|
3881 |
|
3882 |
|
3883 |
|
3884 |
|
3885 |
|
3886 |
|
3887 |
|
3888 | namespace Indexed {}
|
3889 |
|
3890 | |
3891 |
|
3892 |
|
3893 |
|
3894 |
|
3895 |
|
3896 | function Indexed<T>(
|
3897 | collection?: Iterable<T> | ArrayLike<T>
|
3898 | ): Collection.Indexed<T>;
|
3899 |
|
3900 | interface Indexed<T> extends Collection<number, T> {
|
3901 | |
3902 |
|
3903 |
|
3904 | toJS(): Array<DeepCopy<T>>;
|
3905 |
|
3906 | |
3907 |
|
3908 |
|
3909 | toJSON(): Array<T>;
|
3910 |
|
3911 | |
3912 |
|
3913 |
|
3914 | toArray(): Array<T>;
|
3915 |
|
3916 |
|
3917 |
|
3918 | |
3919 |
|
3920 |
|
3921 |
|
3922 |
|
3923 |
|
3924 |
|
3925 | get<NSV>(index: number, notSetValue: NSV): T | NSV;
|
3926 | get(index: number): T | undefined;
|
3927 |
|
3928 |
|
3929 |
|
3930 | |
3931 |
|
3932 |
|
3933 |
|
3934 | toSeq(): Seq.Indexed<T>;
|
3935 |
|
3936 | |
3937 |
|
3938 |
|
3939 |
|
3940 | fromEntrySeq(): Seq.Keyed<unknown, unknown>;
|
3941 |
|
3942 |
|
3943 |
|
3944 | |
3945 |
|
3946 |
|
3947 |
|
3948 | interpose(separator: T): this;
|
3949 |
|
3950 | |
3951 |
|
3952 |
|
3953 |
|
3954 |
|
3955 |
|
3956 |
|
3957 |
|
3958 |
|
3959 |
|
3960 |
|
3961 |
|
3962 |
|
3963 |
|
3964 |
|
3965 |
|
3966 |
|
3967 |
|
3968 |
|
3969 |
|
3970 |
|
3971 |
|
3972 |
|
3973 |
|
3974 |
|
3975 |
|
3976 |
|
3977 |
|
3978 |
|
3979 |
|
3980 |
|
3981 |
|
3982 |
|
3983 |
|
3984 | interleave(...collections: Array<Collection<unknown, T>>): this;
|
3985 |
|
3986 | |
3987 |
|
3988 |
|
3989 |
|
3990 |
|
3991 |
|
3992 |
|
3993 |
|
3994 |
|
3995 |
|
3996 |
|
3997 |
|
3998 |
|
3999 |
|
4000 |
|
4001 |
|
4002 |
|
4003 |
|
4004 |
|
4005 |
|
4006 | splice(index: number, removeNum: number, ...values: Array<T>): this;
|
4007 |
|
4008 | |
4009 |
|
4010 |
|
4011 |
|
4012 |
|
4013 |
|
4014 |
|
4015 |
|
4016 |
|
4017 |
|
4018 |
|
4019 |
|
4020 |
|
4021 |
|
4022 |
|
4023 |
|
4024 | zip<U>(other: Collection<unknown, U>): Collection.Indexed<[T, U]>;
|
4025 | zip<U, V>(
|
4026 | other: Collection<unknown, U>,
|
4027 | other2: Collection<unknown, V>
|
4028 | ): Collection.Indexed<[T, U, V]>;
|
4029 | zip(
|
4030 | ...collections: Array<Collection<unknown, unknown>>
|
4031 | ): Collection.Indexed<unknown>;
|
4032 |
|
4033 | |
4034 |
|
4035 |
|
4036 |
|
4037 |
|
4038 |
|
4039 |
|
4040 |
|
4041 |
|
4042 |
|
4043 |
|
4044 |
|
4045 | zipAll<U>(other: Collection<unknown, U>): Collection.Indexed<[T, U]>;
|
4046 | zipAll<U, V>(
|
4047 | other: Collection<unknown, U>,
|
4048 | other2: Collection<unknown, V>
|
4049 | ): Collection.Indexed<[T, U, V]>;
|
4050 | zipAll(
|
4051 | ...collections: Array<Collection<unknown, unknown>>
|
4052 | ): Collection.Indexed<unknown>;
|
4053 |
|
4054 | |
4055 |
|
4056 |
|
4057 |
|
4058 |
|
4059 |
|
4060 |
|
4061 |
|
4062 |
|
4063 |
|
4064 |
|
4065 |
|
4066 |
|
4067 |
|
4068 | zipWith<U, Z>(
|
4069 | zipper: (value: T, otherValue: U) => Z,
|
4070 | otherCollection: Collection<unknown, U>
|
4071 | ): Collection.Indexed<Z>;
|
4072 | zipWith<U, V, Z>(
|
4073 | zipper: (value: T, otherValue: U, thirdValue: V) => Z,
|
4074 | otherCollection: Collection<unknown, U>,
|
4075 | thirdCollection: Collection<unknown, V>
|
4076 | ): Collection.Indexed<Z>;
|
4077 | zipWith<Z>(
|
4078 | zipper: (...values: Array<unknown>) => Z,
|
4079 | ...collections: Array<Collection<unknown, unknown>>
|
4080 | ): Collection.Indexed<Z>;
|
4081 |
|
4082 |
|
4083 |
|
4084 | |
4085 |
|
4086 |
|
4087 |
|
4088 | indexOf(searchValue: T): number;
|
4089 |
|
4090 | |
4091 |
|
4092 |
|
4093 |
|
4094 | lastIndexOf(searchValue: T): number;
|
4095 |
|
4096 | |
4097 |
|
4098 |
|
4099 |
|
4100 | findIndex(
|
4101 | predicate: (value: T, index: number, iter: this) => boolean,
|
4102 | context?: unknown
|
4103 | ): number;
|
4104 |
|
4105 | |
4106 |
|
4107 |
|
4108 |
|
4109 | findLastIndex(
|
4110 | predicate: (value: T, index: number, iter: this) => boolean,
|
4111 | context?: unknown
|
4112 | ): number;
|
4113 |
|
4114 |
|
4115 |
|
4116 | |
4117 |
|
4118 |
|
4119 | concat<C>(
|
4120 | ...valuesOrCollections: Array<Iterable<C> | C>
|
4121 | ): Collection.Indexed<T | C>;
|
4122 |
|
4123 | |
4124 |
|
4125 |
|
4126 |
|
4127 |
|
4128 |
|
4129 |
|
4130 |
|
4131 |
|
4132 |
|
4133 |
|
4134 |
|
4135 |
|
4136 | map<M>(
|
4137 | mapper: (value: T, key: number, iter: this) => M,
|
4138 | context?: unknown
|
4139 | ): Collection.Indexed<M>;
|
4140 |
|
4141 | |
4142 |
|
4143 |
|
4144 |
|
4145 |
|
4146 | flatMap<M>(
|
4147 | mapper: (value: T, key: number, iter: this) => Iterable<M>,
|
4148 | context?: unknown
|
4149 | ): Collection.Indexed<M>;
|
4150 |
|
4151 | |
4152 |
|
4153 |
|
4154 |
|
4155 |
|
4156 |
|
4157 |
|
4158 | filter<F extends T>(
|
4159 | predicate: (value: T, index: number, iter: this) => value is F,
|
4160 | context?: unknown
|
4161 | ): Collection.Indexed<F>;
|
4162 | filter(
|
4163 | predicate: (value: T, index: number, iter: this) => unknown,
|
4164 | context?: unknown
|
4165 | ): this;
|
4166 |
|
4167 | |
4168 |
|
4169 |
|
4170 |
|
4171 |
|
4172 | partition<F extends T, C>(
|
4173 | predicate: (this: C, value: T, index: number, iter: this) => value is F,
|
4174 | context?: C
|
4175 | ): [Collection.Indexed<T>, Collection.Indexed<F>];
|
4176 | partition<C>(
|
4177 | predicate: (this: C, value: T, index: number, iter: this) => unknown,
|
4178 | context?: C
|
4179 | ): [this, this];
|
4180 |
|
4181 | [Symbol.iterator](): IterableIterator<T>;
|
4182 | }
|
4183 |
|
4184 | |
4185 |
|
4186 |
|
4187 |
|
4188 |
|
4189 |
|
4190 |
|
4191 |
|
4192 |
|
4193 |
|
4194 |
|
4195 |
|
4196 |
|
4197 |
|
4198 |
|
4199 |
|
4200 |
|
4201 | namespace Set {}
|
4202 |
|
4203 | |
4204 |
|
4205 |
|
4206 |
|
4207 |
|
4208 |
|
4209 | function Set<T>(collection?: Iterable<T> | ArrayLike<T>): Collection.Set<T>;
|
4210 |
|
4211 | interface Set<T> extends Collection<T, T> {
|
4212 | |
4213 |
|
4214 |
|
4215 | toJS(): Array<DeepCopy<T>>;
|
4216 |
|
4217 | |
4218 |
|
4219 |
|
4220 | toJSON(): Array<T>;
|
4221 |
|
4222 | |
4223 |
|
4224 |
|
4225 | toArray(): Array<T>;
|
4226 |
|
4227 | |
4228 |
|
4229 |
|
4230 |
|
4231 | toSeq(): Seq.Set<T>;
|
4232 |
|
4233 |
|
4234 |
|
4235 | |
4236 |
|
4237 |
|
4238 | concat<U>(...collections: Array<Iterable<U>>): Collection.Set<T | U>;
|
4239 |
|
4240 | |
4241 |
|
4242 |
|
4243 |
|
4244 |
|
4245 |
|
4246 |
|
4247 |
|
4248 |
|
4249 |
|
4250 |
|
4251 |
|
4252 | map<M>(
|
4253 | mapper: (value: T, key: T, iter: this) => M,
|
4254 | context?: unknown
|
4255 | ): Collection.Set<M>;
|
4256 |
|
4257 | |
4258 |
|
4259 |
|
4260 |
|
4261 |
|
4262 | flatMap<M>(
|
4263 | mapper: (value: T, key: T, iter: this) => Iterable<M>,
|
4264 | context?: unknown
|
4265 | ): Collection.Set<M>;
|
4266 |
|
4267 | |
4268 |
|
4269 |
|
4270 |
|
4271 |
|
4272 |
|
4273 |
|
4274 | filter<F extends T>(
|
4275 | predicate: (value: T, key: T, iter: this) => value is F,
|
4276 | context?: unknown
|
4277 | ): Collection.Set<F>;
|
4278 | filter(
|
4279 | predicate: (value: T, key: T, iter: this) => unknown,
|
4280 | context?: unknown
|
4281 | ): this;
|
4282 |
|
4283 | |
4284 |
|
4285 |
|
4286 |
|
4287 |
|
4288 | partition<F extends T, C>(
|
4289 | predicate: (this: C, value: T, key: T, iter: this) => value is F,
|
4290 | context?: C
|
4291 | ): [Collection.Set<T>, Collection.Set<F>];
|
4292 | partition<C>(
|
4293 | predicate: (this: C, value: T, key: T, iter: this) => unknown,
|
4294 | context?: C
|
4295 | ): [this, this];
|
4296 |
|
4297 | [Symbol.iterator](): IterableIterator<T>;
|
4298 | }
|
4299 | }
|
4300 |
|
4301 | |
4302 |
|
4303 |
|
4304 |
|
4305 |
|
4306 |
|
4307 |
|
4308 |
|
4309 |
|
4310 |
|
4311 |
|
4312 |
|
4313 |
|
4314 |
|
4315 |
|
4316 |
|
4317 |
|
4318 |
|
4319 |
|
4320 |
|
4321 |
|
4322 |
|
4323 | function Collection<I extends Collection<unknown, unknown>>(collection: I): I;
|
4324 | function Collection<T>(
|
4325 | collection: Iterable<T> | ArrayLike<T>
|
4326 | ): Collection.Indexed<T>;
|
4327 | function Collection<V>(obj: {
|
4328 | [key: string]: V;
|
4329 | }): Collection.Keyed<string, V>;
|
4330 | function Collection<K = unknown, V = unknown>(): Collection<K, V>;
|
4331 |
|
4332 | interface Collection<K, V> extends ValueObject {
|
4333 |
|
4334 |
|
4335 | |
4336 |
|
4337 |
|
4338 |
|
4339 |
|
4340 |
|
4341 |
|
4342 | equals(other: unknown): boolean;
|
4343 |
|
4344 | |
4345 |
|
4346 |
|
4347 |
|
4348 |
|
4349 |
|
4350 |
|
4351 |
|
4352 |
|
4353 |
|
4354 |
|
4355 |
|
4356 |
|
4357 |
|
4358 |
|
4359 |
|
4360 |
|
4361 |
|
4362 |
|
4363 |
|
4364 |
|
4365 |
|
4366 |
|
4367 |
|
4368 | hashCode(): number;
|
4369 |
|
4370 |
|
4371 |
|
4372 | |
4373 |
|
4374 |
|
4375 |
|
4376 |
|
4377 |
|
4378 |
|
4379 |
|
4380 | get<NSV>(key: K, notSetValue: NSV): V | NSV;
|
4381 | get(key: K): V | undefined;
|
4382 |
|
4383 | |
4384 |
|
4385 |
|
4386 |
|
4387 | has(key: K): boolean;
|
4388 |
|
4389 | |
4390 |
|
4391 |
|
4392 |
|
4393 |
|
4394 | includes(value: V): boolean;
|
4395 | contains(value: V): boolean;
|
4396 |
|
4397 | |
4398 |
|
4399 |
|
4400 |
|
4401 |
|
4402 |
|
4403 | first<NSV>(notSetValue: NSV): V | NSV;
|
4404 | first(): V | undefined;
|
4405 |
|
4406 | |
4407 |
|
4408 |
|
4409 |
|
4410 |
|
4411 |
|
4412 | last<NSV>(notSetValue: NSV): V | NSV;
|
4413 | last(): V | undefined;
|
4414 |
|
4415 |
|
4416 |
|
4417 | |
4418 |
|
4419 |
|
4420 |
|
4421 |
|
4422 |
|
4423 |
|
4424 |
|
4425 |
|
4426 |
|
4427 |
|
4428 |
|
4429 |
|
4430 |
|
4431 |
|
4432 |
|
4433 |
|
4434 |
|
4435 |
|
4436 |
|
4437 |
|
4438 | getIn(searchKeyPath: Iterable<unknown>, notSetValue?: unknown): unknown;
|
4439 |
|
4440 | |
4441 |
|
4442 |
|
4443 |
|
4444 | hasIn(searchKeyPath: Iterable<unknown>): boolean;
|
4445 |
|
4446 |
|
4447 |
|
4448 | |
4449 |
|
4450 |
|
4451 |
|
4452 |
|
4453 |
|
4454 |
|
4455 |
|
4456 |
|
4457 |
|
4458 |
|
4459 |
|
4460 |
|
4461 |
|
4462 |
|
4463 |
|
4464 |
|
4465 |
|
4466 |
|
4467 |
|
4468 |
|
4469 | update<R>(updater: (value: this) => R): R;
|
4470 |
|
4471 |
|
4472 |
|
4473 | |
4474 |
|
4475 |
|
4476 |
|
4477 |
|
4478 |
|
4479 | toJS():
|
4480 | | Array<DeepCopy<V>>
|
4481 | | { [key in string | number | symbol]: DeepCopy<V> };
|
4482 |
|
4483 | |
4484 |
|
4485 |
|
4486 |
|
4487 |
|
4488 |
|
4489 | toJSON(): Array<V> | { [key in string | number | symbol]: V };
|
4490 |
|
4491 | |
4492 |
|
4493 |
|
4494 |
|
4495 |
|
4496 |
|
4497 | toArray(): Array<V> | Array<[K, V]>;
|
4498 |
|
4499 | |
4500 |
|
4501 |
|
4502 |
|
4503 |
|
4504 | toObject(): { [key: string]: V };
|
4505 |
|
4506 |
|
4507 |
|
4508 | |
4509 |
|
4510 |
|
4511 |
|
4512 |
|
4513 |
|
4514 | toMap(): Map<K, V>;
|
4515 |
|
4516 | |
4517 |
|
4518 |
|
4519 |
|
4520 |
|
4521 |
|
4522 | toOrderedMap(): OrderedMap<K, V>;
|
4523 |
|
4524 | |
4525 |
|
4526 |
|
4527 |
|
4528 |
|
4529 |
|
4530 |
|
4531 | toSet(): Set<V>;
|
4532 |
|
4533 | |
4534 |
|
4535 |
|
4536 |
|
4537 |
|
4538 |
|
4539 |
|
4540 | toOrderedSet(): OrderedSet<V>;
|
4541 |
|
4542 | |
4543 |
|
4544 |
|
4545 |
|
4546 |
|
4547 |
|
4548 |
|
4549 |
|
4550 |
|
4551 |
|
4552 |
|
4553 |
|
4554 |
|
4555 |
|
4556 |
|
4557 |
|
4558 | toList(): List<V>;
|
4559 |
|
4560 | |
4561 |
|
4562 |
|
4563 |
|
4564 |
|
4565 |
|
4566 |
|
4567 | toStack(): Stack<V>;
|
4568 |
|
4569 |
|
4570 |
|
4571 | |
4572 |
|
4573 |
|
4574 |
|
4575 | toSeq(): Seq<K, V>;
|
4576 |
|
4577 | |
4578 |
|
4579 |
|
4580 |
|
4581 |
|
4582 |
|
4583 |
|
4584 |
|
4585 |
|
4586 |
|
4587 |
|
4588 |
|
4589 |
|
4590 |
|
4591 |
|
4592 |
|
4593 |
|
4594 |
|
4595 |
|
4596 |
|
4597 |
|
4598 |
|
4599 | toKeyedSeq(): Seq.Keyed<K, V>;
|
4600 |
|
4601 | |
4602 |
|
4603 |
|
4604 | toIndexedSeq(): Seq.Indexed<V>;
|
4605 |
|
4606 | |
4607 |
|
4608 |
|
4609 | toSetSeq(): Seq.Set<V>;
|
4610 |
|
4611 |
|
4612 |
|
4613 | |
4614 |
|
4615 |
|
4616 |
|
4617 |
|
4618 |
|
4619 |
|
4620 | keys(): IterableIterator<K>;
|
4621 |
|
4622 | |
4623 |
|
4624 |
|
4625 |
|
4626 |
|
4627 |
|
4628 |
|
4629 | values(): IterableIterator<V>;
|
4630 |
|
4631 | |
4632 |
|
4633 |
|
4634 |
|
4635 |
|
4636 |
|
4637 |
|
4638 | entries(): IterableIterator<[K, V]>;
|
4639 |
|
4640 | [Symbol.iterator](): IterableIterator<unknown>;
|
4641 |
|
4642 |
|
4643 |
|
4644 | |
4645 |
|
4646 |
|
4647 |
|
4648 | keySeq(): Seq.Indexed<K>;
|
4649 |
|
4650 | |
4651 |
|
4652 |
|
4653 | valueSeq(): Seq.Indexed<V>;
|
4654 |
|
4655 | |
4656 |
|
4657 |
|
4658 | entrySeq(): Seq.Indexed<[K, V]>;
|
4659 |
|
4660 |
|
4661 |
|
4662 | |
4663 |
|
4664 |
|
4665 |
|
4666 |
|
4667 |
|
4668 |
|
4669 |
|
4670 |
|
4671 |
|
4672 |
|
4673 |
|
4674 |
|
4675 |
|
4676 | map<M>(
|
4677 | mapper: (value: V, key: K, iter: this) => M,
|
4678 | context?: unknown
|
4679 | ): Collection<K, M>;
|
4680 |
|
4681 | |
4682 |
|
4683 |
|
4684 |
|
4685 |
|
4686 |
|
4687 | map(...args: Array<never>): unknown;
|
4688 |
|
4689 | |
4690 |
|
4691 |
|
4692 |
|
4693 |
|
4694 |
|
4695 |
|
4696 |
|
4697 |
|
4698 |
|
4699 |
|
4700 |
|
4701 |
|
4702 |
|
4703 | filter<F extends V>(
|
4704 | predicate: (value: V, key: K, iter: this) => value is F,
|
4705 | context?: unknown
|
4706 | ): Collection<K, F>;
|
4707 | filter(
|
4708 | predicate: (value: V, key: K, iter: this) => unknown,
|
4709 | context?: unknown
|
4710 | ): this;
|
4711 |
|
4712 | |
4713 |
|
4714 |
|
4715 |
|
4716 |
|
4717 |
|
4718 |
|
4719 |
|
4720 |
|
4721 |
|
4722 |
|
4723 |
|
4724 |
|
4725 |
|
4726 | filterNot(
|
4727 | predicate: (value: V, key: K, iter: this) => boolean,
|
4728 | context?: unknown
|
4729 | ): this;
|
4730 |
|
4731 | |
4732 |
|
4733 |
|
4734 |
|
4735 | partition<F extends V, C>(
|
4736 | predicate: (this: C, value: V, key: K, iter: this) => value is F,
|
4737 | context?: C
|
4738 | ): [Collection<K, V>, Collection<K, F>];
|
4739 | partition<C>(
|
4740 | predicate: (this: C, value: V, key: K, iter: this) => unknown,
|
4741 | context?: C
|
4742 | ): [this, this];
|
4743 |
|
4744 | |
4745 |
|
4746 |
|
4747 | reverse(): this;
|
4748 |
|
4749 | |
4750 |
|
4751 |
|
4752 |
|
4753 |
|
4754 |
|
4755 |
|
4756 |
|
4757 |
|
4758 |
|
4759 |
|
4760 |
|
4761 |
|
4762 |
|
4763 |
|
4764 |
|
4765 |
|
4766 |
|
4767 |
|
4768 |
|
4769 |
|
4770 |
|
4771 |
|
4772 |
|
4773 |
|
4774 |
|
4775 |
|
4776 |
|
4777 |
|
4778 |
|
4779 |
|
4780 |
|
4781 |
|
4782 |
|
4783 | sort(comparator?: Comparator<V>): this;
|
4784 |
|
4785 | |
4786 |
|
4787 |
|
4788 |
|
4789 |
|
4790 |
|
4791 |
|
4792 |
|
4793 |
|
4794 |
|
4795 |
|
4796 |
|
4797 |
|
4798 |
|
4799 |
|
4800 |
|
4801 |
|
4802 |
|
4803 |
|
4804 |
|
4805 |
|
4806 | sortBy<C>(
|
4807 | comparatorValueMapper: (value: V, key: K, iter: this) => C,
|
4808 | comparator?: Comparator<C>
|
4809 | ): this;
|
4810 |
|
4811 | |
4812 |
|
4813 |
|
4814 |
|
4815 |
|
4816 |
|
4817 |
|
4818 |
|
4819 |
|
4820 |
|
4821 |
|
4822 |
|
4823 |
|
4824 |
|
4825 |
|
4826 |
|
4827 |
|
4828 |
|
4829 |
|
4830 |
|
4831 |
|
4832 |
|
4833 |
|
4834 |
|
4835 | groupBy<G>(
|
4836 | grouper: (value: V, key: K, iter: this) => G,
|
4837 | context?: unknown
|
4838 | ): Map<G, this>;
|
4839 |
|
4840 |
|
4841 |
|
4842 | |
4843 |
|
4844 |
|
4845 |
|
4846 |
|
4847 |
|
4848 |
|
4849 | forEach(
|
4850 | sideEffect: (value: V, key: K, iter: this) => unknown,
|
4851 | context?: unknown
|
4852 | ): number;
|
4853 |
|
4854 |
|
4855 |
|
4856 | |
4857 |
|
4858 |
|
4859 |
|
4860 |
|
4861 |
|
4862 |
|
4863 |
|
4864 |
|
4865 |
|
4866 |
|
4867 |
|
4868 |
|
4869 |
|
4870 |
|
4871 |
|
4872 | slice(begin?: number, end?: number): this;
|
4873 |
|
4874 | |
4875 |
|
4876 |
|
4877 |
|
4878 | rest(): this;
|
4879 |
|
4880 | |
4881 |
|
4882 |
|
4883 |
|
4884 | butLast(): this;
|
4885 |
|
4886 | |
4887 |
|
4888 |
|
4889 |
|
4890 | skip(amount: number): this;
|
4891 |
|
4892 | |
4893 |
|
4894 |
|
4895 |
|
4896 | skipLast(amount: number): this;
|
4897 |
|
4898 | |
4899 |
|
4900 |
|
4901 |
|
4902 |
|
4903 |
|
4904 |
|
4905 |
|
4906 |
|
4907 |
|
4908 |
|
4909 |
|
4910 | skipWhile(
|
4911 | predicate: (value: V, key: K, iter: this) => boolean,
|
4912 | context?: unknown
|
4913 | ): this;
|
4914 |
|
4915 | |
4916 |
|
4917 |
|
4918 |
|
4919 |
|
4920 |
|
4921 |
|
4922 |
|
4923 |
|
4924 |
|
4925 |
|
4926 |
|
4927 | skipUntil(
|
4928 | predicate: (value: V, key: K, iter: this) => boolean,
|
4929 | context?: unknown
|
4930 | ): this;
|
4931 |
|
4932 | |
4933 |
|
4934 |
|
4935 |
|
4936 | take(amount: number): this;
|
4937 |
|
4938 | |
4939 |
|
4940 |
|
4941 |
|
4942 | takeLast(amount: number): this;
|
4943 |
|
4944 | |
4945 |
|
4946 |
|
4947 |
|
4948 |
|
4949 |
|
4950 |
|
4951 |
|
4952 |
|
4953 |
|
4954 |
|
4955 |
|
4956 | takeWhile(
|
4957 | predicate: (value: V, key: K, iter: this) => boolean,
|
4958 | context?: unknown
|
4959 | ): this;
|
4960 |
|
4961 | |
4962 |
|
4963 |
|
4964 |
|
4965 |
|
4966 |
|
4967 |
|
4968 |
|
4969 |
|
4970 |
|
4971 |
|
4972 |
|
4973 | takeUntil(
|
4974 | predicate: (value: V, key: K, iter: this) => boolean,
|
4975 | context?: unknown
|
4976 | ): this;
|
4977 |
|
4978 |
|
4979 |
|
4980 | |
4981 |
|
4982 |
|
4983 |
|
4984 |
|
4985 |
|
4986 |
|
4987 | concat(
|
4988 | ...valuesOrCollections: Array<unknown>
|
4989 | ): Collection<unknown, unknown>;
|
4990 |
|
4991 | |
4992 |
|
4993 |
|
4994 |
|
4995 |
|
4996 |
|
4997 |
|
4998 |
|
4999 |
|
5000 |
|
5001 |
|
5002 |
|
5003 |
|
5004 | flatten(depth?: number): Collection<unknown, unknown>;
|
5005 | flatten(shallow?: boolean): Collection<unknown, unknown>;
|
5006 |
|
5007 | |
5008 |
|
5009 |
|
5010 |
|
5011 |
|
5012 | flatMap<M>(
|
5013 | mapper: (value: V, key: K, iter: this) => Iterable<M>,
|
5014 | context?: unknown
|
5015 | ): Collection<K, M>;
|
5016 |
|
5017 | |
5018 |
|
5019 |
|
5020 |
|
5021 |
|
5022 |
|
5023 | flatMap<KM, VM>(
|
5024 | mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>,
|
5025 | context?: unknown
|
5026 | ): Collection<KM, VM>;
|
5027 |
|
5028 |
|
5029 |
|
5030 | |
5031 |
|
5032 |
|
5033 |
|
5034 |
|
5035 |
|
5036 |
|
5037 |
|
5038 |
|
5039 | reduce<R>(
|
5040 | reducer: (reduction: R, value: V, key: K, iter: this) => R,
|
5041 | initialReduction: R,
|
5042 | context?: unknown
|
5043 | ): R;
|
5044 | reduce<R>(
|
5045 | reducer: (reduction: V | R, value: V, key: K, iter: this) => R
|
5046 | ): R;
|
5047 |
|
5048 | |
5049 |
|
5050 |
|
5051 |
|
5052 |
|
5053 |
|
5054 | reduceRight<R>(
|
5055 | reducer: (reduction: R, value: V, key: K, iter: this) => R,
|
5056 | initialReduction: R,
|
5057 | context?: unknown
|
5058 | ): R;
|
5059 | reduceRight<R>(
|
5060 | reducer: (reduction: V | R, value: V, key: K, iter: this) => R
|
5061 | ): R;
|
5062 |
|
5063 | |
5064 |
|
5065 |
|
5066 | every(
|
5067 | predicate: (value: V, key: K, iter: this) => boolean,
|
5068 | context?: unknown
|
5069 | ): boolean;
|
5070 |
|
5071 | |
5072 |
|
5073 |
|
5074 | some(
|
5075 | predicate: (value: V, key: K, iter: this) => boolean,
|
5076 | context?: unknown
|
5077 | ): boolean;
|
5078 |
|
5079 | |
5080 |
|
5081 |
|
5082 |
|
5083 | join(separator?: string): string;
|
5084 |
|
5085 | |
5086 |
|
5087 |
|
5088 |
|
5089 |
|
5090 |
|
5091 | isEmpty(): boolean;
|
5092 |
|
5093 | |
5094 |
|
5095 |
|
5096 |
|
5097 |
|
5098 |
|
5099 |
|
5100 |
|
5101 |
|
5102 |
|
5103 | count(): number;
|
5104 | count(
|
5105 | predicate: (value: V, key: K, iter: this) => boolean,
|
5106 | context?: unknown
|
5107 | ): number;
|
5108 |
|
5109 | |
5110 |
|
5111 |
|
5112 |
|
5113 |
|
5114 |
|
5115 | countBy<G>(
|
5116 | grouper: (value: V, key: K, iter: this) => G,
|
5117 | context?: unknown
|
5118 | ): Map<G, number>;
|
5119 |
|
5120 |
|
5121 |
|
5122 | |
5123 |
|
5124 |
|
5125 | find(
|
5126 | predicate: (value: V, key: K, iter: this) => boolean,
|
5127 | context?: unknown,
|
5128 | notSetValue?: V
|
5129 | ): V | undefined;
|
5130 |
|
5131 | |
5132 |
|
5133 |
|
5134 |
|
5135 |
|
5136 | findLast(
|
5137 | predicate: (value: V, key: K, iter: this) => boolean,
|
5138 | context?: unknown,
|
5139 | notSetValue?: V
|
5140 | ): V | undefined;
|
5141 |
|
5142 | |
5143 |
|
5144 |
|
5145 | findEntry(
|
5146 | predicate: (value: V, key: K, iter: this) => boolean,
|
5147 | context?: unknown,
|
5148 | notSetValue?: V
|
5149 | ): [K, V] | undefined;
|
5150 |
|
5151 | |
5152 |
|
5153 |
|
5154 |
|
5155 |
|
5156 |
|
5157 | findLastEntry(
|
5158 | predicate: (value: V, key: K, iter: this) => boolean,
|
5159 | context?: unknown,
|
5160 | notSetValue?: V
|
5161 | ): [K, V] | undefined;
|
5162 |
|
5163 | |
5164 |
|
5165 |
|
5166 | findKey(
|
5167 | predicate: (value: V, key: K, iter: this) => boolean,
|
5168 | context?: unknown
|
5169 | ): K | undefined;
|
5170 |
|
5171 | |
5172 |
|
5173 |
|
5174 |
|
5175 |
|
5176 | findLastKey(
|
5177 | predicate: (value: V, key: K, iter: this) => boolean,
|
5178 | context?: unknown
|
5179 | ): K | undefined;
|
5180 |
|
5181 | |
5182 |
|
5183 |
|
5184 | keyOf(searchValue: V): K | undefined;
|
5185 |
|
5186 | |
5187 |
|
5188 |
|
5189 | lastKeyOf(searchValue: V): K | undefined;
|
5190 |
|
5191 | |
5192 |
|
5193 |
|
5194 |
|
5195 |
|
5196 |
|
5197 |
|
5198 |
|
5199 |
|
5200 |
|
5201 |
|
5202 |
|
5203 |
|
5204 |
|
5205 |
|
5206 | max(comparator?: Comparator<V>): V | undefined;
|
5207 |
|
5208 | |
5209 |
|
5210 |
|
5211 |
|
5212 |
|
5213 |
|
5214 |
|
5215 |
|
5216 |
|
5217 |
|
5218 |
|
5219 |
|
5220 |
|
5221 |
|
5222 |
|
5223 | maxBy<C>(
|
5224 | comparatorValueMapper: (value: V, key: K, iter: this) => C,
|
5225 | comparator?: Comparator<C>
|
5226 | ): V | undefined;
|
5227 |
|
5228 | |
5229 |
|
5230 |
|
5231 |
|
5232 |
|
5233 |
|
5234 |
|
5235 |
|
5236 |
|
5237 |
|
5238 |
|
5239 |
|
5240 |
|
5241 |
|
5242 |
|
5243 | min(comparator?: Comparator<V>): V | undefined;
|
5244 |
|
5245 | |
5246 |
|
5247 |
|
5248 |
|
5249 |
|
5250 |
|
5251 |
|
5252 |
|
5253 |
|
5254 |
|
5255 |
|
5256 |
|
5257 |
|
5258 |
|
5259 |
|
5260 | minBy<C>(
|
5261 | comparatorValueMapper: (value: V, key: K, iter: this) => C,
|
5262 | comparator?: Comparator<C>
|
5263 | ): V | undefined;
|
5264 |
|
5265 |
|
5266 |
|
5267 | |
5268 |
|
5269 |
|
5270 | isSubset(iter: Iterable<V>): boolean;
|
5271 |
|
5272 | |
5273 |
|
5274 |
|
5275 | isSuperset(iter: Iterable<V>): boolean;
|
5276 | }
|
5277 |
|
5278 | |
5279 |
|
5280 |
|
5281 | interface ValueObject {
|
5282 | |
5283 |
|
5284 |
|
5285 |
|
5286 |
|
5287 |
|
5288 |
|
5289 | equals(other: unknown): boolean;
|
5290 |
|
5291 | |
5292 |
|
5293 |
|
5294 |
|
5295 |
|
5296 |
|
5297 |
|
5298 |
|
5299 |
|
5300 |
|
5301 |
|
5302 |
|
5303 |
|
5304 |
|
5305 |
|
5306 |
|
5307 |
|
5308 |
|
5309 |
|
5310 |
|
5311 |
|
5312 |
|
5313 |
|
5314 |
|
5315 |
|
5316 |
|
5317 |
|
5318 |
|
5319 |
|
5320 |
|
5321 |
|
5322 | hashCode(): number;
|
5323 | }
|
5324 |
|
5325 | |
5326 |
|
5327 |
|
5328 |
|
5329 |
|
5330 |
|
5331 |
|
5332 |
|
5333 |
|
5334 |
|
5335 |
|
5336 |
|
5337 |
|
5338 |
|
5339 |
|
5340 |
|
5341 |
|
5342 |
|
5343 |
|
5344 |
|
5345 |
|
5346 |
|
5347 |
|
5348 |
|
5349 |
|
5350 |
|
5351 |
|
5352 |
|
5353 |
|
5354 |
|
5355 |
|
5356 |
|
5357 |
|
5358 |
|
5359 |
|
5360 |
|
5361 |
|
5362 |
|
5363 |
|
5364 |
|
5365 |
|
5366 |
|
5367 |
|
5368 |
|
5369 |
|
5370 |
|
5371 |
|
5372 |
|
5373 |
|
5374 |
|
5375 |
|
5376 |
|
5377 |
|
5378 |
|
5379 |
|
5380 |
|
5381 |
|
5382 |
|
5383 |
|
5384 |
|
5385 |
|
5386 |
|
5387 |
|
5388 |
|
5389 |
|
5390 |
|
5391 |
|
5392 |
|
5393 |
|
5394 |
|
5395 | function fromJS<JSValue>(
|
5396 | jsValue: JSValue,
|
5397 | reviver?: undefined
|
5398 | ): FromJS<JSValue>;
|
5399 | function fromJS(
|
5400 | jsValue: unknown,
|
5401 | reviver?: (
|
5402 | key: string | number,
|
5403 | sequence: Collection.Keyed<string, unknown> | Collection.Indexed<unknown>,
|
5404 | path?: Array<string | number>
|
5405 | ) => unknown
|
5406 | ): Collection<unknown, unknown>;
|
5407 |
|
5408 | type FromJS<JSValue> = JSValue extends FromJSNoTransform
|
5409 | ? JSValue
|
5410 | : JSValue extends Array<any>
|
5411 | ? FromJSArray<JSValue>
|
5412 | : JSValue extends {}
|
5413 | ? FromJSObject<JSValue>
|
5414 | : any;
|
5415 |
|
5416 | type FromJSNoTransform =
|
5417 | | Collection<any, any>
|
5418 | | number
|
5419 | | string
|
5420 | | null
|
5421 | | undefined;
|
5422 |
|
5423 | type FromJSArray<JSValue> = JSValue extends Array<infer T>
|
5424 | ? List<FromJS<T>>
|
5425 | : never;
|
5426 |
|
5427 | type FromJSObject<JSValue> = JSValue extends {}
|
5428 | ? Map<keyof JSValue, FromJS<JSValue[keyof JSValue]>>
|
5429 | : never;
|
5430 |
|
5431 | |
5432 |
|
5433 |
|
5434 |
|
5435 |
|
5436 |
|
5437 |
|
5438 |
|
5439 |
|
5440 |
|
5441 |
|
5442 |
|
5443 |
|
5444 |
|
5445 |
|
5446 |
|
5447 |
|
5448 |
|
5449 |
|
5450 |
|
5451 |
|
5452 |
|
5453 |
|
5454 |
|
5455 |
|
5456 | function is(first: unknown, second: unknown): boolean;
|
5457 |
|
5458 | |
5459 |
|
5460 |
|
5461 |
|
5462 |
|
5463 |
|
5464 |
|
5465 |
|
5466 |
|
5467 |
|
5468 |
|
5469 |
|
5470 |
|
5471 |
|
5472 |
|
5473 |
|
5474 |
|
5475 |
|
5476 |
|
5477 |
|
5478 |
|
5479 |
|
5480 | function hash(value: unknown): number;
|
5481 |
|
5482 | |
5483 |
|
5484 |
|
5485 |
|
5486 |
|
5487 |
|
5488 |
|
5489 |
|
5490 |
|
5491 |
|
5492 |
|
5493 |
|
5494 |
|
5495 |
|
5496 |
|
5497 |
|
5498 | function isImmutable(
|
5499 | maybeImmutable: unknown
|
5500 | ): maybeImmutable is Collection<unknown, unknown>;
|
5501 |
|
5502 | |
5503 |
|
5504 |
|
5505 |
|
5506 |
|
5507 |
|
5508 |
|
5509 |
|
5510 |
|
5511 |
|
5512 |
|
5513 |
|
5514 |
|
5515 | function isCollection(
|
5516 | maybeCollection: unknown
|
5517 | ): maybeCollection is Collection<unknown, unknown>;
|
5518 |
|
5519 | |
5520 |
|
5521 |
|
5522 |
|
5523 |
|
5524 |
|
5525 |
|
5526 |
|
5527 |
|
5528 |
|
5529 |
|
5530 |
|
5531 |
|
5532 | function isKeyed(
|
5533 | maybeKeyed: unknown
|
5534 | ): maybeKeyed is Collection.Keyed<unknown, unknown>;
|
5535 |
|
5536 | |
5537 |
|
5538 |
|
5539 |
|
5540 |
|
5541 |
|
5542 |
|
5543 |
|
5544 |
|
5545 |
|
5546 |
|
5547 |
|
5548 |
|
5549 |
|
5550 | function isIndexed(
|
5551 | maybeIndexed: unknown
|
5552 | ): maybeIndexed is Collection.Indexed<unknown>;
|
5553 |
|
5554 | |
5555 |
|
5556 |
|
5557 |
|
5558 |
|
5559 |
|
5560 |
|
5561 |
|
5562 |
|
5563 |
|
5564 |
|
5565 |
|
5566 |
|
5567 |
|
5568 | function isAssociative(
|
5569 | maybeAssociative: unknown
|
5570 | ): maybeAssociative is
|
5571 | | Collection.Keyed<unknown, unknown>
|
5572 | | Collection.Indexed<unknown>;
|
5573 |
|
5574 | |
5575 |
|
5576 |
|
5577 |
|
5578 |
|
5579 |
|
5580 |
|
5581 |
|
5582 |
|
5583 |
|
5584 |
|
5585 |
|
5586 |
|
5587 |
|
5588 |
|
5589 | function isOrdered(maybeOrdered: unknown): boolean;
|
5590 |
|
5591 | |
5592 |
|
5593 |
|
5594 |
|
5595 |
|
5596 |
|
5597 |
|
5598 | function isValueObject(maybeValue: unknown): maybeValue is ValueObject;
|
5599 |
|
5600 | |
5601 |
|
5602 |
|
5603 | function isSeq(
|
5604 | maybeSeq: unknown
|
5605 | ): maybeSeq is
|
5606 | | Seq.Indexed<unknown>
|
5607 | | Seq.Keyed<unknown, unknown>
|
5608 | | Seq.Set<unknown>;
|
5609 |
|
5610 | |
5611 |
|
5612 |
|
5613 | function isList(maybeList: unknown): maybeList is List<unknown>;
|
5614 |
|
5615 | |
5616 |
|
5617 |
|
5618 |
|
5619 |
|
5620 | function isMap(maybeMap: unknown): maybeMap is Map<unknown, unknown>;
|
5621 |
|
5622 | |
5623 |
|
5624 |
|
5625 | function isOrderedMap(
|
5626 | maybeOrderedMap: unknown
|
5627 | ): maybeOrderedMap is OrderedMap<unknown, unknown>;
|
5628 |
|
5629 | |
5630 |
|
5631 |
|
5632 | function isStack(maybeStack: unknown): maybeStack is Stack<unknown>;
|
5633 |
|
5634 | |
5635 |
|
5636 |
|
5637 |
|
5638 |
|
5639 | function isSet(maybeSet: unknown): maybeSet is Set<unknown>;
|
5640 |
|
5641 | |
5642 |
|
5643 |
|
5644 | function isOrderedSet(
|
5645 | maybeOrderedSet: unknown
|
5646 | ): maybeOrderedSet is OrderedSet<unknown>;
|
5647 |
|
5648 | |
5649 |
|
5650 |
|
5651 | function isRecord(maybeRecord: unknown): maybeRecord is Record<{}>;
|
5652 |
|
5653 | |
5654 |
|
5655 |
|
5656 |
|
5657 |
|
5658 |
|
5659 |
|
5660 |
|
5661 |
|
5662 |
|
5663 |
|
5664 |
|
5665 |
|
5666 |
|
5667 |
|
5668 | function get<K, V>(collection: Collection<K, V>, key: K): V | undefined;
|
5669 | function get<K, V, NSV>(
|
5670 | collection: Collection<K, V>,
|
5671 | key: K,
|
5672 | notSetValue: NSV
|
5673 | ): V | NSV;
|
5674 | function get<TProps extends object, K extends keyof TProps>(
|
5675 | record: Record<TProps>,
|
5676 | key: K,
|
5677 | notSetValue: unknown
|
5678 | ): TProps[K];
|
5679 | function get<V>(collection: Array<V>, key: number): V | undefined;
|
5680 | function get<V, NSV>(
|
5681 | collection: Array<V>,
|
5682 | key: number,
|
5683 | notSetValue: NSV
|
5684 | ): V | NSV;
|
5685 | function get<C extends object, K extends keyof C>(
|
5686 | object: C,
|
5687 | key: K,
|
5688 | notSetValue: unknown
|
5689 | ): C[K];
|
5690 | function get<V>(collection: { [key: string]: V }, key: string): V | undefined;
|
5691 | function get<V, NSV>(
|
5692 | collection: { [key: string]: V },
|
5693 | key: string,
|
5694 | notSetValue: NSV
|
5695 | ): V | NSV;
|
5696 |
|
5697 | |
5698 |
|
5699 |
|
5700 |
|
5701 |
|
5702 |
|
5703 |
|
5704 |
|
5705 |
|
5706 |
|
5707 |
|
5708 |
|
5709 |
|
5710 |
|
5711 |
|
5712 |
|
5713 | function has(collection: object, key: unknown): boolean;
|
5714 |
|
5715 | |
5716 |
|
5717 |
|
5718 |
|
5719 |
|
5720 |
|
5721 |
|
5722 |
|
5723 |
|
5724 |
|
5725 |
|
5726 |
|
5727 |
|
5728 |
|
5729 |
|
5730 |
|
5731 |
|
5732 |
|
5733 | function remove<K, C extends Collection<K, unknown>>(
|
5734 | collection: C,
|
5735 | key: K
|
5736 | ): C;
|
5737 | function remove<
|
5738 | TProps extends object,
|
5739 | C extends Record<TProps>,
|
5740 | K extends keyof TProps
|
5741 | >(collection: C, key: K): C;
|
5742 | function remove<C extends Array<unknown>>(collection: C, key: number): C;
|
5743 | function remove<C, K extends keyof C>(collection: C, key: K): C;
|
5744 | function remove<C extends { [key: string]: unknown }, K extends keyof C>(
|
5745 | collection: C,
|
5746 | key: K
|
5747 | ): C;
|
5748 |
|
5749 | |
5750 |
|
5751 |
|
5752 |
|
5753 |
|
5754 |
|
5755 |
|
5756 |
|
5757 |
|
5758 |
|
5759 |
|
5760 |
|
5761 |
|
5762 |
|
5763 |
|
5764 |
|
5765 |
|
5766 |
|
5767 |
|
5768 | function set<K, V, C extends Collection<K, V>>(
|
5769 | collection: C,
|
5770 | key: K,
|
5771 | value: V
|
5772 | ): C;
|
5773 | function set<
|
5774 | TProps extends object,
|
5775 | C extends Record<TProps>,
|
5776 | K extends keyof TProps
|
5777 | >(record: C, key: K, value: TProps[K]): C;
|
5778 | function set<V, C extends Array<V>>(collection: C, key: number, value: V): C;
|
5779 | function set<C, K extends keyof C>(object: C, key: K, value: C[K]): C;
|
5780 | function set<V, C extends { [key: string]: V }>(
|
5781 | collection: C,
|
5782 | key: string,
|
5783 | value: V
|
5784 | ): C;
|
5785 |
|
5786 | |
5787 |
|
5788 |
|
5789 |
|
5790 |
|
5791 |
|
5792 |
|
5793 |
|
5794 |
|
5795 |
|
5796 |
|
5797 |
|
5798 |
|
5799 |
|
5800 |
|
5801 |
|
5802 |
|
5803 |
|
5804 |
|
5805 | function update<K, V, C extends Collection<K, V>>(
|
5806 | collection: C,
|
5807 | key: K,
|
5808 | updater: (value: V | undefined) => V | undefined
|
5809 | ): C;
|
5810 | function update<K, V, C extends Collection<K, V>, NSV>(
|
5811 | collection: C,
|
5812 | key: K,
|
5813 | notSetValue: NSV,
|
5814 | updater: (value: V | NSV) => V
|
5815 | ): C;
|
5816 | function update<
|
5817 | TProps extends object,
|
5818 | C extends Record<TProps>,
|
5819 | K extends keyof TProps
|
5820 | >(record: C, key: K, updater: (value: TProps[K]) => TProps[K]): C;
|
5821 | function update<
|
5822 | TProps extends object,
|
5823 | C extends Record<TProps>,
|
5824 | K extends keyof TProps,
|
5825 | NSV
|
5826 | >(
|
5827 | record: C,
|
5828 | key: K,
|
5829 | notSetValue: NSV,
|
5830 | updater: (value: TProps[K] | NSV) => TProps[K]
|
5831 | ): C;
|
5832 | function update<V>(
|
5833 | collection: Array<V>,
|
5834 | key: number,
|
5835 | updater: (value: V | undefined) => V | undefined
|
5836 | ): Array<V>;
|
5837 | function update<V, NSV>(
|
5838 | collection: Array<V>,
|
5839 | key: number,
|
5840 | notSetValue: NSV,
|
5841 | updater: (value: V | NSV) => V
|
5842 | ): Array<V>;
|
5843 | function update<C, K extends keyof C>(
|
5844 | object: C,
|
5845 | key: K,
|
5846 | updater: (value: C[K]) => C[K]
|
5847 | ): C;
|
5848 | function update<C, K extends keyof C, NSV>(
|
5849 | object: C,
|
5850 | key: K,
|
5851 | notSetValue: NSV,
|
5852 | updater: (value: C[K] | NSV) => C[K]
|
5853 | ): C;
|
5854 | function update<V, C extends { [key: string]: V }, K extends keyof C>(
|
5855 | collection: C,
|
5856 | key: K,
|
5857 | updater: (value: V) => V
|
5858 | ): { [key: string]: V };
|
5859 | function update<V, C extends { [key: string]: V }, K extends keyof C, NSV>(
|
5860 | collection: C,
|
5861 | key: K,
|
5862 | notSetValue: NSV,
|
5863 | updater: (value: V | NSV) => V
|
5864 | ): { [key: string]: V };
|
5865 |
|
5866 | |
5867 |
|
5868 |
|
5869 |
|
5870 |
|
5871 |
|
5872 |
|
5873 |
|
5874 |
|
5875 |
|
5876 |
|
5877 |
|
5878 |
|
5879 |
|
5880 | function getIn(
|
5881 | collection: unknown,
|
5882 | keyPath: Iterable<unknown>,
|
5883 | notSetValue?: unknown
|
5884 | ): unknown;
|
5885 |
|
5886 | |
5887 |
|
5888 |
|
5889 |
|
5890 |
|
5891 |
|
5892 |
|
5893 |
|
5894 |
|
5895 |
|
5896 |
|
5897 |
|
5898 |
|
5899 | function hasIn(collection: unknown, keyPath: Iterable<unknown>): boolean;
|
5900 |
|
5901 | |
5902 |
|
5903 |
|
5904 |
|
5905 |
|
5906 |
|
5907 |
|
5908 |
|
5909 |
|
5910 |
|
5911 |
|
5912 |
|
5913 |
|
5914 |
|
5915 | function removeIn<C>(collection: C, keyPath: Iterable<unknown>): C;
|
5916 |
|
5917 | |
5918 |
|
5919 |
|
5920 |
|
5921 |
|
5922 |
|
5923 |
|
5924 |
|
5925 |
|
5926 |
|
5927 |
|
5928 |
|
5929 |
|
5930 |
|
5931 |
|
5932 | function setIn<C>(
|
5933 | collection: C,
|
5934 | keyPath: Iterable<unknown>,
|
5935 | value: unknown
|
5936 | ): C;
|
5937 |
|
5938 | |
5939 |
|
5940 |
|
5941 |
|
5942 |
|
5943 |
|
5944 |
|
5945 |
|
5946 |
|
5947 |
|
5948 |
|
5949 |
|
5950 |
|
5951 |
|
5952 |
|
5953 | function updateIn<C>(
|
5954 | collection: C,
|
5955 | keyPath: Iterable<unknown>,
|
5956 | updater: (value: unknown) => unknown
|
5957 | ): C;
|
5958 | function updateIn<C>(
|
5959 | collection: C,
|
5960 | keyPath: Iterable<unknown>,
|
5961 | notSetValue: unknown,
|
5962 | updater: (value: unknown) => unknown
|
5963 | ): C;
|
5964 |
|
5965 | |
5966 |
|
5967 |
|
5968 |
|
5969 |
|
5970 |
|
5971 |
|
5972 |
|
5973 |
|
5974 |
|
5975 |
|
5976 |
|
5977 |
|
5978 |
|
5979 | function merge<C>(
|
5980 | collection: C,
|
5981 | ...collections: Array<
|
5982 | | Iterable<unknown>
|
5983 | | Iterable<[unknown, unknown]>
|
5984 | | { [key: string]: unknown }
|
5985 | >
|
5986 | ): C;
|
5987 |
|
5988 | |
5989 |
|
5990 |
|
5991 |
|
5992 |
|
5993 |
|
5994 |
|
5995 |
|
5996 |
|
5997 |
|
5998 |
|
5999 |
|
6000 |
|
6001 |
|
6002 |
|
6003 |
|
6004 |
|
6005 |
|
6006 |
|
6007 | function mergeWith<C>(
|
6008 | merger: (oldVal: unknown, newVal: unknown, key: unknown) => unknown,
|
6009 | collection: C,
|
6010 | ...collections: Array<
|
6011 | | Iterable<unknown>
|
6012 | | Iterable<[unknown, unknown]>
|
6013 | | { [key: string]: unknown }
|
6014 | >
|
6015 | ): C;
|
6016 |
|
6017 | |
6018 |
|
6019 |
|
6020 |
|
6021 |
|
6022 |
|
6023 |
|
6024 |
|
6025 |
|
6026 |
|
6027 |
|
6028 |
|
6029 |
|
6030 |
|
6031 |
|
6032 |
|
6033 |
|
6034 |
|
6035 |
|
6036 |
|
6037 |
|
6038 |
|
6039 |
|
6040 |
|
6041 |
|
6042 | function mergeDeep<C>(
|
6043 | collection: C,
|
6044 | ...collections: Array<
|
6045 | | Iterable<unknown>
|
6046 | | Iterable<[unknown, unknown]>
|
6047 | | { [key: string]: unknown }
|
6048 | >
|
6049 | ): C;
|
6050 |
|
6051 | |
6052 |
|
6053 |
|
6054 |
|
6055 |
|
6056 |
|
6057 |
|
6058 |
|
6059 |
|
6060 |
|
6061 |
|
6062 |
|
6063 |
|
6064 |
|
6065 |
|
6066 |
|
6067 |
|
6068 |
|
6069 |
|
6070 |
|
6071 |
|
6072 | function mergeDeepWith<C>(
|
6073 | merger: (oldVal: unknown, newVal: unknown, key: unknown) => unknown,
|
6074 | collection: C,
|
6075 | ...collections: Array<
|
6076 | | Iterable<unknown>
|
6077 | | Iterable<[unknown, unknown]>
|
6078 | | { [key: string]: unknown }
|
6079 | >
|
6080 | ): C;
|
6081 | }
|
6082 |
|
6083 |
|
6084 |
|
6085 |
|
6086 |
|
6087 |
|
6088 |
|
6089 |
|
6090 |
|
6091 |
|
6092 |
|
6093 |
|
6094 | export = Immutable;
|
6095 |
|
6096 |
|
6097 |
|
6098 |
|
6099 |
|
6100 |
|
6101 |
|
6102 |
|
6103 |
|
6104 |
|
6105 | export as namespace Immutable;
|
6106 |
|
\ | No newline at end of file |