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