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