immutable 5.0.0-beta.1 → 5.0.0-beta.3

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