Debian Codegraph @

node/immutable/dist/immutable.js

raw
1 /**
2 * @license
3 * MIT License
4 *
5 * Copyright (c) 2014-present, Lee Byron and other contributors.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 */
25 (function (global, factory) {
26 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
27 typeof define === 'function' && define.amd ? define(['exports'], factory) :
28 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Immutable = {}));
29 })(this, (function (exports) { 'use strict';
30
31 var IS_INDEXED_SYMBOL = '@@__IMMUTABLE_INDEXED__@@';
32 /**
33 * True if `maybeIndexed` is a Collection.Indexed, or any of its subclasses.
34 *
35 * ```js
36 * import { isIndexed, Map, List, Stack, Set } from 'immutable';
37 *
38 * isIndexed([]); // false
39 * isIndexed({}); // false
40 * isIndexed(Map()); // false
41 * isIndexed(List()); // true
42 * isIndexed(Stack()); // true
43 * isIndexed(Set()); // false
44 * ```
45 */
46 function isIndexed(maybeIndexed) {
47 return Boolean(maybeIndexed &&
48 // @ts-expect-error: maybeIndexed is typed as `{}`, need to change in 6.0 to `maybeIndexed && typeof maybeIndexed === 'object' && IS_INDEXED_SYMBOL in maybeIndexed`
49 maybeIndexed[IS_INDEXED_SYMBOL]);
50 }
51
52 var IS_KEYED_SYMBOL = '@@__IMMUTABLE_KEYED__@@';
53 /**
54 * True if `maybeKeyed` is a Collection.Keyed, or any of its subclasses.
55 *
56 * ```js
57 * import { isKeyed, Map, List, Stack } from 'immutable';
58 *
59 * isKeyed([]); // false
60 * isKeyed({}); // false
61 * isKeyed(Map()); // true
62 * isKeyed(List()); // false
63 * isKeyed(Stack()); // false
64 * ```
65 */
66 function isKeyed(maybeKeyed) {
67 return Boolean(maybeKeyed &&
68 // @ts-expect-error: maybeKeyed is typed as `{}`, need to change in 6.0 to `maybeKeyed && typeof maybeKeyed === 'object' && IS_KEYED_SYMBOL in maybeKeyed`
69 maybeKeyed[IS_KEYED_SYMBOL]);
70 }
71
72 /**
73 * True if `maybeAssociative` is either a Keyed or Indexed Collection.
74 *
75 * ```js
76 * import { isAssociative, Map, List, Stack, Set } from 'immutable';
77 *
78 * isAssociative([]); // false
79 * isAssociative({}); // false
80 * isAssociative(Map()); // true
81 * isAssociative(List()); // true
82 * isAssociative(Stack()); // true
83 * isAssociative(Set()); // false
84 * ```
85 */
86 function isAssociative(maybeAssociative) {
87 return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
88 }
89
90 // Note: value is unchanged to not break immutable-devtools.
91 var IS_COLLECTION_SYMBOL = '@@__IMMUTABLE_ITERABLE__@@';
92 /**
93 * True if `maybeCollection` is a Collection, or any of its subclasses.
94 *
95 * ```js
96 * import { isCollection, Map, List, Stack } from 'immutable';
97 *
98 * isCollection([]); // false
99 * isCollection({}); // false
100 * isCollection(Map()); // true
101 * isCollection(List()); // true
102 * isCollection(Stack()); // true
103 * ```
104 */
105 function isCollection(maybeCollection) {
106 return Boolean(maybeCollection &&
107 // @ts-expect-error: maybeCollection is typed as `{}`, need to change in 6.0 to `maybeCollection && typeof maybeCollection === 'object' && IS_COLLECTION_SYMBOL in maybeCollection`
108 maybeCollection[IS_COLLECTION_SYMBOL]);
109 }
110
111 var Collection = function Collection(value) {
112 // eslint-disable-next-line no-constructor-return
113 return isCollection(value) ? value : Seq(value);
114 };
115
116 var KeyedCollection = /*@__PURE__*/(function (Collection) {
117 function KeyedCollection(value) {
118 // eslint-disable-next-line no-constructor-return
119 return isKeyed(value) ? value : KeyedSeq(value);
120 }
121
122 if ( Collection ) KeyedCollection.__proto__ = Collection;
123 KeyedCollection.prototype = Object.create( Collection && Collection.prototype );
124 KeyedCollection.prototype.constructor = KeyedCollection;
125
126 return KeyedCollection;
127 }(Collection));
128
129 var IndexedCollection = /*@__PURE__*/(function (Collection) {
130 function IndexedCollection(value) {
131 // eslint-disable-next-line no-constructor-return
132 return isIndexed(value) ? value : IndexedSeq(value);
133 }
134
135 if ( Collection ) IndexedCollection.__proto__ = Collection;
136 IndexedCollection.prototype = Object.create( Collection && Collection.prototype );
137 IndexedCollection.prototype.constructor = IndexedCollection;
138
139 return IndexedCollection;
140 }(Collection));
141
142 var SetCollection = /*@__PURE__*/(function (Collection) {
143 function SetCollection(value) {
144 // eslint-disable-next-line no-constructor-return
145 return isCollection(value) && !isAssociative(value) ? value : SetSeq(value);
146 }
147
148 if ( Collection ) SetCollection.__proto__ = Collection;
149 SetCollection.prototype = Object.create( Collection && Collection.prototype );
150 SetCollection.prototype.constructor = SetCollection;
151
152 return SetCollection;
153 }(Collection));
154
155 Collection.Keyed = KeyedCollection;
156 Collection.Indexed = IndexedCollection;
157 Collection.Set = SetCollection;
158
159 var ITERATE_KEYS = 0;
160 var ITERATE_VALUES = 1;
161 var ITERATE_ENTRIES = 2;
162 // TODO Symbol is widely available in modern JavaScript environments, clean this
163 var REAL_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
164 var FAUX_ITERATOR_SYMBOL = '@@iterator';
165 var ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL;
166 // @ts-expect-error: properties are not supported in buble
167 var Iterator = function Iterator(next) {
168 // @ts-expect-error: properties are not supported in buble
169 this.next = next;
170 };
171 Iterator.prototype.toString = function toString () {
172 return '[Iterator]';
173 };
174 // @ts-expect-error: static properties are not supported in buble
175 Iterator.KEYS = ITERATE_KEYS;
176 // @ts-expect-error: static properties are not supported in buble
177 Iterator.VALUES = ITERATE_VALUES;
178 // @ts-expect-error: static properties are not supported in buble
179 Iterator.ENTRIES = ITERATE_ENTRIES;
180 // @ts-expect-error: properties are not supported in buble
181 Iterator.prototype.inspect = Iterator.prototype.toSource = function () {
182 return this.toString();
183 };
184 // @ts-expect-error don't know how to type this
185 Iterator.prototype[ITERATOR_SYMBOL] = function () {
186 return this;
187 };
188 function iteratorValue(type, k, v, iteratorResult) {
189 var value = type === ITERATE_KEYS ? k : type === ITERATE_VALUES ? v : [k, v];
190 // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
191 iteratorResult
192 ? (iteratorResult.value = value)
193 : (iteratorResult = {
194 // @ts-expect-error ensure value is not undefined
195 value: value,
196 done: false,
197 });
198 return iteratorResult;
199 }
200 function iteratorDone() {
201 return { value: undefined, done: true };
202 }
203 function hasIterator(maybeIterable) {
204 if (Array.isArray(maybeIterable)) {
205 // IE11 trick as it does not support `Symbol.iterator`
206 return true;
207 }
208 return !!getIteratorFn(maybeIterable);
209 }
210 function isIterator(maybeIterator) {
211 return !!(maybeIterator &&
212 // @ts-expect-error: maybeIterator is typed as `{}`
213 typeof maybeIterator.next === 'function');
214 }
215 function getIterator(iterable) {
216 var iteratorFn = getIteratorFn(iterable);
217 return iteratorFn && iteratorFn.call(iterable);
218 }
219 function getIteratorFn(iterable) {
220 var iteratorFn = iterable &&
221 // @ts-expect-error: maybeIterator is typed as `{}`
222 ((REAL_ITERATOR_SYMBOL && iterable[REAL_ITERATOR_SYMBOL]) ||
223 // @ts-expect-error: maybeIterator is typed as `{}`
224 iterable[FAUX_ITERATOR_SYMBOL]);
225 if (typeof iteratorFn === 'function') {
226 return iteratorFn;
227 }
228 }
229 function isEntriesIterable(maybeIterable) {
230 var iteratorFn = getIteratorFn(maybeIterable);
231 // @ts-expect-error: maybeIterator is typed as `{}`
232 return iteratorFn && iteratorFn === maybeIterable.entries;
233 }
234 function isKeysIterable(maybeIterable) {
235 var iteratorFn = getIteratorFn(maybeIterable);
236 // @ts-expect-error: maybeIterator is typed as `{}`
237 return iteratorFn && iteratorFn === maybeIterable.keys;
238 }
239
240 // Used for setting prototype methods that IE8 chokes on.
241 var DELETE = 'delete';
242 // Constants describing the size of trie nodes.
243 var SHIFT = 5; // Resulted in best performance after ______?
244 var SIZE = 1 << SHIFT;
245 var MASK = SIZE - 1;
246 // A consistent shared value representing "not set" which equals nothing other
247 // than itself, and nothing that could be provided externally.
248 var NOT_SET = {};
249 // Boolean references, Rough equivalent of `bool &`.
250 function MakeRef() {
251 return { value: false };
252 }
253 function SetRef(ref) {
254 if (ref) {
255 ref.value = true;
256 }
257 }
258 // A function which returns a value representing an "owner" for transient writes
259 // to tries. The return value will only ever equal itself, and will not equal
260 // the return of any subsequent call of this function.
261 function OwnerID() { }
262 function ensureSize(iter) {
263 // @ts-expect-error size should exists on Collection
264 if (iter.size === undefined) {
265 // @ts-expect-error size should exists on Collection, __iterate does exist on Collection
266 iter.size = iter.__iterate(returnTrue);
267 }
268 // @ts-expect-error size should exists on Collection
269 return iter.size;
270 }
271 function wrapIndex(iter, index) {
272 // This implements "is array index" which the ECMAString spec defines as:
273 //
274 // A String property name P is an array index if and only if
275 // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal
276 // to 2^32−1.
277 //
278 // http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects
279 if (typeof index !== 'number') {
280 var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32
281 if ('' + uint32Index !== index || uint32Index === 4294967295) {
282 return NaN;
283 }
284 index = uint32Index;
285 }
286 return index < 0 ? ensureSize(iter) + index : index;
287 }
288 function returnTrue() {
289 return true;
290 }
291 function wholeSlice(begin, end, size) {
292 return (((begin === 0 && !isNeg(begin)) ||
293 (size !== undefined && begin <= -size)) &&
294 (end === undefined || (size !== undefined && end >= size)));
295 }
296 function resolveBegin(begin, size) {
297 return resolveIndex(begin, size, 0);
298 }
299 function resolveEnd(end, size) {
300 return resolveIndex(end, size, size);
301 }
302 function resolveIndex(index, size, defaultIndex) {
303 // Sanitize indices using this shorthand for ToInt32(argument)
304 // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
305 return index === undefined
306 ? defaultIndex
307 : isNeg(index)
308 ? size === Infinity
309 ? size
310 : Math.max(0, size + index) | 0
311 : size === undefined || size === index
312 ? index
313 : Math.min(size, index) | 0;
314 }
315 function isNeg(value) {
316 // Account for -0 which is negative, but not less than 0.
317 return value < 0 || (value === 0 && 1 / value === -Infinity);
318 }
319
320 var IS_RECORD_SYMBOL = '@@__IMMUTABLE_RECORD__@@';
321 /**
322 * True if `maybeRecord` is a Record.
323 */
324 function isRecord(maybeRecord) {
325 return Boolean(maybeRecord &&
326 // @ts-expect-error: maybeRecord is typed as `{}`, need to change in 6.0 to `maybeRecord && typeof maybeRecord === 'object' && IS_RECORD_SYMBOL in maybeRecord`
327 maybeRecord[IS_RECORD_SYMBOL]);
328 }
329
330 /**
331 * True if `maybeImmutable` is an Immutable Collection or Record.
332 *
333 * Note: Still returns true even if the collections is within a `withMutations()`.
334 *
335 * ```js
336 * import { isImmutable, Map, List, Stack } from 'immutable';
337 * isImmutable([]); // false
338 * isImmutable({}); // false
339 * isImmutable(Map()); // true
340 * isImmutable(List()); // true
341 * isImmutable(Stack()); // true
342 * isImmutable(Map().asMutable()); // true
343 * ```
344 */
345 function isImmutable(maybeImmutable) {
346 return isCollection(maybeImmutable) || isRecord(maybeImmutable);
347 }
348
349 var IS_ORDERED_SYMBOL = '@@__IMMUTABLE_ORDERED__@@';
350 function isOrdered(maybeOrdered) {
351 return Boolean(maybeOrdered &&
352 // @ts-expect-error: maybeOrdered is typed as `{}`, need to change in 6.0 to `maybeOrdered && typeof maybeOrdered === 'object' && IS_ORDERED_SYMBOL in maybeOrdered`
353 maybeOrdered[IS_ORDERED_SYMBOL]);
354 }
355
356 var IS_SEQ_SYMBOL = '@@__IMMUTABLE_SEQ__@@';
357 /**
358 * True if `maybeSeq` is a Seq.
359 */
360 function isSeq(maybeSeq) {
361 return Boolean(maybeSeq &&
362 // @ts-expect-error: maybeSeq is typed as `{}`, need to change in 6.0 to `maybeSeq && typeof maybeSeq === 'object' && MAYBE_SEQ_SYMBOL in maybeSeq`
363 maybeSeq[IS_SEQ_SYMBOL]);
364 }
365
366 var hasOwnProperty = Object.prototype.hasOwnProperty;
367
368 function isArrayLike(value) {
369 if (Array.isArray(value) || typeof value === 'string') {
370 return true;
371 }
372 // @ts-expect-error "Type 'unknown' is not assignable to type 'boolean'" : convert to Boolean
373 return (value &&
374 typeof value === 'object' &&
375 // @ts-expect-error check that `'length' in value &&`
376 Number.isInteger(value.length) &&
377 // @ts-expect-error check that `'length' in value &&`
378 value.length >= 0 &&
379 // @ts-expect-error check that `'length' in value &&`
380 (value.length === 0
381 ? // Only {length: 0} is considered Array-like.
382 Object.keys(value).length === 1
383 : // An object is only Array-like if it has a property where the last value
384 // in the array-like may be found (which could be undefined).
385 // @ts-expect-error check that `'length' in value &&`
386 value.hasOwnProperty(value.length - 1)));
387 }
388
389 var Seq = /*@__PURE__*/(function (Collection) {
390 function Seq(value) {
391 // eslint-disable-next-line no-constructor-return
392 return value === undefined || value === null
393 ? emptySequence()
394 : isImmutable(value)
395 ? value.toSeq()
396 : seqFromValue(value);
397 }
398
399 if ( Collection ) Seq.__proto__ = Collection;
400 Seq.prototype = Object.create( Collection && Collection.prototype );
401 Seq.prototype.constructor = Seq;
402
403 Seq.prototype.toSeq = function toSeq () {
404 return this;
405 };
406
407 Seq.prototype.toString = function toString () {
408 return this.__toString('Seq {', '}');
409 };
410
411 Seq.prototype.cacheResult = function cacheResult () {
412 if (!this._cache && this.__iterateUncached) {
413 this._cache = this.entrySeq().toArray();
414 this.size = this._cache.length;
415 }
416 return this;
417 };
418
419 // abstract __iterateUncached(fn, reverse)
420
421 Seq.prototype.__iterate = function __iterate (fn, reverse) {
422 var cache = this._cache;
423 if (cache) {
424 var size = cache.length;
425 var i = 0;
426 while (i !== size) {
427 var entry = cache[reverse ? size - ++i : i++];
428 if (fn(entry[1], entry[0], this) === false) {
429 break;
430 }
431 }
432 return i;
433 }
434 return this.__iterateUncached(fn, reverse);
435 };
436
437 // abstract __iteratorUncached(type, reverse)
438
439 Seq.prototype.__iterator = function __iterator (type, reverse) {
440 var cache = this._cache;
441 if (cache) {
442 var size = cache.length;
443 var i = 0;
444 return new Iterator(function () {
445 if (i === size) {
446 return iteratorDone();
447 }
448 var entry = cache[reverse ? size - ++i : i++];
449 return iteratorValue(type, entry[0], entry[1]);
450 });
451 }
452 return this.__iteratorUncached(type, reverse);
453 };
454
455 return Seq;
456 }(Collection));
457
458 var KeyedSeq = /*@__PURE__*/(function (Seq) {
459 function KeyedSeq(value) {
460 // eslint-disable-next-line no-constructor-return
461 return value === undefined || value === null
462 ? emptySequence().toKeyedSeq()
463 : isCollection(value)
464 ? isKeyed(value)
465 ? value.toSeq()
466 : value.fromEntrySeq()
467 : isRecord(value)
468 ? value.toSeq()
469 : keyedSeqFromValue(value);
470 }
471
472 if ( Seq ) KeyedSeq.__proto__ = Seq;
473 KeyedSeq.prototype = Object.create( Seq && Seq.prototype );
474 KeyedSeq.prototype.constructor = KeyedSeq;
475
476 KeyedSeq.prototype.toKeyedSeq = function toKeyedSeq () {
477 return this;
478 };
479
480 return KeyedSeq;
481 }(Seq));
482
483 var IndexedSeq = /*@__PURE__*/(function (Seq) {
484 function IndexedSeq(value) {
485 // eslint-disable-next-line no-constructor-return
486 return value === undefined || value === null
487 ? emptySequence()
488 : isCollection(value)
489 ? isKeyed(value)
490 ? value.entrySeq()
491 : value.toIndexedSeq()
492 : isRecord(value)
493 ? value.toSeq().entrySeq()
494 : indexedSeqFromValue(value);
495 }
496
497 if ( Seq ) IndexedSeq.__proto__ = Seq;
498 IndexedSeq.prototype = Object.create( Seq && Seq.prototype );
499 IndexedSeq.prototype.constructor = IndexedSeq;
500
501 IndexedSeq.of = function of (/*...values*/) {
502 return IndexedSeq(arguments);
503 };
504
505 IndexedSeq.prototype.toIndexedSeq = function toIndexedSeq () {
506 return this;
507 };
508
509 IndexedSeq.prototype.toString = function toString () {
510 return this.__toString('Seq [', ']');
511 };
512
513 return IndexedSeq;
514 }(Seq));
515
516 var SetSeq = /*@__PURE__*/(function (Seq) {
517 function SetSeq(value) {
518 // eslint-disable-next-line no-constructor-return
519 return (
520 isCollection(value) && !isAssociative(value) ? value : IndexedSeq(value)
521 ).toSetSeq();
522 }
523
524 if ( Seq ) SetSeq.__proto__ = Seq;
525 SetSeq.prototype = Object.create( Seq && Seq.prototype );
526 SetSeq.prototype.constructor = SetSeq;
527
528 SetSeq.of = function of (/*...values*/) {
529 return SetSeq(arguments);
530 };
531
532 SetSeq.prototype.toSetSeq = function toSetSeq () {
533 return this;
534 };
535
536 return SetSeq;
537 }(Seq));
538
539 Seq.isSeq = isSeq;
540 Seq.Keyed = KeyedSeq;
541 Seq.Set = SetSeq;
542 Seq.Indexed = IndexedSeq;
543
544 Seq.prototype[IS_SEQ_SYMBOL] = true;
545
546 // #pragma Root Sequences
547
548 var ArraySeq = /*@__PURE__*/(function (IndexedSeq) {
549 function ArraySeq(array) {
550 this._array = array;
551 this.size = array.length;
552 }
553
554 if ( IndexedSeq ) ArraySeq.__proto__ = IndexedSeq;
555 ArraySeq.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
556 ArraySeq.prototype.constructor = ArraySeq;
557
558 ArraySeq.prototype.get = function get (index, notSetValue) {
559 return this.has(index) ? this._array[wrapIndex(this, index)] : notSetValue;
560 };
561
562 ArraySeq.prototype.__iterate = function __iterate (fn, reverse) {
563 var array = this._array;
564 var size = array.length;
565 var i = 0;
566 while (i !== size) {
567 var ii = reverse ? size - ++i : i++;
568 if (fn(array[ii], ii, this) === false) {
569 break;
570 }
571 }
572 return i;
573 };
574
575 ArraySeq.prototype.__iterator = function __iterator (type, reverse) {
576 var array = this._array;
577 var size = array.length;
578 var i = 0;
579 return new Iterator(function () {
580 if (i === size) {
581 return iteratorDone();
582 }
583 var ii = reverse ? size - ++i : i++;
584 return iteratorValue(type, ii, array[ii]);
585 });
586 };
587
588 return ArraySeq;
589 }(IndexedSeq));
590
591 var ObjectSeq = /*@__PURE__*/(function (KeyedSeq) {
592 function ObjectSeq(object) {
593 var keys = Object.keys(object).concat(
594 Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(object) : []
595 );
596 this._object = object;
597 this._keys = keys;
598 this.size = keys.length;
599 }
600
601 if ( KeyedSeq ) ObjectSeq.__proto__ = KeyedSeq;
602 ObjectSeq.prototype = Object.create( KeyedSeq && KeyedSeq.prototype );
603 ObjectSeq.prototype.constructor = ObjectSeq;
604
605 ObjectSeq.prototype.get = function get (key, notSetValue) {
606 if (notSetValue !== undefined && !this.has(key)) {
607 return notSetValue;
608 }
609 return this._object[key];
610 };
611
612 ObjectSeq.prototype.has = function has (key) {
613 return hasOwnProperty.call(this._object, key);
614 };
615
616 ObjectSeq.prototype.__iterate = function __iterate (fn, reverse) {
617 var object = this._object;
618 var keys = this._keys;
619 var size = keys.length;
620 var i = 0;
621 while (i !== size) {
622 var key = keys[reverse ? size - ++i : i++];
623 if (fn(object[key], key, this) === false) {
624 break;
625 }
626 }
627 return i;
628 };
629
630 ObjectSeq.prototype.__iterator = function __iterator (type, reverse) {
631 var object = this._object;
632 var keys = this._keys;
633 var size = keys.length;
634 var i = 0;
635 return new Iterator(function () {
636 if (i === size) {
637 return iteratorDone();
638 }
639 var key = keys[reverse ? size - ++i : i++];
640 return iteratorValue(type, key, object[key]);
641 });
642 };
643
644 return ObjectSeq;
645 }(KeyedSeq));
646 ObjectSeq.prototype[IS_ORDERED_SYMBOL] = true;
647
648 var CollectionSeq = /*@__PURE__*/(function (IndexedSeq) {
649 function CollectionSeq(collection) {
650 this._collection = collection;
651 this.size = collection.length || collection.size;
652 }
653
654 if ( IndexedSeq ) CollectionSeq.__proto__ = IndexedSeq;
655 CollectionSeq.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
656 CollectionSeq.prototype.constructor = CollectionSeq;
657
658 CollectionSeq.prototype.__iterateUncached = function __iterateUncached (fn, reverse) {
659 if (reverse) {
660 return this.cacheResult().__iterate(fn, reverse);
661 }
662 var collection = this._collection;
663 var iterator = getIterator(collection);
664 var iterations = 0;
665 if (isIterator(iterator)) {
666 var step;
667 while (!(step = iterator.next()).done) {
668 if (fn(step.value, iterations++, this) === false) {
669 break;
670 }
671 }
672 }
673 return iterations;
674 };
675
676 CollectionSeq.prototype.__iteratorUncached = function __iteratorUncached (type, reverse) {
677 if (reverse) {
678 return this.cacheResult().__iterator(type, reverse);
679 }
680 var collection = this._collection;
681 var iterator = getIterator(collection);
682 if (!isIterator(iterator)) {
683 return new Iterator(iteratorDone);
684 }
685 var iterations = 0;
686 return new Iterator(function () {
687 var step = iterator.next();
688 return step.done ? step : iteratorValue(type, iterations++, step.value);
689 });
690 };
691
692 return CollectionSeq;
693 }(IndexedSeq));
694
695 // # pragma Helper functions
696
697 var EMPTY_SEQ;
698
699 function emptySequence() {
700 return EMPTY_SEQ || (EMPTY_SEQ = new ArraySeq([]));
701 }
702
703 function keyedSeqFromValue(value) {
704 var seq = maybeIndexedSeqFromValue(value);
705 if (seq) {
706 return seq.fromEntrySeq();
707 }
708 if (typeof value === 'object') {
709 return new ObjectSeq(value);
710 }
711 throw new TypeError(
712 'Expected Array or collection object of [k, v] entries, or keyed object: ' +
713 value
714 );
715 }
716
717 function indexedSeqFromValue(value) {
718 var seq = maybeIndexedSeqFromValue(value);
719 if (seq) {
720 return seq;
721 }
722 throw new TypeError(
723 'Expected Array or collection object of values: ' + value
724 );
725 }
726
727 function seqFromValue(value) {
728 var seq = maybeIndexedSeqFromValue(value);
729 if (seq) {
730 return isEntriesIterable(value)
731 ? seq.fromEntrySeq()
732 : isKeysIterable(value)
733 ? seq.toSetSeq()
734 : seq;
735 }
736 if (typeof value === 'object') {
737 return new ObjectSeq(value);
738 }
739 throw new TypeError(
740 'Expected Array or collection object of values, or keyed object: ' + value
741 );
742 }
743
744 function maybeIndexedSeqFromValue(value) {
745 return isArrayLike(value)
746 ? new ArraySeq(value)
747 : hasIterator(value)
748 ? new CollectionSeq(value)
749 : undefined;
750 }
751
752 function asImmutable() {
753 return this.__ensureOwner();
754 }
755
756 function asMutable() {
757 return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
758 }
759
760 // TODO remove in v6 as Math.imul is widely available now: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul
761 var imul = typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2
762 ? Math.imul
763 : function imul(a, b) {
764 a |= 0; // int
765 b |= 0; // int
766 var c = a & 0xffff;
767 var d = b & 0xffff;
768 // Shift by 0 fixes the sign on the high part.
769 return (c * d + ((((a >>> 16) * d + c * (b >>> 16)) << 16) >>> 0)) | 0; // int
770 };
771 // v8 has an optimization for storing 31-bit signed numbers.
772 // Values which have either 00 or 11 as the high order bits qualify.
773 // This function drops the highest order bit in a signed number, maintaining
774 // the sign bit.
775 function smi(i32) {
776 return ((i32 >>> 1) & 0x40000000) | (i32 & 0xbfffffff);
777 }
778
779 var defaultValueOf = Object.prototype.valueOf;
780 function hash(o) {
781 // eslint-disable-next-line eqeqeq
782 if (o == null) {
783 return hashNullish(o);
784 }
785 // @ts-expect-error don't care about object beeing typed as `{}` here
786 if (typeof o.hashCode === 'function') {
787 // Drop any high bits from accidentally long hash codes.
788 // @ts-expect-error don't care about object beeing typed as `{}` here
789 return smi(o.hashCode(o));
790 }
791 var v = valueOf(o);
792 // eslint-disable-next-line eqeqeq
793 if (v == null) {
794 return hashNullish(v);
795 }
796 switch (typeof v) {
797 case 'boolean':
798 // The hash values for built-in constants are a 1 value for each 5-byte
799 // shift region expect for the first, which encodes the value. This
800 // reduces the odds of a hash collision for these common values.
801 return v ? 0x42108421 : 0x42108420;
802 case 'number':
803 return hashNumber(v);
804 case 'string':
805 return v.length > STRING_HASH_CACHE_MIN_STRLEN
806 ? cachedHashString(v)
807 : hashString(v);
808 case 'object':
809 case 'function':
810 return hashJSObj(v);
811 case 'symbol':
812 return hashSymbol(v);
813 default:
814 if (typeof v.toString === 'function') {
815 return hashString(v.toString());
816 }
817 throw new Error('Value type ' + typeof v + ' cannot be hashed.');
818 }
819 }
820 function hashNullish(nullish) {
821 return nullish === null ? 0x42108422 : /* undefined */ 0x42108423;
822 }
823 // Compress arbitrarily large numbers into smi hashes.
824 function hashNumber(n) {
825 if (n !== n || n === Infinity) {
826 return 0;
827 }
828 var hash = n | 0;
829 if (hash !== n) {
830 hash ^= n * 0xffffffff;
831 }
832 while (n > 0xffffffff) {
833 n /= 0xffffffff;
834 hash ^= n;
835 }
836 return smi(hash);
837 }
838 function cachedHashString(string) {
839 var hashed = stringHashCache[string];
840 if (hashed === undefined) {
841 hashed = hashString(string);
842 if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
843 STRING_HASH_CACHE_SIZE = 0;
844 stringHashCache = {};
845 }
846 STRING_HASH_CACHE_SIZE++;
847 stringHashCache[string] = hashed;
848 }
849 return hashed;
850 }
851 // http://jsperf.com/hashing-strings
852 function hashString(string) {
853 // This is the hash from JVM
854 // The hash code for a string is computed as
855 // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
856 // where s[i] is the ith character of the string and n is the length of
857 // the string. We "mod" the result to make it between 0 (inclusive) and 2^31
858 // (exclusive) by dropping high bits.
859 var hashed = 0;
860 for (var ii = 0; ii < string.length; ii++) {
861 hashed = (31 * hashed + string.charCodeAt(ii)) | 0;
862 }
863 return smi(hashed);
864 }
865 // Per-process seed for the secondary collision hash. Never exposed nor
866 // serialized, so the public `hash()` stays deterministic. An odd base in
867 // [3, 2^20) keeps `base * h` exact as a double (no `Math.imul`).
868 var COLLISION_HASH_BASE = ((Math.random() * 0x100000) | 1) % 0x100000 || 0x9e37;
869 // Secondary hash to index entries within a `HashCollisionNode`, where every key
870 // shares the same primary `hash()`. Using a different, seeded base scatters
871 // crafted collision families (e.g. "Aa"/"BB", which only collide under base 31)
872 // that an attacker cannot precompute without the seed. It only narrows
873 // candidates — `is()` still decides equality — so non-string keys can safely
874 // fall back to the (here constant) primary hash and a linear scan.
875 function hashCollisionKey(key) {
876 if (typeof key !== 'string') {
877 return hash(key);
878 }
879 var hashed = 0;
880 for (var ii = 0; ii < key.length; ii++) {
881 hashed = (COLLISION_HASH_BASE * hashed + key.charCodeAt(ii)) | 0;
882 }
883 return hashed;
884 }
885 function hashSymbol(sym) {
886 var hashed = symbolMap[sym];
887 if (hashed !== undefined) {
888 return hashed;
889 }
890 hashed = nextHash();
891 symbolMap[sym] = hashed;
892 return hashed;
893 }
894 // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
895 function hashJSObj(obj) {
896 var hashed;
897 if (usingWeakMap) {
898 // @ts-expect-error weakMap is defined
899 hashed = weakMap.get(obj);
900 if (hashed !== undefined) {
901 return hashed;
902 }
903 }
904 // @ts-expect-error used for old code, will be removed
905 hashed = obj[UID_HASH_KEY];
906 if (hashed !== undefined) {
907 return hashed;
908 }
909 if (!canDefineProperty) {
910 // @ts-expect-error used for old code, will be removed
911 hashed = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
912 if (hashed !== undefined) {
913 return hashed;
914 }
915 hashed = getIENodeHash(obj);
916 if (hashed !== undefined) {
917 return hashed;
918 }
919 }
920 hashed = nextHash();
921 if (usingWeakMap) {
922 // @ts-expect-error weakMap is defined
923 weakMap.set(obj, hashed);
924 }
925 else if (isExtensible !== undefined && isExtensible(obj) === false) {
926 throw new Error('Non-extensible objects are not allowed as keys.');
927 }
928 else if (canDefineProperty) {
929 Object.defineProperty(obj, UID_HASH_KEY, {
930 enumerable: false,
931 configurable: false,
932 writable: false,
933 value: hashed,
934 });
935 }
936 else if (obj.propertyIsEnumerable !== undefined &&
937 obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable) {
938 // Since we can't define a non-enumerable property on the object
939 // we'll hijack one of the less-used non-enumerable properties to
940 // save our hash on it. Since this is a function it will not show up in
941 // `JSON.stringify` which is what we want.
942 obj.propertyIsEnumerable = function () {
943 return this.constructor.prototype.propertyIsEnumerable.apply(this,
944 // eslint-disable-next-line prefer-rest-params
945 arguments);
946 };
947 // @ts-expect-error used for old code, will be removed
948 obj.propertyIsEnumerable[UID_HASH_KEY] = hashed;
949 // @ts-expect-error used for old code, will be removed
950 }
951 else if (obj.nodeType !== undefined) {
952 // At this point we couldn't get the IE `uniqueID` to use as a hash
953 // and we couldn't use a non-enumerable property to exploit the
954 // dontEnum bug so we simply add the `UID_HASH_KEY` on the node
955 // itself.
956 // @ts-expect-error used for old code, will be removed
957 obj[UID_HASH_KEY] = hashed;
958 }
959 else {
960 throw new Error('Unable to set a non-enumerable property on object.');
961 }
962 return hashed;
963 }
964 // Get references to ES5 object methods.
965 var isExtensible = Object.isExtensible;
966 // True if Object.defineProperty works as expected. IE8 fails this test.
967 // TODO remove this as widely available https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty
968 var canDefineProperty = (function () {
969 try {
970 Object.defineProperty({}, '@', {});
971 return true;
972 // eslint-disable-next-line @typescript-eslint/no-unused-vars
973 }
974 catch (e) {
975 return false;
976 }
977 })();
978 // IE has a `uniqueID` property on DOM nodes. We can construct the hash from it
979 // and avoid memory leaks from the IE cloneNode bug.
980 // TODO remove this method as only used if `canDefineProperty` is false
981 function getIENodeHash(node) {
982 // @ts-expect-error don't care
983 if (node && node.nodeType > 0) {
984 // @ts-expect-error don't care
985 switch (node.nodeType) {
986 case 1: // Element
987 // @ts-expect-error don't care
988 return node.uniqueID;
989 case 9: // Document
990 // @ts-expect-error don't care
991 return node.documentElement && node.documentElement.uniqueID;
992 }
993 }
994 }
995 function valueOf(obj) {
996 return obj.valueOf !== defaultValueOf && typeof obj.valueOf === 'function'
997 ? // @ts-expect-error weird the "obj" parameter as `valueOf` should not have a parameter
998 obj.valueOf(obj)
999 : obj;
1000 }
1001 function nextHash() {
1002 var nextHash = ++_objHashUID;
1003 if (_objHashUID & 0x40000000) {
1004 _objHashUID = 0;
1005 }
1006 return nextHash;
1007 }
1008 // If possible, use a WeakMap.
1009 // TODO using WeakMap should be true everywhere now that WeakMap is widely supported: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap
1010 var usingWeakMap = typeof WeakMap === 'function';
1011 var weakMap;
1012 if (usingWeakMap) {
1013 weakMap = new WeakMap();
1014 }
1015 var symbolMap = Object.create(null);
1016 var _objHashUID = 0;
1017 // TODO remove string as Symbol is now widely supported: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol
1018 var UID_HASH_KEY = '__immutablehash__';
1019 if (typeof Symbol === 'function') {
1020 UID_HASH_KEY = Symbol(UID_HASH_KEY);
1021 }
1022 var STRING_HASH_CACHE_MIN_STRLEN = 16;
1023 var STRING_HASH_CACHE_MAX_SIZE = 255;
1024 var STRING_HASH_CACHE_SIZE = 0;
1025 var stringHashCache = {};
1026
1027 var ToKeyedSequence = /*@__PURE__*/(function (KeyedSeq) {
1028 function ToKeyedSequence(indexed, useKeys) {
1029 this._iter = indexed;
1030 this._useKeys = useKeys;
1031 this.size = indexed.size;
1032 }
1033
1034 if ( KeyedSeq ) ToKeyedSequence.__proto__ = KeyedSeq;
1035 ToKeyedSequence.prototype = Object.create( KeyedSeq && KeyedSeq.prototype );
1036 ToKeyedSequence.prototype.constructor = ToKeyedSequence;
1037
1038 ToKeyedSequence.prototype.get = function get (key, notSetValue) {
1039 return this._iter.get(key, notSetValue);
1040 };
1041
1042 ToKeyedSequence.prototype.has = function has (key) {
1043 return this._iter.has(key);
1044 };
1045
1046 ToKeyedSequence.prototype.valueSeq = function valueSeq () {
1047 return this._iter.valueSeq();
1048 };
1049
1050 ToKeyedSequence.prototype.reverse = function reverse () {
1051 var this$1$1 = this;
1052
1053 var reversedSequence = reverseFactory(this, true);
1054 if (!this._useKeys) {
1055 reversedSequence.valueSeq = function () { return this$1$1._iter.toSeq().reverse(); };
1056 }
1057 return reversedSequence;
1058 };
1059
1060 ToKeyedSequence.prototype.map = function map (mapper, context) {
1061 var this$1$1 = this;
1062
1063 var mappedSequence = mapFactory(this, mapper, context);
1064 if (!this._useKeys) {
1065 mappedSequence.valueSeq = function () { return this$1$1._iter.toSeq().map(mapper, context); };
1066 }
1067 return mappedSequence;
1068 };
1069
1070 ToKeyedSequence.prototype.__iterate = function __iterate (fn, reverse) {
1071 var this$1$1 = this;
1072
1073 return this._iter.__iterate(function (v, k) { return fn(v, k, this$1$1); }, reverse);
1074 };
1075
1076 ToKeyedSequence.prototype.__iterator = function __iterator (type, reverse) {
1077 return this._iter.__iterator(type, reverse);
1078 };
1079
1080 return ToKeyedSequence;
1081 }(KeyedSeq));
1082 ToKeyedSequence.prototype[IS_ORDERED_SYMBOL] = true;
1083
1084 var ToIndexedSequence = /*@__PURE__*/(function (IndexedSeq) {
1085 function ToIndexedSequence(iter) {
1086 this._iter = iter;
1087 this.size = iter.size;
1088 }
1089
1090 if ( IndexedSeq ) ToIndexedSequence.__proto__ = IndexedSeq;
1091 ToIndexedSequence.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
1092 ToIndexedSequence.prototype.constructor = ToIndexedSequence;
1093
1094 ToIndexedSequence.prototype.includes = function includes (value) {
1095 return this._iter.includes(value);
1096 };
1097
1098 ToIndexedSequence.prototype.__iterate = function __iterate (fn, reverse) {
1099 var this$1$1 = this;
1100
1101 var i = 0;
1102 // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
1103 reverse && ensureSize(this);
1104 return this._iter.__iterate(
1105 function (v) { return fn(v, reverse ? this$1$1.size - ++i : i++, this$1$1); },
1106 reverse
1107 );
1108 };
1109
1110 ToIndexedSequence.prototype.__iterator = function __iterator (type, reverse) {
1111 var this$1$1 = this;
1112
1113 var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
1114 var i = 0;
1115 // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
1116 reverse && ensureSize(this);
1117 return new Iterator(function () {
1118 var step = iterator.next();
1119 return step.done
1120 ? step
1121 : iteratorValue(
1122 type,
1123 reverse ? this$1$1.size - ++i : i++,
1124 step.value,
1125 step
1126 );
1127 });
1128 };
1129
1130 return ToIndexedSequence;
1131 }(IndexedSeq));
1132
1133 var ToSetSequence = /*@__PURE__*/(function (SetSeq) {
1134 function ToSetSequence(iter) {
1135 this._iter = iter;
1136 this.size = iter.size;
1137 }
1138
1139 if ( SetSeq ) ToSetSequence.__proto__ = SetSeq;
1140 ToSetSequence.prototype = Object.create( SetSeq && SetSeq.prototype );
1141 ToSetSequence.prototype.constructor = ToSetSequence;
1142
1143 ToSetSequence.prototype.has = function has (key) {
1144 return this._iter.includes(key);
1145 };
1146
1147 ToSetSequence.prototype.__iterate = function __iterate (fn, reverse) {
1148 var this$1$1 = this;
1149
1150 return this._iter.__iterate(function (v) { return fn(v, v, this$1$1); }, reverse);
1151 };
1152
1153 ToSetSequence.prototype.__iterator = function __iterator (type, reverse) {
1154 var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
1155 return new Iterator(function () {
1156 var step = iterator.next();
1157 return step.done
1158 ? step
1159 : iteratorValue(type, step.value, step.value, step);
1160 });
1161 };
1162
1163 return ToSetSequence;
1164 }(SetSeq));
1165
1166 var FromEntriesSequence = /*@__PURE__*/(function (KeyedSeq) {
1167 function FromEntriesSequence(entries) {
1168 this._iter = entries;
1169 this.size = entries.size;
1170 }
1171
1172 if ( KeyedSeq ) FromEntriesSequence.__proto__ = KeyedSeq;
1173 FromEntriesSequence.prototype = Object.create( KeyedSeq && KeyedSeq.prototype );
1174 FromEntriesSequence.prototype.constructor = FromEntriesSequence;
1175
1176 FromEntriesSequence.prototype.entrySeq = function entrySeq () {
1177 return this._iter.toSeq();
1178 };
1179
1180 FromEntriesSequence.prototype.__iterate = function __iterate (fn, reverse) {
1181 var this$1$1 = this;
1182
1183 return this._iter.__iterate(function (entry) {
1184 // Check if entry exists first so array access doesn't throw for holes
1185 // in the parent iteration.
1186 if (entry) {
1187 validateEntry(entry);
1188 var indexedCollection = isCollection(entry);
1189 return fn(
1190 indexedCollection ? entry.get(1) : entry[1],
1191 indexedCollection ? entry.get(0) : entry[0],
1192 this$1$1
1193 );
1194 }
1195 }, reverse);
1196 };
1197
1198 FromEntriesSequence.prototype.__iterator = function __iterator (type, reverse) {
1199 var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
1200 return new Iterator(function () {
1201 while (true) {
1202 var step = iterator.next();
1203 if (step.done) {
1204 return step;
1205 }
1206 var entry = step.value;
1207 // Check if entry exists first so array access doesn't throw for holes
1208 // in the parent iteration.
1209 if (entry) {
1210 validateEntry(entry);
1211 var indexedCollection = isCollection(entry);
1212 return iteratorValue(
1213 type,
1214 indexedCollection ? entry.get(0) : entry[0],
1215 indexedCollection ? entry.get(1) : entry[1],
1216 step
1217 );
1218 }
1219 }
1220 });
1221 };
1222
1223 return FromEntriesSequence;
1224 }(KeyedSeq));
1225
1226 ToIndexedSequence.prototype.cacheResult =
1227 ToKeyedSequence.prototype.cacheResult =
1228 ToSetSequence.prototype.cacheResult =
1229 FromEntriesSequence.prototype.cacheResult =
1230 cacheResultThrough;
1231
1232 function flipFactory(collection) {
1233 var flipSequence = makeSequence(collection);
1234 flipSequence._iter = collection;
1235 flipSequence.size = collection.size;
1236 flipSequence.flip = function () { return collection; };
1237 flipSequence.reverse = function () {
1238 var reversedSequence = collection.reverse.apply(this); // super.reverse()
1239 reversedSequence.flip = function () { return collection.reverse(); };
1240 return reversedSequence;
1241 };
1242 flipSequence.has = function (key) { return collection.includes(key); };
1243 flipSequence.includes = function (key) { return collection.has(key); };
1244 flipSequence.cacheResult = cacheResultThrough;
1245 flipSequence.__iterateUncached = function (fn, reverse) {
1246 var this$1$1 = this;
1247
1248 return collection.__iterate(function (v, k) { return fn(k, v, this$1$1) !== false; }, reverse);
1249 };
1250 flipSequence.__iteratorUncached = function (type, reverse) {
1251 if (type === ITERATE_ENTRIES) {
1252 var iterator = collection.__iterator(type, reverse);
1253 return new Iterator(function () {
1254 var step = iterator.next();
1255 if (!step.done) {
1256 var k = step.value[0];
1257 step.value[0] = step.value[1];
1258 step.value[1] = k;
1259 }
1260 return step;
1261 });
1262 }
1263 return collection.__iterator(
1264 type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES,
1265 reverse
1266 );
1267 };
1268 return flipSequence;
1269 }
1270
1271 function mapFactory(collection, mapper, context) {
1272 var mappedSequence = makeSequence(collection);
1273 mappedSequence.size = collection.size;
1274 mappedSequence.has = function (key) { return collection.has(key); };
1275 mappedSequence.get = function (key, notSetValue) {
1276 var v = collection.get(key, NOT_SET);
1277 return v === NOT_SET
1278 ? notSetValue
1279 : mapper.call(context, v, key, collection);
1280 };
1281 mappedSequence.__iterateUncached = function (fn, reverse) {
1282 var this$1$1 = this;
1283
1284 return collection.__iterate(
1285 function (v, k, c) { return fn(mapper.call(context, v, k, c), k, this$1$1) !== false; },
1286 reverse
1287 );
1288 };
1289 mappedSequence.__iteratorUncached = function (type, reverse) {
1290 var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
1291 return new Iterator(function () {
1292 var step = iterator.next();
1293 if (step.done) {
1294 return step;
1295 }
1296 var entry = step.value;
1297 var key = entry[0];
1298 return iteratorValue(
1299 type,
1300 key,
1301 mapper.call(context, entry[1], key, collection),
1302 step
1303 );
1304 });
1305 };
1306 return mappedSequence;
1307 }
1308
1309 function reverseFactory(collection, useKeys) {
1310 var reversedSequence = makeSequence(collection);
1311 reversedSequence._iter = collection;
1312 reversedSequence.size = collection.size;
1313 reversedSequence.reverse = function () { return collection; };
1314 if (collection.flip) {
1315 reversedSequence.flip = function () {
1316 var flipSequence = flipFactory(collection);
1317 flipSequence.reverse = function () { return collection.flip(); };
1318 return flipSequence;
1319 };
1320 }
1321 reversedSequence.get = function (key, notSetValue) { return collection.get(useKeys ? key : -1 - key, notSetValue); };
1322 reversedSequence.has = function (key) { return collection.has(useKeys ? key : -1 - key); };
1323 reversedSequence.includes = function (value) { return collection.includes(value); };
1324 reversedSequence.cacheResult = cacheResultThrough;
1325 reversedSequence.__iterate = function (fn, reverse) {
1326 var this$1$1 = this;
1327
1328 var i = 0;
1329 // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
1330 reverse && ensureSize(collection);
1331 return collection.__iterate(
1332 function (v, k) { return fn(v, useKeys ? k : reverse ? this$1$1.size - ++i : i++, this$1$1); },
1333 !reverse
1334 );
1335 };
1336 reversedSequence.__iterator = function (type, reverse) {
1337 var i = 0;
1338 // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
1339 reverse && ensureSize(collection);
1340 var iterator = collection.__iterator(ITERATE_ENTRIES, !reverse);
1341 return new Iterator(function () {
1342 var step = iterator.next();
1343 if (step.done) {
1344 return step;
1345 }
1346 var entry = step.value;
1347 return iteratorValue(
1348 type,
1349 // `__iterator` is an arrow function, so `this` is not the reversed
1350 // sequence here — read `reversedSequence.size` explicitly.
1351 useKeys ? entry[0] : reverse ? reversedSequence.size - ++i : i++,
1352 entry[1],
1353 step
1354 );
1355 });
1356 };
1357 return reversedSequence;
1358 }
1359
1360 function filterFactory(collection, predicate, context, useKeys) {
1361 var filterSequence = makeSequence(collection);
1362 if (useKeys) {
1363 filterSequence.has = function (key) {
1364 var v = collection.get(key, NOT_SET);
1365 return v !== NOT_SET && !!predicate.call(context, v, key, collection);
1366 };
1367 filterSequence.get = function (key, notSetValue) {
1368 var v = collection.get(key, NOT_SET);
1369 return v !== NOT_SET && predicate.call(context, v, key, collection)
1370 ? v
1371 : notSetValue;
1372 };
1373 }
1374 filterSequence.__iterateUncached = function (fn, reverse) {
1375 var this$1$1 = this;
1376
1377 var iterations = 0;
1378 collection.__iterate(function (v, k, c) {
1379 if (predicate.call(context, v, k, c)) {
1380 iterations++;
1381 return fn(v, useKeys ? k : iterations - 1, this$1$1);
1382 }
1383 }, reverse);
1384 return iterations;
1385 };
1386 filterSequence.__iteratorUncached = function (type, reverse) {
1387 var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
1388 var iterations = 0;
1389 return new Iterator(function () {
1390 while (true) {
1391 var step = iterator.next();
1392 if (step.done) {
1393 return step;
1394 }
1395 var entry = step.value;
1396 var key = entry[0];
1397 var value = entry[1];
1398 if (predicate.call(context, value, key, collection)) {
1399 return iteratorValue(type, useKeys ? key : iterations++, value, step);
1400 }
1401 }
1402 });
1403 };
1404 return filterSequence;
1405 }
1406
1407 function countByFactory(collection, grouper, context) {
1408 var groups = Map().asMutable();
1409 collection.__iterate(function (v, k) {
1410 groups.update(grouper.call(context, v, k, collection), 0, function (a) { return a + 1; });
1411 });
1412 return groups.asImmutable();
1413 }
1414
1415 function groupByFactory(collection, grouper, context) {
1416 var isKeyedIter = isKeyed(collection);
1417 var groups = (isOrdered(collection) ? OrderedMap() : Map()).asMutable();
1418 collection.__iterate(function (v, k) {
1419 groups.update(
1420 grouper.call(context, v, k, collection),
1421 function (a) { return ((a = a || []), a.push(isKeyedIter ? [k, v] : v), a); }
1422 );
1423 });
1424 var coerce = collectionClass(collection);
1425 return groups.map(function (arr) { return reify(collection, coerce(arr)); }).asImmutable();
1426 }
1427
1428 function partitionFactory(collection, predicate, context) {
1429 var isKeyedIter = isKeyed(collection);
1430 var groups = [[], []];
1431 collection.__iterate(function (v, k) {
1432 groups[predicate.call(context, v, k, collection) ? 1 : 0].push(
1433 isKeyedIter ? [k, v] : v
1434 );
1435 });
1436 var coerce = collectionClass(collection);
1437 return groups.map(function (arr) { return reify(collection, coerce(arr)); });
1438 }
1439
1440 function sliceFactory(collection, begin, end, useKeys) {
1441 var originalSize = collection.size;
1442
1443 if (wholeSlice(begin, end, originalSize)) {
1444 return collection;
1445 }
1446
1447 // begin or end can not be resolved if they were provided as negative numbers and
1448 // this collection's size is unknown. In that case, cache first so there is
1449 // a known size and these do not resolve to NaN.
1450 if (typeof originalSize === 'undefined' && (begin < 0 || end < 0)) {
1451 return sliceFactory(collection.toSeq().cacheResult(), begin, end, useKeys);
1452 }
1453
1454 var resolvedBegin = resolveBegin(begin, originalSize);
1455 var resolvedEnd = resolveEnd(end, originalSize);
1456
1457 // Note: resolvedEnd is undefined when the original sequence's length is
1458 // unknown and this slice did not supply an end and should contain all
1459 // elements after resolvedBegin.
1460 // In that case, resolvedSize will be NaN and sliceSize will remain undefined.
1461 var resolvedSize = resolvedEnd - resolvedBegin;
1462 var sliceSize;
1463 if (resolvedSize === resolvedSize) {
1464 sliceSize = resolvedSize < 0 ? 0 : resolvedSize;
1465 }
1466
1467 var sliceSeq = makeSequence(collection);
1468
1469 // If collection.size is undefined, the size of the realized sliceSeq is
1470 // unknown at this point unless the number of items to slice is 0
1471 sliceSeq.size =
1472 sliceSize === 0 ? sliceSize : (collection.size && sliceSize) || undefined;
1473
1474 if (!useKeys && isSeq(collection) && sliceSize >= 0) {
1475 sliceSeq.get = function (index, notSetValue) {
1476 index = wrapIndex(this, index);
1477 return index >= 0 && index < sliceSize
1478 ? collection.get(index + resolvedBegin, notSetValue)
1479 : notSetValue;
1480 };
1481 }
1482
1483 sliceSeq.__iterateUncached = function (fn, reverse) {
1484 var this$1$1 = this;
1485
1486 if (sliceSize === 0) {
1487 return 0;
1488 }
1489 if (reverse) {
1490 return this.cacheResult().__iterate(fn, reverse);
1491 }
1492 var skipped = 0;
1493 var isSkipping = true;
1494 var iterations = 0;
1495 collection.__iterate(function (v, k) {
1496 if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) {
1497 iterations++;
1498 return (
1499 fn(v, useKeys ? k : iterations - 1, this$1$1) !== false &&
1500 iterations !== sliceSize
1501 );
1502 }
1503 });
1504 return iterations;
1505 };
1506
1507 sliceSeq.__iteratorUncached = function (type, reverse) {
1508 if (sliceSize !== 0 && reverse) {
1509 return this.cacheResult().__iterator(type, reverse);
1510 }
1511 // Don't bother instantiating parent iterator if taking 0.
1512 if (sliceSize === 0) {
1513 return new Iterator(iteratorDone);
1514 }
1515 var iterator = collection.__iterator(type, reverse);
1516 var skipped = 0;
1517 var iterations = 0;
1518 return new Iterator(function () {
1519 while (skipped++ < resolvedBegin) {
1520 iterator.next();
1521 }
1522 if (++iterations > sliceSize) {
1523 return iteratorDone();
1524 }
1525 var step = iterator.next();
1526 if (useKeys || type === ITERATE_VALUES || step.done) {
1527 return step;
1528 }
1529 if (type === ITERATE_KEYS) {
1530 return iteratorValue(type, iterations - 1, undefined, step);
1531 }
1532 return iteratorValue(type, iterations - 1, step.value[1], step);
1533 });
1534 };
1535
1536 return sliceSeq;
1537 }
1538
1539 function takeWhileFactory(collection, predicate, context) {
1540 var takeSequence = makeSequence(collection);
1541 takeSequence.__iterateUncached = function (fn, reverse) {
1542 var this$1$1 = this;
1543
1544 if (reverse) {
1545 return this.cacheResult().__iterate(fn, reverse);
1546 }
1547 var iterations = 0;
1548 collection.__iterate(
1549 function (v, k, c) { return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$1$1); }
1550 );
1551 return iterations;
1552 };
1553 takeSequence.__iteratorUncached = function (type, reverse) {
1554 var this$1$1 = this;
1555
1556 if (reverse) {
1557 return this.cacheResult().__iterator(type, reverse);
1558 }
1559 var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
1560 var iterating = true;
1561 return new Iterator(function () {
1562 if (!iterating) {
1563 return iteratorDone();
1564 }
1565 var step = iterator.next();
1566 if (step.done) {
1567 return step;
1568 }
1569 var entry = step.value;
1570 var k = entry[0];
1571 var v = entry[1];
1572 if (!predicate.call(context, v, k, this$1$1)) {
1573 iterating = false;
1574 return iteratorDone();
1575 }
1576 return type === ITERATE_ENTRIES ? step : iteratorValue(type, k, v, step);
1577 });
1578 };
1579 return takeSequence;
1580 }
1581
1582 function skipWhileFactory(collection, predicate, context, useKeys) {
1583 var skipSequence = makeSequence(collection);
1584 skipSequence.__iterateUncached = function (fn, reverse) {
1585 var this$1$1 = this;
1586
1587 if (reverse) {
1588 return this.cacheResult().__iterate(fn, reverse);
1589 }
1590 var isSkipping = true;
1591 var iterations = 0;
1592 collection.__iterate(function (v, k, c) {
1593 if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) {
1594 iterations++;
1595 return fn(v, useKeys ? k : iterations - 1, this$1$1);
1596 }
1597 });
1598 return iterations;
1599 };
1600 skipSequence.__iteratorUncached = function (type, reverse) {
1601 var this$1$1 = this;
1602
1603 if (reverse) {
1604 return this.cacheResult().__iterator(type, reverse);
1605 }
1606 var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
1607 var skipping = true;
1608 var iterations = 0;
1609 return new Iterator(function () {
1610 var step;
1611 var k;
1612 var v;
1613 do {
1614 step = iterator.next();
1615 if (step.done) {
1616 if (useKeys || type === ITERATE_VALUES) {
1617 return step;
1618 }
1619 if (type === ITERATE_KEYS) {
1620 return iteratorValue(type, iterations++, undefined, step);
1621 }
1622 return iteratorValue(type, iterations++, step.value[1], step);
1623 }
1624 var entry = step.value;
1625 k = entry[0];
1626 v = entry[1];
1627 // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
1628 skipping && (skipping = predicate.call(context, v, k, this$1$1));
1629 } while (skipping);
1630 return type === ITERATE_ENTRIES ? step : iteratorValue(type, k, v, step);
1631 });
1632 };
1633 return skipSequence;
1634 }
1635
1636 var ConcatSeq = /*@__PURE__*/(function (Seq) {
1637 function ConcatSeq(iterables) {
1638 this._wrappedIterables = iterables.flatMap(function (iterable) {
1639 if (iterable._wrappedIterables) {
1640 return iterable._wrappedIterables;
1641 }
1642 return [iterable];
1643 });
1644 this.size = this._wrappedIterables.reduce(function (sum, iterable) {
1645 if (sum !== undefined) {
1646 var size = iterable.size;
1647 if (size !== undefined) {
1648 return sum + size;
1649 }
1650 }
1651 }, 0);
1652 this[IS_KEYED_SYMBOL] = this._wrappedIterables[0][IS_KEYED_SYMBOL];
1653 this[IS_INDEXED_SYMBOL] = this._wrappedIterables[0][IS_INDEXED_SYMBOL];
1654 this[IS_ORDERED_SYMBOL] = this._wrappedIterables[0][IS_ORDERED_SYMBOL];
1655 }
1656
1657 if ( Seq ) ConcatSeq.__proto__ = Seq;
1658 ConcatSeq.prototype = Object.create( Seq && Seq.prototype );
1659 ConcatSeq.prototype.constructor = ConcatSeq;
1660
1661 ConcatSeq.prototype.__iterateUncached = function __iterateUncached (fn, reverse) {
1662 if (this._wrappedIterables.length === 0) {
1663 return;
1664 }
1665
1666 if (reverse) {
1667 return this.cacheResult().__iterate(fn, reverse);
1668 }
1669
1670 var iterableIndex = 0;
1671 var useKeys = isKeyed(this);
1672 var iteratorType = useKeys ? ITERATE_ENTRIES : ITERATE_VALUES;
1673 var currentIterator = this._wrappedIterables[iterableIndex].__iterator(
1674 iteratorType,
1675 reverse
1676 );
1677
1678 var keepGoing = true;
1679 var index = 0;
1680 while (keepGoing) {
1681 var next = currentIterator.next();
1682 while (next.done) {
1683 iterableIndex++;
1684 if (iterableIndex === this._wrappedIterables.length) {
1685 return index;
1686 }
1687 currentIterator = this._wrappedIterables[iterableIndex].__iterator(
1688 iteratorType,
1689 reverse
1690 );
1691 next = currentIterator.next();
1692 }
1693 var fnResult = useKeys
1694 ? fn(next.value[1], next.value[0], this)
1695 : fn(next.value, index, this);
1696 keepGoing = fnResult !== false;
1697 index++;
1698 }
1699 return index;
1700 };
1701
1702 ConcatSeq.prototype.__iteratorUncached = function __iteratorUncached (type, reverse) {
1703 var this$1$1 = this;
1704
1705 if (this._wrappedIterables.length === 0) {
1706 return new Iterator(iteratorDone);
1707 }
1708
1709 if (reverse) {
1710 return this.cacheResult().__iterator(type, reverse);
1711 }
1712
1713 var iterableIndex = 0;
1714 var currentIterator = this._wrappedIterables[iterableIndex].__iterator(
1715 type,
1716 reverse
1717 );
1718 return new Iterator(function () {
1719 var next = currentIterator.next();
1720 while (next.done) {
1721 iterableIndex++;
1722 if (iterableIndex === this$1$1._wrappedIterables.length) {
1723 return next;
1724 }
1725 currentIterator = this$1$1._wrappedIterables[iterableIndex].__iterator(
1726 type,
1727 reverse
1728 );
1729 next = currentIterator.next();
1730 }
1731 return next;
1732 });
1733 };
1734
1735 return ConcatSeq;
1736 }(Seq));
1737
1738 function concatFactory(collection, values) {
1739 var isKeyedCollection = isKeyed(collection);
1740 var iters = [collection]
1741 .concat(values)
1742 .map(function (v) {
1743 if (!isCollection(v)) {
1744 v = isKeyedCollection
1745 ? keyedSeqFromValue(v)
1746 : indexedSeqFromValue(Array.isArray(v) ? v : [v]);
1747 } else if (isKeyedCollection) {
1748 v = KeyedCollection(v);
1749 }
1750 return v;
1751 })
1752 .filter(function (v) { return v.size !== 0; });
1753
1754 if (iters.length === 0) {
1755 return collection;
1756 }
1757
1758 if (iters.length === 1) {
1759 var singleton = iters[0];
1760 if (
1761 singleton === collection ||
1762 (isKeyedCollection && isKeyed(singleton)) ||
1763 (isIndexed(collection) && isIndexed(singleton))
1764 ) {
1765 return singleton;
1766 }
1767 }
1768
1769 return new ConcatSeq(iters);
1770 }
1771
1772 function flattenFactory(collection, depth, useKeys) {
1773 var flatSequence = makeSequence(collection);
1774 flatSequence.__iterateUncached = function (fn, reverse) {
1775 if (reverse) {
1776 return this.cacheResult().__iterate(fn, reverse);
1777 }
1778 var iterations = 0;
1779 var stopped = false;
1780 function flatDeep(iter, currentDepth) {
1781 iter.__iterate(function (v, k) {
1782 if ((!depth || currentDepth < depth) && isCollection(v)) {
1783 flatDeep(v, currentDepth + 1);
1784 } else {
1785 iterations++;
1786 if (fn(v, useKeys ? k : iterations - 1, flatSequence) === false) {
1787 stopped = true;
1788 }
1789 }
1790 return !stopped;
1791 }, reverse);
1792 }
1793 flatDeep(collection, 0);
1794 return iterations;
1795 };
1796 flatSequence.__iteratorUncached = function (type, reverse) {
1797 if (reverse) {
1798 return this.cacheResult().__iterator(type, reverse);
1799 }
1800 var iterator = collection.__iterator(type, reverse);
1801 var stack = [];
1802 var iterations = 0;
1803 return new Iterator(function () {
1804 while (iterator) {
1805 var step = iterator.next();
1806 if (step.done !== false) {
1807 iterator = stack.pop();
1808 continue;
1809 }
1810 var v = step.value;
1811 if (type === ITERATE_ENTRIES) {
1812 v = v[1];
1813 }
1814 if ((!depth || stack.length < depth) && isCollection(v)) {
1815 stack.push(iterator);
1816 iterator = v.__iterator(type, reverse);
1817 } else {
1818 return useKeys ? step : iteratorValue(type, iterations++, v, step);
1819 }
1820 }
1821 return iteratorDone();
1822 });
1823 };
1824 return flatSequence;
1825 }
1826
1827 function flatMapFactory(collection, mapper, context) {
1828 var coerce = collectionClass(collection);
1829 return collection
1830 .toSeq()
1831 .map(function (v, k) { return coerce(mapper.call(context, v, k, collection)); })
1832 .flatten(true);
1833 }
1834
1835 function interposeFactory(collection, separator) {
1836 var interposedSequence = makeSequence(collection);
1837 interposedSequence.size = collection.size && collection.size * 2 - 1;
1838 interposedSequence.__iterateUncached = function (fn, reverse) {
1839 var this$1$1 = this;
1840
1841 var iterations = 0;
1842 collection.__iterate(
1843 function (v) { return (!iterations || fn(separator, iterations++, this$1$1) !== false) &&
1844 fn(v, iterations++, this$1$1) !== false; },
1845 reverse
1846 );
1847 return iterations;
1848 };
1849 interposedSequence.__iteratorUncached = function (type, reverse) {
1850 var iterator = collection.__iterator(ITERATE_VALUES, reverse);
1851 var iterations = 0;
1852 var step;
1853 return new Iterator(function () {
1854 if (!step || iterations % 2) {
1855 step = iterator.next();
1856 if (step.done) {
1857 return step;
1858 }
1859 }
1860 return iterations % 2
1861 ? iteratorValue(type, iterations++, separator)
1862 : iteratorValue(type, iterations++, step.value, step);
1863 });
1864 };
1865 return interposedSequence;
1866 }
1867
1868 function sortFactory(collection, comparator, mapper) {
1869 if (!comparator) {
1870 comparator = defaultComparator;
1871 }
1872 var isKeyedCollection = isKeyed(collection);
1873 var index = 0;
1874 var entries = collection
1875 .toSeq()
1876 .map(function (v, k) { return [k, v, index++, mapper ? mapper(v, k, collection) : v]; })
1877 .valueSeq()
1878 .toArray();
1879 entries
1880 .sort(function (a, b) { return comparator(a[3], b[3]) || a[2] - b[2]; })
1881 .forEach(
1882 isKeyedCollection
1883 ? function (v, i) {
1884 entries[i].length = 2;
1885 }
1886 : function (v, i) {
1887 entries[i] = v[1];
1888 }
1889 );
1890 return isKeyedCollection
1891 ? KeyedSeq(entries)
1892 : isIndexed(collection)
1893 ? IndexedSeq(entries)
1894 : SetSeq(entries);
1895 }
1896
1897 function maxFactory(collection, comparator, mapper) {
1898 if (!comparator) {
1899 comparator = defaultComparator;
1900 }
1901 if (mapper) {
1902 var entry = collection
1903 .toSeq()
1904 .map(function (v, k) { return [v, mapper(v, k, collection)]; })
1905 .reduce(function (a, b) { return (maxCompare(comparator, a[1], b[1]) ? b : a); });
1906 return entry && entry[0];
1907 }
1908 return collection.reduce(function (a, b) { return (maxCompare(comparator, a, b) ? b : a); });
1909 }
1910
1911 function maxCompare(comparator, a, b) {
1912 var comp = comparator(b, a);
1913 // b is considered the new max if the comparator declares them equal, but
1914 // they are not equal and b is in fact a nullish value.
1915 return (
1916 (comp === 0 && b !== a && (b === undefined || b === null || b !== b)) ||
1917 comp > 0
1918 );
1919 }
1920
1921 function zipWithFactory(keyIter, zipper, iters, zipAll) {
1922 var zipSequence = makeSequence(keyIter);
1923 var sizes = new ArraySeq(iters).map(function (i) { return i.size; });
1924 zipSequence.size = zipAll ? sizes.max() : sizes.min();
1925 // Note: this a generic base implementation of __iterate in terms of
1926 // __iterator which may be more generically useful in the future.
1927 zipSequence.__iterate = function (fn, reverse) {
1928 /* generic:
1929 var iterator = this.__iterator(ITERATE_ENTRIES, reverse);
1930 var step;
1931 var iterations = 0;
1932 while (!(step = iterator.next()).done) {
1933 iterations++;
1934 if (fn(step.value[1], step.value[0], this) === false) {
1935 break;
1936 }
1937 }
1938 return iterations;
1939 */
1940 // indexed:
1941 var iterator = this.__iterator(ITERATE_VALUES, reverse);
1942 var step;
1943 var iterations = 0;
1944 while (!(step = iterator.next()).done) {
1945 if (fn(step.value, iterations++, this) === false) {
1946 break;
1947 }
1948 }
1949 return iterations;
1950 };
1951 zipSequence.__iteratorUncached = function (type, reverse) {
1952 var iterators = iters.map(
1953 function (i) { return ((i = Collection(i)), getIterator(reverse ? i.reverse() : i)); }
1954 );
1955 var iterations = 0;
1956 var isDone = false;
1957 return new Iterator(function () {
1958 var steps;
1959 if (!isDone) {
1960 steps = iterators.map(function (i) { return i.next(); });
1961 isDone = zipAll
1962 ? steps.every(function (s) { return s.done; })
1963 : steps.some(function (s) { return s.done; });
1964 }
1965 if (isDone) {
1966 return iteratorDone();
1967 }
1968 return iteratorValue(
1969 type,
1970 iterations++,
1971 zipper.apply(
1972 null,
1973 steps.map(function (s) { return s.value; })
1974 )
1975 );
1976 });
1977 };
1978 return zipSequence;
1979 }
1980
1981 // #pragma Helper Functions
1982
1983 function reify(iter, seq) {
1984 return iter === seq ? iter : isSeq(iter) ? seq : iter.constructor(seq);
1985 }
1986
1987 function validateEntry(entry) {
1988 if (entry !== Object(entry)) {
1989 throw new TypeError('Expected [K, V] tuple: ' + entry);
1990 }
1991 }
1992
1993 function collectionClass(collection) {
1994 return isKeyed(collection)
1995 ? KeyedCollection
1996 : isIndexed(collection)
1997 ? IndexedCollection
1998 : SetCollection;
1999 }
2000
2001 function makeSequence(collection) {
2002 return Object.create(
2003 (isKeyed(collection)
2004 ? KeyedSeq
2005 : isIndexed(collection)
2006 ? IndexedSeq
2007 : SetSeq
2008 ).prototype
2009 );
2010 }
2011
2012 function cacheResultThrough() {
2013 if (this._iter.cacheResult) {
2014 this._iter.cacheResult();
2015 this.size = this._iter.size;
2016 return this;
2017 }
2018 return Seq.prototype.cacheResult.call(this);
2019 }
2020
2021 function defaultComparator(a, b) {
2022 if (a === undefined && b === undefined) {
2023 return 0;
2024 }
2025
2026 if (a === undefined) {
2027 return 1;
2028 }
2029
2030 if (b === undefined) {
2031 return -1;
2032 }
2033
2034 return a > b ? 1 : a < b ? -1 : 0;
2035 }
2036
2037 /**
2038 * True if `maybeValue` is a JavaScript Object which has *both* `equals()`
2039 * and `hashCode()` methods.
2040 *
2041 * Any two instances of *value objects* can be compared for value equality with
2042 * `Immutable.is()` and can be used as keys in a `Map` or members in a `Set`.
2043 */
2044 function isValueObject(maybeValue) {
2045 return Boolean(maybeValue &&
2046 // @ts-expect-error: maybeValue is typed as `{}`
2047 typeof maybeValue.equals === 'function' &&
2048 // @ts-expect-error: maybeValue is typed as `{}`
2049 typeof maybeValue.hashCode === 'function');
2050 }
2051
2052 /**
2053 * An extension of the "same-value" algorithm as [described for use by ES6 Map
2054 * and Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality)
2055 *
2056 * NaN is considered the same as NaN, however -0 and 0 are considered the same
2057 * value, which is different from the algorithm described by
2058 * [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).
2059 *
2060 * This is extended further to allow Objects to describe the values they
2061 * represent, by way of `valueOf` or `equals` (and `hashCode`).
2062 *
2063 * Note: because of this extension, the key equality of Immutable.Map and the
2064 * value equality of Immutable.Set will differ from ES6 Map and Set.
2065 *
2066 * ### Defining custom values
2067 *
2068 * The easiest way to describe the value an object represents is by implementing
2069 * `valueOf`. For example, `Date` represents a value by returning a unix
2070 * timestamp for `valueOf`:
2071 *
2072 * var date1 = new Date(1234567890000); // Fri Feb 13 2009 ...
2073 * var date2 = new Date(1234567890000);
2074 * date1.valueOf(); // 1234567890000
2075 * assert( date1 !== date2 );
2076 * assert( Immutable.is( date1, date2 ) );
2077 *
2078 * Note: overriding `valueOf` may have other implications if you use this object
2079 * where JavaScript expects a primitive, such as implicit string coercion.
2080 *
2081 * For more complex types, especially collections, implementing `valueOf` may
2082 * not be performant. An alternative is to implement `equals` and `hashCode`.
2083 *
2084 * `equals` takes another object, presumably of similar type, and returns true
2085 * if it is equal. Equality is symmetrical, so the same result should be
2086 * returned if this and the argument are flipped.
2087 *
2088 * assert( a.equals(b) === b.equals(a) );
2089 *
2090 * `hashCode` returns a 32bit integer number representing the object which will
2091 * be used to determine how to store the value object in a Map or Set. You must
2092 * provide both or neither methods, one must not exist without the other.
2093 *
2094 * Also, an important relationship between these methods must be upheld: if two
2095 * values are equal, they *must* return the same hashCode. If the values are not
2096 * equal, they might have the same hashCode; this is called a hash collision,
2097 * and while undesirable for performance reasons, it is acceptable.
2098 *
2099 * if (a.equals(b)) {
2100 * assert( a.hashCode() === b.hashCode() );
2101 * }
2102 *
2103 * All Immutable collections are Value Objects: they implement `equals()`
2104 * and `hashCode()`.
2105 */
2106 function is(valueA, valueB) {
2107 if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
2108 return true;
2109 }
2110 if (!valueA || !valueB) {
2111 return false;
2112 }
2113 if (typeof valueA.valueOf === 'function' &&
2114 typeof valueB.valueOf === 'function') {
2115 valueA = valueA.valueOf();
2116 valueB = valueB.valueOf();
2117 if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) {
2118 return true;
2119 }
2120 if (!valueA || !valueB) {
2121 return false;
2122 }
2123 }
2124 return !!(isValueObject(valueA) &&
2125 isValueObject(valueB) &&
2126 valueA.equals(valueB));
2127 }
2128
2129 function update$1(collection, key, notSetValue, updater) {
2130 return updateIn(
2131 // @ts-expect-error Index signature for type string is missing in type V[]
2132 collection, [key], notSetValue, updater);
2133 }
2134
2135 function merge$1() {
2136 var iters = [], len = arguments.length;
2137 while ( len-- ) iters[ len ] = arguments[ len ];
2138
2139 return mergeIntoKeyedWith(this, iters);
2140 }
2141
2142 function mergeWith$1(merger) {
2143 var iters = [], len = arguments.length - 1;
2144 while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
2145
2146 if (typeof merger !== 'function') {
2147 throw new TypeError('Invalid merger function: ' + merger);
2148 }
2149 return mergeIntoKeyedWith(this, iters, merger);
2150 }
2151
2152 function mergeIntoKeyedWith(collection, collections, merger) {
2153 var iters = [];
2154 for (var ii = 0; ii < collections.length; ii++) {
2155 var collection$1 = KeyedCollection(collections[ii]);
2156 if (collection$1.size !== 0) {
2157 iters.push(collection$1);
2158 }
2159 }
2160 if (iters.length === 0) {
2161 return collection;
2162 }
2163 if (
2164 collection.toSeq().size === 0 &&
2165 !collection.__ownerID &&
2166 iters.length === 1
2167 ) {
2168 return isRecord(collection)
2169 ? collection // Record is empty and will not be updated: return the same instance
2170 : collection.constructor(iters[0]);
2171 }
2172 return collection.withMutations(function (collection) {
2173 var mergeIntoCollection = merger
2174 ? function (value, key) {
2175 update$1(collection, key, NOT_SET, function (oldVal) { return oldVal === NOT_SET ? value : merger(oldVal, value, key); }
2176 );
2177 }
2178 : function (value, key) {
2179 collection.set(key, value);
2180 };
2181 for (var ii = 0; ii < iters.length; ii++) {
2182 iters[ii].forEach(mergeIntoCollection);
2183 }
2184 });
2185 }
2186
2187 var toString = Object.prototype.toString;
2188 function isPlainObject(value) {
2189 // The base prototype's toString deals with Argument objects and native namespaces like Math
2190 if (!value ||
2191 typeof value !== 'object' ||
2192 toString.call(value) !== '[object Object]') {
2193 return false;
2194 }
2195 var proto = Object.getPrototypeOf(value);
2196 if (proto === null) {
2197 return true;
2198 }
2199 // Iteratively going up the prototype chain is needed for cross-realm environments (differing contexts, iframes, etc)
2200 var parentProto = proto;
2201 var nextProto = Object.getPrototypeOf(proto);
2202 while (nextProto !== null) {
2203 parentProto = nextProto;
2204 nextProto = Object.getPrototypeOf(parentProto);
2205 }
2206 return parentProto === proto;
2207 }
2208
2209 /**
2210 * Returns true if the value is a potentially-persistent data structure, either
2211 * provided by Immutable.js or a plain Array or Object.
2212 */
2213 function isDataStructure(value) {
2214 return (typeof value === 'object' &&
2215 (isImmutable(value) || Array.isArray(value) || isPlainObject(value)));
2216 }
2217
2218 function isProtoKey(key) {
2219 return (typeof key === 'string' && (key === '__proto__' || key === 'constructor'));
2220 }
2221
2222 // http://jsperf.com/copy-array-inline
2223 function arrCopy(arr, offset) {
2224 offset = offset || 0;
2225 var len = Math.max(0, arr.length - offset);
2226 var newArr = new Array(len);
2227 for (var ii = 0; ii < len; ii++) {
2228 // @ts-expect-error We may want to guard for undefined values with `if (arr[ii + offset] !== undefined`, but ths should not happen by design
2229 newArr[ii] = arr[ii + offset];
2230 }
2231 return newArr;
2232 }
2233
2234 function shallowCopy(from) {
2235 if (Array.isArray(from)) {
2236 return arrCopy(from);
2237 }
2238 var to = {};
2239 for (var key in from) {
2240 if (isProtoKey(key)) {
2241 continue;
2242 }
2243 if (hasOwnProperty.call(from, key)) {
2244 to[key] = from[key];
2245 }
2246 }
2247 return to;
2248 }
2249
2250 function merge(collection) {
2251 var sources = [], len = arguments.length - 1;
2252 while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
2253
2254 return mergeWithSources(collection, sources);
2255 }
2256
2257 function mergeWith(merger, collection) {
2258 var sources = [], len = arguments.length - 2;
2259 while ( len-- > 0 ) sources[ len ] = arguments[ len + 2 ];
2260
2261 return mergeWithSources(collection, sources, merger);
2262 }
2263
2264 function mergeDeep$1(collection) {
2265 var sources = [], len = arguments.length - 1;
2266 while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
2267
2268 return mergeDeepWithSources(collection, sources);
2269 }
2270
2271 function mergeDeepWith$1(merger, collection) {
2272 var sources = [], len = arguments.length - 2;
2273 while ( len-- > 0 ) sources[ len ] = arguments[ len + 2 ];
2274
2275 return mergeDeepWithSources(collection, sources, merger);
2276 }
2277
2278 function mergeDeepWithSources(collection, sources, merger) {
2279 return mergeWithSources(collection, sources, deepMergerWith(merger));
2280 }
2281
2282 function mergeWithSources(collection, sources, merger) {
2283 if (!isDataStructure(collection)) {
2284 throw new TypeError(
2285 'Cannot merge into non-data-structure value: ' + collection
2286 );
2287 }
2288 if (isImmutable(collection)) {
2289 return typeof merger === 'function' && collection.mergeWith
2290 ? collection.mergeWith.apply(collection, [ merger ].concat( sources ))
2291 : collection.merge
2292 ? collection.merge.apply(collection, sources)
2293 : collection.concat.apply(collection, sources);
2294 }
2295 var isArray = Array.isArray(collection);
2296 var merged = collection;
2297 var Collection = isArray ? IndexedCollection : KeyedCollection;
2298 var mergeItem = isArray
2299 ? function (value) {
2300 // Copy on write
2301 if (merged === collection) {
2302 merged = shallowCopy(merged);
2303 }
2304 merged.push(value);
2305 }
2306 : function (value, key) {
2307 if (isProtoKey(key)) {
2308 return;
2309 }
2310
2311 var hasVal = hasOwnProperty.call(merged, key);
2312 var nextVal =
2313 hasVal && merger ? merger(merged[key], value, key) : value;
2314 if (!hasVal || nextVal !== merged[key]) {
2315 // Copy on write
2316 if (merged === collection) {
2317 merged = shallowCopy(merged);
2318 }
2319 merged[key] = nextVal;
2320 }
2321 };
2322 for (var i = 0; i < sources.length; i++) {
2323 Collection(sources[i]).forEach(mergeItem);
2324 }
2325 return merged;
2326 }
2327
2328 function deepMergerWith(merger) {
2329 function deepMerger(oldValue, newValue, key) {
2330 return isDataStructure(oldValue) &&
2331 isDataStructure(newValue) &&
2332 areMergeable(oldValue, newValue)
2333 ? mergeWithSources(oldValue, [newValue], deepMerger)
2334 : merger
2335 ? merger(oldValue, newValue, key)
2336 : newValue;
2337 }
2338 return deepMerger;
2339 }
2340
2341 /**
2342 * It's unclear what the desired behavior is for merging two collections that
2343 * fall into separate categories between keyed, indexed, or set-like, so we only
2344 * consider them mergeable if they fall into the same category.
2345 */
2346 function areMergeable(oldDataStructure, newDataStructure) {
2347 var oldSeq = Seq(oldDataStructure);
2348 var newSeq = Seq(newDataStructure);
2349 // This logic assumes that a sequence can only fall into one of the three
2350 // categories mentioned above (since there's no `isSetLike()` method).
2351 return (
2352 isIndexed(oldSeq) === isIndexed(newSeq) &&
2353 isKeyed(oldSeq) === isKeyed(newSeq)
2354 );
2355 }
2356
2357 function mergeDeep() {
2358 var iters = [], len = arguments.length;
2359 while ( len-- ) iters[ len ] = arguments[ len ];
2360
2361 return mergeDeepWithSources(this, iters);
2362 }
2363
2364 function mergeDeepWith(merger) {
2365 var iters = [], len = arguments.length - 1;
2366 while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
2367
2368 return mergeDeepWithSources(this, iters, merger);
2369 }
2370
2371 function mergeDeepIn(keyPath) {
2372 var iters = [], len = arguments.length - 1;
2373 while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
2374
2375 return updateIn(this, keyPath, emptyMap(), function (m) { return mergeDeepWithSources(m, iters); }
2376 );
2377 }
2378
2379 function mergeIn(keyPath) {
2380 var iters = [], len = arguments.length - 1;
2381 while ( len-- > 0 ) iters[ len ] = arguments[ len + 1 ];
2382
2383 return updateIn(this, keyPath, emptyMap(), function (m) { return mergeWithSources(m, iters); });
2384 }
2385
2386 /**
2387 * Returns a copy of the collection with the value at the key path set to the
2388 * provided value.
2389 *
2390 * A functional alternative to `collection.setIn(keypath)` which will also
2391 * work with plain Objects and Arrays.
2392 */
2393 function setIn$1(collection, keyPath, value) {
2394 return updateIn(collection, keyPath, NOT_SET, function () { return value; });
2395 }
2396
2397 function setIn(keyPath, v) {
2398 return setIn$1(this, keyPath, v);
2399 }
2400
2401 function update(key, notSetValue, updater) {
2402 return arguments.length === 1
2403 ? key(this)
2404 : update$1(this, key, notSetValue, updater);
2405 }
2406
2407 function updateIn$1(keyPath, notSetValue, updater) {
2408 return updateIn(this, keyPath, notSetValue, updater);
2409 }
2410
2411 function wasAltered() {
2412 return this.__altered;
2413 }
2414
2415 function withMutations(fn) {
2416 var mutable = this.asMutable();
2417 fn(mutable);
2418 return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
2419 }
2420
2421 var IS_MAP_SYMBOL = '@@__IMMUTABLE_MAP__@@';
2422 /**
2423 * True if `maybeMap` is a Map.
2424 *
2425 * Also true for OrderedMaps.
2426 */
2427 function isMap(maybeMap) {
2428 return Boolean(maybeMap &&
2429 // @ts-expect-error: maybeMap is typed as `{}`, need to change in 6.0 to `maybeMap && typeof maybeMap === 'object' && IS_MAP_SYMBOL in maybeMap`
2430 maybeMap[IS_MAP_SYMBOL]);
2431 }
2432
2433 function invariant(condition, error) {
2434 if (!condition)
2435 { throw new Error(error); }
2436 }
2437
2438 function assertNotInfinite(size) {
2439 invariant(size !== Infinity, 'Cannot perform this action with an infinite size.');
2440 }
2441
2442 var Map = /*@__PURE__*/(function (KeyedCollection) {
2443 function Map(value) {
2444 // eslint-disable-next-line no-constructor-return
2445 return value === undefined || value === null
2446 ? emptyMap()
2447 : isMap(value) && !isOrdered(value)
2448 ? value
2449 : emptyMap().withMutations(function (map) {
2450 var iter = KeyedCollection(value);
2451 assertNotInfinite(iter.size);
2452 iter.forEach(function (v, k) { return map.set(k, v); });
2453 });
2454 }
2455
2456 if ( KeyedCollection ) Map.__proto__ = KeyedCollection;
2457 Map.prototype = Object.create( KeyedCollection && KeyedCollection.prototype );
2458 Map.prototype.constructor = Map;
2459
2460 Map.prototype.toString = function toString () {
2461 return this.__toString('Map {', '}');
2462 };
2463
2464 // @pragma Access
2465
2466 Map.prototype.get = function get (k, notSetValue) {
2467 return this._root
2468 ? this._root.get(0, undefined, k, notSetValue)
2469 : notSetValue;
2470 };
2471
2472 // @pragma Modification
2473
2474 Map.prototype.set = function set (k, v) {
2475 return updateMap(this, k, v);
2476 };
2477
2478 Map.prototype.remove = function remove (k) {
2479 return updateMap(this, k, NOT_SET);
2480 };
2481
2482 Map.prototype.deleteAll = function deleteAll (keys) {
2483 var collection = Collection(keys);
2484
2485 if (collection.size === 0) {
2486 return this;
2487 }
2488
2489 return this.withMutations(function (map) {
2490 collection.forEach(function (key) { return map.remove(key); });
2491 });
2492 };
2493
2494 Map.prototype.clear = function clear () {
2495 if (this.size === 0) {
2496 return this;
2497 }
2498 if (this.__ownerID) {
2499 this.size = 0;
2500 this._root = null;
2501 this.__hash = undefined;
2502 this.__altered = true;
2503 return this;
2504 }
2505 return emptyMap();
2506 };
2507
2508 // @pragma Composition
2509
2510 Map.prototype.sort = function sort (comparator) {
2511 // Late binding
2512 return OrderedMap(sortFactory(this, comparator));
2513 };
2514
2515 Map.prototype.sortBy = function sortBy (mapper, comparator) {
2516 // Late binding
2517 return OrderedMap(sortFactory(this, comparator, mapper));
2518 };
2519
2520 Map.prototype.map = function map (mapper, context) {
2521 var this$1$1 = this;
2522
2523 return this.withMutations(function (map) {
2524 map.forEach(function (value, key) {
2525 map.set(key, mapper.call(context, value, key, this$1$1));
2526 });
2527 });
2528 };
2529
2530 // @pragma Mutability
2531
2532 Map.prototype.__iterator = function __iterator (type, reverse) {
2533 return new MapIterator(this, type, reverse);
2534 };
2535
2536 Map.prototype.__iterate = function __iterate (fn, reverse) {
2537 var this$1$1 = this;
2538
2539 var iterations = 0;
2540 // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
2541 this._root &&
2542 this._root.iterate(function (entry) {
2543 iterations++;
2544 return fn(entry[1], entry[0], this$1$1);
2545 }, reverse);
2546 return iterations;
2547 };
2548
2549 Map.prototype.__ensureOwner = function __ensureOwner (ownerID) {
2550 if (ownerID === this.__ownerID) {
2551 return this;
2552 }
2553 if (!ownerID) {
2554 if (this.size === 0) {
2555 return emptyMap();
2556 }
2557 this.__ownerID = ownerID;
2558 this.__altered = false;
2559 return this;
2560 }
2561 return makeMap(this.size, this._root, ownerID, this.__hash);
2562 };
2563
2564 return Map;
2565 }(KeyedCollection));
2566
2567 Map.isMap = isMap;
2568
2569 var MapPrototype = Map.prototype;
2570 MapPrototype[IS_MAP_SYMBOL] = true;
2571 MapPrototype[DELETE] = MapPrototype.remove;
2572 MapPrototype.removeAll = MapPrototype.deleteAll;
2573 MapPrototype.setIn = setIn;
2574 MapPrototype.removeIn = MapPrototype.deleteIn = deleteIn;
2575 MapPrototype.update = update;
2576 MapPrototype.updateIn = updateIn$1;
2577 MapPrototype.merge = MapPrototype.concat = merge$1;
2578 MapPrototype.mergeWith = mergeWith$1;
2579 MapPrototype.mergeDeep = mergeDeep;
2580 MapPrototype.mergeDeepWith = mergeDeepWith;
2581 MapPrototype.mergeIn = mergeIn;
2582 MapPrototype.mergeDeepIn = mergeDeepIn;
2583 MapPrototype.withMutations = withMutations;
2584 MapPrototype.wasAltered = wasAltered;
2585 MapPrototype.asImmutable = asImmutable;
2586 MapPrototype['@@transducer/init'] = MapPrototype.asMutable = asMutable;
2587 MapPrototype['@@transducer/step'] = function (result, arr) {
2588 return result.set(arr[0], arr[1]);
2589 };
2590 MapPrototype['@@transducer/result'] = function (obj) {
2591 return obj.asImmutable();
2592 };
2593
2594 // #pragma Trie Nodes
2595
2596 var ArrayMapNode = function ArrayMapNode(ownerID, entries) {
2597 this.ownerID = ownerID;
2598 this.entries = entries;
2599 };
2600
2601 ArrayMapNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
2602 var entries = this.entries;
2603 for (var ii = 0, len = entries.length; ii < len; ii++) {
2604 if (is(key, entries[ii][0])) {
2605 return entries[ii][1];
2606 }
2607 }
2608 return notSetValue;
2609 };
2610
2611 ArrayMapNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
2612 var removed = value === NOT_SET;
2613
2614 var entries = this.entries;
2615 var idx = 0;
2616 var len = entries.length;
2617 for (; idx < len; idx++) {
2618 if (is(key, entries[idx][0])) {
2619 break;
2620 }
2621 }
2622 var exists = idx < len;
2623
2624 if (exists ? entries[idx][1] === value : removed) {
2625 return this;
2626 }
2627
2628 SetRef(didAlter);
2629 // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
2630 (removed || !exists) && SetRef(didChangeSize);
2631
2632 if (removed && entries.length === 1) {
2633 return; // undefined
2634 }
2635
2636 if (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) {
2637 return createNodes(ownerID, entries, key, value);
2638 }
2639
2640 var isEditable = ownerID && ownerID === this.ownerID;
2641 var newEntries = isEditable ? entries : arrCopy(entries);
2642
2643 if (exists) {
2644 if (removed) {
2645 // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
2646 idx === len - 1
2647 ? newEntries.pop()
2648 : (newEntries[idx] = newEntries.pop());
2649 } else {
2650 newEntries[idx] = [key, value];
2651 }
2652 } else {
2653 newEntries.push([key, value]);
2654 }
2655
2656 if (isEditable) {
2657 this.entries = newEntries;
2658 return this;
2659 }
2660
2661 return new ArrayMapNode(ownerID, newEntries);
2662 };
2663
2664 var BitmapIndexedNode = function BitmapIndexedNode(ownerID, bitmap, nodes) {
2665 this.ownerID = ownerID;
2666 this.bitmap = bitmap;
2667 this.nodes = nodes;
2668 };
2669
2670 BitmapIndexedNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
2671 if (keyHash === undefined) {
2672 keyHash = hash(key);
2673 }
2674 var bit = 1 << ((shift === 0 ? keyHash : keyHash >>> shift) & MASK);
2675 var bitmap = this.bitmap;
2676 return (bitmap & bit) === 0
2677 ? notSetValue
2678 : this.nodes[popCount(bitmap & (bit - 1))].get(
2679 shift + SHIFT,
2680 keyHash,
2681 key,
2682 notSetValue
2683 );
2684 };
2685
2686 BitmapIndexedNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
2687 if (keyHash === undefined) {
2688 keyHash = hash(key);
2689 }
2690 var keyHashFrag = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
2691 var bit = 1 << keyHashFrag;
2692 var bitmap = this.bitmap;
2693 var exists = (bitmap & bit) !== 0;
2694
2695 if (!exists && value === NOT_SET) {
2696 return this;
2697 }
2698
2699 var idx = popCount(bitmap & (bit - 1));
2700 var nodes = this.nodes;
2701 var node = exists ? nodes[idx] : undefined;
2702 var newNode = updateNode(
2703 node,
2704 ownerID,
2705 shift + SHIFT,
2706 keyHash,
2707 key,
2708 value,
2709 didChangeSize,
2710 didAlter
2711 );
2712
2713 if (newNode === node) {
2714 return this;
2715 }
2716
2717 if (!exists && newNode && nodes.length >= MAX_BITMAP_INDEXED_SIZE) {
2718 return expandNodes(ownerID, nodes, bitmap, keyHashFrag, newNode);
2719 }
2720
2721 if (
2722 exists &&
2723 !newNode &&
2724 nodes.length === 2 &&
2725 isLeafNode(nodes[idx ^ 1])
2726 ) {
2727 return nodes[idx ^ 1];
2728 }
2729
2730 if (exists && newNode && nodes.length === 1 && isLeafNode(newNode)) {
2731 return newNode;
2732 }
2733
2734 var isEditable = ownerID && ownerID === this.ownerID;
2735 var newBitmap = exists ? (newNode ? bitmap : bitmap ^ bit) : bitmap | bit;
2736 var newNodes = exists
2737 ? newNode
2738 ? setAt(nodes, idx, newNode, isEditable)
2739 : spliceOut(nodes, idx, isEditable)
2740 : spliceIn(nodes, idx, newNode, isEditable);
2741
2742 if (isEditable) {
2743 this.bitmap = newBitmap;
2744 this.nodes = newNodes;
2745 return this;
2746 }
2747
2748 return new BitmapIndexedNode(ownerID, newBitmap, newNodes);
2749 };
2750
2751 var HashArrayMapNode = function HashArrayMapNode(ownerID, count, nodes) {
2752 this.ownerID = ownerID;
2753 this.count = count;
2754 this.nodes = nodes;
2755 };
2756
2757 HashArrayMapNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
2758 if (keyHash === undefined) {
2759 keyHash = hash(key);
2760 }
2761 var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
2762 var node = this.nodes[idx];
2763 return node
2764 ? node.get(shift + SHIFT, keyHash, key, notSetValue)
2765 : notSetValue;
2766 };
2767
2768 HashArrayMapNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
2769 if (keyHash === undefined) {
2770 keyHash = hash(key);
2771 }
2772 var idx = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
2773 var removed = value === NOT_SET;
2774 var nodes = this.nodes;
2775 var node = nodes[idx];
2776
2777 if (removed && !node) {
2778 return this;
2779 }
2780
2781 var newNode = updateNode(
2782 node,
2783 ownerID,
2784 shift + SHIFT,
2785 keyHash,
2786 key,
2787 value,
2788 didChangeSize,
2789 didAlter
2790 );
2791 if (newNode === node) {
2792 return this;
2793 }
2794
2795 var newCount = this.count;
2796 if (!node) {
2797 newCount++;
2798 } else if (!newNode) {
2799 newCount--;
2800 if (newCount < MIN_HASH_ARRAY_MAP_SIZE) {
2801 return packNodes(ownerID, nodes, newCount, idx);
2802 }
2803 }
2804
2805 var isEditable = ownerID && ownerID === this.ownerID;
2806 var newNodes = setAt(nodes, idx, newNode, isEditable);
2807
2808 if (isEditable) {
2809 this.count = newCount;
2810 this.nodes = newNodes;
2811 return this;
2812 }
2813
2814 return new HashArrayMapNode(ownerID, newCount, newNodes);
2815 };
2816
2817 /**
2818 * Trie leaf gathering entries whose keys all share the same 32-bit `hash()`.
2819 * The trie routes by hash, so colliding keys cannot be separated and land here
2820 * in a flat `entries` array, disambiguated by `is()`.
2821 *
2822 * To guard against hash-flooding DoS (CWE-407), large buckets build a secondary
2823 * index keyed by a per-process seeded hash (`hashCollisionKey`). `is()` still
2824 * decides equality, so the index can only ever narrow candidates, never lose a key.
2825 */
2826 var HashCollisionNode = function HashCollisionNode(ownerID, keyHash, entries) {
2827 this.ownerID = ownerID;
2828 this.keyHash = keyHash;
2829 this.entries = entries;
2830 // Lazy `{ [secondaryHash]: number[] }`, built only past
2831 // MIN_HASH_COLLISION_INDEX_SIZE so small buckets keep their linear path.
2832 this._index = undefined;
2833 };
2834
2835 // Returns the position of `key` in `this.entries`, or -1. Uses the secondary
2836 // index when present; builds it only when `buildIndex` is true (reads and
2837 // transient inserts, where the node is reused so the O(n) build amortizes).
2838 // Persistent inserts already pay an O(n) copy, so a throwaway index is skipped.
2839 HashCollisionNode.prototype._positionOf = function _positionOf (key, buildIndex) {
2840 var entries = this.entries;
2841 var index = this._index;
2842 if (
2843 index === undefined &&
2844 buildIndex &&
2845 entries.length >= MIN_HASH_COLLISION_INDEX_SIZE
2846 ) {
2847 index = this._buildIndex();
2848 }
2849 if (index !== undefined) {
2850 var positions = index[hashCollisionKey(key)];
2851 if (positions !== undefined) {
2852 for (var jj = 0; jj < positions.length; jj++) {
2853 var ii = positions[jj];
2854 if (is(key, entries[ii][0])) {
2855 return ii;
2856 }
2857 }
2858 }
2859 return -1;
2860 }
2861 for (var ii$1 = 0, len = entries.length; ii$1 < len; ii$1++) {
2862 if (is(key, entries[ii$1][0])) {
2863 return ii$1;
2864 }
2865 }
2866 return -1;
2867 };
2868
2869 // Builds and memoizes the secondary index. A plain object, not `Map` — which
2870 // in this module resolves to the *Immutable* Map, not the native one.
2871 HashCollisionNode.prototype._buildIndex = function _buildIndex () {
2872 var index = Object.create(null);
2873 var entries = this.entries;
2874 for (var ii = 0, len = entries.length; ii < len; ii++) {
2875 var secondaryHash = hashCollisionKey(entries[ii][0]);
2876 var positions = index[secondaryHash];
2877 if (positions !== undefined) {
2878 positions.push(ii);
2879 } else {
2880 index[secondaryHash] = [ii];
2881 }
2882 }
2883 this._index = index;
2884 return index;
2885 };
2886
2887 HashCollisionNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
2888 var idx = this._positionOf(key, true);
2889 return idx === -1 ? notSetValue : this.entries[idx][1];
2890 };
2891
2892 HashCollisionNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
2893 if (keyHash === undefined) {
2894 keyHash = hash(key);
2895 }
2896
2897 var removed = value === NOT_SET;
2898
2899 if (keyHash !== this.keyHash) {
2900 if (removed) {
2901 return this;
2902 }
2903 SetRef(didAlter);
2904 SetRef(didChangeSize);
2905 return mergeIntoNode(this, ownerID, shift, keyHash, [key, value]);
2906 }
2907
2908 var entries = this.entries;
2909 var len = entries.length;
2910 var isEditable = ownerID && ownerID === this.ownerID;
2911 var foundIdx = this._positionOf(key, isEditable);
2912 var idx = foundIdx === -1 ? len : foundIdx;
2913 var exists = foundIdx !== -1;
2914
2915 if (exists ? entries[idx][1] === value : removed) {
2916 return this;
2917 }
2918
2919 SetRef(didAlter);
2920 // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
2921 (removed || !exists) && SetRef(didChangeSize);
2922
2923 if (removed && len === 2) {
2924 return new ValueNode(ownerID, this.keyHash, entries[idx ^ 1]);
2925 }
2926
2927 var newEntries = isEditable ? entries : arrCopy(entries);
2928
2929 if (exists) {
2930 if (removed) {
2931 // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
2932 idx === len - 1
2933 ? newEntries.pop()
2934 : (newEntries[idx] = newEntries.pop());
2935 // The swap-pop reshuffles positions; drop the stale index (rebuilt lazily).
2936 if (isEditable) {
2937 this._index = undefined;
2938 }
2939 } else {
2940 // Same key, same position: the index stays valid.
2941 newEntries[idx] = [key, value];
2942 }
2943 } else {
2944 newEntries.push([key, value]);
2945 // Keep the index in sync on the transient insert path. Persistent inserts
2946 // return a fresh node below whose index rebuilds lazily, so skip them.
2947 if (isEditable && this._index !== undefined) {
2948 var secondaryHash = hashCollisionKey(key);
2949 var positions = this._index[secondaryHash];
2950 if (positions !== undefined) {
2951 positions.push(len);
2952 } else {
2953 this._index[secondaryHash] = [len];
2954 }
2955 }
2956 }
2957
2958 if (isEditable) {
2959 this.entries = newEntries;
2960 return this;
2961 }
2962
2963 return new HashCollisionNode(ownerID, this.keyHash, newEntries);
2964 };
2965
2966 var ValueNode = function ValueNode(ownerID, keyHash, entry) {
2967 this.ownerID = ownerID;
2968 this.keyHash = keyHash;
2969 this.entry = entry;
2970 };
2971
2972 ValueNode.prototype.get = function get (shift, keyHash, key, notSetValue) {
2973 return is(key, this.entry[0]) ? this.entry[1] : notSetValue;
2974 };
2975
2976 ValueNode.prototype.update = function update (ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
2977 var removed = value === NOT_SET;
2978 var keyMatch = is(key, this.entry[0]);
2979 if (keyMatch ? value === this.entry[1] : removed) {
2980 return this;
2981 }
2982
2983 SetRef(didAlter);
2984
2985 if (removed) {
2986 SetRef(didChangeSize);
2987 return; // undefined
2988 }
2989
2990 if (keyMatch) {
2991 if (ownerID && ownerID === this.ownerID) {
2992 this.entry[1] = value;
2993 return this;
2994 }
2995 return new ValueNode(ownerID, this.keyHash, [key, value]);
2996 }
2997
2998 SetRef(didChangeSize);
2999 return mergeIntoNode(this, ownerID, shift, hash(key), [key, value]);
3000 };
3001
3002 // #pragma Iterators
3003
3004 ArrayMapNode.prototype.iterate = HashCollisionNode.prototype.iterate =
3005 function (fn, reverse) {
3006 var entries = this.entries;
3007 for (var ii = 0, maxIndex = entries.length - 1; ii <= maxIndex; ii++) {
3008 if (fn(entries[reverse ? maxIndex - ii : ii]) === false) {
3009 return false;
3010 }
3011 }
3012 };
3013
3014 BitmapIndexedNode.prototype.iterate = HashArrayMapNode.prototype.iterate =
3015 function (fn, reverse) {
3016 var nodes = this.nodes;
3017 for (var ii = 0, maxIndex = nodes.length - 1; ii <= maxIndex; ii++) {
3018 var node = nodes[reverse ? maxIndex - ii : ii];
3019 if (node && node.iterate(fn, reverse) === false) {
3020 return false;
3021 }
3022 }
3023 };
3024
3025 // eslint-disable-next-line @typescript-eslint/no-unused-vars
3026 ValueNode.prototype.iterate = function (fn, reverse) {
3027 return fn(this.entry);
3028 };
3029
3030 var MapIterator = /*@__PURE__*/(function (Iterator) {
3031 function MapIterator(map, type, reverse) {
3032 this._type = type;
3033 this._reverse = reverse;
3034 this._stack = map._root && mapIteratorFrame(map._root);
3035 }
3036
3037 if ( Iterator ) MapIterator.__proto__ = Iterator;
3038 MapIterator.prototype = Object.create( Iterator && Iterator.prototype );
3039 MapIterator.prototype.constructor = MapIterator;
3040
3041 MapIterator.prototype.next = function next () {
3042 var type = this._type;
3043 var stack = this._stack;
3044 while (stack) {
3045 var node = stack.node;
3046 var index = stack.index++;
3047 var maxIndex = (void 0);
3048 if (node.entry) {
3049 if (index === 0) {
3050 return mapIteratorValue(type, node.entry);
3051 }
3052 } else if (node.entries) {
3053 maxIndex = node.entries.length - 1;
3054 if (index <= maxIndex) {
3055 return mapIteratorValue(
3056 type,
3057 node.entries[this._reverse ? maxIndex - index : index]
3058 );
3059 }
3060 } else {
3061 maxIndex = node.nodes.length - 1;
3062 if (index <= maxIndex) {
3063 var subNode = node.nodes[this._reverse ? maxIndex - index : index];
3064 if (subNode) {
3065 if (subNode.entry) {
3066 return mapIteratorValue(type, subNode.entry);
3067 }
3068 stack = this._stack = mapIteratorFrame(subNode, stack);
3069 }
3070 continue;
3071 }
3072 }
3073 stack = this._stack = this._stack.__prev;
3074 }
3075 return iteratorDone();
3076 };
3077
3078 return MapIterator;
3079 }(Iterator));
3080
3081 function mapIteratorValue(type, entry) {
3082 return iteratorValue(type, entry[0], entry[1]);
3083 }
3084
3085 function mapIteratorFrame(node, prev) {
3086 return {
3087 node: node,
3088 index: 0,
3089 __prev: prev,
3090 };
3091 }
3092
3093 function makeMap(size, root, ownerID, hash) {
3094 var map = Object.create(MapPrototype);
3095 map.size = size;
3096 map._root = root;
3097 map.__ownerID = ownerID;
3098 map.__hash = hash;
3099 map.__altered = false;
3100 return map;
3101 }
3102
3103 var EMPTY_MAP;
3104 function emptyMap() {
3105 return EMPTY_MAP || (EMPTY_MAP = makeMap(0));
3106 }
3107
3108 function updateMap(map, k, v) {
3109 var newRoot;
3110 var newSize;
3111 if (!map._root) {
3112 if (v === NOT_SET) {
3113 return map;
3114 }
3115 newSize = 1;
3116 newRoot = new ArrayMapNode(map.__ownerID, [[k, v]]);
3117 } else {
3118 var didChangeSize = MakeRef();
3119 var didAlter = MakeRef();
3120 newRoot = updateNode(
3121 map._root,
3122 map.__ownerID,
3123 0,
3124 undefined,
3125 k,
3126 v,
3127 didChangeSize,
3128 didAlter
3129 );
3130 if (!didAlter.value) {
3131 return map;
3132 }
3133 newSize = map.size + (didChangeSize.value ? (v === NOT_SET ? -1 : 1) : 0);
3134 }
3135 if (map.__ownerID) {
3136 map.size = newSize;
3137 map._root = newRoot;
3138 map.__hash = undefined;
3139 map.__altered = true;
3140 return map;
3141 }
3142 return newRoot ? makeMap(newSize, newRoot) : emptyMap();
3143 }
3144
3145 function updateNode(
3146 node,
3147 ownerID,
3148 shift,
3149 keyHash,
3150 key,
3151 value,
3152 didChangeSize,
3153 didAlter
3154 ) {
3155 if (!node) {
3156 if (value === NOT_SET) {
3157 return node;
3158 }
3159 SetRef(didAlter);
3160 SetRef(didChangeSize);
3161 return new ValueNode(ownerID, keyHash, [key, value]);
3162 }
3163 return node.update(
3164 ownerID,
3165 shift,
3166 keyHash,
3167 key,
3168 value,
3169 didChangeSize,
3170 didAlter
3171 );
3172 }
3173
3174 function isLeafNode(node) {
3175 return (
3176 node.constructor === ValueNode || node.constructor === HashCollisionNode
3177 );
3178 }
3179
3180 function mergeIntoNode(node, ownerID, shift, keyHash, entry) {
3181 if (node.keyHash === keyHash) {
3182 return new HashCollisionNode(ownerID, keyHash, [node.entry, entry]);
3183 }
3184
3185 var idx1 = (shift === 0 ? node.keyHash : node.keyHash >>> shift) & MASK;
3186 var idx2 = (shift === 0 ? keyHash : keyHash >>> shift) & MASK;
3187
3188 var newNode;
3189 var nodes =
3190 idx1 === idx2
3191 ? [mergeIntoNode(node, ownerID, shift + SHIFT, keyHash, entry)]
3192 : ((newNode = new ValueNode(ownerID, keyHash, entry)),
3193 idx1 < idx2 ? [node, newNode] : [newNode, node]);
3194
3195 return new BitmapIndexedNode(ownerID, (1 << idx1) | (1 << idx2), nodes);
3196 }
3197
3198 function createNodes(ownerID, entries, key, value) {
3199 if (!ownerID) {
3200 ownerID = new OwnerID();
3201 }
3202 var node = new ValueNode(ownerID, hash(key), [key, value]);
3203 for (var ii = 0; ii < entries.length; ii++) {
3204 var entry = entries[ii];
3205 node = node.update(ownerID, 0, undefined, entry[0], entry[1]);
3206 }
3207 return node;
3208 }
3209
3210 function packNodes(ownerID, nodes, count, excluding) {
3211 var bitmap = 0;
3212 var packedII = 0;
3213 var packedNodes = new Array(count);
3214 for (var ii = 0, bit = 1, len = nodes.length; ii < len; ii++, bit <<= 1) {
3215 var node = nodes[ii];
3216 if (node !== undefined && ii !== excluding) {
3217 bitmap |= bit;
3218 packedNodes[packedII++] = node;
3219 }
3220 }
3221 return new BitmapIndexedNode(ownerID, bitmap, packedNodes);
3222 }
3223
3224 function expandNodes(ownerID, nodes, bitmap, including, node) {
3225 var count = 0;
3226 var expandedNodes = new Array(SIZE);
3227 for (var ii = 0; bitmap !== 0; ii++, bitmap >>>= 1) {
3228 expandedNodes[ii] = bitmap & 1 ? nodes[count++] : undefined;
3229 }
3230 expandedNodes[including] = node;
3231 return new HashArrayMapNode(ownerID, count + 1, expandedNodes);
3232 }
3233
3234 function popCount(x) {
3235 x -= (x >> 1) & 0x55555555;
3236 x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
3237 x = (x + (x >> 4)) & 0x0f0f0f0f;
3238 x += x >> 8;
3239 x += x >> 16;
3240 return x & 0x7f;
3241 }
3242
3243 function setAt(array, idx, val, canEdit) {
3244 var newArray = canEdit ? array : arrCopy(array);
3245 newArray[idx] = val;
3246 return newArray;
3247 }
3248
3249 function spliceIn(array, idx, val, canEdit) {
3250 var newLen = array.length + 1;
3251 if (canEdit && idx + 1 === newLen) {
3252 array[idx] = val;
3253 return array;
3254 }
3255 var newArray = new Array(newLen);
3256 var after = 0;
3257 for (var ii = 0; ii < newLen; ii++) {
3258 if (ii === idx) {
3259 newArray[ii] = val;
3260 after = -1;
3261 } else {
3262 newArray[ii] = array[ii + after];
3263 }
3264 }
3265 return newArray;
3266 }
3267
3268 function spliceOut(array, idx, canEdit) {
3269 var newLen = array.length - 1;
3270 if (canEdit && idx === newLen) {
3271 array.pop();
3272 return array;
3273 }
3274 var newArray = new Array(newLen);
3275 var after = 0;
3276 for (var ii = 0; ii < newLen; ii++) {
3277 if (ii === idx) {
3278 after = 1;
3279 }
3280 newArray[ii] = array[ii + after];
3281 }
3282 return newArray;
3283 }
3284
3285 var MAX_ARRAY_MAP_SIZE = SIZE / 4;
3286 var MAX_BITMAP_INDEXED_SIZE = SIZE / 2;
3287 var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
3288
3289 // Above this many colliding entries, a `HashCollisionNode` builds a seeded
3290 // secondary index instead of scanning linearly. Kept small so the rare,
3291 // naturally-occurring collision buckets stay overhead-free, while adversarial
3292 // hash-flooding (thousands of keys sharing one hash) degrades gracefully.
3293 var MIN_HASH_COLLISION_INDEX_SIZE = 16;
3294
3295 function coerceKeyPath(keyPath) {
3296 if (isArrayLike(keyPath) && typeof keyPath !== 'string') {
3297 return keyPath;
3298 }
3299 if (isOrdered(keyPath)) {
3300 return keyPath.toArray();
3301 }
3302 throw new TypeError('Invalid keyPath: expected Ordered Collection or Array: ' + keyPath);
3303 }
3304
3305 /**
3306 * Converts a value to a string, adding quotes if a string was provided.
3307 */
3308 function quoteString(value) {
3309 try {
3310 return typeof value === 'string' ? JSON.stringify(value) : String(value);
3311 // eslint-disable-next-line @typescript-eslint/no-unused-vars
3312 }
3313 catch (_ignoreError) {
3314 return JSON.stringify(value);
3315 }
3316 }
3317
3318 /**
3319 * Returns true if the key is defined in the provided collection.
3320 *
3321 * A functional alternative to `collection.has(key)` which will also work with
3322 * plain Objects and Arrays as an alternative for
3323 * `collection.hasOwnProperty(key)`.
3324 */
3325 function has(collection, key) {
3326 return isImmutable(collection)
3327 ? // @ts-expect-error key might be a number or symbol, which is not handled be Record key type
3328 collection.has(key)
3329 : // @ts-expect-error key might be anything else than PropertyKey, and will return false in that case but runtime is OK
3330 isDataStructure(collection) && hasOwnProperty.call(collection, key);
3331 }
3332
3333 function get(collection, key, notSetValue) {
3334 return isImmutable(collection)
3335 ? collection.get(key, notSetValue)
3336 : !has(collection, key)
3337 ? notSetValue
3338 : // @ts-expect-error weird "get" here,
3339 typeof collection.get === 'function'
3340 ? // @ts-expect-error weird "get" here,
3341 collection.get(key)
3342 : // @ts-expect-error key is unknown here,
3343 collection[key];
3344 }
3345
3346 function remove(collection, key) {
3347 if (!isDataStructure(collection)) {
3348 throw new TypeError('Cannot update non-data-structure value: ' + collection);
3349 }
3350 if (isImmutable(collection)) {
3351 // @ts-expect-error weird "remove" here,
3352 if (!collection.remove) {
3353 throw new TypeError('Cannot update immutable value without .remove() method: ' + collection);
3354 }
3355 // @ts-expect-error weird "remove" here,
3356 return collection.remove(key);
3357 }
3358 // @ts-expect-error assert that key is a string, a number or a symbol here
3359 if (!hasOwnProperty.call(collection, key)) {
3360 return collection;
3361 }
3362 var collectionCopy = shallowCopy(collection);
3363 if (Array.isArray(collectionCopy)) {
3364 // @ts-expect-error assert that key is a number here
3365 collectionCopy.splice(key, 1);
3366 }
3367 else {
3368 // @ts-expect-error assert that key is a string, a number or a symbol here
3369 delete collectionCopy[key];
3370 }
3371 return collectionCopy;
3372 }
3373
3374 function set(collection, key, value) {
3375 if (isProtoKey(key)) {
3376 return collection;
3377 }
3378 if (!isDataStructure(collection)) {
3379 throw new TypeError('Cannot update non-data-structure value: ' + collection);
3380 }
3381 if (isImmutable(collection)) {
3382 // @ts-expect-error weird "set" here,
3383 if (!collection.set) {
3384 throw new TypeError('Cannot update immutable value without .set() method: ' + collection);
3385 }
3386 // @ts-expect-error weird "set" here,
3387 return collection.set(key, value);
3388 }
3389 // @ts-expect-error mix of key and string here. Probably need a more fine type here
3390 if (hasOwnProperty.call(collection, key) && value === collection[key]) {
3391 return collection;
3392 }
3393 var collectionCopy = shallowCopy(collection);
3394 // @ts-expect-error mix of key and string here. Probably need a more fine type here
3395 collectionCopy[key] = value;
3396 return collectionCopy;
3397 }
3398
3399 function updateIn(collection, keyPath, notSetValue, updater) {
3400 if (!updater) {
3401 // handle the fact that `notSetValue` is optional here, in that case `updater` is the updater function
3402 // @ts-expect-error updater is a function here
3403 updater = notSetValue;
3404 notSetValue = undefined;
3405 }
3406 var updatedValue = updateInDeeply(isImmutable(collection),
3407 // @ts-expect-error type issues with Record and mixed types
3408 collection, coerceKeyPath(keyPath), 0, notSetValue, updater);
3409 // @ts-expect-error mixed return type
3410 return updatedValue === NOT_SET ? notSetValue : updatedValue;
3411 }
3412 function updateInDeeply(inImmutable, existing, keyPath, i, notSetValue, updater) {
3413 var wasNotSet = existing === NOT_SET;
3414 if (i === keyPath.length) {
3415 var existingValue = wasNotSet ? notSetValue : existing;
3416 // @ts-expect-error mixed type with optional value
3417 var newValue = updater(existingValue);
3418 // @ts-expect-error mixed type
3419 return newValue === existingValue ? existing : newValue;
3420 }
3421 if (!wasNotSet && !isDataStructure(existing)) {
3422 throw new TypeError('Cannot update within non-data-structure value in path [' +
3423 Array.from(keyPath).slice(0, i).map(quoteString) +
3424 ']: ' +
3425 existing);
3426 }
3427 var key = keyPath[i];
3428 var nextExisting = wasNotSet ? NOT_SET : get(existing, key, NOT_SET);
3429 var nextUpdated = updateInDeeply(nextExisting === NOT_SET ? inImmutable : isImmutable(nextExisting),
3430 // @ts-expect-error mixed type
3431 nextExisting, keyPath, i + 1, notSetValue, updater);
3432 return nextUpdated === nextExisting
3433 ? existing
3434 : nextUpdated === NOT_SET
3435 ? remove(existing, key)
3436 : set(wasNotSet ? (inImmutable ? emptyMap() : {}) : existing, key, nextUpdated);
3437 }
3438
3439 /**
3440 * Returns a copy of the collection with the value at the key path removed.
3441 *
3442 * A functional alternative to `collection.removeIn(keypath)` which will also
3443 * work with plain Objects and Arrays.
3444 */
3445 function removeIn(collection, keyPath) {
3446 return updateIn(collection, keyPath, function () { return NOT_SET; });
3447 }
3448
3449 function deleteIn(keyPath) {
3450 return removeIn(this, keyPath);
3451 }
3452
3453 var IS_LIST_SYMBOL = '@@__IMMUTABLE_LIST__@@';
3454 /**
3455 * True if `maybeList` is a List.
3456 */
3457 function isList(maybeList) {
3458 return Boolean(maybeList &&
3459 // @ts-expect-error: maybeList is typed as `{}`, need to change in 6.0 to `maybeList && typeof maybeList === 'object' && IS_LIST_SYMBOL in maybeList`
3460 maybeList[IS_LIST_SYMBOL]);
3461 }
3462
3463 var List = /*@__PURE__*/(function (IndexedCollection) {
3464 function List(value) {
3465 var empty = emptyList();
3466 if (value === undefined || value === null) {
3467 // eslint-disable-next-line no-constructor-return
3468 return empty;
3469 }
3470 if (isList(value)) {
3471 // eslint-disable-next-line no-constructor-return
3472 return value;
3473 }
3474 var iter = IndexedCollection(value);
3475 var size = iter.size;
3476 if (size === 0) {
3477 // eslint-disable-next-line no-constructor-return
3478 return empty;
3479 }
3480 assertNotInfinite(size);
3481 if (size > 0 && size < SIZE) {
3482 // eslint-disable-next-line no-constructor-return
3483 return makeList(0, size, SHIFT, undefined, new VNode(iter.toArray()));
3484 }
3485 // eslint-disable-next-line no-constructor-return
3486 return empty.withMutations(function (list) {
3487 list.setSize(size);
3488 iter.forEach(function (v, i) { return list.set(i, v); });
3489 });
3490 }
3491
3492 if ( IndexedCollection ) List.__proto__ = IndexedCollection;
3493 List.prototype = Object.create( IndexedCollection && IndexedCollection.prototype );
3494 List.prototype.constructor = List;
3495
3496 List.of = function of (/*...values*/) {
3497 return this(arguments);
3498 };
3499
3500 List.prototype.toString = function toString () {
3501 return this.__toString('List [', ']');
3502 };
3503
3504 // @pragma Access
3505
3506 List.prototype.get = function get (index, notSetValue) {
3507 index = wrapIndex(this, index);
3508 if (index >= 0 && index < this.size) {
3509 index += this._origin;
3510 var node = listNodeFor(this, index);
3511 return node && node.array[index & MASK];
3512 }
3513 return notSetValue;
3514 };
3515
3516 // @pragma Modification
3517
3518 List.prototype.set = function set (index, value) {
3519 return updateList(this, index, value);
3520 };
3521
3522 List.prototype.remove = function remove (index) {
3523 return !this.has(index)
3524 ? this
3525 : index === 0
3526 ? this.shift()
3527 : index === this.size - 1
3528 ? this.pop()
3529 : this.splice(index, 1);
3530 };
3531
3532 List.prototype.insert = function insert (index, value) {
3533 return this.splice(index, 0, value);
3534 };
3535
3536 List.prototype.clear = function clear () {
3537 if (this.size === 0) {
3538 return this;
3539 }
3540 if (this.__ownerID) {
3541 this.size = this._origin = this._capacity = 0;
3542 this._level = SHIFT;
3543 this._root = this._tail = this.__hash = undefined;
3544 this.__altered = true;
3545 return this;
3546 }
3547 return emptyList();
3548 };
3549
3550 List.prototype.push = function push (/*...values*/) {
3551 var values = arguments;
3552 var oldSize = this.size;
3553 return this.withMutations(function (list) {
3554 setListBounds(list, 0, oldSize + values.length);
3555 for (var ii = 0; ii < values.length; ii++) {
3556 list.set(oldSize + ii, values[ii]);
3557 }
3558 });
3559 };
3560
3561 List.prototype.pop = function pop () {
3562 return setListBounds(this, 0, -1);
3563 };
3564
3565 List.prototype.unshift = function unshift (/*...values*/) {
3566 var values = arguments;
3567 return this.withMutations(function (list) {
3568 setListBounds(list, -values.length);
3569 for (var ii = 0; ii < values.length; ii++) {
3570 list.set(ii, values[ii]);
3571 }
3572 });
3573 };
3574
3575 List.prototype.shift = function shift () {
3576 return setListBounds(this, 1);
3577 };
3578
3579 List.prototype.shuffle = function shuffle (random) {
3580 if ( random === void 0 ) random = Math.random;
3581
3582 return this.withMutations(function (mutable) {
3583 // implementation of the Fisher-Yates shuffle: https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
3584 var current = mutable.size;
3585 var destination;
3586 var tmp;
3587
3588 while (current) {
3589 destination = Math.floor(random() * current--);
3590
3591 tmp = mutable.get(destination);
3592 mutable.set(destination, mutable.get(current));
3593 mutable.set(current, tmp);
3594 }
3595 });
3596 };
3597
3598 // @pragma Composition
3599
3600 List.prototype.concat = function concat (/*...collections*/) {
3601 var arguments$1 = arguments;
3602
3603 var seqs = [];
3604 for (var i = 0; i < arguments.length; i++) {
3605 var argument = arguments$1[i];
3606 var seq = IndexedCollection(
3607 typeof argument !== 'string' && hasIterator(argument)
3608 ? argument
3609 : [argument]
3610 );
3611 if (seq.size !== 0) {
3612 seqs.push(seq);
3613 }
3614 }
3615 if (seqs.length === 0) {
3616 return this;
3617 }
3618 if (this.size === 0 && !this.__ownerID && seqs.length === 1) {
3619 return this.constructor(seqs[0]);
3620 }
3621 return this.withMutations(function (list) {
3622 seqs.forEach(function (seq) { return seq.forEach(function (value) { return list.push(value); }); });
3623 });
3624 };
3625
3626 List.prototype.setSize = function setSize (size) {
3627 return setListBounds(this, 0, size);
3628 };
3629
3630 List.prototype.map = function map (mapper, context) {
3631 var this$1$1 = this;
3632
3633 return this.withMutations(function (list) {
3634 for (var i = 0; i < this$1$1.size; i++) {
3635 list.set(i, mapper.call(context, list.get(i), i, this$1$1));
3636 }
3637 });
3638 };
3639
3640 // @pragma Iteration
3641
3642 List.prototype.slice = function slice (begin, end) {
3643 var size = this.size;
3644 if (wholeSlice(begin, end, size)) {
3645 return this;
3646 }
3647 return setListBounds(
3648 this,
3649 resolveBegin(begin, size),
3650 resolveEnd(end, size)
3651 );
3652 };
3653
3654 List.prototype.__iterator = function __iterator (type, reverse) {
3655 var index = reverse ? this.size : 0;
3656 var values = iterateList(this, reverse);
3657 return new Iterator(function () {
3658 var value = values();
3659 return value === DONE
3660 ? iteratorDone()
3661 : iteratorValue(type, reverse ? --index : index++, value);
3662 });
3663 };
3664
3665 List.prototype.__iterate = function __iterate (fn, reverse) {
3666 var index = reverse ? this.size : 0;
3667 var values = iterateList(this, reverse);
3668 var value;
3669 while ((value = values()) !== DONE) {
3670 if (fn(value, reverse ? --index : index++, this) === false) {
3671 break;
3672 }
3673 }
3674 return index;
3675 };
3676
3677 List.prototype.__ensureOwner = function __ensureOwner (ownerID) {
3678 if (ownerID === this.__ownerID) {
3679 return this;
3680 }
3681 if (!ownerID) {
3682 if (this.size === 0) {
3683 return emptyList();
3684 }
3685 this.__ownerID = ownerID;
3686 this.__altered = false;
3687 return this;
3688 }
3689 return makeList(
3690 this._origin,
3691 this._capacity,
3692 this._level,
3693 this._root,
3694 this._tail,
3695 ownerID,
3696 this.__hash
3697 );
3698 };
3699
3700 return List;
3701 }(IndexedCollection));
3702
3703 List.isList = isList;
3704
3705 var ListPrototype = List.prototype;
3706 ListPrototype[IS_LIST_SYMBOL] = true;
3707 ListPrototype[DELETE] = ListPrototype.remove;
3708 ListPrototype.merge = ListPrototype.concat;
3709 ListPrototype.setIn = setIn;
3710 ListPrototype.deleteIn = ListPrototype.removeIn = deleteIn;
3711 ListPrototype.update = update;
3712 ListPrototype.updateIn = updateIn$1;
3713 ListPrototype.mergeIn = mergeIn;
3714 ListPrototype.mergeDeepIn = mergeDeepIn;
3715 ListPrototype.withMutations = withMutations;
3716 ListPrototype.wasAltered = wasAltered;
3717 ListPrototype.asImmutable = asImmutable;
3718 ListPrototype['@@transducer/init'] = ListPrototype.asMutable = asMutable;
3719 ListPrototype['@@transducer/step'] = function (result, arr) {
3720 return result.push(arr);
3721 };
3722 ListPrototype['@@transducer/result'] = function (obj) {
3723 return obj.asImmutable();
3724 };
3725
3726 /**
3727 * A node in the List's 32-wide trie. At inner levels `array` holds child
3728 * `VNode`s; at the leaf level it holds the List's values. Missing slots are
3729 * `undefined` array holes.
3730 *
3731 * @template T
3732 */
3733 var VNode = function VNode(array, ownerID) {
3734 this.array = array;
3735 this.ownerID = ownerID;
3736 };
3737
3738 // TODO: seems like these methods are very similar
3739
3740 VNode.prototype.removeBefore = function removeBefore (ownerID, level, index) {
3741 if (
3742 (index & ((1 << (level + SHIFT)) - 1)) === 0 ||
3743 this.array.length === 0
3744 ) {
3745 return this;
3746 }
3747 var originIndex = (index >>> level) & MASK;
3748 if (originIndex >= this.array.length) {
3749 return new VNode([], ownerID);
3750 }
3751 var removingFirst = originIndex === 0;
3752 var newChild;
3753 if (level > 0) {
3754 var oldChild = this.array[originIndex];
3755 newChild =
3756 oldChild && oldChild.removeBefore(ownerID, level - SHIFT, index);
3757 if (newChild === oldChild && removingFirst) {
3758 return this;
3759 }
3760 }
3761 if (removingFirst && !newChild) {
3762 return this;
3763 }
3764 var editable = editableVNode(this, ownerID);
3765 if (!removingFirst) {
3766 for (var ii = 0; ii < originIndex; ii++) {
3767 editable.array[ii] = undefined;
3768 }
3769 }
3770 if (newChild) {
3771 editable.array[originIndex] = newChild;
3772 }
3773 return editable;
3774 };
3775
3776 VNode.prototype.removeAfter = function removeAfter (ownerID, level, index) {
3777 if (
3778 index === (level ? 1 << (level + SHIFT) : SIZE) ||
3779 this.array.length === 0
3780 ) {
3781 return this;
3782 }
3783 var sizeIndex = ((index - 1) >>> level) & MASK;
3784 if (sizeIndex >= this.array.length) {
3785 return this;
3786 }
3787
3788 var newChild;
3789 if (level > 0) {
3790 var oldChild = this.array[sizeIndex];
3791 newChild =
3792 oldChild && oldChild.removeAfter(ownerID, level - SHIFT, index);
3793 if (newChild === oldChild && sizeIndex === this.array.length - 1) {
3794 return this;
3795 }
3796 }
3797
3798 var editable = editableVNode(this, ownerID);
3799 editable.array.splice(sizeIndex + 1);
3800 if (newChild) {
3801 editable.array[sizeIndex] = newChild;
3802 }
3803 return editable;
3804 };
3805
3806 var DONE = {};
3807
3808 function iterateList(list, reverse) {
3809 var left = list._origin;
3810 var right = list._capacity;
3811 var tailPos = getTailOffset(right);
3812 var tail = list._tail;
3813
3814 return iterateNodeOrLeaf(list._root, list._level, 0);
3815
3816 function iterateNodeOrLeaf(node, level, offset) {
3817 return level === 0
3818 ? iterateLeaf(node, offset)
3819 : iterateNode(node, level, offset);
3820 }
3821
3822 function iterateLeaf(node, offset) {
3823 var array = offset === tailPos ? tail && tail.array : node && node.array;
3824 var from = offset > left ? 0 : left - offset;
3825 var to = right - offset;
3826 if (to > SIZE) {
3827 to = SIZE;
3828 }
3829 return function () {
3830 if (from === to) {
3831 return DONE;
3832 }
3833 var idx = reverse ? --to : from++;
3834 return array && array[idx];
3835 };
3836 }
3837
3838 function iterateNode(node, level, offset) {
3839 var values;
3840 var array = node && node.array;
3841 var from = offset > left ? 0 : (left - offset) >> level;
3842 var to = ((right - offset) >> level) + 1;
3843 if (to > SIZE) {
3844 to = SIZE;
3845 }
3846 return function () {
3847 while (true) {
3848 if (values) {
3849 var value = values();
3850 if (value !== DONE) {
3851 return value;
3852 }
3853 values = null;
3854 }
3855 if (from === to) {
3856 return DONE;
3857 }
3858 var idx = reverse ? --to : from++;
3859 values = iterateNodeOrLeaf(
3860 array && array[idx],
3861 level - SHIFT,
3862 offset + (idx << level)
3863 );
3864 }
3865 };
3866 }
3867 }
3868
3869 /**
3870 * @param {number} origin
3871 * @param {number} capacity
3872 * @param {number} level
3873 * @param {VNode | undefined} [root] The trie root, or `undefined` when every
3874 * in-range value lives in the tail (or is a virtual `undefined`).
3875 * @param {VNode | undefined} [tail]
3876 * @param {OwnerID} [ownerID]
3877 * @param {number} [hash]
3878 */
3879 function makeList(origin, capacity, level, root, tail, ownerID, hash) {
3880 var list = Object.create(ListPrototype);
3881 list.size = capacity - origin;
3882 list._origin = origin;
3883 list._capacity = capacity;
3884 list._level = level;
3885 list._root = root;
3886 list._tail = tail;
3887 list.__ownerID = ownerID;
3888 list.__hash = hash;
3889 list.__altered = false;
3890 return list;
3891 }
3892
3893 function emptyList() {
3894 return makeList(0, 0, SHIFT);
3895 }
3896
3897 function updateList(list, index, value) {
3898 index = wrapIndex(list, index);
3899
3900 if (index !== index) {
3901 return list;
3902 }
3903
3904 if (index >= list.size || index < 0) {
3905 return list.withMutations(function (list) {
3906 // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
3907 index < 0
3908 ? setListBounds(list, index).set(0, value)
3909 : setListBounds(list, 0, index + 1).set(index, value);
3910 });
3911 }
3912
3913 index += list._origin;
3914
3915 var newTail = list._tail;
3916 var newRoot = list._root;
3917 var didAlter = MakeRef();
3918 if (index >= getTailOffset(list._capacity)) {
3919 newTail = updateVNode(newTail, list.__ownerID, 0, index, value, didAlter);
3920 } else {
3921 newRoot = updateVNode(
3922 newRoot,
3923 list.__ownerID,
3924 list._level,
3925 index,
3926 value,
3927 didAlter
3928 );
3929 }
3930
3931 if (!didAlter.value) {
3932 return list;
3933 }
3934
3935 if (list.__ownerID) {
3936 list._root = newRoot;
3937 list._tail = newTail;
3938 list.__hash = undefined;
3939 list.__altered = true;
3940 return list;
3941 }
3942 return makeList(list._origin, list._capacity, list._level, newRoot, newTail);
3943 }
3944
3945 function updateVNode(node, ownerID, level, index, value, didAlter) {
3946 var idx = (index >>> level) & MASK;
3947 var nodeHas = node && idx < node.array.length;
3948 if (!nodeHas && value === undefined) {
3949 return node;
3950 }
3951
3952 var newNode;
3953
3954 if (level > 0) {
3955 var lowerNode = node && node.array[idx];
3956 var newLowerNode = updateVNode(
3957 lowerNode,
3958 ownerID,
3959 level - SHIFT,
3960 index,
3961 value,
3962 didAlter
3963 );
3964 if (newLowerNode === lowerNode) {
3965 return node;
3966 }
3967 newNode = editableVNode(node, ownerID);
3968 newNode.array[idx] = newLowerNode;
3969 return newNode;
3970 }
3971
3972 if (nodeHas && node.array[idx] === value) {
3973 return node;
3974 }
3975
3976 if (didAlter) {
3977 SetRef(didAlter);
3978 }
3979
3980 newNode = editableVNode(node, ownerID);
3981 if (value === undefined && idx === newNode.array.length - 1) {
3982 newNode.array.pop();
3983 } else {
3984 newNode.array[idx] = value;
3985 }
3986 return newNode;
3987 }
3988
3989 function editableVNode(node, ownerID) {
3990 if (ownerID && node && ownerID === node.ownerID) {
3991 return node;
3992 }
3993 return new VNode(node ? node.array.slice() : [], ownerID);
3994 }
3995
3996 /**
3997 * Returns the leaf `VNode` holding `rawIndex`, or `undefined` when no node is
3998 * allocated for it (an all-`undefined` region).
3999 *
4000 * @param {List} list
4001 * @param {number} rawIndex
4002 * @returns {VNode | undefined}
4003 */
4004 function listNodeFor(list, rawIndex) {
4005 if (rawIndex >= getTailOffset(list._capacity)) {
4006 return list._tail;
4007 }
4008 if (rawIndex < 1 << (list._level + SHIFT)) {
4009 var node = list._root;
4010 var level = list._level;
4011 while (node && level > 0) {
4012 node = node.array[(rawIndex >>> level) & MASK];
4013 level -= SHIFT;
4014 }
4015 return node;
4016 }
4017 }
4018
4019 /**
4020 * Validates requested bounds before int32 coercion in setListBounds().
4021 * Throws when origin/capacity would exceed the trie's safe range.
4022 */
4023 function validateListBoundsRequest(list, begin, end) {
4024 var requestedOrigin = list._origin + (begin === undefined ? 0 : begin);
4025 var requestedCapacity =
4026 end === undefined
4027 ? list._capacity
4028 : end < 0
4029 ? list._capacity + end
4030 : list._origin + end;
4031
4032 // Keep origin/capacity within the trie's safe signed 32-bit range.
4033 if (
4034 (Number.isFinite(requestedCapacity) && requestedCapacity > MAX_LIST_SIZE) ||
4035 (Number.isFinite(requestedOrigin) && requestedOrigin < -MAX_LIST_SIZE) ||
4036 (Number.isFinite(requestedCapacity) &&
4037 Number.isFinite(requestedOrigin) &&
4038 requestedCapacity - requestedOrigin > MAX_LIST_SIZE)
4039 ) {
4040 throw new RangeError(
4041 'Invalid List size: a List cannot hold more than ' +
4042 MAX_LIST_SIZE +
4043 ' (2 ** 30) values.'
4044 );
4045 }
4046 }
4047
4048 function setListBounds(list, begin, end) {
4049 // Validate full-precision bounds before int32 coercion.
4050 validateListBoundsRequest(list, begin, end);
4051
4052 // Sanitize begin & end using this shorthand for ToInt32(argument)
4053 // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
4054 if (begin !== undefined) {
4055 begin |= 0;
4056 }
4057 if (end !== undefined) {
4058 end |= 0;
4059 }
4060 var owner = list.__ownerID || new OwnerID();
4061 var oldOrigin = list._origin;
4062 var oldCapacity = list._capacity;
4063 var newOrigin = oldOrigin + begin;
4064 var newCapacity =
4065 end === undefined
4066 ? oldCapacity
4067 : end < 0
4068 ? oldCapacity + end
4069 : oldOrigin + end;
4070 if (newOrigin === oldOrigin && newCapacity === oldCapacity) {
4071 return list;
4072 }
4073
4074 // If it's going to end after it starts, it's empty.
4075 if (newOrigin >= newCapacity) {
4076 return list.clear();
4077 }
4078
4079 var newLevel = list._level;
4080 var newRoot = list._root;
4081
4082 // New origin might need creating a higher root.
4083 var offsetShift = 0;
4084 while (newOrigin + offsetShift < 0) {
4085 newRoot = new VNode(
4086 newRoot && newRoot.array.length ? [undefined, newRoot] : [],
4087 owner
4088 );
4089 newLevel += SHIFT;
4090 // Shift origin into non-negative space as trie height grows.
4091 offsetShift += levelCapacity(newLevel);
4092 }
4093 if (offsetShift) {
4094 newOrigin += offsetShift;
4095 oldOrigin += offsetShift;
4096 newCapacity += offsetShift;
4097 oldCapacity += offsetShift;
4098 }
4099
4100 var oldTailOffset = getTailOffset(oldCapacity);
4101 var newTailOffset = getTailOffset(newCapacity);
4102
4103 // New size might need creating a higher root.
4104 while (newTailOffset >= levelCapacity(newLevel + SHIFT)) {
4105 newRoot = new VNode(
4106 newRoot && newRoot.array.length ? [newRoot] : [],
4107 owner
4108 );
4109 newLevel += SHIFT;
4110 }
4111
4112 // Locate or create the new tail.
4113 var oldTail = list._tail;
4114 var newTail =
4115 newTailOffset < oldTailOffset
4116 ? listNodeFor(list, newCapacity - 1)
4117 : newTailOffset > oldTailOffset
4118 ? new VNode([], owner)
4119 : oldTail;
4120
4121 // Merge Tail into tree.
4122 if (
4123 oldTail &&
4124 newTailOffset > oldTailOffset &&
4125 newOrigin < oldCapacity &&
4126 oldTail.array.length
4127 ) {
4128 newRoot = editableVNode(newRoot, owner);
4129 var node = newRoot;
4130 for (var level = newLevel; level > SHIFT; level -= SHIFT) {
4131 var idx = (oldTailOffset >>> level) & MASK;
4132 node = node.array[idx] = editableVNode(node.array[idx], owner);
4133 }
4134 node.array[(oldTailOffset >>> SHIFT) & MASK] = oldTail;
4135 }
4136
4137 // If the size has been reduced, there's a chance the tail needs to be trimmed.
4138 if (newCapacity < oldCapacity) {
4139 newTail = newTail && newTail.removeAfter(owner, 0, newCapacity);
4140 }
4141
4142 // If the new origin is within the tail, then we do not need a root.
4143 if (newOrigin >= newTailOffset) {
4144 newOrigin -= newTailOffset;
4145 newCapacity -= newTailOffset;
4146 newLevel = SHIFT;
4147 newRoot = undefined;
4148 newTail = newTail && newTail.removeBefore(owner, 0, newOrigin);
4149
4150 // Otherwise, if the root has been trimmed, garbage collect.
4151 } else if (newOrigin > oldOrigin || newTailOffset < oldTailOffset) {
4152 offsetShift = 0;
4153
4154 // Identify the new top root node of the subtree of the old root.
4155 while (newRoot) {
4156 var beginIndex = (newOrigin >>> newLevel) & MASK;
4157 if ((beginIndex !== newTailOffset >>> newLevel) & MASK) {
4158 break;
4159 }
4160 if (beginIndex) {
4161 offsetShift += (1 << newLevel) * beginIndex;
4162 }
4163 newLevel -= SHIFT;
4164 newRoot = newRoot.array[beginIndex];
4165 }
4166
4167 // Trim the new sides of the new root.
4168 if (newRoot && newOrigin > oldOrigin) {
4169 newRoot = newRoot.removeBefore(owner, newLevel, newOrigin - offsetShift);
4170 }
4171 if (newRoot && newTailOffset < oldTailOffset) {
4172 newRoot = newRoot.removeAfter(
4173 owner,
4174 newLevel,
4175 newTailOffset - offsetShift
4176 );
4177 }
4178 if (offsetShift) {
4179 newOrigin -= offsetShift;
4180 newCapacity -= offsetShift;
4181 }
4182 }
4183
4184 if (list.__ownerID) {
4185 list.size = newCapacity - newOrigin;
4186 list._origin = newOrigin;
4187 list._capacity = newCapacity;
4188 list._level = newLevel;
4189 list._root = newRoot;
4190 list._tail = newTail;
4191 list.__hash = undefined;
4192 list.__altered = true;
4193 return list;
4194 }
4195 return makeList(newOrigin, newCapacity, newLevel, newRoot, newTail);
4196 }
4197
4198 function getTailOffset(size) {
4199 return size < SIZE ? 0 : ((size - 1) >>> SHIFT) << SHIFT;
4200 }
4201
4202 // The largest number of values a List can hold. Above this the 32-bit trie math
4203 // in setListBounds() stays in the safe signed 32-bit range.
4204 var MAX_LIST_SIZE = Math.pow( 2, 30 ); // 1073741824
4205
4206 /**
4207 * Computes 2 ** exp for the trie level-raising loops in setListBounds().
4208 * Use the cheap bitwise operator shift whenever possible, otherwise fall back to exponentiation.
4209 * This is necessary because bitwise operators in JavaScript only work on 32-bit signed integers, so for exp >= 31, we need to use exponentiation to avoid overflow.
4210 */
4211 function levelCapacity(exp) {
4212 return exp < 31 ? 1 << exp : Math.pow( 2, exp );
4213 }
4214
4215 /**
4216 * True if `maybeOrderedMap` is an OrderedMap.
4217 */
4218 function isOrderedMap(maybeOrderedMap) {
4219 return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
4220 }
4221
4222 var OrderedMap = /*@__PURE__*/(function (Map) {
4223 function OrderedMap(value) {
4224 // eslint-disable-next-line no-constructor-return
4225 return value === undefined || value === null
4226 ? emptyOrderedMap()
4227 : isOrderedMap(value)
4228 ? value
4229 : emptyOrderedMap().withMutations(function (map) {
4230 var iter = KeyedCollection(value);
4231 assertNotInfinite(iter.size);
4232 iter.forEach(function (v, k) { return map.set(k, v); });
4233 });
4234 }
4235
4236 if ( Map ) OrderedMap.__proto__ = Map;
4237 OrderedMap.prototype = Object.create( Map && Map.prototype );
4238 OrderedMap.prototype.constructor = OrderedMap;
4239
4240 OrderedMap.of = function of (/*...values*/) {
4241 return this(arguments);
4242 };
4243
4244 OrderedMap.prototype.toString = function toString () {
4245 return this.__toString('OrderedMap {', '}');
4246 };
4247
4248 // @pragma Access
4249
4250 OrderedMap.prototype.get = function get (k, notSetValue) {
4251 var index = this._map.get(k);
4252 return index !== undefined ? this._list.get(index)[1] : notSetValue;
4253 };
4254
4255 // @pragma Modification
4256
4257 OrderedMap.prototype.clear = function clear () {
4258 if (this.size === 0) {
4259 return this;
4260 }
4261 if (this.__ownerID) {
4262 this.size = 0;
4263 this._map.clear();
4264 this._list.clear();
4265 this.__altered = true;
4266 return this;
4267 }
4268 return emptyOrderedMap();
4269 };
4270
4271 OrderedMap.prototype.set = function set (k, v) {
4272 return updateOrderedMap(this, k, v);
4273 };
4274
4275 OrderedMap.prototype.remove = function remove (k) {
4276 return updateOrderedMap(this, k, NOT_SET);
4277 };
4278
4279 OrderedMap.prototype.__iterate = function __iterate (fn, reverse) {
4280 var this$1$1 = this;
4281
4282 return this._list.__iterate(
4283 function (entry) { return entry && fn(entry[1], entry[0], this$1$1); },
4284 reverse
4285 );
4286 };
4287
4288 OrderedMap.prototype.__iterator = function __iterator (type, reverse) {
4289 return this._list.fromEntrySeq().__iterator(type, reverse);
4290 };
4291
4292 OrderedMap.prototype.__ensureOwner = function __ensureOwner (ownerID) {
4293 if (ownerID === this.__ownerID) {
4294 return this;
4295 }
4296 var newMap = this._map.__ensureOwner(ownerID);
4297 var newList = this._list.__ensureOwner(ownerID);
4298 if (!ownerID) {
4299 if (this.size === 0) {
4300 return emptyOrderedMap();
4301 }
4302 this.__ownerID = ownerID;
4303 this.__altered = false;
4304 this._map = newMap;
4305 this._list = newList;
4306 return this;
4307 }
4308 return makeOrderedMap(newMap, newList, ownerID, this.__hash);
4309 };
4310
4311 return OrderedMap;
4312 }(Map));
4313
4314 OrderedMap.isOrderedMap = isOrderedMap;
4315
4316 OrderedMap.prototype[IS_ORDERED_SYMBOL] = true;
4317 OrderedMap.prototype[DELETE] = OrderedMap.prototype.remove;
4318
4319 function makeOrderedMap(map, list, ownerID, hash) {
4320 var omap = Object.create(OrderedMap.prototype);
4321 omap.size = map ? map.size : 0;
4322 omap._map = map;
4323 omap._list = list;
4324 omap.__ownerID = ownerID;
4325 omap.__hash = hash;
4326 omap.__altered = false;
4327 return omap;
4328 }
4329
4330 var EMPTY_ORDERED_MAP;
4331 function emptyOrderedMap() {
4332 return (
4333 EMPTY_ORDERED_MAP ||
4334 (EMPTY_ORDERED_MAP = makeOrderedMap(emptyMap(), emptyList()))
4335 );
4336 }
4337
4338 function updateOrderedMap(omap, k, v) {
4339 var map = omap._map;
4340 var list = omap._list;
4341 var i = map.get(k);
4342 var has = i !== undefined;
4343 var newMap;
4344 var newList;
4345 if (v === NOT_SET) {
4346 // removed
4347 if (!has) {
4348 return omap;
4349 }
4350 if (list.size >= SIZE && list.size >= map.size * 2) {
4351 newList = list.filter(function (entry, idx) { return entry !== undefined && i !== idx; });
4352 newMap = newList
4353 .toKeyedSeq()
4354 .map(function (entry) { return entry[0]; })
4355 .flip()
4356 .toMap();
4357 if (omap.__ownerID) {
4358 newMap.__ownerID = newList.__ownerID = omap.__ownerID;
4359 }
4360 } else {
4361 newMap = map.remove(k);
4362 newList = i === list.size - 1 ? list.pop() : list.set(i, undefined);
4363 }
4364 } else if (has) {
4365 if (v === list.get(i)[1]) {
4366 return omap;
4367 }
4368 newMap = map;
4369 newList = list.set(i, [k, v]);
4370 } else {
4371 newMap = map.set(k, list.size);
4372 newList = list.set(list.size, [k, v]);
4373 }
4374 if (omap.__ownerID) {
4375 omap.size = newMap.size;
4376 omap._map = newMap;
4377 omap._list = newList;
4378 omap.__hash = undefined;
4379 omap.__altered = true;
4380 return omap;
4381 }
4382 return makeOrderedMap(newMap, newList);
4383 }
4384
4385 var IS_STACK_SYMBOL = '@@__IMMUTABLE_STACK__@@';
4386 /**
4387 * True if `maybeStack` is a Stack.
4388 */
4389 function isStack(maybeStack) {
4390 return Boolean(maybeStack &&
4391 // @ts-expect-error: maybeStack is typed as `{}`, need to change in 6.0 to `maybeStack && typeof maybeStack === 'object' && MAYBE_STACK_SYMBOL in maybeStack`
4392 maybeStack[IS_STACK_SYMBOL]);
4393 }
4394
4395 var Stack = /*@__PURE__*/(function (IndexedCollection) {
4396 function Stack(value) {
4397 // eslint-disable-next-line no-constructor-return
4398 return value === undefined || value === null
4399 ? emptyStack()
4400 : isStack(value)
4401 ? value
4402 : emptyStack().pushAll(value);
4403 }
4404
4405 if ( IndexedCollection ) Stack.__proto__ = IndexedCollection;
4406 Stack.prototype = Object.create( IndexedCollection && IndexedCollection.prototype );
4407 Stack.prototype.constructor = Stack;
4408
4409 Stack.of = function of (/*...values*/) {
4410 return this(arguments);
4411 };
4412
4413 Stack.prototype.toString = function toString () {
4414 return this.__toString('Stack [', ']');
4415 };
4416
4417 // @pragma Access
4418
4419 Stack.prototype.get = function get (index, notSetValue) {
4420 var head = this._head;
4421 index = wrapIndex(this, index);
4422 while (head && index--) {
4423 head = head.next;
4424 }
4425 return head ? head.value : notSetValue;
4426 };
4427
4428 Stack.prototype.peek = function peek () {
4429 return this._head && this._head.value;
4430 };
4431
4432 // @pragma Modification
4433
4434 Stack.prototype.push = function push (/*...values*/) {
4435 var arguments$1 = arguments;
4436
4437 if (arguments.length === 0) {
4438 return this;
4439 }
4440 var newSize = this.size + arguments.length;
4441 var head = this._head;
4442 for (var ii = arguments.length - 1; ii >= 0; ii--) {
4443 head = {
4444 value: arguments$1[ii],
4445 next: head,
4446 };
4447 }
4448 if (this.__ownerID) {
4449 this.size = newSize;
4450 this._head = head;
4451 this.__hash = undefined;
4452 this.__altered = true;
4453 return this;
4454 }
4455 return makeStack(newSize, head);
4456 };
4457
4458 Stack.prototype.pushAll = function pushAll (iter) {
4459 iter = IndexedCollection(iter);
4460 if (iter.size === 0) {
4461 return this;
4462 }
4463 if (this.size === 0 && isStack(iter)) {
4464 return iter;
4465 }
4466 assertNotInfinite(iter.size);
4467 var newSize = this.size;
4468 var head = this._head;
4469 iter.__iterate(function (value) {
4470 newSize++;
4471 head = {
4472 value: value,
4473 next: head,
4474 };
4475 }, /* reverse */ true);
4476 if (this.__ownerID) {
4477 this.size = newSize;
4478 this._head = head;
4479 this.__hash = undefined;
4480 this.__altered = true;
4481 return this;
4482 }
4483 return makeStack(newSize, head);
4484 };
4485
4486 Stack.prototype.pop = function pop () {
4487 return this.slice(1);
4488 };
4489
4490 Stack.prototype.clear = function clear () {
4491 if (this.size === 0) {
4492 return this;
4493 }
4494 if (this.__ownerID) {
4495 this.size = 0;
4496 this._head = undefined;
4497 this.__hash = undefined;
4498 this.__altered = true;
4499 return this;
4500 }
4501 return emptyStack();
4502 };
4503
4504 Stack.prototype.slice = function slice (begin, end) {
4505 if (wholeSlice(begin, end, this.size)) {
4506 return this;
4507 }
4508 var resolvedBegin = resolveBegin(begin, this.size);
4509 var resolvedEnd = resolveEnd(end, this.size);
4510 if (resolvedEnd !== this.size) {
4511 // super.slice(begin, end);
4512 return IndexedCollection.prototype.slice.call(this, begin, end);
4513 }
4514 var newSize = this.size - resolvedBegin;
4515 var head = this._head;
4516 while (resolvedBegin--) {
4517 head = head.next;
4518 }
4519 if (this.__ownerID) {
4520 this.size = newSize;
4521 this._head = head;
4522 this.__hash = undefined;
4523 this.__altered = true;
4524 return this;
4525 }
4526 return makeStack(newSize, head);
4527 };
4528
4529 // @pragma Mutability
4530
4531 Stack.prototype.__ensureOwner = function __ensureOwner (ownerID) {
4532 if (ownerID === this.__ownerID) {
4533 return this;
4534 }
4535 if (!ownerID) {
4536 if (this.size === 0) {
4537 return emptyStack();
4538 }
4539 this.__ownerID = ownerID;
4540 this.__altered = false;
4541 return this;
4542 }
4543 return makeStack(this.size, this._head, ownerID, this.__hash);
4544 };
4545
4546 // @pragma Iteration
4547
4548 Stack.prototype.__iterate = function __iterate (fn, reverse) {
4549 var this$1$1 = this;
4550
4551 if (reverse) {
4552 return new ArraySeq(this.toArray()).__iterate(
4553 function (v, k) { return fn(v, k, this$1$1); },
4554 reverse
4555 );
4556 }
4557 var iterations = 0;
4558 var node = this._head;
4559 while (node) {
4560 if (fn(node.value, iterations++, this) === false) {
4561 break;
4562 }
4563 node = node.next;
4564 }
4565 return iterations;
4566 };
4567
4568 Stack.prototype.__iterator = function __iterator (type, reverse) {
4569 if (reverse) {
4570 return new ArraySeq(this.toArray()).__iterator(type, reverse);
4571 }
4572 var iterations = 0;
4573 var node = this._head;
4574 return new Iterator(function () {
4575 if (node) {
4576 var value = node.value;
4577 node = node.next;
4578 return iteratorValue(type, iterations++, value);
4579 }
4580 return iteratorDone();
4581 });
4582 };
4583
4584 return Stack;
4585 }(IndexedCollection));
4586
4587 Stack.isStack = isStack;
4588
4589 var StackPrototype = Stack.prototype;
4590 StackPrototype[IS_STACK_SYMBOL] = true;
4591 StackPrototype.shift = StackPrototype.pop;
4592 StackPrototype.unshift = StackPrototype.push;
4593 StackPrototype.unshiftAll = StackPrototype.pushAll;
4594 StackPrototype.withMutations = withMutations;
4595 StackPrototype.wasAltered = wasAltered;
4596 StackPrototype.asImmutable = asImmutable;
4597 StackPrototype['@@transducer/init'] = StackPrototype.asMutable = asMutable;
4598 StackPrototype['@@transducer/step'] = function (result, arr) {
4599 return result.unshift(arr);
4600 };
4601 StackPrototype['@@transducer/result'] = function (obj) {
4602 return obj.asImmutable();
4603 };
4604
4605 function makeStack(size, head, ownerID, hash) {
4606 var map = Object.create(StackPrototype);
4607 map.size = size;
4608 map._head = head;
4609 map.__ownerID = ownerID;
4610 map.__hash = hash;
4611 map.__altered = false;
4612 return map;
4613 }
4614
4615 var EMPTY_STACK;
4616 function emptyStack() {
4617 return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
4618 }
4619
4620 function reduce(collection, reducer, reduction, context, useFirst, reverse) {
4621 // @ts-expect-error Migrate to CollectionImpl in v6
4622 assertNotInfinite(collection.size);
4623 // @ts-expect-error Migrate to CollectionImpl in v6
4624 collection.__iterate(function (v, k, c) {
4625 if (useFirst) {
4626 useFirst = false;
4627 reduction = v;
4628 }
4629 else {
4630 // `reduction` has already been seeded here (either with the provided
4631 // initial value or with the first iterated value), so it is never the
4632 // `undefined` placeholder — only a `V` or a `R`.
4633 reduction = reducer.call(context, reduction, v, k, c);
4634 }
4635 }, reverse);
4636 return reduction;
4637 }
4638 function keyMapper(v, k) {
4639 return k;
4640 }
4641 function entryMapper(v, k) {
4642 return [k, v];
4643 }
4644 function not(predicate) {
4645 return function () {
4646 var args = [], len = arguments.length;
4647 while ( len-- ) args[ len ] = arguments[ len ];
4648
4649 return !predicate.apply(this, args);
4650 };
4651 }
4652 function neg(predicate) {
4653 return function () {
4654 var args = [], len = arguments.length;
4655 while ( len-- ) args[ len ] = arguments[ len ];
4656
4657 return -predicate.apply(this, args);
4658 };
4659 }
4660 function defaultNegComparator(a, b) {
4661 return a < b ? 1 : a > b ? -1 : 0;
4662 }
4663
4664 function deepEqual(a, b) {
4665 if (a === b) {
4666 return true;
4667 }
4668 if (!isCollection(b) ||
4669 // @ts-expect-error size should exists on Collection
4670 (a.size !== undefined && b.size !== undefined && a.size !== b.size) ||
4671 // @ts-expect-error __hash exists on Collection
4672 (a.__hash !== undefined &&
4673 // @ts-expect-error __hash exists on Collection
4674 b.__hash !== undefined &&
4675 // @ts-expect-error __hash exists on Collection
4676 a.__hash !== b.__hash) ||
4677 isKeyed(a) !== isKeyed(b) ||
4678 isIndexed(a) !== isIndexed(b) ||
4679 // @ts-expect-error Range extends Collection, which implements [Symbol.iterator], so it is valid
4680 isOrdered(a) !== isOrdered(b)) {
4681 return false;
4682 }
4683 // @ts-expect-error size should exists on Collection
4684 if (a.size === 0 && b.size === 0) {
4685 return true;
4686 }
4687 var notAssociative = !isAssociative(a);
4688 // @ts-expect-error Range extends Collection, which implements [Symbol.iterator], so it is valid
4689 if (isOrdered(a)) {
4690 var entries = a.entries();
4691 // @ts-expect-error need to cast as boolean
4692 return (b.every(function (v, k) {
4693 var entry = entries.next().value;
4694 return entry && is(entry[1], v) && (notAssociative || is(entry[0], k));
4695 }) && entries.next().done);
4696 }
4697 var flipped = false;
4698 if (a.size === undefined) {
4699 // @ts-expect-error size should exists on Collection
4700 if (b.size === undefined) {
4701 if (typeof a.cacheResult === 'function') {
4702 a.cacheResult();
4703 }
4704 }
4705 else {
4706 flipped = true;
4707 var _ = a;
4708 a = b;
4709 b = _;
4710 }
4711 }
4712 var allEqual = true;
4713 var bSize =
4714 // @ts-expect-error b is Range | Repeat | Collection<unknown, unknown> as it may have been flipped, and __iterate is valid
4715 b.__iterate(function (v, k) {
4716 if (notAssociative
4717 ? // @ts-expect-error has exists on Collection
4718 !a.has(v)
4719 : flipped
4720 ? // @ts-expect-error type of `get` does not "catch" the version with `notSetValue`
4721 !is(v, a.get(k, NOT_SET))
4722 : // @ts-expect-error type of `get` does not "catch" the version with `notSetValue`
4723 !is(a.get(k, NOT_SET), v)) {
4724 allEqual = false;
4725 return false;
4726 }
4727 });
4728 return (allEqual &&
4729 // @ts-expect-error size should exists on Collection
4730 a.size === bSize);
4731 }
4732
4733 /**
4734 * Returns a lazy seq of nums from start (inclusive) to end
4735 * (exclusive), by step, where start defaults to 0, step to 1, and end to
4736 * infinity. When start is equal to end, returns empty list.
4737 */
4738 var Range = /*@__PURE__*/(function (IndexedSeq) {
4739 function Range(start, end, step) {
4740 if ( step === void 0 ) step = 1;
4741
4742 if (!(this instanceof Range)) {
4743 // eslint-disable-next-line no-constructor-return
4744 return new Range(start, end, step);
4745 }
4746 invariant(step !== 0, 'Cannot step a Range by 0');
4747 invariant(
4748 start !== undefined,
4749 'You must define a start value when using Range'
4750 );
4751 invariant(
4752 end !== undefined,
4753 'You must define an end value when using Range'
4754 );
4755
4756 step = Math.abs(step);
4757 if (end < start) {
4758 step = -step;
4759 }
4760 this._start = start;
4761 this._end = end;
4762 this._step = step;
4763 this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
4764 if (this.size === 0) {
4765 if (EMPTY_RANGE) {
4766 // eslint-disable-next-line no-constructor-return
4767 return EMPTY_RANGE;
4768 }
4769 // eslint-disable-next-line @typescript-eslint/no-this-alias
4770 EMPTY_RANGE = this;
4771 }
4772 }
4773
4774 if ( IndexedSeq ) Range.__proto__ = IndexedSeq;
4775 Range.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
4776 Range.prototype.constructor = Range;
4777
4778 Range.prototype.toString = function toString () {
4779 return this.size === 0
4780 ? 'Range []'
4781 : ("Range [ " + (this._start) + "..." + (this._end) + (this._step !== 1 ? ' by ' + this._step : '') + " ]");
4782 };
4783
4784 Range.prototype.get = function get (index, notSetValue) {
4785 return this.has(index)
4786 ? this._start + wrapIndex(this, index) * this._step
4787 : notSetValue;
4788 };
4789
4790 Range.prototype.includes = function includes (searchValue) {
4791 var possibleIndex = (searchValue - this._start) / this._step;
4792 return (
4793 possibleIndex >= 0 &&
4794 possibleIndex < this.size &&
4795 possibleIndex === Math.floor(possibleIndex)
4796 );
4797 };
4798
4799 Range.prototype.slice = function slice (begin, end) {
4800 if (wholeSlice(begin, end, this.size)) {
4801 return this;
4802 }
4803 begin = resolveBegin(begin, this.size);
4804 end = resolveEnd(end, this.size);
4805 if (end <= begin) {
4806 return new Range(0, 0);
4807 }
4808 return new Range(
4809 this.get(begin, this._end),
4810 this.get(end, this._end),
4811 this._step
4812 );
4813 };
4814
4815 Range.prototype.indexOf = function indexOf (searchValue) {
4816 var offsetValue = searchValue - this._start;
4817 if (offsetValue % this._step === 0) {
4818 var index = offsetValue / this._step;
4819 if (index >= 0 && index < this.size) {
4820 return index;
4821 }
4822 }
4823 return -1;
4824 };
4825
4826 Range.prototype.lastIndexOf = function lastIndexOf (searchValue) {
4827 return this.indexOf(searchValue);
4828 };
4829
4830 Range.prototype.__iterate = function __iterate (fn, reverse) {
4831 var size = this.size;
4832 var step = this._step;
4833 var value = reverse ? this._start + (size - 1) * step : this._start;
4834 var i = 0;
4835 while (i !== size) {
4836 if (fn(value, reverse ? size - ++i : i++, this) === false) {
4837 break;
4838 }
4839 value += reverse ? -step : step;
4840 }
4841 return i;
4842 };
4843
4844 Range.prototype.__iterator = function __iterator (type, reverse) {
4845 var size = this.size;
4846 var step = this._step;
4847 var value = reverse ? this._start + (size - 1) * step : this._start;
4848 var i = 0;
4849 return new Iterator(function () {
4850 if (i === size) {
4851 return iteratorDone();
4852 }
4853 var v = value;
4854 value += reverse ? -step : step;
4855 return iteratorValue(type, reverse ? size - ++i : i++, v);
4856 });
4857 };
4858
4859 Range.prototype.equals = function equals (other) {
4860 return other instanceof Range
4861 ? this._start === other._start &&
4862 this._end === other._end &&
4863 this._step === other._step
4864 : deepEqual(this, other);
4865 };
4866
4867 return Range;
4868 }(IndexedSeq));
4869
4870 var EMPTY_RANGE;
4871
4872 var IS_SET_SYMBOL = '@@__IMMUTABLE_SET__@@';
4873 /**
4874 * True if `maybeSet` is a Set.
4875 *
4876 * Also true for OrderedSets.
4877 */
4878 function isSet(maybeSet) {
4879 return Boolean(maybeSet &&
4880 // @ts-expect-error: maybeSet is typed as `{}`, need to change in 6.0 to `maybeSeq && typeof maybeSet === 'object' && MAYBE_SET_SYMBOL in maybeSet`
4881 maybeSet[IS_SET_SYMBOL]);
4882 }
4883
4884 var Set = /*@__PURE__*/(function (SetCollection) {
4885 function Set(value) {
4886 // eslint-disable-next-line no-constructor-return
4887 return value === undefined || value === null
4888 ? emptySet()
4889 : isSet(value) && !isOrdered(value)
4890 ? value
4891 : emptySet().withMutations(function (set) {
4892 var iter = SetCollection(value);
4893 assertNotInfinite(iter.size);
4894 iter.forEach(function (v) { return set.add(v); });
4895 });
4896 }
4897
4898 if ( SetCollection ) Set.__proto__ = SetCollection;
4899 Set.prototype = Object.create( SetCollection && SetCollection.prototype );
4900 Set.prototype.constructor = Set;
4901
4902 Set.of = function of (/*...values*/) {
4903 return this(arguments);
4904 };
4905
4906 Set.fromKeys = function fromKeys (value) {
4907 return this(KeyedCollection(value).keySeq());
4908 };
4909
4910 Set.intersect = function intersect (sets) {
4911 sets = Collection(sets).toArray();
4912 return sets.length
4913 ? SetPrototype.intersect.apply(Set(sets.pop()), sets)
4914 : emptySet();
4915 };
4916
4917 Set.union = function union (sets) {
4918 sets = Collection(sets).toArray();
4919 return sets.length
4920 ? SetPrototype.union.apply(Set(sets.pop()), sets)
4921 : emptySet();
4922 };
4923
4924 Set.prototype.toString = function toString () {
4925 return this.__toString('Set {', '}');
4926 };
4927
4928 // @pragma Access
4929
4930 Set.prototype.has = function has (value) {
4931 return this._map.has(value);
4932 };
4933
4934 // @pragma Modification
4935
4936 Set.prototype.add = function add (value) {
4937 return updateSet(this, this._map.set(value, value));
4938 };
4939
4940 Set.prototype.remove = function remove (value) {
4941 return updateSet(this, this._map.remove(value));
4942 };
4943
4944 Set.prototype.clear = function clear () {
4945 return updateSet(this, this._map.clear());
4946 };
4947
4948 // @pragma Composition
4949
4950 Set.prototype.map = function map (mapper, context) {
4951 var this$1$1 = this;
4952
4953 // keep track if the set is altered by the map function
4954 var didChanges = false;
4955
4956 var newMap = updateSet(
4957 this,
4958 this._map.mapEntries(function (ref) {
4959 var v = ref[1];
4960
4961 var mapped = mapper.call(context, v, v, this$1$1);
4962
4963 if (mapped !== v) {
4964 didChanges = true;
4965 }
4966
4967 return [mapped, mapped];
4968 }, context)
4969 );
4970
4971 return didChanges ? newMap : this;
4972 };
4973
4974 Set.prototype.union = function union () {
4975 var iters = [], len = arguments.length;
4976 while ( len-- ) iters[ len ] = arguments[ len ];
4977
4978 iters = iters.filter(function (x) { return x.size !== 0; });
4979 if (iters.length === 0) {
4980 return this;
4981 }
4982 if (this.size === 0 && !this.__ownerID && iters.length === 1) {
4983 return this.constructor(iters[0]);
4984 }
4985 return this.withMutations(function (set) {
4986 for (var ii = 0; ii < iters.length; ii++) {
4987 if (typeof iters[ii] === 'string') {
4988 set.add(iters[ii]);
4989 } else {
4990 SetCollection(iters[ii]).forEach(function (value) { return set.add(value); });
4991 }
4992 }
4993 });
4994 };
4995
4996 Set.prototype.intersect = function intersect () {
4997 var iters = [], len = arguments.length;
4998 while ( len-- ) iters[ len ] = arguments[ len ];
4999
5000 if (iters.length === 0) {
5001 return this;
5002 }
5003 iters = iters.map(function (iter) { return SetCollection(iter); });
5004 var toRemove = [];
5005 this.forEach(function (value) {
5006 if (!iters.every(function (iter) { return iter.includes(value); })) {
5007 toRemove.push(value);
5008 }
5009 });
5010 return this.withMutations(function (set) {
5011 toRemove.forEach(function (value) {
5012 set.remove(value);
5013 });
5014 });
5015 };
5016
5017 Set.prototype.subtract = function subtract () {
5018 var iters = [], len = arguments.length;
5019 while ( len-- ) iters[ len ] = arguments[ len ];
5020
5021 if (iters.length === 0) {
5022 return this;
5023 }
5024 iters = iters.map(function (iter) { return SetCollection(iter); });
5025 var toRemove = [];
5026 this.forEach(function (value) {
5027 if (iters.some(function (iter) { return iter.includes(value); })) {
5028 toRemove.push(value);
5029 }
5030 });
5031 return this.withMutations(function (set) {
5032 toRemove.forEach(function (value) {
5033 set.remove(value);
5034 });
5035 });
5036 };
5037
5038 Set.prototype.sort = function sort (comparator) {
5039 // Late binding
5040 return OrderedSet(sortFactory(this, comparator));
5041 };
5042
5043 Set.prototype.sortBy = function sortBy (mapper, comparator) {
5044 // Late binding
5045 return OrderedSet(sortFactory(this, comparator, mapper));
5046 };
5047
5048 Set.prototype.wasAltered = function wasAltered () {
5049 return this._map.wasAltered();
5050 };
5051
5052 Set.prototype.__iterate = function __iterate (fn, reverse) {
5053 var this$1$1 = this;
5054
5055 return this._map.__iterate(function (k) { return fn(k, k, this$1$1); }, reverse);
5056 };
5057
5058 Set.prototype.__iterator = function __iterator (type, reverse) {
5059 return this._map.__iterator(type, reverse);
5060 };
5061
5062 Set.prototype.__ensureOwner = function __ensureOwner (ownerID) {
5063 if (ownerID === this.__ownerID) {
5064 return this;
5065 }
5066 var newMap = this._map.__ensureOwner(ownerID);
5067 if (!ownerID) {
5068 if (this.size === 0) {
5069 return this.__empty();
5070 }
5071 this.__ownerID = ownerID;
5072 this._map = newMap;
5073 return this;
5074 }
5075 return this.__make(newMap, ownerID);
5076 };
5077
5078 return Set;
5079 }(SetCollection));
5080
5081 Set.isSet = isSet;
5082
5083 var SetPrototype = Set.prototype;
5084 SetPrototype[IS_SET_SYMBOL] = true;
5085 SetPrototype[DELETE] = SetPrototype.remove;
5086 SetPrototype.merge = SetPrototype.concat = SetPrototype.union;
5087 SetPrototype.withMutations = withMutations;
5088 SetPrototype.asImmutable = asImmutable;
5089 SetPrototype['@@transducer/init'] = SetPrototype.asMutable = asMutable;
5090 SetPrototype['@@transducer/step'] = function (result, arr) {
5091 return result.add(arr);
5092 };
5093 SetPrototype['@@transducer/result'] = function (obj) {
5094 return obj.asImmutable();
5095 };
5096
5097 SetPrototype.__empty = emptySet;
5098 SetPrototype.__make = makeSet;
5099
5100 function updateSet(set, newMap) {
5101 if (set.__ownerID) {
5102 set.size = newMap.size;
5103 set._map = newMap;
5104 return set;
5105 }
5106 return newMap === set._map
5107 ? set
5108 : newMap.size === 0
5109 ? set.__empty()
5110 : set.__make(newMap);
5111 }
5112
5113 function makeSet(map, ownerID) {
5114 var set = Object.create(SetPrototype);
5115 set.size = map ? map.size : 0;
5116 set._map = map;
5117 set.__ownerID = ownerID;
5118 return set;
5119 }
5120
5121 var EMPTY_SET;
5122 function emptySet() {
5123 return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
5124 }
5125
5126 /**
5127 * Returns the value at the provided key path starting at the provided
5128 * collection, or notSetValue if the key path is not defined.
5129 *
5130 * A functional alternative to `collection.getIn(keypath)` which will also
5131 * work with plain Objects and Arrays.
5132 */
5133 function getIn$1(collection, searchKeyPath, notSetValue) {
5134 var keyPath = coerceKeyPath(searchKeyPath);
5135 var i = 0;
5136 while (i !== keyPath.length) {
5137 // @ts-expect-error keyPath[i++] can not be undefined by design
5138 collection = get(collection, keyPath[i++], NOT_SET);
5139 if (collection === NOT_SET) {
5140 return notSetValue;
5141 }
5142 }
5143 return collection;
5144 }
5145
5146 function getIn(searchKeyPath, notSetValue) {
5147 return getIn$1(this, searchKeyPath, notSetValue);
5148 }
5149
5150 /**
5151 * Returns true if the key path is defined in the provided collection.
5152 *
5153 * A functional alternative to `collection.hasIn(keypath)` which will also
5154 * work with plain Objects and Arrays.
5155 */
5156 function hasIn$1(collection, keyPath) {
5157 return getIn$1(collection, keyPath, NOT_SET) !== NOT_SET;
5158 }
5159
5160 function hasIn(searchKeyPath) {
5161 return hasIn$1(this, searchKeyPath);
5162 }
5163
5164 function toObject() {
5165 assertNotInfinite(this.size);
5166 var object = {};
5167 this.__iterate(function (v, k) {
5168 if (isProtoKey(k)) {
5169 return;
5170 }
5171
5172 object[k] = v;
5173 });
5174 return object;
5175 }
5176
5177 function toJS(value) {
5178 if (!value || typeof value !== 'object') {
5179 return value;
5180 }
5181 if (!isCollection(value)) {
5182 if (!isDataStructure(value)) {
5183 return value;
5184 }
5185 // @ts-expect-error until Seq has been migrated to TypeScript
5186 value = Seq(value);
5187 }
5188 if (isKeyed(value)) {
5189 var result$1 = {};
5190 // @ts-expect-error `__iterate` exists on all Keyed collections but method is not defined in the type
5191 value.__iterate(function (v, k) {
5192 if (isProtoKey(k)) {
5193 return;
5194 }
5195 result$1[k] = toJS(v);
5196 });
5197 return result$1;
5198 }
5199 var result = [];
5200 // @ts-expect-error value "should" be a non-keyed collection, but we may need to assert for stricter types
5201 value.__iterate(function (v) {
5202 result.push(toJS(v));
5203 });
5204 return result;
5205 }
5206
5207 function hashCollection(collection) {
5208 // @ts-expect-error Migrate to CollectionImpl in v6
5209 if (collection.size === Infinity) {
5210 return 0;
5211 }
5212 var ordered = isOrdered(collection);
5213 var keyed = isKeyed(collection);
5214 var h = ordered ? 1 : 0;
5215 // @ts-expect-error Migrate to CollectionImpl in v6
5216 collection.__iterate(keyed
5217 ? ordered
5218 ? function (v, k) {
5219 h = (31 * h + hashMerge(hash(v), hash(k))) | 0;
5220 }
5221 : function (v, k) {
5222 h = (h + hashMerge(hash(v), hash(k))) | 0;
5223 }
5224 : ordered
5225 ? function (v) {
5226 h = (31 * h + hash(v)) | 0;
5227 }
5228 : function (v) {
5229 h = (h + hash(v)) | 0;
5230 });
5231 // @ts-expect-error Migrate to CollectionImpl in v6
5232 return murmurHashOfSize(collection.size, h);
5233 }
5234 function murmurHashOfSize(size, h) {
5235 h = imul(h, 0xcc9e2d51);
5236 h = imul((h << 15) | (h >>> -15), 0x1b873593);
5237 h = imul((h << 13) | (h >>> -13), 5);
5238 h = ((h + 0xe6546b64) | 0) ^ size;
5239 h = imul(h ^ (h >>> 16), 0x85ebca6b);
5240 h = imul(h ^ (h >>> 13), 0xc2b2ae35);
5241 h = smi(h ^ (h >>> 16));
5242 return h;
5243 }
5244 function hashMerge(a, b) {
5245 return (a ^ (b + 0x9e3779b9 + (a << 6) + (a >> 2))) | 0; // int
5246 }
5247
5248 /**
5249 * Contributes additional methods to a constructor
5250 */
5251 function mixin(ctor,
5252 // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
5253 methods) {
5254 var keyCopier = function (key) {
5255 // @ts-expect-error how to handle symbol ?
5256 ctor.prototype[key] = methods[key];
5257 };
5258 Object.keys(methods).forEach(keyCopier);
5259 // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
5260 Object.getOwnPropertySymbols &&
5261 Object.getOwnPropertySymbols(methods).forEach(keyCopier);
5262 return ctor;
5263 }
5264
5265 Collection.Iterator = Iterator;
5266
5267 mixin(Collection, {
5268 // ### Conversion to other types
5269
5270 toArray: function toArray() {
5271 assertNotInfinite(this.size);
5272 var array = new Array(this.size || 0);
5273 var useTuples = isKeyed(this);
5274 var i = 0;
5275 this.__iterate(function (v, k) {
5276 // Keyed collections produce an array of tuples.
5277 array[i++] = useTuples ? [k, v] : v;
5278 });
5279 return array;
5280 },
5281
5282 toIndexedSeq: function toIndexedSeq() {
5283 return new ToIndexedSequence(this);
5284 },
5285
5286 toJS: function toJS$1() {
5287 return toJS(this);
5288 },
5289
5290 toKeyedSeq: function toKeyedSeq() {
5291 return new ToKeyedSequence(this, true);
5292 },
5293
5294 toMap: function toMap() {
5295 // Use Late Binding here to solve the circular dependency.
5296 return Map(this.toKeyedSeq());
5297 },
5298
5299 toObject: toObject,
5300
5301 toOrderedMap: function toOrderedMap() {
5302 // Use Late Binding here to solve the circular dependency.
5303 return OrderedMap(this.toKeyedSeq());
5304 },
5305
5306 toOrderedSet: function toOrderedSet() {
5307 // Use Late Binding here to solve the circular dependency.
5308 return OrderedSet(isKeyed(this) ? this.valueSeq() : this);
5309 },
5310
5311 toSet: function toSet() {
5312 // Use Late Binding here to solve the circular dependency.
5313 return Set(isKeyed(this) ? this.valueSeq() : this);
5314 },
5315
5316 toSetSeq: function toSetSeq() {
5317 return new ToSetSequence(this);
5318 },
5319
5320 toSeq: function toSeq() {
5321 return isIndexed(this)
5322 ? this.toIndexedSeq()
5323 : isKeyed(this)
5324 ? this.toKeyedSeq()
5325 : this.toSetSeq();
5326 },
5327
5328 toStack: function toStack() {
5329 // Use Late Binding here to solve the circular dependency.
5330 return Stack(isKeyed(this) ? this.valueSeq() : this);
5331 },
5332
5333 toList: function toList() {
5334 // Use Late Binding here to solve the circular dependency.
5335 return List(isKeyed(this) ? this.valueSeq() : this);
5336 },
5337
5338 // ### Common JavaScript methods and properties
5339
5340 toString: function toString() {
5341 return '[Collection]';
5342 },
5343
5344 __toString: function __toString(head, tail) {
5345 if (this.size === 0) {
5346 return head + tail;
5347 }
5348 return (
5349 head +
5350 ' ' +
5351 this.toSeq().map(this.__toStringMapper).join(', ') +
5352 ' ' +
5353 tail
5354 );
5355 },
5356
5357 // ### ES6 Collection methods (ES6 Array and Map)
5358
5359 concat: function concat() {
5360 var values = [], len = arguments.length;
5361 while ( len-- ) values[ len ] = arguments[ len ];
5362
5363 return reify(this, concatFactory(this, values));
5364 },
5365
5366 includes: function includes(searchValue) {
5367 return this.some(function (value) { return is(value, searchValue); });
5368 },
5369
5370 entries: function entries() {
5371 return this.__iterator(ITERATE_ENTRIES);
5372 },
5373
5374 every: function every(predicate, context) {
5375 assertNotInfinite(this.size);
5376 var returnValue = true;
5377 this.__iterate(function (v, k, c) {
5378 if (!predicate.call(context, v, k, c)) {
5379 returnValue = false;
5380 return false;
5381 }
5382 });
5383 return returnValue;
5384 },
5385
5386 filter: function filter(predicate, context) {
5387 return reify(this, filterFactory(this, predicate, context, true));
5388 },
5389
5390 partition: function partition(predicate, context) {
5391 return partitionFactory(this, predicate, context);
5392 },
5393
5394 find: function find(predicate, context, notSetValue) {
5395 var entry = this.findEntry(predicate, context);
5396 return entry ? entry[1] : notSetValue;
5397 },
5398
5399 forEach: function forEach(sideEffect, context) {
5400 assertNotInfinite(this.size);
5401 return this.__iterate(context ? sideEffect.bind(context) : sideEffect);
5402 },
5403
5404 join: function join(separator) {
5405 assertNotInfinite(this.size);
5406 separator = separator !== undefined ? '' + separator : ',';
5407 var joined = '';
5408 var isFirst = true;
5409 this.__iterate(function (v) {
5410 // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
5411 isFirst ? (isFirst = false) : (joined += separator);
5412 joined += v !== null && v !== undefined ? v.toString() : '';
5413 });
5414 return joined;
5415 },
5416
5417 keys: function keys() {
5418 return this.__iterator(ITERATE_KEYS);
5419 },
5420
5421 map: function map(mapper, context) {
5422 return reify(this, mapFactory(this, mapper, context));
5423 },
5424
5425 reduce: function reduce$1(reducer, initialReduction, context) {
5426 return reduce(
5427 this,
5428 reducer,
5429 initialReduction,
5430 context,
5431 arguments.length < 2,
5432 false
5433 );
5434 },
5435
5436 reduceRight: function reduceRight(reducer, initialReduction, context) {
5437 return reduce(
5438 this,
5439 reducer,
5440 initialReduction,
5441 context,
5442 arguments.length < 2,
5443 true
5444 );
5445 },
5446
5447 reverse: function reverse() {
5448 return reify(this, reverseFactory(this, true));
5449 },
5450
5451 slice: function slice(begin, end) {
5452 return reify(this, sliceFactory(this, begin, end, true));
5453 },
5454
5455 some: function some(predicate, context) {
5456 assertNotInfinite(this.size);
5457 var returnValue = false;
5458 this.__iterate(function (v, k, c) {
5459 if (predicate.call(context, v, k, c)) {
5460 returnValue = true;
5461 return false;
5462 }
5463 });
5464 return returnValue;
5465 },
5466
5467 sort: function sort(comparator) {
5468 return reify(this, sortFactory(this, comparator));
5469 },
5470
5471 values: function values() {
5472 return this.__iterator(ITERATE_VALUES);
5473 },
5474
5475 // ### More sequential methods
5476
5477 butLast: function butLast() {
5478 return this.slice(0, -1);
5479 },
5480
5481 isEmpty: function isEmpty() {
5482 return this.size !== undefined ? this.size === 0 : !this.some(function () { return true; });
5483 },
5484
5485 count: function count(predicate, context) {
5486 return ensureSize(
5487 predicate ? this.toSeq().filter(predicate, context) : this
5488 );
5489 },
5490
5491 countBy: function countBy(grouper, context) {
5492 return countByFactory(this, grouper, context);
5493 },
5494
5495 equals: function equals(other) {
5496 return deepEqual(this, other);
5497 },
5498
5499 entrySeq: function entrySeq() {
5500 // eslint-disable-next-line @typescript-eslint/no-this-alias
5501 var collection = this;
5502 if (collection._cache) {
5503 // We cache as an entries array, so we can just return the cache!
5504 return new ArraySeq(collection._cache);
5505 }
5506 var entriesSequence = collection.toSeq().map(entryMapper).toIndexedSeq();
5507 entriesSequence.fromEntrySeq = function () { return collection.toSeq(); };
5508 return entriesSequence;
5509 },
5510
5511 filterNot: function filterNot(predicate, context) {
5512 return this.filter(not(predicate), context);
5513 },
5514
5515 findEntry: function findEntry(predicate, context, notSetValue) {
5516 var found = notSetValue;
5517 this.__iterate(function (v, k, c) {
5518 if (predicate.call(context, v, k, c)) {
5519 found = [k, v];
5520 return false;
5521 }
5522 });
5523 return found;
5524 },
5525
5526 findKey: function findKey(predicate, context) {
5527 var entry = this.findEntry(predicate, context);
5528 return entry && entry[0];
5529 },
5530
5531 findLast: function findLast(predicate, context, notSetValue) {
5532 return this.toKeyedSeq().reverse().find(predicate, context, notSetValue);
5533 },
5534
5535 findLastEntry: function findLastEntry(predicate, context, notSetValue) {
5536 return this.toKeyedSeq()
5537 .reverse()
5538 .findEntry(predicate, context, notSetValue);
5539 },
5540
5541 findLastKey: function findLastKey(predicate, context) {
5542 return this.toKeyedSeq().reverse().findKey(predicate, context);
5543 },
5544
5545 first: function first(notSetValue) {
5546 return this.find(returnTrue, null, notSetValue);
5547 },
5548
5549 flatMap: function flatMap(mapper, context) {
5550 return reify(this, flatMapFactory(this, mapper, context));
5551 },
5552
5553 flatten: function flatten(depth) {
5554 return reify(this, flattenFactory(this, depth, true));
5555 },
5556
5557 fromEntrySeq: function fromEntrySeq() {
5558 return new FromEntriesSequence(this);
5559 },
5560
5561 get: function get(searchKey, notSetValue) {
5562 return this.find(function (_, key) { return is(key, searchKey); }, undefined, notSetValue);
5563 },
5564
5565 getIn: getIn,
5566
5567 groupBy: function groupBy(grouper, context) {
5568 return groupByFactory(this, grouper, context);
5569 },
5570
5571 has: function has(searchKey) {
5572 return this.get(searchKey, NOT_SET) !== NOT_SET;
5573 },
5574
5575 hasIn: hasIn,
5576
5577 isSubset: function isSubset(iter) {
5578 iter = typeof iter.includes === 'function' ? iter : Collection(iter);
5579 return this.every(function (value) { return iter.includes(value); });
5580 },
5581
5582 isSuperset: function isSuperset(iter) {
5583 iter = typeof iter.isSubset === 'function' ? iter : Collection(iter);
5584 return iter.isSubset(this);
5585 },
5586
5587 keyOf: function keyOf(searchValue) {
5588 return this.findKey(function (value) { return is(value, searchValue); });
5589 },
5590
5591 keySeq: function keySeq() {
5592 return this.toSeq().map(keyMapper).toIndexedSeq();
5593 },
5594
5595 last: function last(notSetValue) {
5596 return this.toSeq().reverse().first(notSetValue);
5597 },
5598
5599 lastKeyOf: function lastKeyOf(searchValue) {
5600 return this.toKeyedSeq().reverse().keyOf(searchValue);
5601 },
5602
5603 max: function max(comparator) {
5604 return maxFactory(this, comparator);
5605 },
5606
5607 maxBy: function maxBy(mapper, comparator) {
5608 return maxFactory(this, comparator, mapper);
5609 },
5610
5611 min: function min(comparator) {
5612 return maxFactory(
5613 this,
5614 comparator ? neg(comparator) : defaultNegComparator
5615 );
5616 },
5617
5618 minBy: function minBy(mapper, comparator) {
5619 return maxFactory(
5620 this,
5621 comparator ? neg(comparator) : defaultNegComparator,
5622 mapper
5623 );
5624 },
5625
5626 rest: function rest() {
5627 return this.slice(1);
5628 },
5629
5630 skip: function skip(amount) {
5631 return amount === 0 ? this : this.slice(Math.max(0, amount));
5632 },
5633
5634 skipLast: function skipLast(amount) {
5635 return amount === 0 ? this : this.slice(0, -Math.max(0, amount));
5636 },
5637
5638 skipWhile: function skipWhile(predicate, context) {
5639 return reify(this, skipWhileFactory(this, predicate, context, true));
5640 },
5641
5642 skipUntil: function skipUntil(predicate, context) {
5643 return this.skipWhile(not(predicate), context);
5644 },
5645
5646 sortBy: function sortBy(mapper, comparator) {
5647 return reify(this, sortFactory(this, comparator, mapper));
5648 },
5649
5650 take: function take(amount) {
5651 return this.slice(0, Math.max(0, amount));
5652 },
5653
5654 takeLast: function takeLast(amount) {
5655 return this.slice(-Math.max(0, amount));
5656 },
5657
5658 takeWhile: function takeWhile(predicate, context) {
5659 return reify(this, takeWhileFactory(this, predicate, context));
5660 },
5661
5662 takeUntil: function takeUntil(predicate, context) {
5663 return this.takeWhile(not(predicate), context);
5664 },
5665
5666 update: function update(fn) {
5667 return fn(this);
5668 },
5669
5670 valueSeq: function valueSeq() {
5671 return this.toIndexedSeq();
5672 },
5673
5674 // ### Hashable Object
5675
5676 hashCode: function hashCode() {
5677 return this.__hash || (this.__hash = hashCollection(this));
5678 },
5679
5680 // ### Internal
5681
5682 // abstract __iterate(fn, reverse)
5683
5684 // abstract __iterator(type, reverse)
5685 });
5686
5687 var CollectionPrototype = Collection.prototype;
5688 CollectionPrototype[IS_COLLECTION_SYMBOL] = true;
5689 CollectionPrototype[ITERATOR_SYMBOL] = CollectionPrototype.values;
5690 CollectionPrototype.toJSON = CollectionPrototype.toArray;
5691 CollectionPrototype.__toStringMapper = quoteString;
5692 CollectionPrototype.inspect = CollectionPrototype.toSource = function () {
5693 return this.toString();
5694 };
5695 CollectionPrototype.chain = CollectionPrototype.flatMap;
5696 CollectionPrototype.contains = CollectionPrototype.includes;
5697
5698 mixin(KeyedCollection, {
5699 // ### More sequential methods
5700
5701 flip: function flip() {
5702 return reify(this, flipFactory(this));
5703 },
5704
5705 mapEntries: function mapEntries(mapper, context) {
5706 var this$1$1 = this;
5707
5708 var iterations = 0;
5709 return reify(
5710 this,
5711 this.toSeq()
5712 .map(function (v, k) { return mapper.call(context, [k, v], iterations++, this$1$1); })
5713 .fromEntrySeq()
5714 );
5715 },
5716
5717 mapKeys: function mapKeys(mapper, context) {
5718 var this$1$1 = this;
5719
5720 return reify(
5721 this,
5722 this.toSeq()
5723 .flip()
5724 .map(function (k, v) { return mapper.call(context, k, v, this$1$1); })
5725 .flip()
5726 );
5727 },
5728 });
5729
5730 var KeyedCollectionPrototype = KeyedCollection.prototype;
5731 KeyedCollectionPrototype[IS_KEYED_SYMBOL] = true;
5732 KeyedCollectionPrototype[ITERATOR_SYMBOL] = CollectionPrototype.entries;
5733 KeyedCollectionPrototype.toJSON = toObject;
5734 KeyedCollectionPrototype.__toStringMapper = function (v, k) { return quoteString(k) + ': ' + quoteString(v); };
5735
5736 mixin(IndexedCollection, {
5737 // ### Conversion to other types
5738
5739 toKeyedSeq: function toKeyedSeq() {
5740 return new ToKeyedSequence(this, false);
5741 },
5742
5743 // ### ES6 Collection methods (ES6 Array and Map)
5744
5745 filter: function filter(predicate, context) {
5746 return reify(this, filterFactory(this, predicate, context, false));
5747 },
5748
5749 findIndex: function findIndex(predicate, context) {
5750 var entry = this.findEntry(predicate, context);
5751 return entry ? entry[0] : -1;
5752 },
5753
5754 indexOf: function indexOf(searchValue) {
5755 var key = this.keyOf(searchValue);
5756 return key === undefined ? -1 : key;
5757 },
5758
5759 lastIndexOf: function lastIndexOf(searchValue) {
5760 var key = this.lastKeyOf(searchValue);
5761 return key === undefined ? -1 : key;
5762 },
5763
5764 reverse: function reverse() {
5765 return reify(this, reverseFactory(this, false));
5766 },
5767
5768 slice: function slice(begin, end) {
5769 return reify(this, sliceFactory(this, begin, end, false));
5770 },
5771
5772 splice: function splice(index, removeNum /*, ...values*/) {
5773 var numArgs = arguments.length;
5774 removeNum = Math.max(removeNum || 0, 0);
5775 if (numArgs === 0 || (numArgs === 2 && !removeNum)) {
5776 return this;
5777 }
5778 // If index is negative, it should resolve relative to the size of the
5779 // collection. However size may be expensive to compute if not cached, so
5780 // only call count() if the number is in fact negative.
5781 index = resolveBegin(index, index < 0 ? this.count() : this.size);
5782 var spliced = this.slice(0, index);
5783 return reify(
5784 this,
5785 numArgs === 1
5786 ? spliced
5787 : spliced.concat(arrCopy(arguments, 2), this.slice(index + removeNum))
5788 );
5789 },
5790
5791 // ### More collection methods
5792
5793 findLastIndex: function findLastIndex(predicate, context) {
5794 var entry = this.findLastEntry(predicate, context);
5795 return entry ? entry[0] : -1;
5796 },
5797
5798 first: function first(notSetValue) {
5799 return this.get(0, notSetValue);
5800 },
5801
5802 flatten: function flatten(depth) {
5803 return reify(this, flattenFactory(this, depth, false));
5804 },
5805
5806 get: function get(index, notSetValue) {
5807 index = wrapIndex(this, index);
5808 return index < 0 ||
5809 this.size === Infinity ||
5810 (this.size !== undefined && index > this.size)
5811 ? notSetValue
5812 : this.find(function (_, key) { return key === index; }, undefined, notSetValue);
5813 },
5814
5815 has: function has(index) {
5816 index = wrapIndex(this, index);
5817
5818 return (
5819 index >= 0 &&
5820 (this.size !== undefined
5821 ? this.size === Infinity || index < this.size
5822 : this.find(function (_, key) { return key === index; }, undefined, NOT_SET) !== NOT_SET)
5823 );
5824 },
5825
5826 interpose: function interpose(separator) {
5827 return reify(this, interposeFactory(this, separator));
5828 },
5829
5830 interleave: function interleave(/*...collections*/) {
5831 var collections = [this].concat(arrCopy(arguments));
5832 var zipped = zipWithFactory(this.toSeq(), IndexedSeq.of, collections);
5833 var interleaved = zipped.flatten(true);
5834 if (zipped.size) {
5835 interleaved.size = zipped.size * collections.length;
5836 }
5837 return reify(this, interleaved);
5838 },
5839
5840 keySeq: function keySeq() {
5841 return Range(0, this.size);
5842 },
5843
5844 last: function last(notSetValue) {
5845 return this.get(-1, notSetValue);
5846 },
5847
5848 skipWhile: function skipWhile(predicate, context) {
5849 return reify(this, skipWhileFactory(this, predicate, context, false));
5850 },
5851
5852 zip: function zip(/*, ...collections */) {
5853 var collections = [this].concat(arrCopy(arguments));
5854 return reify(this, zipWithFactory(this, defaultZipper, collections));
5855 },
5856
5857 zipAll: function zipAll(/*, ...collections */) {
5858 var collections = [this].concat(arrCopy(arguments));
5859 return reify(this, zipWithFactory(this, defaultZipper, collections, true));
5860 },
5861
5862 zipWith: function zipWith(zipper /*, ...collections */) {
5863 var collections = arrCopy(arguments);
5864 collections[0] = this;
5865 return reify(this, zipWithFactory(this, zipper, collections));
5866 },
5867 });
5868
5869 var IndexedCollectionPrototype = IndexedCollection.prototype;
5870 IndexedCollectionPrototype[IS_INDEXED_SYMBOL] = true;
5871 IndexedCollectionPrototype[IS_ORDERED_SYMBOL] = true;
5872
5873 mixin(SetCollection, {
5874 // ### ES6 Collection methods (ES6 Array and Map)
5875
5876 get: function get(value, notSetValue) {
5877 return this.has(value) ? value : notSetValue;
5878 },
5879
5880 includes: function includes(value) {
5881 return this.has(value);
5882 },
5883
5884 // ### More sequential methods
5885
5886 keySeq: function keySeq() {
5887 return this.valueSeq();
5888 },
5889 });
5890
5891 var SetCollectionPrototype = SetCollection.prototype;
5892 SetCollectionPrototype.has = CollectionPrototype.includes;
5893 SetCollectionPrototype.contains = SetCollectionPrototype.includes;
5894 SetCollectionPrototype.keys = SetCollectionPrototype.values;
5895
5896 // Mixin subclasses
5897
5898 mixin(KeyedSeq, KeyedCollectionPrototype);
5899 mixin(IndexedSeq, IndexedCollectionPrototype);
5900 mixin(SetSeq, SetCollectionPrototype);
5901
5902 // #pragma Helper functions
5903
5904 function defaultZipper() {
5905 return arrCopy(arguments);
5906 }
5907
5908 /**
5909 * True if `maybeOrderedSet` is an OrderedSet.
5910 */
5911 function isOrderedSet(maybeOrderedSet) {
5912 return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
5913 }
5914
5915 var OrderedSet = /*@__PURE__*/(function (Set) {
5916 function OrderedSet(value) {
5917 // eslint-disable-next-line no-constructor-return
5918 return value === undefined || value === null
5919 ? emptyOrderedSet()
5920 : isOrderedSet(value)
5921 ? value
5922 : emptyOrderedSet().withMutations(function (set) {
5923 var iter = SetCollection(value);
5924 assertNotInfinite(iter.size);
5925 iter.forEach(function (v) { return set.add(v); });
5926 });
5927 }
5928
5929 if ( Set ) OrderedSet.__proto__ = Set;
5930 OrderedSet.prototype = Object.create( Set && Set.prototype );
5931 OrderedSet.prototype.constructor = OrderedSet;
5932
5933 OrderedSet.of = function of (/*...values*/) {
5934 return this(arguments);
5935 };
5936
5937 OrderedSet.fromKeys = function fromKeys (value) {
5938 return this(KeyedCollection(value).keySeq());
5939 };
5940
5941 OrderedSet.prototype.toString = function toString () {
5942 return this.__toString('OrderedSet {', '}');
5943 };
5944
5945 return OrderedSet;
5946 }(Set));
5947
5948 OrderedSet.isOrderedSet = isOrderedSet;
5949
5950 var OrderedSetPrototype = OrderedSet.prototype;
5951 OrderedSetPrototype[IS_ORDERED_SYMBOL] = true;
5952 OrderedSetPrototype.zip = IndexedCollectionPrototype.zip;
5953 OrderedSetPrototype.zipWith = IndexedCollectionPrototype.zipWith;
5954 OrderedSetPrototype.zipAll = IndexedCollectionPrototype.zipAll;
5955
5956 OrderedSetPrototype.__empty = emptyOrderedSet;
5957 OrderedSetPrototype.__make = makeOrderedSet;
5958
5959 function makeOrderedSet(map, ownerID) {
5960 var set = Object.create(OrderedSetPrototype);
5961 set.size = map ? map.size : 0;
5962 set._map = map;
5963 set.__ownerID = ownerID;
5964 return set;
5965 }
5966
5967 var EMPTY_ORDERED_SET;
5968 function emptyOrderedSet() {
5969 return (
5970 EMPTY_ORDERED_SET || (EMPTY_ORDERED_SET = makeOrderedSet(emptyOrderedMap()))
5971 );
5972 }
5973
5974 /**
5975 * Describes which item in a pair should be placed first when sorting
5976 */
5977 var PairSorting = {
5978 LeftThenRight: -1,
5979 RightThenLeft: 1,
5980 };
5981
5982 function throwOnInvalidDefaultValues(defaultValues) {
5983 if (isRecord(defaultValues)) {
5984 throw new Error(
5985 'Can not call `Record` with an immutable Record as default values. Use a plain javascript object instead.'
5986 );
5987 }
5988
5989 if (isImmutable(defaultValues)) {
5990 throw new Error(
5991 'Can not call `Record` with an immutable Collection as default values. Use a plain javascript object instead.'
5992 );
5993 }
5994
5995 if (defaultValues === null || typeof defaultValues !== 'object') {
5996 throw new Error(
5997 'Can not call `Record` with a non-object as default values. Use a plain javascript object instead.'
5998 );
5999 }
6000 }
6001
6002 var Record = function Record(defaultValues, name) {
6003 var hasInitialized;
6004
6005 throwOnInvalidDefaultValues(defaultValues);
6006
6007 var RecordType = function Record(values) {
6008 var this$1$1 = this;
6009
6010 if (values instanceof RecordType) {
6011 return values;
6012 }
6013 if (!(this instanceof RecordType)) {
6014 return new RecordType(values);
6015 }
6016 if (!hasInitialized) {
6017 hasInitialized = true;
6018 var keys = Object.keys(defaultValues);
6019 var indices = (RecordTypePrototype._indices = {});
6020 // Deprecated: left to attempt not to break any external code which
6021 // relies on a ._name property existing on record instances.
6022 // Use Record.getDescriptiveName() instead
6023 RecordTypePrototype._name = name;
6024 RecordTypePrototype._keys = keys;
6025 RecordTypePrototype._defaultValues = defaultValues;
6026 for (var i = 0; i < keys.length; i++) {
6027 var propName = keys[i];
6028 indices[propName] = i;
6029 if (RecordTypePrototype[propName]) {
6030 /* eslint-disable no-console */
6031 // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
6032 typeof console === 'object' &&
6033 console.warn &&
6034 console.warn(
6035 'Cannot define ' +
6036 recordName(this) +
6037 ' with property "' +
6038 propName +
6039 '" since that property name is part of the Record API.'
6040 );
6041 /* eslint-enable no-console */
6042 } else {
6043 setProp(RecordTypePrototype, propName);
6044 }
6045 }
6046 }
6047 this.__ownerID = undefined;
6048 this._values = List().withMutations(function (l) {
6049 l.setSize(this$1$1._keys.length);
6050 KeyedCollection(values).forEach(function (v, k) {
6051 l.set(this$1$1._indices[k], v === this$1$1._defaultValues[k] ? undefined : v);
6052 });
6053 });
6054 return this;
6055 };
6056
6057 var RecordTypePrototype = (RecordType.prototype =
6058 Object.create(RecordPrototype));
6059 RecordTypePrototype.constructor = RecordType;
6060
6061 if (name) {
6062 RecordType.displayName = name;
6063 }
6064
6065 // eslint-disable-next-line no-constructor-return
6066 return RecordType;
6067 };
6068
6069 Record.prototype.toString = function toString () {
6070 var str = recordName(this) + ' { ';
6071 var keys = this._keys;
6072 var k;
6073 for (var i = 0, l = keys.length; i !== l; i++) {
6074 k = keys[i];
6075 str += (i ? ', ' : '') + k + ': ' + quoteString(this.get(k));
6076 }
6077 return str + ' }';
6078 };
6079
6080 Record.prototype.equals = function equals (other) {
6081 return (
6082 this === other ||
6083 (isRecord(other) && recordSeq(this).equals(recordSeq(other)))
6084 );
6085 };
6086
6087 Record.prototype.hashCode = function hashCode () {
6088 return recordSeq(this).hashCode();
6089 };
6090
6091 // @pragma Access
6092
6093 Record.prototype.has = function has (k) {
6094 return this._indices.hasOwnProperty(k);
6095 };
6096
6097 Record.prototype.get = function get (k, notSetValue) {
6098 if (!this.has(k)) {
6099 return notSetValue;
6100 }
6101 var index = this._indices[k];
6102 var value = this._values.get(index);
6103 return value === undefined ? this._defaultValues[k] : value;
6104 };
6105
6106 // @pragma Modification
6107
6108 Record.prototype.set = function set (k, v) {
6109 if (this.has(k)) {
6110 var newValues = this._values.set(
6111 this._indices[k],
6112 v === this._defaultValues[k] ? undefined : v
6113 );
6114 if (newValues !== this._values && !this.__ownerID) {
6115 return makeRecord(this, newValues);
6116 }
6117 }
6118 return this;
6119 };
6120
6121 Record.prototype.remove = function remove (k) {
6122 return this.set(k);
6123 };
6124
6125 Record.prototype.clear = function clear () {
6126 var newValues = this._values.clear().setSize(this._keys.length);
6127
6128 return this.__ownerID ? this : makeRecord(this, newValues);
6129 };
6130
6131 Record.prototype.wasAltered = function wasAltered () {
6132 return this._values.wasAltered();
6133 };
6134
6135 Record.prototype.toSeq = function toSeq () {
6136 return recordSeq(this);
6137 };
6138
6139 Record.prototype.toJS = function toJS$1 () {
6140 return toJS(this);
6141 };
6142
6143 Record.prototype.entries = function entries () {
6144 return this.__iterator(ITERATE_ENTRIES);
6145 };
6146
6147 Record.prototype.__iterator = function __iterator (type, reverse) {
6148 return recordSeq(this).__iterator(type, reverse);
6149 };
6150
6151 Record.prototype.__iterate = function __iterate (fn, reverse) {
6152 return recordSeq(this).__iterate(fn, reverse);
6153 };
6154
6155 Record.prototype.__ensureOwner = function __ensureOwner (ownerID) {
6156 if (ownerID === this.__ownerID) {
6157 return this;
6158 }
6159 var newValues = this._values.__ensureOwner(ownerID);
6160 if (!ownerID) {
6161 this.__ownerID = ownerID;
6162 this._values = newValues;
6163 return this;
6164 }
6165 return makeRecord(this, newValues, ownerID);
6166 };
6167
6168 Record.isRecord = isRecord;
6169 Record.getDescriptiveName = recordName;
6170 var RecordPrototype = Record.prototype;
6171 RecordPrototype[IS_RECORD_SYMBOL] = true;
6172 RecordPrototype[DELETE] = RecordPrototype.remove;
6173 RecordPrototype.deleteIn = RecordPrototype.removeIn = deleteIn;
6174 RecordPrototype.getIn = getIn;
6175 RecordPrototype.hasIn = CollectionPrototype.hasIn;
6176 RecordPrototype.merge = merge$1;
6177 RecordPrototype.mergeWith = mergeWith$1;
6178 RecordPrototype.mergeIn = mergeIn;
6179 RecordPrototype.mergeDeep = mergeDeep;
6180 RecordPrototype.mergeDeepWith = mergeDeepWith;
6181 RecordPrototype.mergeDeepIn = mergeDeepIn;
6182 RecordPrototype.setIn = setIn;
6183 RecordPrototype.update = update;
6184 RecordPrototype.updateIn = updateIn$1;
6185 RecordPrototype.withMutations = withMutations;
6186 RecordPrototype.asMutable = asMutable;
6187 RecordPrototype.asImmutable = asImmutable;
6188 RecordPrototype[ITERATOR_SYMBOL] = RecordPrototype.entries;
6189 RecordPrototype.toJSON = RecordPrototype.toObject =
6190 CollectionPrototype.toObject;
6191 RecordPrototype.inspect = RecordPrototype.toSource = function () {
6192 return this.toString();
6193 };
6194
6195 function makeRecord(likeRecord, values, ownerID) {
6196 var record = Object.create(Object.getPrototypeOf(likeRecord));
6197 record._values = values;
6198 record.__ownerID = ownerID;
6199 return record;
6200 }
6201
6202 function recordName(record) {
6203 return record.constructor.displayName || record.constructor.name || 'Record';
6204 }
6205
6206 function recordSeq(record) {
6207 return keyedSeqFromValue(record._keys.map(function (k) { return [k, record.get(k)]; }));
6208 }
6209
6210 function setProp(prototype, name) {
6211 try {
6212 Object.defineProperty(prototype, name, {
6213 get: function () {
6214 return this.get(name);
6215 },
6216 set: function (value) {
6217 invariant(this.__ownerID, 'Cannot set on an immutable record.');
6218 this.set(name, value);
6219 },
6220 });
6221 // eslint-disable-next-line @typescript-eslint/no-unused-vars -- TODO enable eslint here
6222 } catch (error) {
6223 // Object.defineProperty failed. Probably IE8.
6224 }
6225 }
6226
6227 /**
6228 * Returns a lazy Seq of `value` repeated `times` times. When `times` is
6229 * undefined, returns an infinite sequence of `value`.
6230 */
6231 var Repeat = /*@__PURE__*/(function (IndexedSeq) {
6232 function Repeat(value, times) {
6233 if (!(this instanceof Repeat)) {
6234 // eslint-disable-next-line no-constructor-return
6235 return new Repeat(value, times);
6236 }
6237 this._value = value;
6238 this.size = times === undefined ? Infinity : Math.max(0, times);
6239 if (this.size === 0) {
6240 if (EMPTY_REPEAT) {
6241 // eslint-disable-next-line no-constructor-return
6242 return EMPTY_REPEAT;
6243 }
6244 // eslint-disable-next-line @typescript-eslint/no-this-alias
6245 EMPTY_REPEAT = this;
6246 }
6247 }
6248
6249 if ( IndexedSeq ) Repeat.__proto__ = IndexedSeq;
6250 Repeat.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
6251 Repeat.prototype.constructor = Repeat;
6252
6253 Repeat.prototype.toString = function toString () {
6254 if (this.size === 0) {
6255 return 'Repeat []';
6256 }
6257 return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]';
6258 };
6259
6260 Repeat.prototype.get = function get (index, notSetValue) {
6261 return this.has(index) ? this._value : notSetValue;
6262 };
6263
6264 Repeat.prototype.includes = function includes (searchValue) {
6265 return is(this._value, searchValue);
6266 };
6267
6268 Repeat.prototype.slice = function slice (begin, end) {
6269 var size = this.size;
6270 return wholeSlice(begin, end, size)
6271 ? this
6272 : new Repeat(
6273 this._value,
6274 resolveEnd(end, size) - resolveBegin(begin, size)
6275 );
6276 };
6277
6278 Repeat.prototype.reverse = function reverse () {
6279 return this;
6280 };
6281
6282 Repeat.prototype.indexOf = function indexOf (searchValue) {
6283 if (this.size !== 0 && is(this._value, searchValue)) {
6284 return 0;
6285 }
6286 return -1;
6287 };
6288
6289 Repeat.prototype.lastIndexOf = function lastIndexOf (searchValue) {
6290 if (this.size !== 0 && is(this._value, searchValue)) {
6291 return this.size - 1;
6292 }
6293 return -1;
6294 };
6295
6296 Repeat.prototype.__iterate = function __iterate (fn, reverse) {
6297 var size = this.size;
6298 var i = 0;
6299 while (i !== size) {
6300 if (fn(this._value, reverse ? size - ++i : i++, this) === false) {
6301 break;
6302 }
6303 }
6304 return i;
6305 };
6306
6307 Repeat.prototype.__iterator = function __iterator (type, reverse) {
6308 var this$1$1 = this;
6309
6310 var size = this.size;
6311 var i = 0;
6312 return new Iterator(function () { return i === size
6313 ? iteratorDone()
6314 : iteratorValue(type, reverse ? size - ++i : i++, this$1$1._value); }
6315 );
6316 };
6317
6318 Repeat.prototype.equals = function equals (other) {
6319 return other instanceof Repeat
6320 ? is(this._value, other._value)
6321 : deepEqual(this, other);
6322 };
6323
6324 return Repeat;
6325 }(IndexedSeq));
6326
6327 var EMPTY_REPEAT;
6328
6329 function fromJS(value, converter) {
6330 return fromJSWith(
6331 [],
6332 converter || defaultConverter,
6333 value,
6334 '',
6335 converter && converter.length > 2 ? [] : undefined,
6336 { '': value }
6337 );
6338 }
6339
6340 function fromJSWith(stack, converter, value, key, keyPath, parentValue) {
6341 if (
6342 typeof value !== 'string' &&
6343 !isImmutable(value) &&
6344 (isArrayLike(value) || hasIterator(value) || isPlainObject(value))
6345 ) {
6346 if (~stack.indexOf(value)) {
6347 throw new TypeError('Cannot convert circular structure to Immutable');
6348 }
6349 stack.push(value);
6350 // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
6351 keyPath && key !== '' && keyPath.push(key);
6352 var converted = converter.call(
6353 parentValue,
6354 key,
6355 Seq(value).map(function (v, k) { return fromJSWith(stack, converter, v, k, keyPath, value); }
6356 ),
6357 keyPath && keyPath.slice()
6358 );
6359 stack.pop();
6360 // eslint-disable-next-line @typescript-eslint/no-unused-expressions -- TODO enable eslint here
6361 keyPath && keyPath.pop();
6362 return converted;
6363 }
6364 return value;
6365 }
6366
6367 function defaultConverter(k, v) {
6368 // Effectively the opposite of "Collection.toSeq()"
6369 return isIndexed(v) ? v.toList() : isKeyed(v) ? v.toMap() : v.toSet();
6370 }
6371
6372 var version = "5.1.9";
6373
6374 /* eslint-disable import/order */
6375
6376 // Note: Iterable is deprecated
6377 var Iterable = Collection;
6378
6379 exports.Collection = Collection;
6380 exports.Iterable = Iterable;
6381 exports.List = List;
6382 exports.Map = Map;
6383 exports.OrderedMap = OrderedMap;
6384 exports.OrderedSet = OrderedSet;
6385 exports.PairSorting = PairSorting;
6386 exports.Range = Range;
6387 exports.Record = Record;
6388 exports.Repeat = Repeat;
6389 exports.Seq = Seq;
6390 exports.Set = Set;
6391 exports.Stack = Stack;
6392 exports.fromJS = fromJS;
6393 exports.get = get;
6394 exports.getIn = getIn$1;
6395 exports.has = has;
6396 exports.hasIn = hasIn$1;
6397 exports.hash = hash;
6398 exports.is = is;
6399 exports.isAssociative = isAssociative;
6400 exports.isCollection = isCollection;
6401 exports.isImmutable = isImmutable;
6402 exports.isIndexed = isIndexed;
6403 exports.isKeyed = isKeyed;
6404 exports.isList = isList;
6405 exports.isMap = isMap;
6406 exports.isOrdered = isOrdered;
6407 exports.isOrderedMap = isOrderedMap;
6408 exports.isOrderedSet = isOrderedSet;
6409 exports.isPlainObject = isPlainObject;
6410 exports.isRecord = isRecord;
6411 exports.isSeq = isSeq;
6412 exports.isSet = isSet;
6413 exports.isStack = isStack;
6414 exports.isValueObject = isValueObject;
6415 exports.merge = merge;
6416 exports.mergeDeep = mergeDeep$1;
6417 exports.mergeDeepWith = mergeDeepWith$1;
6418 exports.mergeWith = mergeWith;
6419 exports.remove = remove;
6420 exports.removeIn = removeIn;
6421 exports.set = set;
6422 exports.setIn = setIn$1;
6423 exports.update = update$1;
6424 exports.updateIn = updateIn;
6425 exports.version = version;
6426
6427 }));