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