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.
Files changed (81) hide show
  1. package/dist/immutable.es.js +5930 -0
  2. package/dist/immutable.js +1 -1
  3. package/dist/immutable.js.flow +3 -3
  4. package/dist/immutable.min.js +1 -1
  5. package/package.json +1 -1
  6. package/dist/es/Collection.js +0 -79
  7. package/dist/es/CollectionImpl.js +0 -776
  8. package/dist/es/Hash.js +0 -260
  9. package/dist/es/Immutable.js +0 -73
  10. package/dist/es/Iterator.js +0 -106
  11. package/dist/es/List.js +0 -696
  12. package/dist/es/Map.js +0 -820
  13. package/dist/es/Math.js +0 -45
  14. package/dist/es/Operations.js +0 -953
  15. package/dist/es/OrderedMap.js +0 -196
  16. package/dist/es/OrderedSet.js +0 -92
  17. package/dist/es/PairSorting.js +0 -30
  18. package/dist/es/Range.js +0 -178
  19. package/dist/es/Record.js +0 -292
  20. package/dist/es/Repeat.js +0 -133
  21. package/dist/es/Seq.js +0 -401
  22. package/dist/es/Set.js +0 -279
  23. package/dist/es/Stack.js +0 -261
  24. package/dist/es/TrieUtils.js +0 -117
  25. package/dist/es/fromJS.js +0 -74
  26. package/dist/es/functional/get.js +0 -38
  27. package/dist/es/functional/getIn.js +0 -41
  28. package/dist/es/functional/has.js +0 -35
  29. package/dist/es/functional/hasIn.js +0 -32
  30. package/dist/es/functional/merge.js +0 -137
  31. package/dist/es/functional/remove.js +0 -56
  32. package/dist/es/functional/removeIn.js +0 -32
  33. package/dist/es/functional/set.js +0 -52
  34. package/dist/es/functional/setIn.js +0 -32
  35. package/dist/es/functional/update.js +0 -31
  36. package/dist/es/functional/updateIn.js +0 -94
  37. package/dist/es/is.js +0 -108
  38. package/dist/es/methods/asImmutable.js +0 -29
  39. package/dist/es/methods/asMutable.js +0 -31
  40. package/dist/es/methods/deleteIn.js +0 -31
  41. package/dist/es/methods/getIn.js +0 -31
  42. package/dist/es/methods/hasIn.js +0 -31
  43. package/dist/es/methods/merge.js +0 -79
  44. package/dist/es/methods/mergeDeep.js +0 -41
  45. package/dist/es/methods/mergeDeepIn.js +0 -37
  46. package/dist/es/methods/mergeIn.js +0 -36
  47. package/dist/es/methods/setIn.js +0 -31
  48. package/dist/es/methods/toObject.js +0 -36
  49. package/dist/es/methods/update.js +0 -33
  50. package/dist/es/methods/updateIn.js +0 -31
  51. package/dist/es/methods/wasAltered.js +0 -29
  52. package/dist/es/methods/withMutations.js +0 -31
  53. package/dist/es/package.json.js +0 -27
  54. package/dist/es/predicates/isAssociative.js +0 -32
  55. package/dist/es/predicates/isCollection.js +0 -32
  56. package/dist/es/predicates/isImmutable.js +0 -32
  57. package/dist/es/predicates/isIndexed.js +0 -31
  58. package/dist/es/predicates/isKeyed.js +0 -31
  59. package/dist/es/predicates/isList.js +0 -31
  60. package/dist/es/predicates/isMap.js +0 -31
  61. package/dist/es/predicates/isOrdered.js +0 -31
  62. package/dist/es/predicates/isOrderedMap.js +0 -32
  63. package/dist/es/predicates/isOrderedSet.js +0 -32
  64. package/dist/es/predicates/isRecord.js +0 -31
  65. package/dist/es/predicates/isSeq.js +0 -31
  66. package/dist/es/predicates/isSet.js +0 -31
  67. package/dist/es/predicates/isStack.js +0 -31
  68. package/dist/es/predicates/isValueObject.js +0 -33
  69. package/dist/es/toJS.js +0 -54
  70. package/dist/es/utils/arrCopy.js +0 -36
  71. package/dist/es/utils/assertNotInfinite.js +0 -34
  72. package/dist/es/utils/coerceKeyPath.js +0 -40
  73. package/dist/es/utils/deepEqual.js +0 -99
  74. package/dist/es/utils/hasOwnProperty.js +0 -27
  75. package/dist/es/utils/invariant.js +0 -29
  76. package/dist/es/utils/isArrayLike.js +0 -44
  77. package/dist/es/utils/isDataStructure.js +0 -39
  78. package/dist/es/utils/isPlainObj.js +0 -52
  79. package/dist/es/utils/mixin.js +0 -38
  80. package/dist/es/utils/quoteString.js +0 -36
  81. package/dist/es/utils/shallowCopy.js +0 -41
