immutable 5.0.0-rc.2 → 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.js.flow +3 -3
- 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
|
@@ -1,776 +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 { Collection, KeyedCollection, IndexedCollection, SetCollection } from './Collection.js';
|
|
26
|
-
import { IS_COLLECTION_SYMBOL } from './predicates/isCollection.js';
|
|
27
|
-
import { isKeyed, IS_KEYED_SYMBOL } from './predicates/isKeyed.js';
|
|
28
|
-
import { isIndexed, IS_INDEXED_SYMBOL } from './predicates/isIndexed.js';
|
|
29
|
-
import { IS_ORDERED_SYMBOL, isOrdered } from './predicates/isOrdered.js';
|
|
30
|
-
import { is } from './is.js';
|
|
31
|
-
import { ensureSize, returnTrue, NOT_SET, resolveBegin, wrapIndex } from './TrieUtils.js';
|
|
32
|
-
import { hash } from './Hash.js';
|
|
33
|
-
import { imul, smi } from './Math.js';
|
|
34
|
-
import { ITERATE_ENTRIES, ITERATE_KEYS, ITERATE_VALUES, ITERATOR_SYMBOL, Iterator } from './Iterator.js';
|
|
35
|
-
import arrCopy from './utils/arrCopy.js';
|
|
36
|
-
import assertNotInfinite from './utils/assertNotInfinite.js';
|
|
37
|
-
import deepEqual from './utils/deepEqual.js';
|
|
38
|
-
import mixin from './utils/mixin.js';
|
|
39
|
-
import quoteString from './utils/quoteString.js';
|
|
40
|
-
import { toJS } from './toJS.js';
|
|
41
|
-
import { Map } from './Map.js';
|
|
42
|
-
import { OrderedMap } from './OrderedMap.js';
|
|
43
|
-
import { List } from './List.js';
|
|
44
|
-
import { Set } from './Set.js';
|
|
45
|
-
import { OrderedSet } from './OrderedSet.js';
|
|
46
|
-
import { Stack } from './Stack.js';
|
|
47
|
-
import { Range } from './Range.js';
|
|
48
|
-
import { ArraySeq, IndexedSeq, KeyedSeq, SetSeq } from './Seq.js';
|
|
49
|
-
import { ToIndexedSequence, ToKeyedSequence, ToSetSequence, reify, concatFactory, filterFactory, partitionFactory, mapFactory, reverseFactory, sliceFactory, sortFactory, countByFactory, flatMapFactory, flattenFactory, FromEntriesSequence, groupByFactory, maxFactory, skipWhileFactory, takeWhileFactory, flipFactory, interposeFactory, zipWithFactory } from './Operations.js';
|
|
50
|
-
import { getIn } from './methods/getIn.js';
|
|
51
|
-
import { hasIn } from './methods/hasIn.js';
|
|
52
|
-
import { toObject } from './methods/toObject.js';
|
|
53
|
-
|
|
54
|
-
Collection.Iterator = Iterator;
|
|
55
|
-
|
|
56
|
-
mixin(Collection, {
|
|
57
|
-
// ### Conversion to other types
|
|
58
|
-
|
|
59
|
-
toArray: function toArray() {
|
|
60
|
-
assertNotInfinite(this.size);
|
|
61
|
-
var array = new Array(this.size || 0);
|
|
62
|
-
var useTuples = isKeyed(this);
|
|
63
|
-
var i = 0;
|
|
64
|
-
this.__iterate(function (v, k) {
|
|
65
|
-
// Keyed collections produce an array of tuples.
|
|
66
|
-
array[i++] = useTuples ? [k, v] : v;
|
|
67
|
-
});
|
|
68
|
-
return array;
|
|
69
|
-
},
|
|
70
|
-
|
|
71
|
-
toIndexedSeq: function toIndexedSeq() {
|
|
72
|
-
return new ToIndexedSequence(this);
|
|
73
|
-
},
|
|
74
|
-
|
|
75
|
-
toJS: function toJS$1() {
|
|
76
|
-
return toJS(this);
|
|
77
|
-
},
|
|
78
|
-
|
|
79
|
-
toKeyedSeq: function toKeyedSeq() {
|
|
80
|
-
return new ToKeyedSequence(this, true);
|
|
81
|
-
},
|
|
82
|
-
|
|
83
|
-
toMap: function toMap() {
|
|
84
|
-
// Use Late Binding here to solve the circular dependency.
|
|
85
|
-
return Map(this.toKeyedSeq());
|
|
86
|
-
},
|
|
87
|
-
|
|
88
|
-
toObject: toObject,
|
|
89
|
-
|
|
90
|
-
toOrderedMap: function toOrderedMap() {
|
|
91
|
-
// Use Late Binding here to solve the circular dependency.
|
|
92
|
-
return OrderedMap(this.toKeyedSeq());
|
|
93
|
-
},
|
|
94
|
-
|
|
95
|
-
toOrderedSet: function toOrderedSet() {
|
|
96
|
-
// Use Late Binding here to solve the circular dependency.
|
|
97
|
-
return OrderedSet(isKeyed(this) ? this.valueSeq() : this);
|
|
98
|
-
},
|
|
99
|
-
|
|
100
|
-
toSet: function toSet() {
|
|
101
|
-
// Use Late Binding here to solve the circular dependency.
|
|
102
|
-
return Set(isKeyed(this) ? this.valueSeq() : this);
|
|
103
|
-
},
|
|
104
|
-
|
|
105
|
-
toSetSeq: function toSetSeq() {
|
|
106
|
-
return new ToSetSequence(this);
|
|
107
|
-
},
|
|
108
|
-
|
|
109
|
-
toSeq: function toSeq() {
|
|
110
|
-
return isIndexed(this)
|
|
111
|
-
? this.toIndexedSeq()
|
|
112
|
-
: isKeyed(this)
|
|
113
|
-
? this.toKeyedSeq()
|
|
114
|
-
: this.toSetSeq();
|
|
115
|
-
},
|
|
116
|
-
|
|
117
|
-
toStack: function toStack() {
|
|
118
|
-
// Use Late Binding here to solve the circular dependency.
|
|
119
|
-
return Stack(isKeyed(this) ? this.valueSeq() : this);
|
|
120
|
-
},
|
|
121
|
-
|
|
122
|
-
toList: function toList() {
|
|
123
|
-
// Use Late Binding here to solve the circular dependency.
|
|
124
|
-
return List(isKeyed(this) ? this.valueSeq() : this);
|
|
125
|
-
},
|
|
126
|
-
|
|
127
|
-
// ### Common JavaScript methods and properties
|
|
128
|
-
|
|
129
|
-
toString: function toString() {
|
|
130
|
-
return '[Collection]';
|
|
131
|
-
},
|
|
132
|
-
|
|
133
|
-
__toString: function __toString(head, tail) {
|
|
134
|
-
if (this.size === 0) {
|
|
135
|
-
return head + tail;
|
|
136
|
-
}
|
|
137
|
-
return (
|
|
138
|
-
head +
|
|
139
|
-
' ' +
|
|
140
|
-
this.toSeq().map(this.__toStringMapper).join(', ') +
|
|
141
|
-
' ' +
|
|
142
|
-
tail
|
|
143
|
-
);
|
|
144
|
-
},
|
|
145
|
-
|
|
146
|
-
// ### ES6 Collection methods (ES6 Array and Map)
|
|
147
|
-
|
|
148
|
-
concat: function concat() {
|
|
149
|
-
var values = [], len = arguments.length;
|
|
150
|
-
while ( len-- ) values[ len ] = arguments[ len ];
|
|
151
|
-
|
|
152
|
-
return reify(this, concatFactory(this, values));
|
|
153
|
-
},
|
|
154
|
-
|
|
155
|
-
includes: function includes(searchValue) {
|
|
156
|
-
return this.some(function (value) { return is(value, searchValue); });
|
|
157
|
-
},
|
|
158
|
-
|
|
159
|
-
entries: function entries() {
|
|
160
|
-
return this.__iterator(ITERATE_ENTRIES);
|
|
161
|
-
},
|
|
162
|
-
|
|
163
|
-
every: function every(predicate, context) {
|
|
164
|
-
assertNotInfinite(this.size);
|
|
165
|
-
var returnValue = true;
|
|
166
|
-
this.__iterate(function (v, k, c) {
|
|
167
|
-
if (!predicate.call(context, v, k, c)) {
|
|
168
|
-
returnValue = false;
|
|
169
|
-
return false;
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
return returnValue;
|
|
173
|
-
},
|
|
174
|
-
|
|
175
|
-
filter: function filter(predicate, context) {
|
|
176
|
-
return reify(this, filterFactory(this, predicate, context, true));
|
|
177
|
-
},
|
|
178
|
-
|
|
179
|
-
partition: function partition(predicate, context) {
|
|
180
|
-
return partitionFactory(this, predicate, context);
|
|
181
|
-
},
|
|
182
|
-
|
|
183
|
-
find: function find(predicate, context, notSetValue) {
|
|
184
|
-
var entry = this.findEntry(predicate, context);
|
|
185
|
-
return entry ? entry[1] : notSetValue;
|
|
186
|
-
},
|
|
187
|
-
|
|
188
|
-
forEach: function forEach(sideEffect, context) {
|
|
189
|
-
assertNotInfinite(this.size);
|
|
190
|
-
return this.__iterate(context ? sideEffect.bind(context) : sideEffect);
|
|
191
|
-
},
|
|
192
|
-
|
|
193
|
-
join: function join(separator) {
|
|
194
|
-
assertNotInfinite(this.size);
|
|
195
|
-
separator = separator !== undefined ? '' + separator : ',';
|
|
196
|
-
var joined = '';
|
|
197
|
-
var isFirst = true;
|
|
198
|
-
this.__iterate(function (v) {
|
|
199
|
-
isFirst ? (isFirst = false) : (joined += separator);
|
|
200
|
-
joined += v !== null && v !== undefined ? v.toString() : '';
|
|
201
|
-
});
|
|
202
|
-
return joined;
|
|
203
|
-
},
|
|
204
|
-
|
|
205
|
-
keys: function keys() {
|
|
206
|
-
return this.__iterator(ITERATE_KEYS);
|
|
207
|
-
},
|
|
208
|
-
|
|
209
|
-
map: function map(mapper, context) {
|
|
210
|
-
return reify(this, mapFactory(this, mapper, context));
|
|
211
|
-
},
|
|
212
|
-
|
|
213
|
-
reduce: function reduce$1(reducer, initialReduction, context) {
|
|
214
|
-
return reduce(
|
|
215
|
-
this,
|
|
216
|
-
reducer,
|
|
217
|
-
initialReduction,
|
|
218
|
-
context,
|
|
219
|
-
arguments.length < 2,
|
|
220
|
-
false
|
|
221
|
-
);
|
|
222
|
-
},
|
|
223
|
-
|
|
224
|
-
reduceRight: function reduceRight(reducer, initialReduction, context) {
|
|
225
|
-
return reduce(
|
|
226
|
-
this,
|
|
227
|
-
reducer,
|
|
228
|
-
initialReduction,
|
|
229
|
-
context,
|
|
230
|
-
arguments.length < 2,
|
|
231
|
-
true
|
|
232
|
-
);
|
|
233
|
-
},
|
|
234
|
-
|
|
235
|
-
reverse: function reverse() {
|
|
236
|
-
return reify(this, reverseFactory(this, true));
|
|
237
|
-
},
|
|
238
|
-
|
|
239
|
-
slice: function slice(begin, end) {
|
|
240
|
-
return reify(this, sliceFactory(this, begin, end, true));
|
|
241
|
-
},
|
|
242
|
-
|
|
243
|
-
some: function some(predicate, context) {
|
|
244
|
-
assertNotInfinite(this.size);
|
|
245
|
-
var returnValue = false;
|
|
246
|
-
this.__iterate(function (v, k, c) {
|
|
247
|
-
if (predicate.call(context, v, k, c)) {
|
|
248
|
-
returnValue = true;
|
|
249
|
-
return false;
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
return returnValue;
|
|
253
|
-
},
|
|
254
|
-
|
|
255
|
-
sort: function sort(comparator) {
|
|
256
|
-
return reify(this, sortFactory(this, comparator));
|
|
257
|
-
},
|
|
258
|
-
|
|
259
|
-
values: function values() {
|
|
260
|
-
return this.__iterator(ITERATE_VALUES);
|
|
261
|
-
},
|
|
262
|
-
|
|
263
|
-
// ### More sequential methods
|
|
264
|
-
|
|
265
|
-
butLast: function butLast() {
|
|
266
|
-
return this.slice(0, -1);
|
|
267
|
-
},
|
|
268
|
-
|
|
269
|
-
isEmpty: function isEmpty() {
|
|
270
|
-
return this.size !== undefined ? this.size === 0 : !this.some(function () { return true; });
|
|
271
|
-
},
|
|
272
|
-
|
|
273
|
-
count: function count(predicate, context) {
|
|
274
|
-
return ensureSize(
|
|
275
|
-
predicate ? this.toSeq().filter(predicate, context) : this
|
|
276
|
-
);
|
|
277
|
-
},
|
|
278
|
-
|
|
279
|
-
countBy: function countBy(grouper, context) {
|
|
280
|
-
return countByFactory(this, grouper, context);
|
|
281
|
-
},
|
|
282
|
-
|
|
283
|
-
equals: function equals(other) {
|
|
284
|
-
return deepEqual(this, other);
|
|
285
|
-
},
|
|
286
|
-
|
|
287
|
-
entrySeq: function entrySeq() {
|
|
288
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
289
|
-
var collection = this;
|
|
290
|
-
if (collection._cache) {
|
|
291
|
-
// We cache as an entries array, so we can just return the cache!
|
|
292
|
-
return new ArraySeq(collection._cache);
|
|
293
|
-
}
|
|
294
|
-
var entriesSequence = collection.toSeq().map(entryMapper).toIndexedSeq();
|
|
295
|
-
entriesSequence.fromEntrySeq = function () { return collection.toSeq(); };
|
|
296
|
-
return entriesSequence;
|
|
297
|
-
},
|
|
298
|
-
|
|
299
|
-
filterNot: function filterNot(predicate, context) {
|
|
300
|
-
return this.filter(not(predicate), context);
|
|
301
|
-
},
|
|
302
|
-
|
|
303
|
-
findEntry: function findEntry(predicate, context, notSetValue) {
|
|
304
|
-
var found = notSetValue;
|
|
305
|
-
this.__iterate(function (v, k, c) {
|
|
306
|
-
if (predicate.call(context, v, k, c)) {
|
|
307
|
-
found = [k, v];
|
|
308
|
-
return false;
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
return found;
|
|
312
|
-
},
|
|
313
|
-
|
|
314
|
-
findKey: function findKey(predicate, context) {
|
|
315
|
-
var entry = this.findEntry(predicate, context);
|
|
316
|
-
return entry && entry[0];
|
|
317
|
-
},
|
|
318
|
-
|
|
319
|
-
findLast: function findLast(predicate, context, notSetValue) {
|
|
320
|
-
return this.toKeyedSeq().reverse().find(predicate, context, notSetValue);
|
|
321
|
-
},
|
|
322
|
-
|
|
323
|
-
findLastEntry: function findLastEntry(predicate, context, notSetValue) {
|
|
324
|
-
return this.toKeyedSeq()
|
|
325
|
-
.reverse()
|
|
326
|
-
.findEntry(predicate, context, notSetValue);
|
|
327
|
-
},
|
|
328
|
-
|
|
329
|
-
findLastKey: function findLastKey(predicate, context) {
|
|
330
|
-
return this.toKeyedSeq().reverse().findKey(predicate, context);
|
|
331
|
-
},
|
|
332
|
-
|
|
333
|
-
first: function first(notSetValue) {
|
|
334
|
-
return this.find(returnTrue, null, notSetValue);
|
|
335
|
-
},
|
|
336
|
-
|
|
337
|
-
flatMap: function flatMap(mapper, context) {
|
|
338
|
-
return reify(this, flatMapFactory(this, mapper, context));
|
|
339
|
-
},
|
|
340
|
-
|
|
341
|
-
flatten: function flatten(depth) {
|
|
342
|
-
return reify(this, flattenFactory(this, depth, true));
|
|
343
|
-
},
|
|
344
|
-
|
|
345
|
-
fromEntrySeq: function fromEntrySeq() {
|
|
346
|
-
return new FromEntriesSequence(this);
|
|
347
|
-
},
|
|
348
|
-
|
|
349
|
-
get: function get(searchKey, notSetValue) {
|
|
350
|
-
return this.find(function (_, key) { return is(key, searchKey); }, undefined, notSetValue);
|
|
351
|
-
},
|
|
352
|
-
|
|
353
|
-
getIn: getIn,
|
|
354
|
-
|
|
355
|
-
groupBy: function groupBy(grouper, context) {
|
|
356
|
-
return groupByFactory(this, grouper, context);
|
|
357
|
-
},
|
|
358
|
-
|
|
359
|
-
has: function has(searchKey) {
|
|
360
|
-
return this.get(searchKey, NOT_SET) !== NOT_SET;
|
|
361
|
-
},
|
|
362
|
-
|
|
363
|
-
hasIn: hasIn,
|
|
364
|
-
|
|
365
|
-
isSubset: function isSubset(iter) {
|
|
366
|
-
iter = typeof iter.includes === 'function' ? iter : Collection(iter);
|
|
367
|
-
return this.every(function (value) { return iter.includes(value); });
|
|
368
|
-
},
|
|
369
|
-
|
|
370
|
-
isSuperset: function isSuperset(iter) {
|
|
371
|
-
iter = typeof iter.isSubset === 'function' ? iter : Collection(iter);
|
|
372
|
-
return iter.isSubset(this);
|
|
373
|
-
},
|
|
374
|
-
|
|
375
|
-
keyOf: function keyOf(searchValue) {
|
|
376
|
-
return this.findKey(function (value) { return is(value, searchValue); });
|
|
377
|
-
},
|
|
378
|
-
|
|
379
|
-
keySeq: function keySeq() {
|
|
380
|
-
return this.toSeq().map(keyMapper).toIndexedSeq();
|
|
381
|
-
},
|
|
382
|
-
|
|
383
|
-
last: function last(notSetValue) {
|
|
384
|
-
return this.toSeq().reverse().first(notSetValue);
|
|
385
|
-
},
|
|
386
|
-
|
|
387
|
-
lastKeyOf: function lastKeyOf(searchValue) {
|
|
388
|
-
return this.toKeyedSeq().reverse().keyOf(searchValue);
|
|
389
|
-
},
|
|
390
|
-
|
|
391
|
-
max: function max(comparator) {
|
|
392
|
-
return maxFactory(this, comparator);
|
|
393
|
-
},
|
|
394
|
-
|
|
395
|
-
maxBy: function maxBy(mapper, comparator) {
|
|
396
|
-
return maxFactory(this, comparator, mapper);
|
|
397
|
-
},
|
|
398
|
-
|
|
399
|
-
min: function min(comparator) {
|
|
400
|
-
return maxFactory(
|
|
401
|
-
this,
|
|
402
|
-
comparator ? neg(comparator) : defaultNegComparator
|
|
403
|
-
);
|
|
404
|
-
},
|
|
405
|
-
|
|
406
|
-
minBy: function minBy(mapper, comparator) {
|
|
407
|
-
return maxFactory(
|
|
408
|
-
this,
|
|
409
|
-
comparator ? neg(comparator) : defaultNegComparator,
|
|
410
|
-
mapper
|
|
411
|
-
);
|
|
412
|
-
},
|
|
413
|
-
|
|
414
|
-
rest: function rest() {
|
|
415
|
-
return this.slice(1);
|
|
416
|
-
},
|
|
417
|
-
|
|
418
|
-
skip: function skip(amount) {
|
|
419
|
-
return amount === 0 ? this : this.slice(Math.max(0, amount));
|
|
420
|
-
},
|
|
421
|
-
|
|
422
|
-
skipLast: function skipLast(amount) {
|
|
423
|
-
return amount === 0 ? this : this.slice(0, -Math.max(0, amount));
|
|
424
|
-
},
|
|
425
|
-
|
|
426
|
-
skipWhile: function skipWhile(predicate, context) {
|
|
427
|
-
return reify(this, skipWhileFactory(this, predicate, context, true));
|
|
428
|
-
},
|
|
429
|
-
|
|
430
|
-
skipUntil: function skipUntil(predicate, context) {
|
|
431
|
-
return this.skipWhile(not(predicate), context);
|
|
432
|
-
},
|
|
433
|
-
|
|
434
|
-
sortBy: function sortBy(mapper, comparator) {
|
|
435
|
-
return reify(this, sortFactory(this, comparator, mapper));
|
|
436
|
-
},
|
|
437
|
-
|
|
438
|
-
take: function take(amount) {
|
|
439
|
-
return this.slice(0, Math.max(0, amount));
|
|
440
|
-
},
|
|
441
|
-
|
|
442
|
-
takeLast: function takeLast(amount) {
|
|
443
|
-
return this.slice(-Math.max(0, amount));
|
|
444
|
-
},
|
|
445
|
-
|
|
446
|
-
takeWhile: function takeWhile(predicate, context) {
|
|
447
|
-
return reify(this, takeWhileFactory(this, predicate, context));
|
|
448
|
-
},
|
|
449
|
-
|
|
450
|
-
takeUntil: function takeUntil(predicate, context) {
|
|
451
|
-
return this.takeWhile(not(predicate), context);
|
|
452
|
-
},
|
|
453
|
-
|
|
454
|
-
update: function update(fn) {
|
|
455
|
-
return fn(this);
|
|
456
|
-
},
|
|
457
|
-
|
|
458
|
-
valueSeq: function valueSeq() {
|
|
459
|
-
return this.toIndexedSeq();
|
|
460
|
-
},
|
|
461
|
-
|
|
462
|
-
// ### Hashable Object
|
|
463
|
-
|
|
464
|
-
hashCode: function hashCode() {
|
|
465
|
-
return this.__hash || (this.__hash = hashCollection(this));
|
|
466
|
-
},
|
|
467
|
-
|
|
468
|
-
// ### Internal
|
|
469
|
-
|
|
470
|
-
// abstract __iterate(fn, reverse)
|
|
471
|
-
|
|
472
|
-
// abstract __iterator(type, reverse)
|
|
473
|
-
});
|
|
474
|
-
|
|
475
|
-
var CollectionPrototype = Collection.prototype;
|
|
476
|
-
CollectionPrototype[IS_COLLECTION_SYMBOL] = true;
|
|
477
|
-
CollectionPrototype[ITERATOR_SYMBOL] = CollectionPrototype.values;
|
|
478
|
-
CollectionPrototype.toJSON = CollectionPrototype.toArray;
|
|
479
|
-
CollectionPrototype.__toStringMapper = quoteString;
|
|
480
|
-
CollectionPrototype.inspect = CollectionPrototype.toSource = function () {
|
|
481
|
-
return this.toString();
|
|
482
|
-
};
|
|
483
|
-
CollectionPrototype.chain = CollectionPrototype.flatMap;
|
|
484
|
-
CollectionPrototype.contains = CollectionPrototype.includes;
|
|
485
|
-
|
|
486
|
-
mixin(KeyedCollection, {
|
|
487
|
-
// ### More sequential methods
|
|
488
|
-
|
|
489
|
-
flip: function flip() {
|
|
490
|
-
return reify(this, flipFactory(this));
|
|
491
|
-
},
|
|
492
|
-
|
|
493
|
-
mapEntries: function mapEntries(mapper, context) {
|
|
494
|
-
var this$1$1 = this;
|
|
495
|
-
|
|
496
|
-
var iterations = 0;
|
|
497
|
-
return reify(
|
|
498
|
-
this,
|
|
499
|
-
this.toSeq()
|
|
500
|
-
.map(function (v, k) { return mapper.call(context, [k, v], iterations++, this$1$1); })
|
|
501
|
-
.fromEntrySeq()
|
|
502
|
-
);
|
|
503
|
-
},
|
|
504
|
-
|
|
505
|
-
mapKeys: function mapKeys(mapper, context) {
|
|
506
|
-
var this$1$1 = this;
|
|
507
|
-
|
|
508
|
-
return reify(
|
|
509
|
-
this,
|
|
510
|
-
this.toSeq()
|
|
511
|
-
.flip()
|
|
512
|
-
.map(function (k, v) { return mapper.call(context, k, v, this$1$1); })
|
|
513
|
-
.flip()
|
|
514
|
-
);
|
|
515
|
-
},
|
|
516
|
-
});
|
|
517
|
-
|
|
518
|
-
var KeyedCollectionPrototype = KeyedCollection.prototype;
|
|
519
|
-
KeyedCollectionPrototype[IS_KEYED_SYMBOL] = true;
|
|
520
|
-
KeyedCollectionPrototype[ITERATOR_SYMBOL] = CollectionPrototype.entries;
|
|
521
|
-
KeyedCollectionPrototype.toJSON = toObject;
|
|
522
|
-
KeyedCollectionPrototype.__toStringMapper = function (v, k) { return quoteString(k) + ': ' + quoteString(v); };
|
|
523
|
-
|
|
524
|
-
mixin(IndexedCollection, {
|
|
525
|
-
// ### Conversion to other types
|
|
526
|
-
|
|
527
|
-
toKeyedSeq: function toKeyedSeq() {
|
|
528
|
-
return new ToKeyedSequence(this, false);
|
|
529
|
-
},
|
|
530
|
-
|
|
531
|
-
// ### ES6 Collection methods (ES6 Array and Map)
|
|
532
|
-
|
|
533
|
-
filter: function filter(predicate, context) {
|
|
534
|
-
return reify(this, filterFactory(this, predicate, context, false));
|
|
535
|
-
},
|
|
536
|
-
|
|
537
|
-
findIndex: function findIndex(predicate, context) {
|
|
538
|
-
var entry = this.findEntry(predicate, context);
|
|
539
|
-
return entry ? entry[0] : -1;
|
|
540
|
-
},
|
|
541
|
-
|
|
542
|
-
indexOf: function indexOf(searchValue) {
|
|
543
|
-
var key = this.keyOf(searchValue);
|
|
544
|
-
return key === undefined ? -1 : key;
|
|
545
|
-
},
|
|
546
|
-
|
|
547
|
-
lastIndexOf: function lastIndexOf(searchValue) {
|
|
548
|
-
var key = this.lastKeyOf(searchValue);
|
|
549
|
-
return key === undefined ? -1 : key;
|
|
550
|
-
},
|
|
551
|
-
|
|
552
|
-
reverse: function reverse() {
|
|
553
|
-
return reify(this, reverseFactory(this, false));
|
|
554
|
-
},
|
|
555
|
-
|
|
556
|
-
slice: function slice(begin, end) {
|
|
557
|
-
return reify(this, sliceFactory(this, begin, end, false));
|
|
558
|
-
},
|
|
559
|
-
|
|
560
|
-
splice: function splice(index, removeNum /*, ...values*/) {
|
|
561
|
-
var numArgs = arguments.length;
|
|
562
|
-
removeNum = Math.max(removeNum || 0, 0);
|
|
563
|
-
if (numArgs === 0 || (numArgs === 2 && !removeNum)) {
|
|
564
|
-
return this;
|
|
565
|
-
}
|
|
566
|
-
// If index is negative, it should resolve relative to the size of the
|
|
567
|
-
// collection. However size may be expensive to compute if not cached, so
|
|
568
|
-
// only call count() if the number is in fact negative.
|
|
569
|
-
index = resolveBegin(index, index < 0 ? this.count() : this.size);
|
|
570
|
-
var spliced = this.slice(0, index);
|
|
571
|
-
return reify(
|
|
572
|
-
this,
|
|
573
|
-
numArgs === 1
|
|
574
|
-
? spliced
|
|
575
|
-
: spliced.concat(arrCopy(arguments, 2), this.slice(index + removeNum))
|
|
576
|
-
);
|
|
577
|
-
},
|
|
578
|
-
|
|
579
|
-
// ### More collection methods
|
|
580
|
-
|
|
581
|
-
findLastIndex: function findLastIndex(predicate, context) {
|
|
582
|
-
var entry = this.findLastEntry(predicate, context);
|
|
583
|
-
return entry ? entry[0] : -1;
|
|
584
|
-
},
|
|
585
|
-
|
|
586
|
-
first: function first(notSetValue) {
|
|
587
|
-
return this.get(0, notSetValue);
|
|
588
|
-
},
|
|
589
|
-
|
|
590
|
-
flatten: function flatten(depth) {
|
|
591
|
-
return reify(this, flattenFactory(this, depth, false));
|
|
592
|
-
},
|
|
593
|
-
|
|
594
|
-
get: function get(index, notSetValue) {
|
|
595
|
-
index = wrapIndex(this, index);
|
|
596
|
-
return index < 0 ||
|
|
597
|
-
this.size === Infinity ||
|
|
598
|
-
(this.size !== undefined && index > this.size)
|
|
599
|
-
? notSetValue
|
|
600
|
-
: this.find(function (_, key) { return key === index; }, undefined, notSetValue);
|
|
601
|
-
},
|
|
602
|
-
|
|
603
|
-
has: function has(index) {
|
|
604
|
-
index = wrapIndex(this, index);
|
|
605
|
-
return (
|
|
606
|
-
index >= 0 &&
|
|
607
|
-
(this.size !== undefined
|
|
608
|
-
? this.size === Infinity || index < this.size
|
|
609
|
-
: this.indexOf(index) !== -1)
|
|
610
|
-
);
|
|
611
|
-
},
|
|
612
|
-
|
|
613
|
-
interpose: function interpose(separator) {
|
|
614
|
-
return reify(this, interposeFactory(this, separator));
|
|
615
|
-
},
|
|
616
|
-
|
|
617
|
-
interleave: function interleave(/*...collections*/) {
|
|
618
|
-
var collections = [this].concat(arrCopy(arguments));
|
|
619
|
-
var zipped = zipWithFactory(this.toSeq(), IndexedSeq.of, collections);
|
|
620
|
-
var interleaved = zipped.flatten(true);
|
|
621
|
-
if (zipped.size) {
|
|
622
|
-
interleaved.size = zipped.size * collections.length;
|
|
623
|
-
}
|
|
624
|
-
return reify(this, interleaved);
|
|
625
|
-
},
|
|
626
|
-
|
|
627
|
-
keySeq: function keySeq() {
|
|
628
|
-
return Range(0, this.size);
|
|
629
|
-
},
|
|
630
|
-
|
|
631
|
-
last: function last(notSetValue) {
|
|
632
|
-
return this.get(-1, notSetValue);
|
|
633
|
-
},
|
|
634
|
-
|
|
635
|
-
skipWhile: function skipWhile(predicate, context) {
|
|
636
|
-
return reify(this, skipWhileFactory(this, predicate, context, false));
|
|
637
|
-
},
|
|
638
|
-
|
|
639
|
-
zip: function zip(/*, ...collections */) {
|
|
640
|
-
var collections = [this].concat(arrCopy(arguments));
|
|
641
|
-
return reify(this, zipWithFactory(this, defaultZipper, collections));
|
|
642
|
-
},
|
|
643
|
-
|
|
644
|
-
zipAll: function zipAll(/*, ...collections */) {
|
|
645
|
-
var collections = [this].concat(arrCopy(arguments));
|
|
646
|
-
return reify(this, zipWithFactory(this, defaultZipper, collections, true));
|
|
647
|
-
},
|
|
648
|
-
|
|
649
|
-
zipWith: function zipWith(zipper /*, ...collections */) {
|
|
650
|
-
var collections = arrCopy(arguments);
|
|
651
|
-
collections[0] = this;
|
|
652
|
-
return reify(this, zipWithFactory(this, zipper, collections));
|
|
653
|
-
},
|
|
654
|
-
});
|
|
655
|
-
|
|
656
|
-
var IndexedCollectionPrototype = IndexedCollection.prototype;
|
|
657
|
-
IndexedCollectionPrototype[IS_INDEXED_SYMBOL] = true;
|
|
658
|
-
IndexedCollectionPrototype[IS_ORDERED_SYMBOL] = true;
|
|
659
|
-
|
|
660
|
-
mixin(SetCollection, {
|
|
661
|
-
// ### ES6 Collection methods (ES6 Array and Map)
|
|
662
|
-
|
|
663
|
-
get: function get(value, notSetValue) {
|
|
664
|
-
return this.has(value) ? value : notSetValue;
|
|
665
|
-
},
|
|
666
|
-
|
|
667
|
-
includes: function includes(value) {
|
|
668
|
-
return this.has(value);
|
|
669
|
-
},
|
|
670
|
-
|
|
671
|
-
// ### More sequential methods
|
|
672
|
-
|
|
673
|
-
keySeq: function keySeq() {
|
|
674
|
-
return this.valueSeq();
|
|
675
|
-
},
|
|
676
|
-
});
|
|
677
|
-
|
|
678
|
-
var SetCollectionPrototype = SetCollection.prototype;
|
|
679
|
-
SetCollectionPrototype.has = CollectionPrototype.includes;
|
|
680
|
-
SetCollectionPrototype.contains = SetCollectionPrototype.includes;
|
|
681
|
-
SetCollectionPrototype.keys = SetCollectionPrototype.values;
|
|
682
|
-
|
|
683
|
-
// Mixin subclasses
|
|
684
|
-
|
|
685
|
-
mixin(KeyedSeq, KeyedCollectionPrototype);
|
|
686
|
-
mixin(IndexedSeq, IndexedCollectionPrototype);
|
|
687
|
-
mixin(SetSeq, SetCollectionPrototype);
|
|
688
|
-
|
|
689
|
-
// #pragma Helper functions
|
|
690
|
-
|
|
691
|
-
function reduce(collection, reducer, reduction, context, useFirst, reverse) {
|
|
692
|
-
assertNotInfinite(collection.size);
|
|
693
|
-
collection.__iterate(function (v, k, c) {
|
|
694
|
-
if (useFirst) {
|
|
695
|
-
useFirst = false;
|
|
696
|
-
reduction = v;
|
|
697
|
-
} else {
|
|
698
|
-
reduction = reducer.call(context, reduction, v, k, c);
|
|
699
|
-
}
|
|
700
|
-
}, reverse);
|
|
701
|
-
return reduction;
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
function keyMapper(v, k) {
|
|
705
|
-
return k;
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
function entryMapper(v, k) {
|
|
709
|
-
return [k, v];
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
function not(predicate) {
|
|
713
|
-
return function () {
|
|
714
|
-
return !predicate.apply(this, arguments);
|
|
715
|
-
};
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
function neg(predicate) {
|
|
719
|
-
return function () {
|
|
720
|
-
return -predicate.apply(this, arguments);
|
|
721
|
-
};
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
function defaultZipper() {
|
|
725
|
-
return arrCopy(arguments);
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
function defaultNegComparator(a, b) {
|
|
729
|
-
return a < b ? 1 : a > b ? -1 : 0;
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
function hashCollection(collection) {
|
|
733
|
-
if (collection.size === Infinity) {
|
|
734
|
-
return 0;
|
|
735
|
-
}
|
|
736
|
-
var ordered = isOrdered(collection);
|
|
737
|
-
var keyed = isKeyed(collection);
|
|
738
|
-
var h = ordered ? 1 : 0;
|
|
739
|
-
|
|
740
|
-
collection.__iterate(
|
|
741
|
-
keyed
|
|
742
|
-
? ordered
|
|
743
|
-
? function (v, k) {
|
|
744
|
-
h = (31 * h + hashMerge(hash(v), hash(k))) | 0;
|
|
745
|
-
}
|
|
746
|
-
: function (v, k) {
|
|
747
|
-
h = (h + hashMerge(hash(v), hash(k))) | 0;
|
|
748
|
-
}
|
|
749
|
-
: ordered
|
|
750
|
-
? function (v) {
|
|
751
|
-
h = (31 * h + hash(v)) | 0;
|
|
752
|
-
}
|
|
753
|
-
: function (v) {
|
|
754
|
-
h = (h + hash(v)) | 0;
|
|
755
|
-
}
|
|
756
|
-
);
|
|
757
|
-
|
|
758
|
-
return murmurHashOfSize(collection.size, h);
|
|
759
|
-
}
|
|
760
|
-
|
|
761
|
-
function murmurHashOfSize(size, h) {
|
|
762
|
-
h = imul(h, 0xcc9e2d51);
|
|
763
|
-
h = imul((h << 15) | (h >>> -15), 0x1b873593);
|
|
764
|
-
h = imul((h << 13) | (h >>> -13), 5);
|
|
765
|
-
h = ((h + 0xe6546b64) | 0) ^ size;
|
|
766
|
-
h = imul(h ^ (h >>> 16), 0x85ebca6b);
|
|
767
|
-
h = imul(h ^ (h >>> 13), 0xc2b2ae35);
|
|
768
|
-
h = smi(h ^ (h >>> 16));
|
|
769
|
-
return h;
|
|
770
|
-
}
|
|
771
|
-
|
|
772
|
-
function hashMerge(a, b) {
|
|
773
|
-
return (a ^ (b + 0x9e3779b9 + (a << 6) + (a >> 2))) | 0; // int
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
export { Collection, CollectionPrototype, IndexedCollectionPrototype };
|