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