package/dist/es/Seq.js DELETED
@@ -1,401 +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 { wrapIndex } from './TrieUtils.js';
26
- import { Collection } from './Collection.js';
27
- import { isSeq, IS_SEQ_SYMBOL } from './predicates/isSeq.js';
28
- import { isImmutable } from './predicates/isImmutable.js';
29
- import { isCollection } from './predicates/isCollection.js';
30
- import { isKeyed } from './predicates/isKeyed.js';
31
- import { isAssociative } from './predicates/isAssociative.js';
32
- import { isRecord } from './predicates/isRecord.js';
33
- import { IS_ORDERED_SYMBOL } from './predicates/isOrdered.js';
34
- import { Iterator, iteratorDone, iteratorValue, isEntriesIterable, isKeysIterable, hasIterator, getIterator, isIterator } from './Iterator.js';
35
- import hasOwnProperty from './utils/hasOwnProperty.js';
36
- import isArrayLike from './utils/isArrayLike.js';
37
-
38
- var Seq = /*@__PURE__*/(function (Collection) {
39
- function Seq(value) {
40
- // eslint-disable-next-line no-constructor-return
41
- return value === undefined || value === null
42
- ? emptySequence()
43
- : isImmutable(value)
44
- ? value.toSeq()
45
- : seqFromValue(value);
46
- }
47
-
48
- if ( Collection ) Seq.__proto__ = Collection;
49
- Seq.prototype = Object.create( Collection && Collection.prototype );
50
- Seq.prototype.constructor = Seq;
51
-
52
- Seq.prototype.toSeq = function toSeq () {
53
- return this;
54
- };
55
-
56
- Seq.prototype.toString = function toString () {
57
- return this.__toString('Seq {', '}');
58
- };
59
-
60
- Seq.prototype.cacheResult = function cacheResult () {
61
- if (!this._cache && this.__iterateUncached) {
62
- this._cache = this.entrySeq().toArray();
63
- this.size = this._cache.length;
64
- }
65
- return this;
66
- };
67
-
68
- // abstract __iterateUncached(fn, reverse)
69
-
70
- Seq.prototype.__iterate = function __iterate (fn, reverse) {
71
- var cache = this._cache;
72
- if (cache) {
73
- var size = cache.length;
74
- var i = 0;
75
- while (i !== size) {
76
- var entry = cache[reverse ? size - ++i : i++];
77
- if (fn(entry[1], entry[0], this) === false) {
78
- break;
79
- }
80
- }
81
- return i;
82
- }
83
- return this.__iterateUncached(fn, reverse);
84
- };
85
-
86
- // abstract __iteratorUncached(type, reverse)
87
-
88
- Seq.prototype.__iterator = function __iterator (type, reverse) {
89
- var cache = this._cache;
90
- if (cache) {
91
- var size = cache.length;
92
- var i = 0;
93
- return new Iterator(function () {
94
- if (i === size) {
95
- return iteratorDone();
96
- }
97
- var entry = cache[reverse ? size - ++i : i++];
98
- return iteratorValue(type, entry[0], entry[1]);
99
- });
100
- }
101
- return this.__iteratorUncached(type, reverse);
102
- };
103
-
104
- return Seq;
105
- }(Collection));
106
-
107
- var KeyedSeq = /*@__PURE__*/(function (Seq) {
108
- function KeyedSeq(value) {
109
- // eslint-disable-next-line no-constructor-return
110
- return value === undefined || value === null
111
- ? emptySequence().toKeyedSeq()
112
- : isCollection(value)
113
- ? isKeyed(value)
114
- ? value.toSeq()
115
- : value.fromEntrySeq()
116
- : isRecord(value)
117
- ? value.toSeq()
118
- : keyedSeqFromValue(value);
119
- }
120
-
121
- if ( Seq ) KeyedSeq.__proto__ = Seq;
122
- KeyedSeq.prototype = Object.create( Seq && Seq.prototype );
123
- KeyedSeq.prototype.constructor = KeyedSeq;
124
-
125
- KeyedSeq.prototype.toKeyedSeq = function toKeyedSeq () {
126
- return this;
127
- };
128
-
129
- return KeyedSeq;
130
- }(Seq));
131
-
132
- var IndexedSeq = /*@__PURE__*/(function (Seq) {
133
- function IndexedSeq(value) {
134
- // eslint-disable-next-line no-constructor-return
135
- return value === undefined || value === null
136
- ? emptySequence()
137
- : isCollection(value)
138
- ? isKeyed(value)
139
- ? value.entrySeq()
140
- : value.toIndexedSeq()
141
- : isRecord(value)
142
- ? value.toSeq().entrySeq()
143
- : indexedSeqFromValue(value);
144
- }
145
-
146
- if ( Seq ) IndexedSeq.__proto__ = Seq;
147
- IndexedSeq.prototype = Object.create( Seq && Seq.prototype );
148
- IndexedSeq.prototype.constructor = IndexedSeq;
149
-
150
- IndexedSeq.of = function of (/*...values*/) {
151
- return IndexedSeq(arguments);
152
- };
153
-
154
- IndexedSeq.prototype.toIndexedSeq = function toIndexedSeq () {
155
- return this;
156
- };
157
-
158
- IndexedSeq.prototype.toString = function toString () {
159
- return this.__toString('Seq [', ']');
160
- };
161
-
162
- return IndexedSeq;
163
- }(Seq));
164
-
165
- var SetSeq = /*@__PURE__*/(function (Seq) {
166
- function SetSeq(value) {
167
- // eslint-disable-next-line no-constructor-return
168
- return (
169
- isCollection(value) && !isAssociative(value) ? value : IndexedSeq(value)
170
- ).toSetSeq();
171
- }
172
-
173
- if ( Seq ) SetSeq.__proto__ = Seq;
174
- SetSeq.prototype = Object.create( Seq && Seq.prototype );
175
- SetSeq.prototype.constructor = SetSeq;
176
-
177
- SetSeq.of = function of (/*...values*/) {
178
- return SetSeq(arguments);
179
- };
180
-
181
- SetSeq.prototype.toSetSeq = function toSetSeq () {
182
- return this;
183
- };
184
-
185
- return SetSeq;
186
- }(Seq));
187
-
188
- Seq.isSeq = isSeq;
189
- Seq.Keyed = KeyedSeq;
190
- Seq.Set = SetSeq;
191
- Seq.Indexed = IndexedSeq;
192
-
193
- Seq.prototype[IS_SEQ_SYMBOL] = true;
194
-
195
- // #pragma Root Sequences
196
-
197
- var ArraySeq = /*@__PURE__*/(function (IndexedSeq) {
198
- function ArraySeq(array) {
199
- this._array = array;
200
- this.size = array.length;
201
- }
202
-
203
- if ( IndexedSeq ) ArraySeq.__proto__ = IndexedSeq;
204
- ArraySeq.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
205
- ArraySeq.prototype.constructor = ArraySeq;
206
-
207
- ArraySeq.prototype.get = function get (index, notSetValue) {
208
- return this.has(index) ? this._array[wrapIndex(this, index)] : notSetValue;
209
- };
210
-
211
- ArraySeq.prototype.__iterate = function __iterate (fn, reverse) {
212
- var array = this._array;
213
- var size = array.length;
214
- var i = 0;
215
- while (i !== size) {
216
- var ii = reverse ? size - ++i : i++;
217
- if (fn(array[ii], ii, this) === false) {
218
- break;
219
- }
220
- }
221
- return i;
222
- };
223
-
224
- ArraySeq.prototype.__iterator = function __iterator (type, reverse) {
225
- var array = this._array;
226
- var size = array.length;
227
- var i = 0;
228
- return new Iterator(function () {
229
- if (i === size) {
230
- return iteratorDone();
231
- }
232
- var ii = reverse ? size - ++i : i++;
233
- return iteratorValue(type, ii, array[ii]);
234
- });
235
- };
236
-
237
- return ArraySeq;
238
- }(IndexedSeq));
239
-
240
- var ObjectSeq = /*@__PURE__*/(function (KeyedSeq) {
241
- function ObjectSeq(object) {
242
- var keys = Object.keys(object).concat(
243
- Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(object) : []
244
- );
245
- this._object = object;
246
- this._keys = keys;
247
- this.size = keys.length;
248
- }
249
-
250
- if ( KeyedSeq ) ObjectSeq.__proto__ = KeyedSeq;
251
- ObjectSeq.prototype = Object.create( KeyedSeq && KeyedSeq.prototype );
252
- ObjectSeq.prototype.constructor = ObjectSeq;
253
-
254
- ObjectSeq.prototype.get = function get (key, notSetValue) {
255
- if (notSetValue !== undefined && !this.has(key)) {
256
- return notSetValue;
257
- }
258
- return this._object[key];
259
- };
260
-
261
- ObjectSeq.prototype.has = function has (key) {
262
- return hasOwnProperty.call(this._object, key);
263
- };
264
-
265
- ObjectSeq.prototype.__iterate = function __iterate (fn, reverse) {
266
- var object = this._object;
267
- var keys = this._keys;
268
- var size = keys.length;
269
- var i = 0;
270
- while (i !== size) {
271
- var key = keys[reverse ? size - ++i : i++];
272
- if (fn(object[key], key, this) === false) {
273
- break;
274
- }
275
- }
276
- return i;
277
- };
278
-
279
- ObjectSeq.prototype.__iterator = function __iterator (type, reverse) {
280
- var object = this._object;
281
- var keys = this._keys;
282
- var size = keys.length;
283
- var i = 0;
284
- return new Iterator(function () {
285
- if (i === size) {
286
- return iteratorDone();
287
- }
288
- var key = keys[reverse ? size - ++i : i++];
289
- return iteratorValue(type, key, object[key]);
290
- });
291
- };
292
-
293
- return ObjectSeq;
294
- }(KeyedSeq));
295
- ObjectSeq.prototype[IS_ORDERED_SYMBOL] = true;
296
-
297
- var CollectionSeq = /*@__PURE__*/(function (IndexedSeq) {
298
- function CollectionSeq(collection) {
299
- this._collection = collection;
300
- this.size = collection.length || collection.size;
301
- }
302
-
303
- if ( IndexedSeq ) CollectionSeq.__proto__ = IndexedSeq;
304
- CollectionSeq.prototype = Object.create( IndexedSeq && IndexedSeq.prototype );
305
- CollectionSeq.prototype.constructor = CollectionSeq;
306
-
307
- CollectionSeq.prototype.__iterateUncached = function __iterateUncached (fn, reverse) {
308
- if (reverse) {
309
- return this.cacheResult().__iterate(fn, reverse);
310
- }
311
- var collection = this._collection;
312
- var iterator = getIterator(collection);
313
- var iterations = 0;
314
- if (isIterator(iterator)) {
315
- var step;
316
- while (!(step = iterator.next()).done) {
317
- if (fn(step.value, iterations++, this) === false) {
318
- break;
319
- }
320
- }
321
- }
322
- return iterations;
323
- };
324
-
325
- CollectionSeq.prototype.__iteratorUncached = function __iteratorUncached (type, reverse) {
326
- if (reverse) {
327
- return this.cacheResult().__iterator(type, reverse);
328
- }
329
- var collection = this._collection;
330
- var iterator = getIterator(collection);
331
- if (!isIterator(iterator)) {
332
- return new Iterator(iteratorDone);
333
- }
334
- var iterations = 0;
335
- return new Iterator(function () {
336
- var step = iterator.next();
337
- return step.done ? step : iteratorValue(type, iterations++, step.value);
338
- });
339
- };
340
-
341
- return CollectionSeq;
342
- }(IndexedSeq));
343
-
344
- // # pragma Helper functions
345
-
346
- var EMPTY_SEQ;
347
-
348
- function emptySequence() {
349
- return EMPTY_SEQ || (EMPTY_SEQ = new ArraySeq([]));
350
- }
351
-
352
- function keyedSeqFromValue(value) {
353
- var seq = maybeIndexedSeqFromValue(value);
354
- if (seq) {
355
- return seq.fromEntrySeq();
356
- }
357
- if (typeof value === 'object') {
358
- return new ObjectSeq(value);
359
- }
360
- throw new TypeError(
361
- 'Expected Array or collection object of [k, v] entries, or keyed object: ' +
362
- value
363
- );
364
- }
365
-
366
- function indexedSeqFromValue(value) {
367
- var seq = maybeIndexedSeqFromValue(value);
368
- if (seq) {
369
- return seq;
370
- }
371
- throw new TypeError(
372
- 'Expected Array or collection object of values: ' + value
373
- );
374
- }
375
-
376
- function seqFromValue(value) {
377
- var seq = maybeIndexedSeqFromValue(value);
378
- if (seq) {
379
- return isEntriesIterable(value)
380
- ? seq.fromEntrySeq()
381
- : isKeysIterable(value)
382
- ? seq.toSetSeq()
383
- : seq;
384
- }
385
- if (typeof value === 'object') {
386
- return new ObjectSeq(value);
387
- }
388
- throw new TypeError(
389
- 'Expected Array or collection object of values, or keyed object: ' + value
390
- );
391
- }
392
-
393
- function maybeIndexedSeqFromValue(value) {
394
- return isArrayLike(value)
395
- ? new ArraySeq(value)
396
- : hasIterator(value)
397
- ? new CollectionSeq(value)
398
- : undefined;
399
- }
400
-
401
- export { ArraySeq, IndexedSeq, KeyedSeq, Seq, SetSeq, indexedSeqFromValue, keyedSeqFromValue };
package/dist/es/Set.js DELETED
@@ -1,279 +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 { KeyedCollection, Collection, SetCollection } from './Collection.js';
26
- import { isOrdered } from './predicates/isOrdered.js';
27
- import { isSet, IS_SET_SYMBOL } from './predicates/isSet.js';
28
- import { emptyMap } from './Map.js';
29
- import { DELETE } from './TrieUtils.js';
30
- import { sortFactory } from './Operations.js';
31
- import assertNotInfinite from './utils/assertNotInfinite.js';
32
- import { asImmutable } from './methods/asImmutable.js';
33
- import { asMutable } from './methods/asMutable.js';
34
- import { withMutations } from './methods/withMutations.js';
35
- import { OrderedSet } from './OrderedSet.js';
36
-
37
- var Set = /*@__PURE__*/(function (SetCollection) {
38
- function Set(value) {
39
- // eslint-disable-next-line no-constructor-return
40
- return value === undefined || value === null
41
- ? emptySet()
42
- : isSet(value) && !isOrdered(value)
43
- ? value
44
- : emptySet().withMutations(function (set) {
45
- var iter = SetCollection(value);
46
- assertNotInfinite(iter.size);
47
- iter.forEach(function (v) { return set.add(v); });
48
- });
49
- }
50
-
51
- if ( SetCollection ) Set.__proto__ = SetCollection;
52
- Set.prototype = Object.create( SetCollection && SetCollection.prototype );
53
- Set.prototype.constructor = Set;
54
-
55
- Set.of = function of (/*...values*/) {
56
- return this(arguments);
57
- };
58
-
59
- Set.fromKeys = function fromKeys (value) {
60
- return this(KeyedCollection(value).keySeq());
61
- };
62
-
63
- Set.intersect = function intersect (sets) {
64
- sets = Collection(sets).toArray();
65
- return sets.length
66
- ? SetPrototype.intersect.apply(Set(sets.pop()), sets)
67
- : emptySet();
68
- };
69
-
70
- Set.union = function union (sets) {
71
- sets = Collection(sets).toArray();
72
- return sets.length
73
- ? SetPrototype.union.apply(Set(sets.pop()), sets)
74
- : emptySet();
75
- };
76
-
77
- Set.prototype.toString = function toString () {
78
- return this.__toString('Set {', '}');
79
- };
80
-
81
- // @pragma Access
82
-
83
- Set.prototype.has = function has (value) {
84
- return this._map.has(value);
85
- };
86
-
87
- // @pragma Modification
88
-
89
- Set.prototype.add = function add (value) {
90
- return updateSet(this, this._map.set(value, value));
91
- };
92
-
93
- Set.prototype.remove = function remove (value) {
94
- return updateSet(this, this._map.remove(value));
95
- };
96
-
97
- Set.prototype.clear = function clear () {
98
- return updateSet(this, this._map.clear());
99
- };
100
-
101
- // @pragma Composition
102
-
103
- Set.prototype.map = function map (mapper, context) {
104
- var this$1$1 = this;
105
-
106
- // keep track if the set is altered by the map function
107
- var didChanges = false;
108
-
109
- var newMap = updateSet(
110
- this,
111
- this._map.mapEntries(function (ref) {
112
- var v = ref[1];
113
-
114
- var mapped = mapper.call(context, v, v, this$1$1);
115
-
116
- if (mapped !== v) {
117
- didChanges = true;
118
- }
119
-
120
- return [mapped, mapped];
121
- }, context)
122
- );
123
-
124
- return didChanges ? newMap : this;
125
- };
126
-
127
- Set.prototype.union = function union () {
128
- var iters = [], len = arguments.length;
129
- while ( len-- ) iters[ len ] = arguments[ len ];
130
-
131
- iters = iters.filter(function (x) { return x.size !== 0; });
132
- if (iters.length === 0) {
133
- return this;
134
- }
135
- if (this.size === 0 && !this.__ownerID && iters.length === 1) {
136
- return this.constructor(iters[0]);
137
- }
138
- return this.withMutations(function (set) {
139
- for (var ii = 0; ii < iters.length; ii++) {
140
- if (typeof iters[ii] === 'string') {
141
- set.add(iters[ii]);
142
- } else {
143
- SetCollection(iters[ii]).forEach(function (value) { return set.add(value); });
144
- }
145
- }
146
- });
147
- };
148
-
149
- Set.prototype.intersect = function intersect () {
150
- var iters = [], len = arguments.length;
151
- while ( len-- ) iters[ len ] = arguments[ len ];
152
-
153
- if (iters.length === 0) {
154
- return this;
155
- }
156
- iters = iters.map(function (iter) { return SetCollection(iter); });
157
- var toRemove = [];
158
- this.forEach(function (value) {
159
- if (!iters.every(function (iter) { return iter.includes(value); })) {
160
- toRemove.push(value);
161
- }
162
- });
163
- return this.withMutations(function (set) {
164
- toRemove.forEach(function (value) {
165
- set.remove(value);
166
- });
167
- });
168
- };
169
-
170
- Set.prototype.subtract = function subtract () {
171
- var iters = [], len = arguments.length;
172
- while ( len-- ) iters[ len ] = arguments[ len ];
173
-
174
- if (iters.length === 0) {
175
- return this;
176
- }
177
- iters = iters.map(function (iter) { return SetCollection(iter); });
178
- var toRemove = [];
179
- this.forEach(function (value) {
180
- if (iters.some(function (iter) { return iter.includes(value); })) {
181
- toRemove.push(value);
182
- }
183
- });
184
- return this.withMutations(function (set) {
185
- toRemove.forEach(function (value) {
186
- set.remove(value);
187
- });
188
- });
189
- };
190
-
191
- Set.prototype.sort = function sort (comparator) {
192
- // Late binding
193
- return OrderedSet(sortFactory(this, comparator));
194
- };
195
-
196
- Set.prototype.sortBy = function sortBy (mapper, comparator) {
197
- // Late binding
198
- return OrderedSet(sortFactory(this, comparator, mapper));
199
- };
200
-
201
- Set.prototype.wasAltered = function wasAltered () {
202
- return this._map.wasAltered();
203
- };
204
-
205
- Set.prototype.__iterate = function __iterate (fn, reverse) {
206
- var this$1$1 = this;
207
-
208
- return this._map.__iterate(function (k) { return fn(k, k, this$1$1); }, reverse);
209
- };
210
-
211
- Set.prototype.__iterator = function __iterator (type, reverse) {
212
- return this._map.__iterator(type, reverse);
213
- };
214
-
215
- Set.prototype.__ensureOwner = function __ensureOwner (ownerID) {
216
- if (ownerID === this.__ownerID) {
217
- return this;
218
- }
219
- var newMap = this._map.__ensureOwner(ownerID);
220
- if (!ownerID) {
221
- if (this.size === 0) {
222
- return this.__empty();
223
- }
224
- this.__ownerID = ownerID;
225
- this._map = newMap;
226
- return this;
227
- }
228
- return this.__make(newMap, ownerID);
229
- };
230
-
231
- return Set;
232
- }(SetCollection));
233
-
234
- Set.isSet = isSet;
235
-
236
- var SetPrototype = Set.prototype;
237
- SetPrototype[IS_SET_SYMBOL] = true;
238
- SetPrototype[DELETE] = SetPrototype.remove;
239
- SetPrototype.merge = SetPrototype.concat = SetPrototype.union;
240
- SetPrototype.withMutations = withMutations;
241
- SetPrototype.asImmutable = asImmutable;
242
- SetPrototype['@@transducer/init'] = SetPrototype.asMutable = asMutable;
243
- SetPrototype['@@transducer/step'] = function (result, arr) {
244
- return result.add(arr);
245
- };
246
- SetPrototype['@@transducer/result'] = function (obj) {
247
- return obj.asImmutable();
248
- };
249
-
250
- SetPrototype.__empty = emptySet;
251
- SetPrototype.__make = makeSet;
252
-
253
- function updateSet(set, newMap) {
254
- if (set.__ownerID) {
255
- set.size = newMap.size;
256
- set._map = newMap;
257
- return set;
258
- }
259
- return newMap === set._map
260
- ? set
261
- : newMap.size === 0
262
- ? set.__empty()
263
- : set.__make(newMap);
264
- }
265
-
266
- function makeSet(map, ownerID) {
267
- var set = Object.create(SetPrototype);
268
- set.size = map ? map.size : 0;
269
- set._map = map;
270
- set.__ownerID = ownerID;
271
- return set;
272
- }
273
-
274
- var EMPTY_SET;
275
- function emptySet() {
276
- return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
277
- }
278
-
279
- export { Set };