immutable 5.0.0 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/immutable.es.js +5930 -0
- package/dist/immutable.js +1 -1
- package/dist/immutable.min.js +1 -1
- package/package.json +1 -1
- package/dist/es/Collection.js +0 -79
- package/dist/es/CollectionImpl.js +0 -776
- package/dist/es/Hash.js +0 -260
- package/dist/es/Immutable.js +0 -73
- package/dist/es/Iterator.js +0 -106
- package/dist/es/List.js +0 -696
- package/dist/es/Map.js +0 -820
- package/dist/es/Math.js +0 -45
- package/dist/es/Operations.js +0 -953
- package/dist/es/OrderedMap.js +0 -196
- package/dist/es/OrderedSet.js +0 -92
- package/dist/es/PairSorting.js +0 -30
- package/dist/es/Range.js +0 -178
- package/dist/es/Record.js +0 -292
- package/dist/es/Repeat.js +0 -133
- package/dist/es/Seq.js +0 -401
- package/dist/es/Set.js +0 -279
- package/dist/es/Stack.js +0 -261
- package/dist/es/TrieUtils.js +0 -117
- package/dist/es/fromJS.js +0 -74
- package/dist/es/functional/get.js +0 -38
- package/dist/es/functional/getIn.js +0 -41
- package/dist/es/functional/has.js +0 -35
- package/dist/es/functional/hasIn.js +0 -32
- package/dist/es/functional/merge.js +0 -137
- package/dist/es/functional/remove.js +0 -56
- package/dist/es/functional/removeIn.js +0 -32
- package/dist/es/functional/set.js +0 -52
- package/dist/es/functional/setIn.js +0 -32
- package/dist/es/functional/update.js +0 -31
- package/dist/es/functional/updateIn.js +0 -94
- package/dist/es/is.js +0 -108
- package/dist/es/methods/asImmutable.js +0 -29
- package/dist/es/methods/asMutable.js +0 -31
- package/dist/es/methods/deleteIn.js +0 -31
- package/dist/es/methods/getIn.js +0 -31
- package/dist/es/methods/hasIn.js +0 -31
- package/dist/es/methods/merge.js +0 -79
- package/dist/es/methods/mergeDeep.js +0 -41
- package/dist/es/methods/mergeDeepIn.js +0 -37
- package/dist/es/methods/mergeIn.js +0 -36
- package/dist/es/methods/setIn.js +0 -31
- package/dist/es/methods/toObject.js +0 -36
- package/dist/es/methods/update.js +0 -33
- package/dist/es/methods/updateIn.js +0 -31
- package/dist/es/methods/wasAltered.js +0 -29
- package/dist/es/methods/withMutations.js +0 -31
- package/dist/es/package.json.js +0 -27
- package/dist/es/predicates/isAssociative.js +0 -32
- package/dist/es/predicates/isCollection.js +0 -32
- package/dist/es/predicates/isImmutable.js +0 -32
- package/dist/es/predicates/isIndexed.js +0 -31
- package/dist/es/predicates/isKeyed.js +0 -31
- package/dist/es/predicates/isList.js +0 -31
- package/dist/es/predicates/isMap.js +0 -31
- package/dist/es/predicates/isOrdered.js +0 -31
- package/dist/es/predicates/isOrderedMap.js +0 -32
- package/dist/es/predicates/isOrderedSet.js +0 -32
- package/dist/es/predicates/isRecord.js +0 -31
- package/dist/es/predicates/isSeq.js +0 -31
- package/dist/es/predicates/isSet.js +0 -31
- package/dist/es/predicates/isStack.js +0 -31
- package/dist/es/predicates/isValueObject.js +0 -33
- package/dist/es/toJS.js +0 -54
- package/dist/es/utils/arrCopy.js +0 -36
- package/dist/es/utils/assertNotInfinite.js +0 -34
- package/dist/es/utils/coerceKeyPath.js +0 -40
- package/dist/es/utils/deepEqual.js +0 -99
- package/dist/es/utils/hasOwnProperty.js +0 -27
- package/dist/es/utils/invariant.js +0 -29
- package/dist/es/utils/isArrayLike.js +0 -44
- package/dist/es/utils/isDataStructure.js +0 -39
- package/dist/es/utils/isPlainObj.js +0 -52
- package/dist/es/utils/mixin.js +0 -38
- package/dist/es/utils/quoteString.js +0 -36
- package/dist/es/utils/shallowCopy.js +0 -41
package/dist/es/Operations.js
DELETED
|
@@ -1,953 +0,0 @@
|
|
|
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
|
-
import { ensureSize, NOT_SET, wholeSlice, wrapIndex, resolveBegin, resolveEnd } from './TrieUtils.js';
|
|
26
|
-
import { KeyedCollection, Collection, IndexedCollection, SetCollection } from './Collection.js';
|
|
27
|
-
import { isCollection } from './predicates/isCollection.js';
|
|
28
|
-
import { isKeyed } from './predicates/isKeyed.js';
|
|
29
|
-
import { isIndexed } from './predicates/isIndexed.js';
|
|
30
|
-
import { IS_ORDERED_SYMBOL, isOrdered } from './predicates/isOrdered.js';
|
|
31
|
-
import { isSeq } from './predicates/isSeq.js';
|
|
32
|
-
import { ITERATE_VALUES, Iterator, iteratorValue, ITERATE_ENTRIES, ITERATE_KEYS, iteratorDone, getIterator } from './Iterator.js';
|
|
33
|
-
import { KeyedSeq, IndexedSeq, SetSeq, keyedSeqFromValue, indexedSeqFromValue, ArraySeq, Seq } from './Seq.js';
|
|
34
|
-
import { Map } from './Map.js';
|
|
35
|
-
import { OrderedMap } from './OrderedMap.js';
|
|
36
|
-
|
|
37
|
-
var ToKeyedSequence = /*@__PURE__*/(function (KeyedSeq) {
|
|
38
|
-
function ToKeyedSequence(indexed, useKeys) {
|
|
39
|
-
this._iter = indexed;
|
|
40
|
-
this._useKeys = useKeys;
|
|
41
|
-
this.size = indexed.size;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if ( KeyedSeq ) ToKeyedSequence.__proto__ = KeyedSeq;
|
|
45
|
-
ToKeyedSequence.prototype = Object.create( KeyedSeq && KeyedSeq.prototype );
|
|
46
|
-
ToKeyedSequence.prototype.constructor = ToKeyedSequence;
|
|
47
|
-
|
|
48
|
-
ToKeyedSequence.prototype.get = function get (key, notSetValue) {
|
|
49
|
-
return this._iter.get(key, notSetValue);
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
ToKeyedSequence.prototype.has = function has (key) {
|
|
53
|
-
return this._iter.has(key);
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
ToKeyedSequence.prototype.valueSeq = function valueSeq () {
|
|
57
|
-
return this._iter.valueSeq();
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
ToKeyedSequence.prototype.reverse = function reverse () {
|
|
61
|
-
var this$1$1 = this;
|
|
62
|
-
|
|
63
|
-
var reversedSequence = reverseFactory(this, true);
|
|
64
|
-
if (!this._useKeys) {
|
|
65
|
-
reversedSequence.valueSeq = function () { return this$1$1._iter.toSeq().reverse(); };
|
|
66
|
-
}
|
|
67
|
-
return reversedSequence;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
ToKeyedSequence.prototype.map = function map (mapper, context) {
|
|
71
|
-
var this$1$1 = this;
|
|
72
|
-
|
|
73
|
-
var mappedSequence = mapFactory(this, mapper, context);
|
|
74
|
-
if (!this._useKeys) {
|
|
75
|
-
mappedSequence.valueSeq = function () { return this$1$1._iter.toSeq().map(mapper, context); };
|
|
76
|
-
}
|
|
77
|
-
return mappedSequence;
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
ToKeyedSequence.prototype.__iterate = function __iterate (fn, reverse) {
|
|
81
|
-
var this$1$1 = this;
|
|
82
|
-
|
|
83
|
-
return this._iter.__iterate(function (v, k) { return fn(v, k, this$1$1); }, reverse);
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
ToKeyedSequence.prototype.__iterator = function __iterator (type, reverse) {
|
|
87
|
-
return this._iter.__iterator(type, reverse);
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
return ToKeyedSequence;
|
|
91
|
-
}(KeyedSeq));
|
|
92
|
-
ToKeyedSequence.prototype[IS_ORDERED_SYMBOL] = true;
|
|
93
|
-
|
|
94
|
-
var ToIndexedSequence = /*@__PURE__*/(function (IndexedSeq) {
|
|
95
|
-
function ToIndexedSequence(iter) {
|
|
96
|
-
this._iter = iter;
|
|
97
|
-
this.size = iter.size;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if ( IndexedSeq ) ToIndexedSequence.__proto__ = IndexedSeq;
|
|
101
|
-
ToIndexedSequence.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
|
|
102
|
-
ToIndexedSequence.prototype.constructor = ToIndexedSequence;
|
|
103
|
-
|
|
104
|
-
ToIndexedSequence.prototype.includes = function includes (value) {
|
|
105
|
-
return this._iter.includes(value);
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
ToIndexedSequence.prototype.__iterate = function __iterate (fn, reverse) {
|
|
109
|
-
var this$1$1 = this;
|
|
110
|
-
|
|
111
|
-
var i = 0;
|
|
112
|
-
reverse && ensureSize(this);
|
|
113
|
-
return this._iter.__iterate(
|
|
114
|
-
function (v) { return fn(v, reverse ? this$1$1.size - ++i : i++, this$1$1); },
|
|
115
|
-
reverse
|
|
116
|
-
);
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
ToIndexedSequence.prototype.__iterator = function __iterator (type, reverse) {
|
|
120
|
-
var this$1$1 = this;
|
|
121
|
-
|
|
122
|
-
var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
|
|
123
|
-
var i = 0;
|
|
124
|
-
reverse && ensureSize(this);
|
|
125
|
-
return new Iterator(function () {
|
|
126
|
-
var step = iterator.next();
|
|
127
|
-
return step.done
|
|
128
|
-
? step
|
|
129
|
-
: iteratorValue(
|
|
130
|
-
type,
|
|
131
|
-
reverse ? this$1$1.size - ++i : i++,
|
|
132
|
-
step.value,
|
|
133
|
-
step
|
|
134
|
-
);
|
|
135
|
-
});
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
return ToIndexedSequence;
|
|
139
|
-
}(IndexedSeq));
|
|
140
|
-
|
|
141
|
-
var ToSetSequence = /*@__PURE__*/(function (SetSeq) {
|
|
142
|
-
function ToSetSequence(iter) {
|
|
143
|
-
this._iter = iter;
|
|
144
|
-
this.size = iter.size;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
if ( SetSeq ) ToSetSequence.__proto__ = SetSeq;
|
|
148
|
-
ToSetSequence.prototype = Object.create( SetSeq && SetSeq.prototype );
|
|
149
|
-
ToSetSequence.prototype.constructor = ToSetSequence;
|
|
150
|
-
|
|
151
|
-
ToSetSequence.prototype.has = function has (key) {
|
|
152
|
-
return this._iter.includes(key);
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
ToSetSequence.prototype.__iterate = function __iterate (fn, reverse) {
|
|
156
|
-
var this$1$1 = this;
|
|
157
|
-
|
|
158
|
-
return this._iter.__iterate(function (v) { return fn(v, v, this$1$1); }, reverse);
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
ToSetSequence.prototype.__iterator = function __iterator (type, reverse) {
|
|
162
|
-
var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
|
|
163
|
-
return new Iterator(function () {
|
|
164
|
-
var step = iterator.next();
|
|
165
|
-
return step.done
|
|
166
|
-
? step
|
|
167
|
-
: iteratorValue(type, step.value, step.value, step);
|
|
168
|
-
});
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
return ToSetSequence;
|
|
172
|
-
}(SetSeq));
|
|
173
|
-
|
|
174
|
-
var FromEntriesSequence = /*@__PURE__*/(function (KeyedSeq) {
|
|
175
|
-
function FromEntriesSequence(entries) {
|
|
176
|
-
this._iter = entries;
|
|
177
|
-
this.size = entries.size;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
if ( KeyedSeq ) FromEntriesSequence.__proto__ = KeyedSeq;
|
|
181
|
-
FromEntriesSequence.prototype = Object.create( KeyedSeq && KeyedSeq.prototype );
|
|
182
|
-
FromEntriesSequence.prototype.constructor = FromEntriesSequence;
|
|
183
|
-
|
|
184
|
-
FromEntriesSequence.prototype.entrySeq = function entrySeq () {
|
|
185
|
-
return this._iter.toSeq();
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
FromEntriesSequence.prototype.__iterate = function __iterate (fn, reverse) {
|
|
189
|
-
var this$1$1 = this;
|
|
190
|
-
|
|
191
|
-
return this._iter.__iterate(function (entry) {
|
|
192
|
-
// Check if entry exists first so array access doesn't throw for holes
|
|
193
|
-
// in the parent iteration.
|
|
194
|
-
if (entry) {
|
|
195
|
-
validateEntry(entry);
|
|
196
|
-
var indexedCollection = isCollection(entry);
|
|
197
|
-
return fn(
|
|
198
|
-
indexedCollection ? entry.get(1) : entry[1],
|
|
199
|
-
indexedCollection ? entry.get(0) : entry[0],
|
|
200
|
-
this$1$1
|
|
201
|
-
);
|
|
202
|
-
}
|
|
203
|
-
}, reverse);
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
FromEntriesSequence.prototype.__iterator = function __iterator (type, reverse) {
|
|
207
|
-
var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
|
|
208
|
-
return new Iterator(function () {
|
|
209
|
-
while (true) {
|
|
210
|
-
var step = iterator.next();
|
|
211
|
-
if (step.done) {
|
|
212
|
-
return step;
|
|
213
|
-
}
|
|
214
|
-
var entry = step.value;
|
|
215
|
-
// Check if entry exists first so array access doesn't throw for holes
|
|
216
|
-
// in the parent iteration.
|
|
217
|
-
if (entry) {
|
|
218
|
-
validateEntry(entry);
|
|
219
|
-
var indexedCollection = isCollection(entry);
|
|
220
|
-
return iteratorValue(
|
|
221
|
-
type,
|
|
222
|
-
indexedCollection ? entry.get(0) : entry[0],
|
|
223
|
-
indexedCollection ? entry.get(1) : entry[1],
|
|
224
|
-
step
|
|
225
|
-
);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
});
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
return FromEntriesSequence;
|
|
232
|
-
}(KeyedSeq));
|
|
233
|
-
|
|
234
|
-
ToIndexedSequence.prototype.cacheResult =
|
|
235
|
-
ToKeyedSequence.prototype.cacheResult =
|
|
236
|
-
ToSetSequence.prototype.cacheResult =
|
|
237
|
-
FromEntriesSequence.prototype.cacheResult =
|
|
238
|
-
cacheResultThrough;
|
|
239
|
-
|
|
240
|
-
function flipFactory(collection) {
|
|
241
|
-
var flipSequence = makeSequence(collection);
|
|
242
|
-
flipSequence._iter = collection;
|
|
243
|
-
flipSequence.size = collection.size;
|
|
244
|
-
flipSequence.flip = function () { return collection; };
|
|
245
|
-
flipSequence.reverse = function () {
|
|
246
|
-
var reversedSequence = collection.reverse.apply(this); // super.reverse()
|
|
247
|
-
reversedSequence.flip = function () { return collection.reverse(); };
|
|
248
|
-
return reversedSequence;
|
|
249
|
-
};
|
|
250
|
-
flipSequence.has = function (key) { return collection.includes(key); };
|
|
251
|
-
flipSequence.includes = function (key) { return collection.has(key); };
|
|
252
|
-
flipSequence.cacheResult = cacheResultThrough;
|
|
253
|
-
flipSequence.__iterateUncached = function (fn, reverse) {
|
|
254
|
-
var this$1$1 = this;
|
|
255
|
-
|
|
256
|
-
return collection.__iterate(function (v, k) { return fn(k, v, this$1$1) !== false; }, reverse);
|
|
257
|
-
};
|
|
258
|
-
flipSequence.__iteratorUncached = function (type, reverse) {
|
|
259
|
-
if (type === ITERATE_ENTRIES) {
|
|
260
|
-
var iterator = collection.__iterator(type, reverse);
|
|
261
|
-
return new Iterator(function () {
|
|
262
|
-
var step = iterator.next();
|
|
263
|
-
if (!step.done) {
|
|
264
|
-
var k = step.value[0];
|
|
265
|
-
step.value[0] = step.value[1];
|
|
266
|
-
step.value[1] = k;
|
|
267
|
-
}
|
|
268
|
-
return step;
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
return collection.__iterator(
|
|
272
|
-
type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES,
|
|
273
|
-
reverse
|
|
274
|
-
);
|
|
275
|
-
};
|
|
276
|
-
return flipSequence;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
function mapFactory(collection, mapper, context) {
|
|
280
|
-
var mappedSequence = makeSequence(collection);
|
|
281
|
-
mappedSequence.size = collection.size;
|
|
282
|
-
mappedSequence.has = function (key) { return collection.has(key); };
|
|
283
|
-
mappedSequence.get = function (key, notSetValue) {
|
|
284
|
-
var v = collection.get(key, NOT_SET);
|
|
285
|
-
return v === NOT_SET
|
|
286
|
-
? notSetValue
|
|
287
|
-
: mapper.call(context, v, key, collection);
|
|
288
|
-
};
|
|
289
|
-
mappedSequence.__iterateUncached = function (fn, reverse) {
|
|
290
|
-
var this$1$1 = this;
|
|
291
|
-
|
|
292
|
-
return collection.__iterate(
|
|
293
|
-
function (v, k, c) { return fn(mapper.call(context, v, k, c), k, this$1$1) !== false; },
|
|
294
|
-
reverse
|
|
295
|
-
);
|
|
296
|
-
};
|
|
297
|
-
mappedSequence.__iteratorUncached = function (type, reverse) {
|
|
298
|
-
var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
|
|
299
|
-
return new Iterator(function () {
|
|
300
|
-
var step = iterator.next();
|
|
301
|
-
if (step.done) {
|
|
302
|
-
return step;
|
|
303
|
-
}
|
|
304
|
-
var entry = step.value;
|
|
305
|
-
var key = entry[0];
|
|
306
|
-
return iteratorValue(
|
|
307
|
-
type,
|
|
308
|
-
key,
|
|
309
|
-
mapper.call(context, entry[1], key, collection),
|
|
310
|
-
step
|
|
311
|
-
);
|
|
312
|
-
});
|
|
313
|
-
};
|
|
314
|
-
return mappedSequence;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
function reverseFactory(collection, useKeys) {
|
|
318
|
-
var this$1$1 = this;
|
|
319
|
-
|
|
320
|
-
var reversedSequence = makeSequence(collection);
|
|
321
|
-
reversedSequence._iter = collection;
|
|
322
|
-
reversedSequence.size = collection.size;
|
|
323
|
-
reversedSequence.reverse = function () { return collection; };
|
|
324
|
-
if (collection.flip) {
|
|
325
|
-
reversedSequence.flip = function () {
|
|
326
|
-
var flipSequence = flipFactory(collection);
|
|
327
|
-
flipSequence.reverse = function () { return collection.flip(); };
|
|
328
|
-
return flipSequence;
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
reversedSequence.get = function (key, notSetValue) { return collection.get(useKeys ? key : -1 - key, notSetValue); };
|
|
332
|
-
reversedSequence.has = function (key) { return collection.has(useKeys ? key : -1 - key); };
|
|
333
|
-
reversedSequence.includes = function (value) { return collection.includes(value); };
|
|
334
|
-
reversedSequence.cacheResult = cacheResultThrough;
|
|
335
|
-
reversedSequence.__iterate = function (fn, reverse) {
|
|
336
|
-
var this$1$1 = this;
|
|
337
|
-
|
|
338
|
-
var i = 0;
|
|
339
|
-
reverse && ensureSize(collection);
|
|
340
|
-
return collection.__iterate(
|
|
341
|
-
function (v, k) { return fn(v, useKeys ? k : reverse ? this$1$1.size - ++i : i++, this$1$1); },
|
|
342
|
-
!reverse
|
|
343
|
-
);
|
|
344
|
-
};
|
|
345
|
-
reversedSequence.__iterator = function (type, reverse) {
|
|
346
|
-
var i = 0;
|
|
347
|
-
reverse && ensureSize(collection);
|
|
348
|
-
var iterator = collection.__iterator(ITERATE_ENTRIES, !reverse);
|
|
349
|
-
return new Iterator(function () {
|
|
350
|
-
var step = iterator.next();
|
|
351
|
-
if (step.done) {
|
|
352
|
-
return step;
|
|
353
|
-
}
|
|
354
|
-
var entry = step.value;
|
|
355
|
-
return iteratorValue(
|
|
356
|
-
type,
|
|
357
|
-
useKeys ? entry[0] : reverse ? this$1$1.size - ++i : i++,
|
|
358
|
-
entry[1],
|
|
359
|
-
step
|
|
360
|
-
);
|
|
361
|
-
});
|
|
362
|
-
};
|
|
363
|
-
return reversedSequence;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
function filterFactory(collection, predicate, context, useKeys) {
|
|
367
|
-
var filterSequence = makeSequence(collection);
|
|
368
|
-
if (useKeys) {
|
|
369
|
-
filterSequence.has = function (key) {
|
|
370
|
-
var v = collection.get(key, NOT_SET);
|
|
371
|
-
return v !== NOT_SET && !!predicate.call(context, v, key, collection);
|
|
372
|
-
};
|
|
373
|
-
filterSequence.get = function (key, notSetValue) {
|
|
374
|
-
var v = collection.get(key, NOT_SET);
|
|
375
|
-
return v !== NOT_SET && predicate.call(context, v, key, collection)
|
|
376
|
-
? v
|
|
377
|
-
: notSetValue;
|
|
378
|
-
};
|
|
379
|
-
}
|
|
380
|
-
filterSequence.__iterateUncached = function (fn, reverse) {
|
|
381
|
-
var this$1$1 = this;
|
|
382
|
-
|
|
383
|
-
var iterations = 0;
|
|
384
|
-
collection.__iterate(function (v, k, c) {
|
|
385
|
-
if (predicate.call(context, v, k, c)) {
|
|
386
|
-
iterations++;
|
|
387
|
-
return fn(v, useKeys ? k : iterations - 1, this$1$1);
|
|
388
|
-
}
|
|
389
|
-
}, reverse);
|
|
390
|
-
return iterations;
|
|
391
|
-
};
|
|
392
|
-
filterSequence.__iteratorUncached = function (type, reverse) {
|
|
393
|
-
var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
|
|
394
|
-
var iterations = 0;
|
|
395
|
-
return new Iterator(function () {
|
|
396
|
-
while (true) {
|
|
397
|
-
var step = iterator.next();
|
|
398
|
-
if (step.done) {
|
|
399
|
-
return step;
|
|
400
|
-
}
|
|
401
|
-
var entry = step.value;
|
|
402
|
-
var key = entry[0];
|
|
403
|
-
var value = entry[1];
|
|
404
|
-
if (predicate.call(context, value, key, collection)) {
|
|
405
|
-
return iteratorValue(type, useKeys ? key : iterations++, value, step);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
});
|
|
409
|
-
};
|
|
410
|
-
return filterSequence;
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
function countByFactory(collection, grouper, context) {
|
|
414
|
-
var groups = Map().asMutable();
|
|
415
|
-
collection.__iterate(function (v, k) {
|
|
416
|
-
groups.update(grouper.call(context, v, k, collection), 0, function (a) { return a + 1; });
|
|
417
|
-
});
|
|
418
|
-
return groups.asImmutable();
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
function groupByFactory(collection, grouper, context) {
|
|
422
|
-
var isKeyedIter = isKeyed(collection);
|
|
423
|
-
var groups = (isOrdered(collection) ? OrderedMap() : Map()).asMutable();
|
|
424
|
-
collection.__iterate(function (v, k) {
|
|
425
|
-
groups.update(
|
|
426
|
-
grouper.call(context, v, k, collection),
|
|
427
|
-
function (a) { return ((a = a || []), a.push(isKeyedIter ? [k, v] : v), a); }
|
|
428
|
-
);
|
|
429
|
-
});
|
|
430
|
-
var coerce = collectionClass(collection);
|
|
431
|
-
return groups.map(function (arr) { return reify(collection, coerce(arr)); }).asImmutable();
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
function partitionFactory(collection, predicate, context) {
|
|
435
|
-
var isKeyedIter = isKeyed(collection);
|
|
436
|
-
var groups = [[], []];
|
|
437
|
-
collection.__iterate(function (v, k) {
|
|
438
|
-
groups[predicate.call(context, v, k, collection) ? 1 : 0].push(
|
|
439
|
-
isKeyedIter ? [k, v] : v
|
|
440
|
-
);
|
|
441
|
-
});
|
|
442
|
-
var coerce = collectionClass(collection);
|
|
443
|
-
return groups.map(function (arr) { return reify(collection, coerce(arr)); });
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
function sliceFactory(collection, begin, end, useKeys) {
|
|
447
|
-
var originalSize = collection.size;
|
|
448
|
-
|
|
449
|
-
if (wholeSlice(begin, end, originalSize)) {
|
|
450
|
-
return collection;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
// begin or end can not be resolved if they were provided as negative numbers and
|
|
454
|
-
// this collection's size is unknown. In that case, cache first so there is
|
|
455
|
-
// a known size and these do not resolve to NaN.
|
|
456
|
-
if (typeof originalSize === 'undefined' && (begin < 0 || end < 0)) {
|
|
457
|
-
return sliceFactory(collection.toSeq().cacheResult(), begin, end, useKeys);
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
var resolvedBegin = resolveBegin(begin, originalSize);
|
|
461
|
-
var resolvedEnd = resolveEnd(end, originalSize);
|
|
462
|
-
|
|
463
|
-
// Note: resolvedEnd is undefined when the original sequence's length is
|
|
464
|
-
// unknown and this slice did not supply an end and should contain all
|
|
465
|
-
// elements after resolvedBegin.
|
|
466
|
-
// In that case, resolvedSize will be NaN and sliceSize will remain undefined.
|
|
467
|
-
var resolvedSize = resolvedEnd - resolvedBegin;
|
|
468
|
-
var sliceSize;
|
|
469
|
-
if (resolvedSize === resolvedSize) {
|
|
470
|
-
sliceSize = resolvedSize < 0 ? 0 : resolvedSize;
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
var sliceSeq = makeSequence(collection);
|
|
474
|
-
|
|
475
|
-
// If collection.size is undefined, the size of the realized sliceSeq is
|
|
476
|
-
// unknown at this point unless the number of items to slice is 0
|
|
477
|
-
sliceSeq.size =
|
|
478
|
-
sliceSize === 0 ? sliceSize : (collection.size && sliceSize) || undefined;
|
|
479
|
-
|
|
480
|
-
if (!useKeys && isSeq(collection) && sliceSize >= 0) {
|
|
481
|
-
sliceSeq.get = function (index, notSetValue) {
|
|
482
|
-
index = wrapIndex(this, index);
|
|
483
|
-
return index >= 0 && index < sliceSize
|
|
484
|
-
? collection.get(index + resolvedBegin, notSetValue)
|
|
485
|
-
: notSetValue;
|
|
486
|
-
};
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
sliceSeq.__iterateUncached = function (fn, reverse) {
|
|
490
|
-
var this$1$1 = this;
|
|
491
|
-
|
|
492
|
-
if (sliceSize === 0) {
|
|
493
|
-
return 0;
|
|
494
|
-
}
|
|
495
|
-
if (reverse) {
|
|
496
|
-
return this.cacheResult().__iterate(fn, reverse);
|
|
497
|
-
}
|
|
498
|
-
var skipped = 0;
|
|
499
|
-
var isSkipping = true;
|
|
500
|
-
var iterations = 0;
|
|
501
|
-
collection.__iterate(function (v, k) {
|
|
502
|
-
if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) {
|
|
503
|
-
iterations++;
|
|
504
|
-
return (
|
|
505
|
-
fn(v, useKeys ? k : iterations - 1, this$1$1) !== false &&
|
|
506
|
-
iterations !== sliceSize
|
|
507
|
-
);
|
|
508
|
-
}
|
|
509
|
-
});
|
|
510
|
-
return iterations;
|
|
511
|
-
};
|
|
512
|
-
|
|
513
|
-
sliceSeq.__iteratorUncached = function (type, reverse) {
|
|
514
|
-
if (sliceSize !== 0 && reverse) {
|
|
515
|
-
return this.cacheResult().__iterator(type, reverse);
|
|
516
|
-
}
|
|
517
|
-
// Don't bother instantiating parent iterator if taking 0.
|
|
518
|
-
if (sliceSize === 0) {
|
|
519
|
-
return new Iterator(iteratorDone);
|
|
520
|
-
}
|
|
521
|
-
var iterator = collection.__iterator(type, reverse);
|
|
522
|
-
var skipped = 0;
|
|
523
|
-
var iterations = 0;
|
|
524
|
-
return new Iterator(function () {
|
|
525
|
-
while (skipped++ < resolvedBegin) {
|
|
526
|
-
iterator.next();
|
|
527
|
-
}
|
|
528
|
-
if (++iterations > sliceSize) {
|
|
529
|
-
return iteratorDone();
|
|
530
|
-
}
|
|
531
|
-
var step = iterator.next();
|
|
532
|
-
if (useKeys || type === ITERATE_VALUES || step.done) {
|
|
533
|
-
return step;
|
|
534
|
-
}
|
|
535
|
-
if (type === ITERATE_KEYS) {
|
|
536
|
-
return iteratorValue(type, iterations - 1, undefined, step);
|
|
537
|
-
}
|
|
538
|
-
return iteratorValue(type, iterations - 1, step.value[1], step);
|
|
539
|
-
});
|
|
540
|
-
};
|
|
541
|
-
|
|
542
|
-
return sliceSeq;
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
function takeWhileFactory(collection, predicate, context) {
|
|
546
|
-
var takeSequence = makeSequence(collection);
|
|
547
|
-
takeSequence.__iterateUncached = function (fn, reverse) {
|
|
548
|
-
var this$1$1 = this;
|
|
549
|
-
|
|
550
|
-
if (reverse) {
|
|
551
|
-
return this.cacheResult().__iterate(fn, reverse);
|
|
552
|
-
}
|
|
553
|
-
var iterations = 0;
|
|
554
|
-
collection.__iterate(
|
|
555
|
-
function (v, k, c) { return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$1$1); }
|
|
556
|
-
);
|
|
557
|
-
return iterations;
|
|
558
|
-
};
|
|
559
|
-
takeSequence.__iteratorUncached = function (type, reverse) {
|
|
560
|
-
var this$1$1 = this;
|
|
561
|
-
|
|
562
|
-
if (reverse) {
|
|
563
|
-
return this.cacheResult().__iterator(type, reverse);
|
|
564
|
-
}
|
|
565
|
-
var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
|
|
566
|
-
var iterating = true;
|
|
567
|
-
return new Iterator(function () {
|
|
568
|
-
if (!iterating) {
|
|
569
|
-
return iteratorDone();
|
|
570
|
-
}
|
|
571
|
-
var step = iterator.next();
|
|
572
|
-
if (step.done) {
|
|
573
|
-
return step;
|
|
574
|
-
}
|
|
575
|
-
var entry = step.value;
|
|
576
|
-
var k = entry[0];
|
|
577
|
-
var v = entry[1];
|
|
578
|
-
if (!predicate.call(context, v, k, this$1$1)) {
|
|
579
|
-
iterating = false;
|
|
580
|
-
return iteratorDone();
|
|
581
|
-
}
|
|
582
|
-
return type === ITERATE_ENTRIES ? step : iteratorValue(type, k, v, step);
|
|
583
|
-
});
|
|
584
|
-
};
|
|
585
|
-
return takeSequence;
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
function skipWhileFactory(collection, predicate, context, useKeys) {
|
|
589
|
-
var skipSequence = makeSequence(collection);
|
|
590
|
-
skipSequence.__iterateUncached = function (fn, reverse) {
|
|
591
|
-
var this$1$1 = this;
|
|
592
|
-
|
|
593
|
-
if (reverse) {
|
|
594
|
-
return this.cacheResult().__iterate(fn, reverse);
|
|
595
|
-
}
|
|
596
|
-
var isSkipping = true;
|
|
597
|
-
var iterations = 0;
|
|
598
|
-
collection.__iterate(function (v, k, c) {
|
|
599
|
-
if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) {
|
|
600
|
-
iterations++;
|
|
601
|
-
return fn(v, useKeys ? k : iterations - 1, this$1$1);
|
|
602
|
-
}
|
|
603
|
-
});
|
|
604
|
-
return iterations;
|
|
605
|
-
};
|
|
606
|
-
skipSequence.__iteratorUncached = function (type, reverse) {
|
|
607
|
-
var this$1$1 = this;
|
|
608
|
-
|
|
609
|
-
if (reverse) {
|
|
610
|
-
return this.cacheResult().__iterator(type, reverse);
|
|
611
|
-
}
|
|
612
|
-
var iterator = collection.__iterator(ITERATE_ENTRIES, reverse);
|
|
613
|
-
var skipping = true;
|
|
614
|
-
var iterations = 0;
|
|
615
|
-
return new Iterator(function () {
|
|
616
|
-
var step;
|
|
617
|
-
var k;
|
|
618
|
-
var v;
|
|
619
|
-
do {
|
|
620
|
-
step = iterator.next();
|
|
621
|
-
if (step.done) {
|
|
622
|
-
if (useKeys || type === ITERATE_VALUES) {
|
|
623
|
-
return step;
|
|
624
|
-
}
|
|
625
|
-
if (type === ITERATE_KEYS) {
|
|
626
|
-
return iteratorValue(type, iterations++, undefined, step);
|
|
627
|
-
}
|
|
628
|
-
return iteratorValue(type, iterations++, step.value[1], step);
|
|
629
|
-
}
|
|
630
|
-
var entry = step.value;
|
|
631
|
-
k = entry[0];
|
|
632
|
-
v = entry[1];
|
|
633
|
-
skipping && (skipping = predicate.call(context, v, k, this$1$1));
|
|
634
|
-
} while (skipping);
|
|
635
|
-
return type === ITERATE_ENTRIES ? step : iteratorValue(type, k, v, step);
|
|
636
|
-
});
|
|
637
|
-
};
|
|
638
|
-
return skipSequence;
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
function concatFactory(collection, values) {
|
|
642
|
-
var isKeyedCollection = isKeyed(collection);
|
|
643
|
-
var iters = [collection]
|
|
644
|
-
.concat(values)
|
|
645
|
-
.map(function (v) {
|
|
646
|
-
if (!isCollection(v)) {
|
|
647
|
-
v = isKeyedCollection
|
|
648
|
-
? keyedSeqFromValue(v)
|
|
649
|
-
: indexedSeqFromValue(Array.isArray(v) ? v : [v]);
|
|
650
|
-
} else if (isKeyedCollection) {
|
|
651
|
-
v = KeyedCollection(v);
|
|
652
|
-
}
|
|
653
|
-
return v;
|
|
654
|
-
})
|
|
655
|
-
.filter(function (v) { return v.size !== 0; });
|
|
656
|
-
|
|
657
|
-
if (iters.length === 0) {
|
|
658
|
-
return collection;
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
if (iters.length === 1) {
|
|
662
|
-
var singleton = iters[0];
|
|
663
|
-
if (
|
|
664
|
-
singleton === collection ||
|
|
665
|
-
(isKeyedCollection && isKeyed(singleton)) ||
|
|
666
|
-
(isIndexed(collection) && isIndexed(singleton))
|
|
667
|
-
) {
|
|
668
|
-
return singleton;
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
var concatSeq = new ArraySeq(iters);
|
|
673
|
-
if (isKeyedCollection) {
|
|
674
|
-
concatSeq = concatSeq.toKeyedSeq();
|
|
675
|
-
} else if (!isIndexed(collection)) {
|
|
676
|
-
concatSeq = concatSeq.toSetSeq();
|
|
677
|
-
}
|
|
678
|
-
concatSeq = concatSeq.flatten(true);
|
|
679
|
-
concatSeq.size = iters.reduce(function (sum, seq) {
|
|
680
|
-
if (sum !== undefined) {
|
|
681
|
-
var size = seq.size;
|
|
682
|
-
if (size !== undefined) {
|
|
683
|
-
return sum + size;
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
}, 0);
|
|
687
|
-
return concatSeq;
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
function flattenFactory(collection, depth, useKeys) {
|
|
691
|
-
var flatSequence = makeSequence(collection);
|
|
692
|
-
flatSequence.__iterateUncached = function (fn, reverse) {
|
|
693
|
-
if (reverse) {
|
|
694
|
-
return this.cacheResult().__iterate(fn, reverse);
|
|
695
|
-
}
|
|
696
|
-
var iterations = 0;
|
|
697
|
-
var stopped = false;
|
|
698
|
-
function flatDeep(iter, currentDepth) {
|
|
699
|
-
iter.__iterate(function (v, k) {
|
|
700
|
-
if ((!depth || currentDepth < depth) && isCollection(v)) {
|
|
701
|
-
flatDeep(v, currentDepth + 1);
|
|
702
|
-
} else {
|
|
703
|
-
iterations++;
|
|
704
|
-
if (fn(v, useKeys ? k : iterations - 1, flatSequence) === false) {
|
|
705
|
-
stopped = true;
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
return !stopped;
|
|
709
|
-
}, reverse);
|
|
710
|
-
}
|
|
711
|
-
flatDeep(collection, 0);
|
|
712
|
-
return iterations;
|
|
713
|
-
};
|
|
714
|
-
flatSequence.__iteratorUncached = function (type, reverse) {
|
|
715
|
-
if (reverse) {
|
|
716
|
-
return this.cacheResult().__iterator(type, reverse);
|
|
717
|
-
}
|
|
718
|
-
var iterator = collection.__iterator(type, reverse);
|
|
719
|
-
var stack = [];
|
|
720
|
-
var iterations = 0;
|
|
721
|
-
return new Iterator(function () {
|
|
722
|
-
while (iterator) {
|
|
723
|
-
var step = iterator.next();
|
|
724
|
-
if (step.done !== false) {
|
|
725
|
-
iterator = stack.pop();
|
|
726
|
-
continue;
|
|
727
|
-
}
|
|
728
|
-
var v = step.value;
|
|
729
|
-
if (type === ITERATE_ENTRIES) {
|
|
730
|
-
v = v[1];
|
|
731
|
-
}
|
|
732
|
-
if ((!depth || stack.length < depth) && isCollection(v)) {
|
|
733
|
-
stack.push(iterator);
|
|
734
|
-
iterator = v.__iterator(type, reverse);
|
|
735
|
-
} else {
|
|
736
|
-
return useKeys ? step : iteratorValue(type, iterations++, v, step);
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
return iteratorDone();
|
|
740
|
-
});
|
|
741
|
-
};
|
|
742
|
-
return flatSequence;
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
function flatMapFactory(collection, mapper, context) {
|
|
746
|
-
var coerce = collectionClass(collection);
|
|
747
|
-
return collection
|
|
748
|
-
.toSeq()
|
|
749
|
-
.map(function (v, k) { return coerce(mapper.call(context, v, k, collection)); })
|
|
750
|
-
.flatten(true);
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
function interposeFactory(collection, separator) {
|
|
754
|
-
var interposedSequence = makeSequence(collection);
|
|
755
|
-
interposedSequence.size = collection.size && collection.size * 2 - 1;
|
|
756
|
-
interposedSequence.__iterateUncached = function (fn, reverse) {
|
|
757
|
-
var this$1$1 = this;
|
|
758
|
-
|
|
759
|
-
var iterations = 0;
|
|
760
|
-
collection.__iterate(
|
|
761
|
-
function (v) { return (!iterations || fn(separator, iterations++, this$1$1) !== false) &&
|
|
762
|
-
fn(v, iterations++, this$1$1) !== false; },
|
|
763
|
-
reverse
|
|
764
|
-
);
|
|
765
|
-
return iterations;
|
|
766
|
-
};
|
|
767
|
-
interposedSequence.__iteratorUncached = function (type, reverse) {
|
|
768
|
-
var iterator = collection.__iterator(ITERATE_VALUES, reverse);
|
|
769
|
-
var iterations = 0;
|
|
770
|
-
var step;
|
|
771
|
-
return new Iterator(function () {
|
|
772
|
-
if (!step || iterations % 2) {
|
|
773
|
-
step = iterator.next();
|
|
774
|
-
if (step.done) {
|
|
775
|
-
return step;
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
return iterations % 2
|
|
779
|
-
? iteratorValue(type, iterations++, separator)
|
|
780
|
-
: iteratorValue(type, iterations++, step.value, step);
|
|
781
|
-
});
|
|
782
|
-
};
|
|
783
|
-
return interposedSequence;
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
function sortFactory(collection, comparator, mapper) {
|
|
787
|
-
if (!comparator) {
|
|
788
|
-
comparator = defaultComparator;
|
|
789
|
-
}
|
|
790
|
-
var isKeyedCollection = isKeyed(collection);
|
|
791
|
-
var index = 0;
|
|
792
|
-
var entries = collection
|
|
793
|
-
.toSeq()
|
|
794
|
-
.map(function (v, k) { return [k, v, index++, mapper ? mapper(v, k, collection) : v]; })
|
|
795
|
-
.valueSeq()
|
|
796
|
-
.toArray();
|
|
797
|
-
entries
|
|
798
|
-
.sort(function (a, b) { return comparator(a[3], b[3]) || a[2] - b[2]; })
|
|
799
|
-
.forEach(
|
|
800
|
-
isKeyedCollection
|
|
801
|
-
? function (v, i) {
|
|
802
|
-
entries[i].length = 2;
|
|
803
|
-
}
|
|
804
|
-
: function (v, i) {
|
|
805
|
-
entries[i] = v[1];
|
|
806
|
-
}
|
|
807
|
-
);
|
|
808
|
-
return isKeyedCollection
|
|
809
|
-
? KeyedSeq(entries)
|
|
810
|
-
: isIndexed(collection)
|
|
811
|
-
? IndexedSeq(entries)
|
|
812
|
-
: SetSeq(entries);
|
|
813
|
-
}
|
|
814
|
-
|
|
815
|
-
function maxFactory(collection, comparator, mapper) {
|
|
816
|
-
if (!comparator) {
|
|
817
|
-
comparator = defaultComparator;
|
|
818
|
-
}
|
|
819
|
-
if (mapper) {
|
|
820
|
-
var entry = collection
|
|
821
|
-
.toSeq()
|
|
822
|
-
.map(function (v, k) { return [v, mapper(v, k, collection)]; })
|
|
823
|
-
.reduce(function (a, b) { return (maxCompare(comparator, a[1], b[1]) ? b : a); });
|
|
824
|
-
return entry && entry[0];
|
|
825
|
-
}
|
|
826
|
-
return collection.reduce(function (a, b) { return (maxCompare(comparator, a, b) ? b : a); });
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
function maxCompare(comparator, a, b) {
|
|
830
|
-
var comp = comparator(b, a);
|
|
831
|
-
// b is considered the new max if the comparator declares them equal, but
|
|
832
|
-
// they are not equal and b is in fact a nullish value.
|
|
833
|
-
return (
|
|
834
|
-
(comp === 0 && b !== a && (b === undefined || b === null || b !== b)) ||
|
|
835
|
-
comp > 0
|
|
836
|
-
);
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
function zipWithFactory(keyIter, zipper, iters, zipAll) {
|
|
840
|
-
var zipSequence = makeSequence(keyIter);
|
|
841
|
-
var sizes = new ArraySeq(iters).map(function (i) { return i.size; });
|
|
842
|
-
zipSequence.size = zipAll ? sizes.max() : sizes.min();
|
|
843
|
-
// Note: this a generic base implementation of __iterate in terms of
|
|
844
|
-
// __iterator which may be more generically useful in the future.
|
|
845
|
-
zipSequence.__iterate = function (fn, reverse) {
|
|
846
|
-
/* generic:
|
|
847
|
-
var iterator = this.__iterator(ITERATE_ENTRIES, reverse);
|
|
848
|
-
var step;
|
|
849
|
-
var iterations = 0;
|
|
850
|
-
while (!(step = iterator.next()).done) {
|
|
851
|
-
iterations++;
|
|
852
|
-
if (fn(step.value[1], step.value[0], this) === false) {
|
|
853
|
-
break;
|
|
854
|
-
}
|
|
855
|
-
}
|
|
856
|
-
return iterations;
|
|
857
|
-
*/
|
|
858
|
-
// indexed:
|
|
859
|
-
var iterator = this.__iterator(ITERATE_VALUES, reverse);
|
|
860
|
-
var step;
|
|
861
|
-
var iterations = 0;
|
|
862
|
-
while (!(step = iterator.next()).done) {
|
|
863
|
-
if (fn(step.value, iterations++, this) === false) {
|
|
864
|
-
break;
|
|
865
|
-
}
|
|
866
|
-
}
|
|
867
|
-
return iterations;
|
|
868
|
-
};
|
|
869
|
-
zipSequence.__iteratorUncached = function (type, reverse) {
|
|
870
|
-
var iterators = iters.map(
|
|
871
|
-
function (i) { return ((i = Collection(i)), getIterator(reverse ? i.reverse() : i)); }
|
|
872
|
-
);
|
|
873
|
-
var iterations = 0;
|
|
874
|
-
var isDone = false;
|
|
875
|
-
return new Iterator(function () {
|
|
876
|
-
var steps;
|
|
877
|
-
if (!isDone) {
|
|
878
|
-
steps = iterators.map(function (i) { return i.next(); });
|
|
879
|
-
isDone = zipAll ? steps.every(function (s) { return s.done; }) : steps.some(function (s) { return s.done; });
|
|
880
|
-
}
|
|
881
|
-
if (isDone) {
|
|
882
|
-
return iteratorDone();
|
|
883
|
-
}
|
|
884
|
-
return iteratorValue(
|
|
885
|
-
type,
|
|
886
|
-
iterations++,
|
|
887
|
-
zipper.apply(
|
|
888
|
-
null,
|
|
889
|
-
steps.map(function (s) { return s.value; })
|
|
890
|
-
)
|
|
891
|
-
);
|
|
892
|
-
});
|
|
893
|
-
};
|
|
894
|
-
return zipSequence;
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
// #pragma Helper Functions
|
|
898
|
-
|
|
899
|
-
function reify(iter, seq) {
|
|
900
|
-
return iter === seq ? iter : isSeq(iter) ? seq : iter.constructor(seq);
|
|
901
|
-
}
|
|
902
|
-
|
|
903
|
-
function validateEntry(entry) {
|
|
904
|
-
if (entry !== Object(entry)) {
|
|
905
|
-
throw new TypeError('Expected [K, V] tuple: ' + entry);
|
|
906
|
-
}
|
|
907
|
-
}
|
|
908
|
-
|
|
909
|
-
function collectionClass(collection) {
|
|
910
|
-
return isKeyed(collection)
|
|
911
|
-
? KeyedCollection
|
|
912
|
-
: isIndexed(collection)
|
|
913
|
-
? IndexedCollection
|
|
914
|
-
: SetCollection;
|
|
915
|
-
}
|
|
916
|
-
|
|
917
|
-
function makeSequence(collection) {
|
|
918
|
-
return Object.create(
|
|
919
|
-
(isKeyed(collection)
|
|
920
|
-
? KeyedSeq
|
|
921
|
-
: isIndexed(collection)
|
|
922
|
-
? IndexedSeq
|
|
923
|
-
: SetSeq
|
|
924
|
-
).prototype
|
|
925
|
-
);
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
function cacheResultThrough() {
|
|
929
|
-
if (this._iter.cacheResult) {
|
|
930
|
-
this._iter.cacheResult();
|
|
931
|
-
this.size = this._iter.size;
|
|
932
|
-
return this;
|
|
933
|
-
}
|
|
934
|
-
return Seq.prototype.cacheResult.call(this);
|
|
935
|
-
}
|
|
936
|
-
|
|
937
|
-
function defaultComparator(a, b) {
|
|
938
|
-
if (a === undefined && b === undefined) {
|
|
939
|
-
return 0;
|
|
940
|
-
}
|
|
941
|
-
|
|
942
|
-
if (a === undefined) {
|
|
943
|
-
return 1;
|
|
944
|
-
}
|
|
945
|
-
|
|
946
|
-
if (b === undefined) {
|
|
947
|
-
return -1;
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
return a > b ? 1 : a < b ? -1 : 0;
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
export { FromEntriesSequence, ToIndexedSequence, ToKeyedSequence, ToSetSequence, concatFactory, countByFactory, filterFactory, flatMapFactory, flattenFactory, flipFactory, groupByFactory, interposeFactory, mapFactory, maxFactory, partitionFactory, reify, reverseFactory, skipWhileFactory, sliceFactory, sortFactory, takeWhileFactory, zipWithFactory };
|