source: imaps-frontend/node_modules/immutable/dist/immutable.js

main
Last change on this file was 0c6b92a, checked in by stefan toskovski <stefantoska84@…>, 5 weeks ago

Pred finalna verzija

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