time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

immutable.es.js (160017B)


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