/** * Copyright (c) 2014-2015, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory.
*/
var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@'; var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@'; var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@'; var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
// Used for setting prototype methods that IE8 chokes on. varDELETE = 'delete';
// Constants describing the size of trie nodes. var SHIFT = 5; // Resulted in best performance after ______? var SIZE = 1 << SHIFT; var MASK = SIZE - 1;
// A consistent shared value representing "not set" which equals nothing other // than itself, and nothing that could be provided externally. var NOT_SET = {};
// Boolean references, Rough equivalent of `bool &`. var CHANGE_LENGTH = { value: false }; var DID_ALTER = { value: false };
function MakeRef(ref) {
ref.value = false; return ref;
}
function SetRef(ref) {
ref && (ref.value = true);
}
// A function which returns a value representing an "owner" for transient writes // to tries. The return value will only ever equal itself, and will not equal // the return of any subsequent call of this function. function OwnerID() {}
// http://jsperf.com/copy-array-inline function arrCopy(arr, offset) {
offset = offset || 0; var len = Math.max(0, arr.length - offset); var newArr = new Array(len); for (var ii = 0; ii < len; ii++) {
newArr[ii] = arr[ii + offset];
} return newArr;
}
function ensureSize(iter) { if (iter.size === undefined) {
iter.size = iter.__iterate(returnTrue);
} return iter.size;
}
function wrapIndex(iter, index) { // This implements "is array index" which the ECMAString spec defines as: // // A String property name P is an array index if and only if // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal // to 2^32−1. // // http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects if (typeof index !== 'number') { var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32 if ('' + uint32Index !== index || uint32Index === 4294967295) { return NaN;
}
index = uint32Index;
} return index < 0 ? ensureSize(iter) + index : index;
}
function returnTrue() { returntrue;
}
function wholeSlice(begin, end, size) { return (begin === 0 || (size !== undefined && begin <= -size)) &&
(end === undefined || (size !== undefined && end >= size));
}
function resolveBegin(begin, size) { return resolveIndex(begin, size, 0);
}
function resolveEnd(end, size) { return resolveIndex(end, size, size);
}
function resolveIndex(index, size, defaultIndex) { return index === undefined ?
defaultIndex :
index < 0 ?
Math.max(0, size + index) :
size === undefined ?
index :
Math.min(size, index);
}
/* global Symbol */
var ITERATE_KEYS = 0; var ITERATE_VALUES = 1; var ITERATE_ENTRIES = 2;
var REAL_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator; var FAUX_ITERATOR_SYMBOL = '@@iterator';
var ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL;
IteratorSeq.prototype.__iterateUncached = function(fn, reverse) { if (reverse) { returnthis.cacheResult().__iterate(fn, reverse);
} var iterator = this._iterator; var cache = this._iteratorCache; var iterations = 0; while (iterations < cache.length) { if (fn(cache[iterations], iterations++, this) === false) { return iterations;
}
} var step; while (!(step = iterator.next()).done) { var val = step.value;
cache[iterations] = val; if (fn(val, iterations++, this) === false) { break;
}
} return iterations;
};
IteratorSeq.prototype.__iteratorUncached = function(type, reverse) { if (reverse) { returnthis.cacheResult().__iterator(type, reverse);
} var iterator = this._iterator; var cache = this._iteratorCache; var iterations = 0; returnnew Iterator(function() { if (iterations >= cache.length) { var step = iterator.next(); if (step.done) { return step;
}
cache[iterations] = step.value;
} return iteratorValue(type, iterations, cache[iterations++]);
});
};
// # pragma Helper functions
function isSeq(maybeSeq) { return !!(maybeSeq && maybeSeq[IS_SEQ_SENTINEL]);
}
var EMPTY_SEQ;
function emptySequence() { return EMPTY_SEQ || (EMPTY_SEQ = new ArraySeq([]));
}
function keyedSeqFromValue(value) { var seq =
Array.isArray(value) ? new ArraySeq(value).fromEntrySeq() :
isIterator(value) ? new IteratorSeq(value).fromEntrySeq() :
hasIterator(value) ? new IterableSeq(value).fromEntrySeq() : typeof value === 'object' ? new ObjectSeq(value) :
undefined; if (!seq) { thrownew TypeError( 'Expected Array or iterable object of [k, v] entries, '+ 'or keyed object: ' + value
);
} return seq;
}
function indexedSeqFromValue(value) { var seq = maybeIndexedSeqFromValue(value); if (!seq) { thrownew TypeError( 'Expected Array or iterable object of values: ' + value
);
} return seq;
}
function seqFromValue(value) { var seq = maybeIndexedSeqFromValue(value) ||
(typeof value === 'object' && new ObjectSeq(value)); if (!seq) { thrownew TypeError( 'Expected Array or iterable object of values, or keyed object: ' + value
);
} return seq;
}
function maybeIndexedSeqFromValue(value) { return (
isArrayLike(value) ? new ArraySeq(value) :
isIterator(value) ? new IteratorSeq(value) :
hasIterator(value) ? new IterableSeq(value) :
undefined
);
}
function seqIterate(seq, fn, reverse, useKeys) { var cache = seq._cache; if (cache) { var maxIndex = cache.length - 1; for (var ii = 0; ii <= maxIndex; ii++) { var entry = cache[reverse ? maxIndex - ii : ii]; if (fn(entry[1], useKeys ? entry[0] : ii, seq) === false) { return ii + 1;
}
} return ii;
} return seq.__iterateUncached(fn, reverse);
}
function seqIterator(seq, type, reverse, useKeys) { var cache = seq._cache; if (cache) { var maxIndex = cache.length - 1; var ii = 0; returnnew Iterator(function() { var entry = cache[reverse ? maxIndex - ii : ii]; return ii++ > maxIndex ?
iteratorDone() :
iteratorValue(type, useKeys ? entry[0] : ii - 1, entry[1]);
});
} return seq.__iteratorUncached(type, reverse);
}
function fromJSDefault(json) { if (Array.isArray(json)) { return IndexedSeq(json).map(fromJSDefault).toList();
} if (isPlainObj(json)) { return KeyedSeq(json).map(fromJSDefault).toMap();
} return json;
}
function isPlainObj(value) { return value && (value.constructor === Object || value.constructor === undefined);
}
/** * An extension of the "same-value" algorithm as [described for use by ES6 Map * and Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality) * * NaN is considered the same as NaN, however -0 and 0 are considered the same * value, which is different from the algorithm described by * [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is). * * This is extended further to allow Objects to describe the values they * represent, by way of `valueOf` or `equals` (and `hashCode`). * * Note: because of this extension, the key equality of Immutable.Map and the * value equality of Immutable.Set will differ from ES6 Map and Set. * * ### Defining custom values * * The easiest way to describe the value an object represents is by implementing * `valueOf`. For example, `Date` represents a value by returning a unix * timestamp for `valueOf`: * * var date1 = new Date(1234567890000); // Fri Feb 13 2009 ... * var date2 = new Date(1234567890000); * date1.valueOf(); // 1234567890000 * assert( date1 !== date2 ); * assert( Immutable.is( date1, date2 ) ); * * Note: overriding `valueOf` may have other implications if you use this object * where JavaScript expects a primitive, such as implicit string coercion. * * For more complex types, especially collections, implementing `valueOf` may * not be performant. An alternative is to implement `equals` and `hashCode`. * * `equals` takes another object, presumably of similar type, and returns true * if the it is equal. Equality is symmetrical, so the same result should be * returned if this and the argument are flipped. * * assert( a.equals(b) === b.equals(a) ); * * `hashCode` returns a 32bit integer number representing the object which will * be used to determine how to store the value object in a Map or Set. You must * provide both or neither methods, one must not exist without the other. * * Also, an important relationship between these methods must be upheld: if two * values are equal, they *must* return the same hashCode. If the values are not * equal, they might have the same hashCode; this is called a hash collision, * and while undesirable for performance reasons, it is acceptable. * * if (a.equals(b)) { * assert( a.hashCode() === b.hashCode() ); * } * * All Immutable collections implement `equals` and `hashCode`. *
*/ function is(valueA, valueB) { if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) { returntrue;
} if (!valueA || !valueB) { returnfalse;
} if (typeof valueA.valueOf === 'function' && typeof valueB.valueOf === 'function') {
valueA = valueA.valueOf();
valueB = valueB.valueOf(); if (valueA === valueB || (valueA !== valueA && valueB !== valueB)) { returntrue;
} if (!valueA || !valueB) { returnfalse;
}
} if (typeof valueA.equals === 'function' && typeof valueB.equals === 'function' &&
valueA.equals(valueB)) { returntrue;
} returnfalse;
}
function deepEqual(a, b) { if (a === b) { returntrue;
}
var imul = typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2 ?
Math.imul : function imul(a, b) {
a = a | 0; // int
b = b | 0; // int var c = a & 0xffff; var d = b & 0xffff; // Shift by 0 fixes the sign on the high part. return (c * d) + ((((a >>> 16) * d + c * (b >>> 16)) << 16) >>> 0) | 0; // int
};
// v8 has an optimization for storing 31-bit signed numbers. // Values which have either 00 or 11 as the high order bits qualify. // This function drops the highest order bit in a signed number, maintaining // the sign bit. function smi(i32) { return ((i32 >>> 1) & 0x40000000) | (i32 & 0xBFFFFFFF);
}
function hash(o) { if (o === false || o === null || o === undefined) { return 0;
} if (typeof o.valueOf === 'function') {
o = o.valueOf(); if (o === false || o === null || o === undefined) { return 0;
}
} if (o === true) { return 1;
} var type = typeof o; if (type === 'number') { var h = o | 0; if (h !== o) {
h ^= o * 0xFFFFFFFF;
} while (o > 0xFFFFFFFF) {
o /= 0xFFFFFFFF;
h ^= o;
} return smi(h);
} if (type === 'string') { return o.length > STRING_HASH_CACHE_MIN_STRLEN ? cachedHashString(o) : hashString(o);
} if (typeof o.hashCode === 'function') { return o.hashCode();
} if (type === 'object') { return hashJSObj(o);
} if (typeof o.toString === 'function') { return hashString(o.toString());
} thrownew Error('Value type ' + type + ' cannot be hashed.');
}
function cachedHashString(string) { var hash = stringHashCache[string]; if (hash === undefined) {
hash = hashString(string); if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
STRING_HASH_CACHE_SIZE = 0;
stringHashCache = {};
}
STRING_HASH_CACHE_SIZE++;
stringHashCache[string] = hash;
} return hash;
}
// http://jsperf.com/hashing-strings function hashString(string) { // This is the hash from JVM // The hash code for a string is computed as // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1], // where s[i] is the ith character of the string and n is the length of // the string. We "mod" the result to make it between 0 (inclusive) and 2^31 // (exclusive) by dropping high bits. var hash = 0; for (var ii = 0; ii < string.length; ii++) {
hash = 31 * hash + string.charCodeAt(ii) | 0;
} return smi(hash);
}
function hashJSObj(obj) { var hash; if (usingWeakMap) {
hash = weakMap.get(obj); if (hash !== undefined) { return hash;
}
}
if (usingWeakMap) {
weakMap.set(obj, hash);
} elseif (isExtensible !== undefined && isExtensible(obj) === false) { thrownew Error('Non-extensible objects are not allowed as keys.');
} elseif (canDefineProperty) {
Object.defineProperty(obj, UID_HASH_KEY, { 'enumerable': false, 'configurable': false, 'writable': false, 'value': hash
});
} elseif (obj.propertyIsEnumerable !== undefined &&
obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable) { // Since we can't define a non-enumerable property on the object // we'll hijack one of the less-used non-enumerable properties to // save our hash on it. Since this is a function it will not show up in // `JSON.stringify` which is what we want.
obj.propertyIsEnumerable = function() { returnthis.constructor.prototype.propertyIsEnumerable.apply(this, arguments);
};
obj.propertyIsEnumerable[UID_HASH_KEY] = hash;
} elseif (obj.nodeType !== undefined) { // At this point we couldn't get the IE `uniqueID` to use as a hash // and we couldn't use a non-enumerable property to exploit the // dontEnum bug so we simply add the `UID_HASH_KEY` on the node // itself.
obj[UID_HASH_KEY] = hash;
} else { thrownew Error('Unable to set a non-enumerable property on object.');
}
return hash;
}
// Get references to ES5 object methods. var isExtensible = Object.isExtensible;
// True if Object.defineProperty works as expected. IE8 fails this test. var canDefineProperty = (function() { try {
Object.defineProperty({}, '@', {}); returntrue;
} catch (e) { returnfalse;
}
}());
// IE has a `uniqueID` property on DOM nodes. We can construct the hash from it // and avoid memory leaks from the IE cloneNode bug. function getIENodeHash(node) { if (node && node.nodeType > 0) { switch (node.nodeType) { case 1: // Element return node.uniqueID; case 9: // Document return node.documentElement && node.documentElement.uniqueID;
}
}
}
// If possible, use a WeakMap. var usingWeakMap = typeof WeakMap === 'function'; var weakMap; if (usingWeakMap) {
weakMap = new WeakMap();
}
var objHashUID = 0;
var UID_HASH_KEY = '__immutablehash__'; if (typeof Symbol === 'function') {
UID_HASH_KEY = Symbol(UID_HASH_KEY);
}
var STRING_HASH_CACHE_MIN_STRLEN = 16; var STRING_HASH_CACHE_MAX_SIZE = 255; var STRING_HASH_CACHE_SIZE = 0; var stringHashCache = {};
function assertNotInfinite(size) {
invariant(
size !== Infinity, 'Cannot perform this action with an infinite size.'
);
}
createClass(Map, KeyedCollection);
// @pragma Construction
function Map(value) { return value === null || value === undefined ? emptyMap() :
isMap(value) && !isOrdered(value) ? value :
emptyMap().withMutations(function(map ) { var iter = KeyedIterable(value);
assertNotInfinite(iter.size);
iter.forEach(function(v, k) {return map.set(k, v)});
});
}
Map.of = function() {var keyValues = SLICE$0.call(arguments, 0); return emptyMap().withMutations(function(map ) { for (var i = 0; i < keyValues.length; i += 2) { if (i + 1 >= keyValues.length) { thrownew Error('Missing value for key: ' + keyValues[i]);
}
map.set(keyValues[i], keyValues[i + 1]);
}
});
};
function createNodes(ownerID, entries, key, value) { if (!ownerID) {
ownerID = new OwnerID();
} var node = new ValueNode(ownerID, hash(key), [key, value]); for (var ii = 0; ii < entries.length; ii++) { var entry = entries[ii];
node = node.update(ownerID, 0, undefined, entry[0], entry[1]);
} return node;
}
function packNodes(ownerID, nodes, count, excluding) { var bitmap = 0; var packedII = 0; var packedNodes = new Array(count); for (var ii = 0, bit = 1, len = nodes.length; ii < len; ii++, bit <<= 1) { var node = nodes[ii]; if (node !== undefined && ii !== excluding) {
bitmap |= bit;
packedNodes[packedII++] = node;
}
} returnnew BitmapIndexedNode(ownerID, bitmap, packedNodes);
}
function expandNodes(ownerID, nodes, bitmap, including, node) { var count = 0; var expandedNodes = new Array(SIZE); for (var ii = 0; bitmap !== 0; ii++, bitmap >>>= 1) {
expandedNodes[ii] = bitmap & 1 ? nodes[count++] : undefined;
}
expandedNodes[including] = node; returnnew HashArrayMapNode(ownerID, count + 1, expandedNodes);
}
function mergeIntoMapWith(map, merger, iterables) { var iters = []; for (var ii = 0; ii < iterables.length; ii++) { var value = iterables[ii]; var iter = KeyedIterable(value); if (!isIterable(value)) {
iter = iter.map(function(v ) {return fromJS(v)});
}
iters.push(iter);
} return mergeIntoCollectionWith(map, merger, iters);
}
function popCount(x) {
x = x - ((x >> 1) & 0x55555555);
x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
x = (x + (x >> 4)) & 0x0f0f0f0f;
x = x + (x >> 8);
x = x + (x >> 16); return x & 0x7f;
}
function setIn(array, idx, val, canEdit) { var newArray = canEdit ? array : arrCopy(array);
newArray[idx] = val; return newArray;
}
function spliceIn(array, idx, val, canEdit) { var newLen = array.length + 1; if (canEdit && idx + 1 === newLen) {
array[idx] = val; return array;
} var newArray = new Array(newLen); var after = 0; for (var ii = 0; ii < newLen; ii++) { if (ii === idx) {
newArray[ii] = val;
after = -1;
} else {
newArray[ii] = array[ii + after];
}
} return newArray;
}
function spliceOut(array, idx, canEdit) { var newLen = array.length - 1; if (canEdit && idx === newLen) {
array.pop(); return array;
} var newArray = new Array(newLen); var after = 0; for (var ii = 0; ii < newLen; ii++) { if (ii === idx) {
after = 1;
}
newArray[ii] = array[ii + after];
} return newArray;
}
var MAX_ARRAY_MAP_SIZE = SIZE / 4; var MAX_BITMAP_INDEXED_SIZE = SIZE / 2; var MIN_HASH_ARRAY_MAP_SIZE = SIZE / 4;
createClass(List, IndexedCollection);
// @pragma Construction
function List(value) { var empty = emptyList(); if (value === null || value === undefined) { return empty;
} if (isList(value)) { return value;
} var iter = IndexedIterable(value); var size = iter.size; if (size === 0) { return empty;
}
assertNotInfinite(size); if (size > 0 && size < SIZE) { return makeList(0, size, SHIFT, null, new VNode(iter.toArray()));
} return empty.withMutations(function(list ) {
list.setSize(size);
iter.forEach(function(v, i) {return list.set(i, v)});
});
}
function listNodeFor(list, rawIndex) { if (rawIndex >= getTailOffset(list._capacity)) { return list._tail;
} if (rawIndex < 1 << (list._level + SHIFT)) { var node = list._root; var level = list._level; while (node && level > 0) {
node = node.array[(rawIndex >>> level) & MASK];
level -= SHIFT;
} return node;
}
}
function setListBounds(list, begin, end) { // Sanitize begin & end using this shorthand for ToInt32(argument) // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32 if (begin !== undefined) {
begin = begin | 0;
} if (end !== undefined) {
end = end | 0;
} var owner = list.__ownerID || new OwnerID(); var oldOrigin = list._origin; var oldCapacity = list._capacity; var newOrigin = oldOrigin + begin; var newCapacity = end === undefined ? oldCapacity : end < 0 ? oldCapacity + end : oldOrigin + end; if (newOrigin === oldOrigin && newCapacity === oldCapacity) { return list;
}
// If it's going to end after it starts, it's empty. if (newOrigin >= newCapacity) { return list.clear();
}
var newLevel = list._level; var newRoot = list._root;
// New origin might need creating a higher root. var offsetShift = 0; while (newOrigin + offsetShift < 0) {
newRoot = new VNode(newRoot && newRoot.array.length ? [undefined, newRoot] : [], owner);
newLevel += SHIFT;
offsetShift += 1 << newLevel;
} if (offsetShift) {
newOrigin += offsetShift;
oldOrigin += offsetShift;
newCapacity += offsetShift;
oldCapacity += offsetShift;
}
var oldTailOffset = getTailOffset(oldCapacity); var newTailOffset = getTailOffset(newCapacity);
// New size might need creating a higher root. while (newTailOffset >= 1 << (newLevel + SHIFT)) {
newRoot = new VNode(newRoot && newRoot.array.length ? [newRoot] : [], owner);
newLevel += SHIFT;
}
// Locate or create the new tail. var oldTail = list._tail; var newTail = newTailOffset < oldTailOffset ?
listNodeFor(list, newCapacity - 1) :
newTailOffset > oldTailOffset ? new VNode([], owner) : oldTail;
// If the size has been reduced, there's a chance the tail needs to be trimmed. if (newCapacity < oldCapacity) {
newTail = newTail && newTail.removeAfter(owner, 0, newCapacity);
}
// If the new origin is within the tail, then we do not need a root. if (newOrigin >= newTailOffset) {
newOrigin -= newTailOffset;
newCapacity -= newTailOffset;
newLevel = SHIFT;
newRoot = null;
newTail = newTail && newTail.removeBefore(owner, 0, newOrigin);
// Otherwise, if the root has been trimmed, garbage collect.
} elseif (newOrigin > oldOrigin || newTailOffset < oldTailOffset) {
offsetShift = 0;
// Identify the new top root node of the subtree of the old root. while (newRoot) { var beginIndex = (newOrigin >>> newLevel) & MASK; if (beginIndex !== (newTailOffset >>> newLevel) & MASK) { break;
} if (beginIndex) {
offsetShift += (1 << newLevel) * beginIndex;
}
newLevel -= SHIFT;
newRoot = newRoot.array[beginIndex];
}
// Trim the new sides of the new root. if (newRoot && newOrigin > oldOrigin) {
newRoot = newRoot.removeBefore(owner, newLevel, newOrigin - offsetShift);
} if (newRoot && newTailOffset < oldTailOffset) {
newRoot = newRoot.removeAfter(owner, newLevel, newTailOffset - offsetShift);
} if (offsetShift) {
newOrigin -= offsetShift;
newCapacity -= offsetShift;
}
}
function mergeIntoListWith(list, merger, iterables) { var iters = []; var maxSize = 0; for (var ii = 0; ii < iterables.length; ii++) { var value = iterables[ii]; var iter = IndexedIterable(value); if (iter.size > maxSize) {
maxSize = iter.size;
} if (!isIterable(value)) {
iter = iter.map(function(v ) {return fromJS(v)});
}
iters.push(iter);
} if (maxSize > list.size) {
list = list.setSize(maxSize);
} return mergeIntoCollectionWith(list, merger, iters);
}
if (wholeSlice(begin, end, originalSize)) { return iterable;
}
var resolvedBegin = resolveBegin(begin, originalSize); var resolvedEnd = resolveEnd(end, originalSize);
// begin or end will be NaN if they were provided as negative numbers and // this iterable's size is unknown. In that case, cache first so there is // a known size and these do not resolve to NaN. if (resolvedBegin !== resolvedBegin || resolvedEnd !== resolvedEnd) { return sliceFactory(iterable.toSeq().cacheResult(), begin, end, useKeys);
}
// Note: resolvedEnd is undefined when the original sequence's length is // unknown and this slice did not supply an end and should contain all // elements after resolvedBegin. // In that case, resolvedSize will be NaN and sliceSize will remain undefined. var resolvedSize = resolvedEnd - resolvedBegin; var sliceSize; if (resolvedSize === resolvedSize) {
sliceSize = resolvedSize < 0 ? 0 : resolvedSize;
}
var sliceSeq = makeSequence(iterable);
// If iterable.size is undefined, the size of the realized sliceSeq is // unknown at this point unless the number of items to slice is 0
sliceSeq.size = sliceSize === 0 ? sliceSize : iterable.size && sliceSize || undefined;
if (!useKeys && isSeq(iterable) && sliceSize >= 0) {
sliceSeq.get = function (index, notSetValue) {
index = wrapIndex(this, index); return index >= 0 && index < sliceSize ?
iterable.get(index + resolvedBegin, notSetValue) :
notSetValue;
}
}
sliceSeq.__iterateUncached = function(fn, reverse) {varthis$0 = this; if (sliceSize === 0) { return 0;
} if (reverse) { returnthis.cacheResult().__iterate(fn, reverse);
} var skipped = 0; var isSkipping = true; var iterations = 0;
iterable.__iterate(function(v, k) { if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) {
iterations++; return fn(v, useKeys ? k : iterations - 1, this$0) !== false &&
iterations !== sliceSize;
}
}); return iterations;
};
sliceSeq.__iteratorUncached = function(type, reverse) { if (sliceSize !== 0 && reverse) { returnthis.cacheResult().__iterator(type, reverse);
} // Don't bother instantiating parent iterator if taking 0. var iterator = sliceSize !== 0 && iterable.__iterator(type, reverse); var skipped = 0; var iterations = 0; returnnew Iterator(function() { while (skipped++ < resolvedBegin) {
iterator.next();
} if (++iterations > sliceSize) { return iteratorDone();
} var step = iterator.next(); if (useKeys || type === ITERATE_VALUES) { return step;
} elseif (type === ITERATE_KEYS) { return iteratorValue(type, iterations - 1, undefined, step);
} else { return iteratorValue(type, iterations - 1, step.value[1], step);
}
});
}
return sliceSeq;
}
function takeWhileFactory(iterable, predicate, context) { var takeSequence = makeSequence(iterable);
takeSequence.__iterateUncached = function(fn, reverse) {varthis$0 = this; if (reverse) { returnthis.cacheResult().__iterate(fn, reverse);
} var iterations = 0;
iterable.__iterate(function(v, k, c)
{return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$0)}
); return iterations;
};
takeSequence.__iteratorUncached = function(type, reverse) {varthis$0 = this; if (reverse) { returnthis.cacheResult().__iterator(type, reverse);
} var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse); var iterating = true; returnnew Iterator(function() { if (!iterating) { return iteratorDone();
} var step = iterator.next(); if (step.done) { return step;
} var entry = step.value; var k = entry[0]; var v = entry[1]; if (!predicate.call(context, v, k, this$0)) {
iterating = false; return iteratorDone();
} return type === ITERATE_ENTRIES ? step :
iteratorValue(type, k, v, step);
});
}; return takeSequence;
}
function skipWhileFactory(iterable, predicate, context, useKeys) { var skipSequence = makeSequence(iterable);
skipSequence.__iterateUncached = function (fn, reverse) {varthis$0 = this; if (reverse) { returnthis.cacheResult().__iterate(fn, reverse);
} var isSkipping = true; var iterations = 0;
iterable.__iterate(function(v, k, c) { if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) {
iterations++; return fn(v, useKeys ? k : iterations - 1, this$0);
}
}); return iterations;
};
skipSequence.__iteratorUncached = function(type, reverse) {varthis$0 = this; if (reverse) { returnthis.cacheResult().__iterator(type, reverse);
} var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse); var skipping = true; var iterations = 0; returnnew Iterator(function() { var step, k, v; do {
step = iterator.next(); if (step.done) { if (useKeys || type === ITERATE_VALUES) { return step;
} elseif (type === ITERATE_KEYS) { return iteratorValue(type, iterations++, undefined, step);
} else { return iteratorValue(type, iterations++, step.value[1], step);
}
} var entry = step.value;
k = entry[0];
v = entry[1];
skipping && (skipping = predicate.call(context, v, k, this$0));
} while (skipping); return type === ITERATE_ENTRIES ? step :
iteratorValue(type, k, v, step);
});
}; return skipSequence;
}
function concatFactory(iterable, values) { var isKeyedIterable = isKeyed(iterable); var iters = [iterable].concat(values).map(function(v ) { if (!isIterable(v)) {
v = isKeyedIterable ?
keyedSeqFromValue(v) :
indexedSeqFromValue(Array.isArray(v) ? v : [v]);
} elseif (isKeyedIterable) {
v = KeyedIterable(v);
} return v;
}).filter(function(v ) {return v.size !== 0});
if (iters.length === 0) { return iterable;
}
if (iters.length === 1) { var singleton = iters[0]; if (singleton === iterable ||
isKeyedIterable && isKeyed(singleton) ||
isIndexed(iterable) && isIndexed(singleton)) { return singleton;
}
}
var concatSeq = new ArraySeq(iters); if (isKeyedIterable) {
concatSeq = concatSeq.toKeyedSeq();
} elseif (!isIndexed(iterable)) {
concatSeq = concatSeq.toSetSeq();
}
concatSeq = concatSeq.flatten(true);
concatSeq.size = iters.reduce( function(sum, seq) { if (sum !== undefined) { var size = seq.size; if (size !== undefined) { return sum + size;
}
}
},
0
); return concatSeq;
}
function flattenFactory(iterable, depth, useKeys) { var flatSequence = makeSequence(iterable);
flatSequence.__iterateUncached = function(fn, reverse) { var iterations = 0; var stopped = false; function flatDeep(iter, currentDepth) {varthis$0 = this;
iter.__iterate(function(v, k) { if ((!depth || currentDepth < depth) && isIterable(v)) {
flatDeep(v, currentDepth + 1);
} elseif (fn(v, useKeys ? k : iterations++, this$0) === false) {
stopped = true;
} return !stopped;
}, reverse);
}
flatDeep(iterable, 0); return iterations;
}
flatSequence.__iteratorUncached = function(type, reverse) { var iterator = iterable.__iterator(type, reverse); var stack = []; var iterations = 0; returnnew Iterator(function() { while (iterator) { var step = iterator.next(); if (step.done !== false) {
iterator = stack.pop(); continue;
} var v = step.value; if (type === ITERATE_ENTRIES) {
v = v[1];
} if ((!depth || stack.length < depth) && isIterable(v)) {
stack.push(iterator);
iterator = v.__iterator(type, reverse);
} else { return useKeys ? step : iteratorValue(type, iterations++, v, step);
}
} return iteratorDone();
});
} return flatSequence;
}
function flatMapFactory(iterable, mapper, context) { var coerce = iterableClass(iterable); return iterable.toSeq().map( function(v, k) {return coerce(mapper.call(context, v, k, iterable))}
).flatten(true);
}
function maxFactory(iterable, comparator, mapper) { if (!comparator) {
comparator = defaultComparator;
} if (mapper) { var entry = iterable.toSeq()
.map(function(v, k) {return [v, mapper(v, k, iterable)]})
.reduce(function(a, b) {return maxCompare(comparator, a[1], b[1]) ? b : a}); return entry && entry[0];
} else { return iterable.reduce(function(a, b) {return maxCompare(comparator, a, b) ? b : a});
}
}
function maxCompare(comparator, a, b) { var comp = comparator(b, a); // b is considered the new max if the comparator declares them equal, but // they are not equal and b is in fact a nullish value. return (comp === 0 && b !== a && (b === undefined || b === null || b !== b)) || comp > 0;
}
function zipWithFactory(keyIter, zipper, iters) { var zipSequence = makeSequence(keyIter);
zipSequence.size = new ArraySeq(iters).map(function(i ) {return i.size}).min(); // Note: this a generic base implementation of __iterate in terms of // __iterator which may be more generically useful in the future.
zipSequence.__iterate = function(fn, reverse) { /* generic: var iterator = this.__iterator(ITERATE_ENTRIES, reverse); var step; var iterations = 0; while (!(step = iterator.next()).done) { iterations++; if (fn(step.value[1], step.value[0], this) === false) { break; } } return iterations;
*/ // indexed: var iterator = this.__iterator(ITERATE_VALUES, reverse); var step; var iterations = 0; while (!(step = iterator.next()).done) { if (fn(step.value, iterations++, this) === false) { break;
}
} return iterations;
};
zipSequence.__iteratorUncached = function(type, reverse) { var iterators = iters.map(function(i )
{return (i = Iterable(i), getIterator(reverse ? i.reverse() : i))}
); var iterations = 0; var isDone = false; returnnew Iterator(function() { var steps; if (!isDone) {
steps = iterators.map(function(i ) {return i.next()});
isDone = steps.some(function(s ) {return s.done});
} if (isDone) { return iteratorDone();
} return iteratorValue(
type,
iterations++,
zipper.apply(null, steps.map(function(s ) {return s.value}))
);
});
}; return zipSequence
}
function cacheResultThrough() { if (this._iter.cacheResult) { this._iter.cacheResult(); this.size = this._iter.size; returnthis;
} else { return Seq.prototype.cacheResult.call(this);
}
}
function defaultComparator(a, b) { return a > b ? 1 : a < b ? -1 : 0;
}
function forceIterator(keyPath) { var iter = getIterator(keyPath); if (!iter) { // Array might not be iterable in this environment, so we need a fallback // to our wrapped type. if (!isArrayLike(keyPath)) { thrownew TypeError('Expected iterable or array-like: ' + keyPath);
}
iter = getIterator(Iterable(keyPath));
} return iter;
}
createClass(Record, KeyedCollection);
function Record(defaultValues, name) { var hasInitialized;
var RecordType = function Record(values) { if (values instanceof RecordType) { return values;
} if (!(thisinstanceof RecordType)) { returnnew RecordType(values);
} if (!hasInitialized) {
hasInitialized = true; var keys = Object.keys(defaultValues);
setProps(RecordTypePrototype, keys);
RecordTypePrototype.size = keys.length;
RecordTypePrototype._name = name;
RecordTypePrototype._keys = keys;
RecordTypePrototype._defaultValues = defaultValues;
} this._map = Map(values);
};
var RecordTypePrototype = RecordType.prototype = Object.create(RecordPrototype);
RecordTypePrototype.constructor = RecordType;
Stack.prototype.get = function(index, notSetValue) { var head = this._head;
index = wrapIndex(this, index); while (head && index--) {
head = head.next;
} return head ? head.value : notSetValue;
};
entrySeq: function() { var iterable = this; if (iterable._cache) { // We cache as an entries array, so we can just return the cache! returnnew ArraySeq(iterable._cache);
} var entriesSequence = iterable.toSeq().map(entryMapper).toIndexedSeq();
entriesSequence.fromEntrySeq = function() {return iterable.toSeq()}; return entriesSequence;
},
getIn: function(searchKeyPath, notSetValue) { var nested = this; // Note: in an ES6 environment, we would prefer: // for (var key of searchKeyPath) { var iter = forceIterator(searchKeyPath); var step; while (!(step = iter.next()).done) { var key = step.value;
nested = nested && nested.get ? nested.get(key, NOT_SET) : NOT_SET; if (nested === NOT_SET) { return notSetValue;
}
} return nested;
},
// var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@'; // var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@'; // var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@'; // var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
splice: function(index, removeNum /*, ...values*/) { var numArgs = arguments.length;
removeNum = Math.max(removeNum | 0, 0); if (numArgs === 0 || (numArgs === 2 && !removeNum)) { returnthis;
} // If index is negative, it should resolve relative to the size of the // collection. However size may be expensive to compute if not cached, so // only call count() if the number is in fact negative.
index = resolveBegin(index, index < 0 ? this.count() : this.size); var spliced = this.slice(0, index); return reify( this,
numArgs === 1 ?
spliced :
spliced.concat(arrCopy(arguments, 2), this.slice(index + removeNum))
);
},
function not(predicate) { returnfunction() { return !predicate.apply(this, arguments);
}
}
function neg(predicate) { returnfunction() { return -predicate.apply(this, arguments);
}
}
function quoteString(value) { returntypeof value === 'string' ? JSON.stringify(value) : value;
}
function defaultZipper() { return arrCopy(arguments);
}
function defaultNegComparator(a, b) { return a < b ? 1 : a > b ? -1 : 0;
}
function hashIterable(iterable) { if (iterable.size === Infinity) { return 0;
} var ordered = isOrdered(iterable); var keyed = isKeyed(iterable); var h = ordered ? 1 : 0; var size = iterable.__iterate(
keyed ?
ordered ? function(v, k) { h = 31 * h + hashMerge(hash(v), hash(k)) | 0; } : function(v, k) { h = h + hashMerge(hash(v), hash(k)) | 0; } :
ordered ? function(v ) { h = 31 * h + hash(v) | 0; } : function(v ) { h = h + hash(v) | 0; }
); return murmurHashOfSize(size, h);
}
function murmurHashOfSize(size, h) {
h = imul(h, 0xCC9E2D51);
h = imul(h << 15 | h >>> -15, 0x1B873593);
h = imul(h << 13 | h >>> -13, 5);
h = (h + 0xE6546B64 | 0) ^ size;
h = imul(h ^ h >>> 16, 0x85EBCA6B);
h = imul(h ^ h >>> 13, 0xC2B2AE35);
h = smi(h ^ h >>> 16); return h;
}
function hashMerge(a, b) { return a ^ b + 0x9E3779B9 + (a << 6) + (a >> 2) | 0; // int
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.162Bemerkung:
(vorverarbeitet am 2026-05-07)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.