immutable 3.7.4 → 3.8.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.js CHANGED
@@ -6,10 +6,11 @@
6
6
  * LICENSE file in the root directory of this source tree. An additional grant
7
7
  * of patent rights can be found in the PATENTS file in the same directory.
8
8
  */
9
+
9
10
  (function (global, factory) {
10
11
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
11
12
  typeof define === 'function' && define.amd ? define(factory) :
12
- global.Immutable = factory()
13
+ (global.Immutable = factory());
13
14
  }(this, function () { 'use strict';var SLICE$0 = Array.prototype.slice;
14
15
 
15
16
  function createClass(ctor, superClass) {
@@ -19,6 +20,66 @@
19
20
  ctor.prototype.constructor = ctor;
20
21
  }
21
22
 
23
+ function Iterable(value) {
24
+ return isIterable(value) ? value : Seq(value);
25
+ }
26
+
27
+
28
+ createClass(KeyedIterable, Iterable);
29
+ function KeyedIterable(value) {
30
+ return isKeyed(value) ? value : KeyedSeq(value);
31
+ }
32
+
33
+
34
+ createClass(IndexedIterable, Iterable);
35
+ function IndexedIterable(value) {
36
+ return isIndexed(value) ? value : IndexedSeq(value);
37
+ }
38
+
39
+
40
+ createClass(SetIterable, Iterable);
41
+ function SetIterable(value) {
42
+ return isIterable(value) && !isAssociative(value) ? value : SetSeq(value);
43
+ }
44
+
45
+
46
+
47
+ function isIterable(maybeIterable) {
48
+ return !!(maybeIterable && maybeIterable[IS_ITERABLE_SENTINEL]);
49
+ }
50
+
51
+ function isKeyed(maybeKeyed) {
52
+ return !!(maybeKeyed && maybeKeyed[IS_KEYED_SENTINEL]);
53
+ }
54
+
55
+ function isIndexed(maybeIndexed) {
56
+ return !!(maybeIndexed && maybeIndexed[IS_INDEXED_SENTINEL]);
57
+ }
58
+
59
+ function isAssociative(maybeAssociative) {
60
+ return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
61
+ }
62
+
63
+ function isOrdered(maybeOrdered) {
64
+ return !!(maybeOrdered && maybeOrdered[IS_ORDERED_SENTINEL]);
65
+ }
66
+
67
+ Iterable.isIterable = isIterable;
68
+ Iterable.isKeyed = isKeyed;
69
+ Iterable.isIndexed = isIndexed;
70
+ Iterable.isAssociative = isAssociative;
71
+ Iterable.isOrdered = isOrdered;
72
+
73
+ Iterable.Keyed = KeyedIterable;
74
+ Iterable.Indexed = IndexedIterable;
75
+ Iterable.Set = SetIterable;
76
+
77
+
78
+ var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
79
+ var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
80
+ var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
81
+ var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
82
+
22
83
  // Used for setting prototype methods that IE8 chokes on.
23
84
  var DELETE = 'delete';
24
85
 
@@ -68,7 +129,21 @@
68
129
  }
69
130
 
70
131
  function wrapIndex(iter, index) {
71
- return index >= 0 ? (+index) : ensureSize(iter) + (+index);
132
+ // This implements "is array index" which the ECMAString spec defines as:
133
+ //
134
+ // A String property name P is an array index if and only if
135
+ // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal
136
+ // to 2^32−1.
137
+ //
138
+ // http://www.ecma-international.org/ecma-262/6.0/#sec-array-exotic-objects
139
+ if (typeof index !== 'number') {
140
+ var uint32Index = index >>> 0; // N >>> 0 is shorthand for ToUint32
141
+ if ('' + uint32Index !== index || uint32Index === 4294967295) {
142
+ return NaN;
143
+ }
144
+ index = uint32Index;
145
+ }
146
+ return index < 0 ? ensureSize(iter) + index : index;
72
147
  }
73
148
 
74
149
  function returnTrue() {
@@ -98,66 +173,6 @@
98
173
  Math.min(size, index);
99
174
  }
100
175
 
101
- function Iterable(value) {
102
- return isIterable(value) ? value : Seq(value);
103
- }
104
-
105
-
106
- createClass(KeyedIterable, Iterable);
107
- function KeyedIterable(value) {
108
- return isKeyed(value) ? value : KeyedSeq(value);
109
- }
110
-
111
-
112
- createClass(IndexedIterable, Iterable);
113
- function IndexedIterable(value) {
114
- return isIndexed(value) ? value : IndexedSeq(value);
115
- }
116
-
117
-
118
- createClass(SetIterable, Iterable);
119
- function SetIterable(value) {
120
- return isIterable(value) && !isAssociative(value) ? value : SetSeq(value);
121
- }
122
-
123
-
124
-
125
- function isIterable(maybeIterable) {
126
- return !!(maybeIterable && maybeIterable[IS_ITERABLE_SENTINEL]);
127
- }
128
-
129
- function isKeyed(maybeKeyed) {
130
- return !!(maybeKeyed && maybeKeyed[IS_KEYED_SENTINEL]);
131
- }
132
-
133
- function isIndexed(maybeIndexed) {
134
- return !!(maybeIndexed && maybeIndexed[IS_INDEXED_SENTINEL]);
135
- }
136
-
137
- function isAssociative(maybeAssociative) {
138
- return isKeyed(maybeAssociative) || isIndexed(maybeAssociative);
139
- }
140
-
141
- function isOrdered(maybeOrdered) {
142
- return !!(maybeOrdered && maybeOrdered[IS_ORDERED_SENTINEL]);
143
- }
144
-
145
- Iterable.isIterable = isIterable;
146
- Iterable.isKeyed = isKeyed;
147
- Iterable.isIndexed = isIndexed;
148
- Iterable.isAssociative = isAssociative;
149
- Iterable.isOrdered = isOrdered;
150
-
151
- Iterable.Keyed = KeyedIterable;
152
- Iterable.Indexed = IndexedIterable;
153
- Iterable.Set = SetIterable;
154
-
155
-
156
- var IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@';
157
- var IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
158
- var IS_INDEXED_SENTINEL = '@@__IMMUTABLE_INDEXED__@@';
159
- var IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
160
-
161
176
  /* global Symbol */
162
177
 
163
178
  var ITERATE_KEYS = 0;
@@ -170,22 +185,22 @@
170
185
  var ITERATOR_SYMBOL = REAL_ITERATOR_SYMBOL || FAUX_ITERATOR_SYMBOL;
171
186
 
172
187
 
173
- function src_Iterator__Iterator(next) {
188
+ function Iterator(next) {
174
189
  this.next = next;
175
190
  }
176
191
 
177
- src_Iterator__Iterator.prototype.toString = function() {
192
+ Iterator.prototype.toString = function() {
178
193
  return '[Iterator]';
179
194
  };
180
195
 
181
196
 
182
- src_Iterator__Iterator.KEYS = ITERATE_KEYS;
183
- src_Iterator__Iterator.VALUES = ITERATE_VALUES;
184
- src_Iterator__Iterator.ENTRIES = ITERATE_ENTRIES;
197
+ Iterator.KEYS = ITERATE_KEYS;
198
+ Iterator.VALUES = ITERATE_VALUES;
199
+ Iterator.ENTRIES = ITERATE_ENTRIES;
185
200
 
186
- src_Iterator__Iterator.prototype.inspect =
187
- src_Iterator__Iterator.prototype.toSource = function () { return this.toString(); }
188
- src_Iterator__Iterator.prototype[ITERATOR_SYMBOL] = function () {
201
+ Iterator.prototype.inspect =
202
+ Iterator.prototype.toSource = function () { return this.toString(); }
203
+ Iterator.prototype[ITERATOR_SYMBOL] = function () {
189
204
  return this;
190
205
  };
191
206
 
@@ -343,8 +358,6 @@
343
358
 
344
359
 
345
360
 
346
- // #pragma Root Sequences
347
-
348
361
  createClass(ArraySeq, IndexedSeq);
349
362
  function ArraySeq(array) {
350
363
  this._array = array;
@@ -370,7 +383,7 @@
370
383
  var array = this._array;
371
384
  var maxIndex = array.length - 1;
372
385
  var ii = 0;
373
- return new src_Iterator__Iterator(function()
386
+ return new Iterator(function()
374
387
  {return ii > maxIndex ?
375
388
  iteratorDone() :
376
389
  iteratorValue(type, ii, array[reverse ? maxIndex - ii++ : ii++])}
@@ -416,7 +429,7 @@
416
429
  var keys = this._keys;
417
430
  var maxIndex = keys.length - 1;
418
431
  var ii = 0;
419
- return new src_Iterator__Iterator(function() {
432
+ return new Iterator(function() {
420
433
  var key = keys[reverse ? maxIndex - ii : ii];
421
434
  return ii++ > maxIndex ?
422
435
  iteratorDone() :
@@ -458,10 +471,10 @@
458
471
  var iterable = this._iterable;
459
472
  var iterator = getIterator(iterable);
460
473
  if (!isIterator(iterator)) {
461
- return new src_Iterator__Iterator(iteratorDone);
474
+ return new Iterator(iteratorDone);
462
475
  }
463
476
  var iterations = 0;
464
- return new src_Iterator__Iterator(function() {
477
+ return new Iterator(function() {
465
478
  var step = iterator.next();
466
479
  return step.done ? step : iteratorValue(type, iterations++, step.value);
467
480
  });
@@ -505,7 +518,7 @@
505
518
  var iterator = this._iterator;
506
519
  var cache = this._iteratorCache;
507
520
  var iterations = 0;
508
- return new src_Iterator__Iterator(function() {
521
+ return new Iterator(function() {
509
522
  if (iterations >= cache.length) {
510
523
  var step = iterator.next();
511
524
  if (step.done) {
@@ -598,7 +611,7 @@
598
611
  if (cache) {
599
612
  var maxIndex = cache.length - 1;
600
613
  var ii = 0;
601
- return new src_Iterator__Iterator(function() {
614
+ return new Iterator(function() {
602
615
  var entry = cache[reverse ? maxIndex - ii : ii];
603
616
  return ii++ > maxIndex ?
604
617
  iteratorDone() :
@@ -608,22 +621,35 @@
608
621
  return seq.__iteratorUncached(type, reverse);
609
622
  }
610
623
 
611
- createClass(Collection, Iterable);
612
- function Collection() {
613
- throw TypeError('Abstract');
614
- }
615
-
616
-
617
- createClass(KeyedCollection, Collection);function KeyedCollection() {}
618
-
619
- createClass(IndexedCollection, Collection);function IndexedCollection() {}
624
+ function fromJS(json, converter) {
625
+ return converter ?
626
+ fromJSWith(converter, json, '', {'': json}) :
627
+ fromJSDefault(json);
628
+ }
620
629
 
621
- createClass(SetCollection, Collection);function SetCollection() {}
630
+ function fromJSWith(converter, json, key, parentJSON) {
631
+ if (Array.isArray(json)) {
632
+ return converter.call(parentJSON, key, IndexedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
633
+ }
634
+ if (isPlainObj(json)) {
635
+ return converter.call(parentJSON, key, KeyedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
636
+ }
637
+ return json;
638
+ }
622
639
 
640
+ function fromJSDefault(json) {
641
+ if (Array.isArray(json)) {
642
+ return IndexedSeq(json).map(fromJSDefault).toList();
643
+ }
644
+ if (isPlainObj(json)) {
645
+ return KeyedSeq(json).map(fromJSDefault).toMap();
646
+ }
647
+ return json;
648
+ }
623
649
 
624
- Collection.Keyed = KeyedCollection;
625
- Collection.Indexed = IndexedCollection;
626
- Collection.Set = SetCollection;
650
+ function isPlainObj(value) {
651
+ return value && (value.constructor === Object || value.constructor === undefined);
652
+ }
627
653
 
628
654
  /**
629
655
  * An extension of the "same-value" algorithm as [described for use by ES6 Map
@@ -705,1303 +731,741 @@
705
731
  return false;
706
732
  }
707
733
 
708
- function fromJS(json, converter) {
709
- return converter ?
710
- fromJSWith(converter, json, '', {'': json}) :
711
- fromJSDefault(json);
712
- }
713
-
714
- function fromJSWith(converter, json, key, parentJSON) {
715
- if (Array.isArray(json)) {
716
- return converter.call(parentJSON, key, IndexedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
717
- }
718
- if (isPlainObj(json)) {
719
- return converter.call(parentJSON, key, KeyedSeq(json).map(function(v, k) {return fromJSWith(converter, v, k, json)}));
734
+ function deepEqual(a, b) {
735
+ if (a === b) {
736
+ return true;
720
737
  }
721
- return json;
722
- }
723
738
 
724
- function fromJSDefault(json) {
725
- if (Array.isArray(json)) {
726
- return IndexedSeq(json).map(fromJSDefault).toList();
739
+ if (
740
+ !isIterable(b) ||
741
+ a.size !== undefined && b.size !== undefined && a.size !== b.size ||
742
+ a.__hash !== undefined && b.__hash !== undefined && a.__hash !== b.__hash ||
743
+ isKeyed(a) !== isKeyed(b) ||
744
+ isIndexed(a) !== isIndexed(b) ||
745
+ isOrdered(a) !== isOrdered(b)
746
+ ) {
747
+ return false;
727
748
  }
728
- if (isPlainObj(json)) {
729
- return KeyedSeq(json).map(fromJSDefault).toMap();
749
+
750
+ if (a.size === 0 && b.size === 0) {
751
+ return true;
730
752
  }
731
- return json;
732
- }
733
753
 
734
- function isPlainObj(value) {
735
- return value && (value.constructor === Object || value.constructor === undefined);
736
- }
754
+ var notAssociative = !isAssociative(a);
737
755
 
738
- var src_Math__imul =
739
- typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2 ?
740
- Math.imul :
741
- function src_Math__imul(a, b) {
742
- a = a | 0; // int
743
- b = b | 0; // int
744
- var c = a & 0xffff;
745
- var d = b & 0xffff;
746
- // Shift by 0 fixes the sign on the high part.
747
- return (c * d) + ((((a >>> 16) * d + c * (b >>> 16)) << 16) >>> 0) | 0; // int
748
- };
756
+ if (isOrdered(a)) {
757
+ var entries = a.entries();
758
+ return b.every(function(v, k) {
759
+ var entry = entries.next().value;
760
+ return entry && is(entry[1], v) && (notAssociative || is(entry[0], k));
761
+ }) && entries.next().done;
762
+ }
749
763
 
750
- // v8 has an optimization for storing 31-bit signed numbers.
751
- // Values which have either 00 or 11 as the high order bits qualify.
752
- // This function drops the highest order bit in a signed number, maintaining
753
- // the sign bit.
754
- function smi(i32) {
755
- return ((i32 >>> 1) & 0x40000000) | (i32 & 0xBFFFFFFF);
756
- }
764
+ var flipped = false;
757
765
 
758
- function hash(o) {
759
- if (o === false || o === null || o === undefined) {
760
- return 0;
761
- }
762
- if (typeof o.valueOf === 'function') {
763
- o = o.valueOf();
764
- if (o === false || o === null || o === undefined) {
765
- return 0;
766
+ if (a.size === undefined) {
767
+ if (b.size === undefined) {
768
+ if (typeof a.cacheResult === 'function') {
769
+ a.cacheResult();
770
+ }
771
+ } else {
772
+ flipped = true;
773
+ var _ = a;
774
+ a = b;
775
+ b = _;
766
776
  }
767
777
  }
768
- if (o === true) {
769
- return 1;
770
- }
771
- var type = typeof o;
772
- if (type === 'number') {
773
- var h = o | 0;
774
- if (h !== o) {
775
- h ^= o * 0xFFFFFFFF;
776
- }
777
- while (o > 0xFFFFFFFF) {
778
- o /= 0xFFFFFFFF;
779
- h ^= o;
780
- }
781
- return smi(h);
782
- }
783
- if (type === 'string') {
784
- return o.length > STRING_HASH_CACHE_MIN_STRLEN ? cachedHashString(o) : hashString(o);
785
- }
786
- if (typeof o.hashCode === 'function') {
787
- return o.hashCode();
788
- }
789
- return hashJSObj(o);
790
- }
791
778
 
792
- function cachedHashString(string) {
793
- var hash = stringHashCache[string];
794
- if (hash === undefined) {
795
- hash = hashString(string);
796
- if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
797
- STRING_HASH_CACHE_SIZE = 0;
798
- stringHashCache = {};
779
+ var allEqual = true;
780
+ var bSize = b.__iterate(function(v, k) {
781
+ if (notAssociative ? !a.has(v) :
782
+ flipped ? !is(v, a.get(k, NOT_SET)) : !is(a.get(k, NOT_SET), v)) {
783
+ allEqual = false;
784
+ return false;
799
785
  }
800
- STRING_HASH_CACHE_SIZE++;
801
- stringHashCache[string] = hash;
802
- }
803
- return hash;
804
- }
786
+ });
805
787
 
806
- // http://jsperf.com/hashing-strings
807
- function hashString(string) {
808
- // This is the hash from JVM
809
- // The hash code for a string is computed as
810
- // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
811
- // where s[i] is the ith character of the string and n is the length of
812
- // the string. We "mod" the result to make it between 0 (inclusive) and 2^31
813
- // (exclusive) by dropping high bits.
814
- var hash = 0;
815
- for (var ii = 0; ii < string.length; ii++) {
816
- hash = 31 * hash + string.charCodeAt(ii) | 0;
817
- }
818
- return smi(hash);
788
+ return allEqual && a.size === bSize;
819
789
  }
820
790
 
821
- function hashJSObj(obj) {
822
- var hash;
823
- if (usingWeakMap) {
824
- hash = weakMap.get(obj);
825
- if (hash !== undefined) {
826
- return hash;
827
- }
828
- }
791
+ createClass(Repeat, IndexedSeq);
829
792
 
830
- hash = obj[UID_HASH_KEY];
831
- if (hash !== undefined) {
832
- return hash;
793
+ function Repeat(value, times) {
794
+ if (!(this instanceof Repeat)) {
795
+ return new Repeat(value, times);
796
+ }
797
+ this._value = value;
798
+ this.size = times === undefined ? Infinity : Math.max(0, times);
799
+ if (this.size === 0) {
800
+ if (EMPTY_REPEAT) {
801
+ return EMPTY_REPEAT;
802
+ }
803
+ EMPTY_REPEAT = this;
804
+ }
833
805
  }
834
806
 
835
- if (!canDefineProperty) {
836
- hash = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
837
- if (hash !== undefined) {
838
- return hash;
807
+ Repeat.prototype.toString = function() {
808
+ if (this.size === 0) {
809
+ return 'Repeat []';
839
810
  }
811
+ return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]';
812
+ };
840
813
 
841
- hash = getIENodeHash(obj);
842
- if (hash !== undefined) {
843
- return hash;
844
- }
845
- }
814
+ Repeat.prototype.get = function(index, notSetValue) {
815
+ return this.has(index) ? this._value : notSetValue;
816
+ };
846
817
 
847
- hash = ++objHashUID;
848
- if (objHashUID & 0x40000000) {
849
- objHashUID = 0;
850
- }
818
+ Repeat.prototype.includes = function(searchValue) {
819
+ return is(this._value, searchValue);
820
+ };
851
821
 
852
- if (usingWeakMap) {
853
- weakMap.set(obj, hash);
854
- } else if (isExtensible !== undefined && isExtensible(obj) === false) {
855
- throw new Error('Non-extensible objects are not allowed as keys.');
856
- } else if (canDefineProperty) {
857
- Object.defineProperty(obj, UID_HASH_KEY, {
858
- 'enumerable': false,
859
- 'configurable': false,
860
- 'writable': false,
861
- 'value': hash
862
- });
863
- } else if (obj.propertyIsEnumerable !== undefined &&
864
- obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable) {
865
- // Since we can't define a non-enumerable property on the object
866
- // we'll hijack one of the less-used non-enumerable properties to
867
- // save our hash on it. Since this is a function it will not show up in
868
- // `JSON.stringify` which is what we want.
869
- obj.propertyIsEnumerable = function() {
870
- return this.constructor.prototype.propertyIsEnumerable.apply(this, arguments);
871
- };
872
- obj.propertyIsEnumerable[UID_HASH_KEY] = hash;
873
- } else if (obj.nodeType !== undefined) {
874
- // At this point we couldn't get the IE `uniqueID` to use as a hash
875
- // and we couldn't use a non-enumerable property to exploit the
876
- // dontEnum bug so we simply add the `UID_HASH_KEY` on the node
877
- // itself.
878
- obj[UID_HASH_KEY] = hash;
879
- } else {
880
- throw new Error('Unable to set a non-enumerable property on object.');
881
- }
822
+ Repeat.prototype.slice = function(begin, end) {
823
+ var size = this.size;
824
+ return wholeSlice(begin, end, size) ? this :
825
+ new Repeat(this._value, resolveEnd(end, size) - resolveBegin(begin, size));
826
+ };
882
827
 
883
- return hash;
884
- }
828
+ Repeat.prototype.reverse = function() {
829
+ return this;
830
+ };
885
831
 
886
- // Get references to ES5 object methods.
887
- var isExtensible = Object.isExtensible;
832
+ Repeat.prototype.indexOf = function(searchValue) {
833
+ if (is(this._value, searchValue)) {
834
+ return 0;
835
+ }
836
+ return -1;
837
+ };
888
838
 
889
- // True if Object.defineProperty works as expected. IE8 fails this test.
890
- var canDefineProperty = (function() {
891
- try {
892
- Object.defineProperty({}, '@', {});
893
- return true;
894
- } catch (e) {
895
- return false;
896
- }
897
- }());
839
+ Repeat.prototype.lastIndexOf = function(searchValue) {
840
+ if (is(this._value, searchValue)) {
841
+ return this.size;
842
+ }
843
+ return -1;
844
+ };
898
845
 
899
- // IE has a `uniqueID` property on DOM nodes. We can construct the hash from it
900
- // and avoid memory leaks from the IE cloneNode bug.
901
- function getIENodeHash(node) {
902
- if (node && node.nodeType > 0) {
903
- switch (node.nodeType) {
904
- case 1: // Element
905
- return node.uniqueID;
906
- case 9: // Document
907
- return node.documentElement && node.documentElement.uniqueID;
846
+ Repeat.prototype.__iterate = function(fn, reverse) {
847
+ for (var ii = 0; ii < this.size; ii++) {
848
+ if (fn(this._value, ii, this) === false) {
849
+ return ii + 1;
850
+ }
908
851
  }
909
- }
910
- }
852
+ return ii;
853
+ };
911
854
 
912
- // If possible, use a WeakMap.
913
- var usingWeakMap = typeof WeakMap === 'function';
914
- var weakMap;
915
- if (usingWeakMap) {
916
- weakMap = new WeakMap();
917
- }
855
+ Repeat.prototype.__iterator = function(type, reverse) {var this$0 = this;
856
+ var ii = 0;
857
+ return new Iterator(function()
858
+ {return ii < this$0.size ? iteratorValue(type, ii++, this$0._value) : iteratorDone()}
859
+ );
860
+ };
918
861
 
919
- var objHashUID = 0;
862
+ Repeat.prototype.equals = function(other) {
863
+ return other instanceof Repeat ?
864
+ is(this._value, other._value) :
865
+ deepEqual(other);
866
+ };
920
867
 
921
- var UID_HASH_KEY = '__immutablehash__';
922
- if (typeof Symbol === 'function') {
923
- UID_HASH_KEY = Symbol(UID_HASH_KEY);
924
- }
925
868
 
926
- var STRING_HASH_CACHE_MIN_STRLEN = 16;
927
- var STRING_HASH_CACHE_MAX_SIZE = 255;
928
- var STRING_HASH_CACHE_SIZE = 0;
929
- var stringHashCache = {};
869
+ var EMPTY_REPEAT;
930
870
 
931
871
  function invariant(condition, error) {
932
872
  if (!condition) throw new Error(error);
933
873
  }
934
874
 
935
- function assertNotInfinite(size) {
936
- invariant(
937
- size !== Infinity,
938
- 'Cannot perform this action with an infinite size.'
939
- );
940
- }
875
+ createClass(Range, IndexedSeq);
941
876
 
942
- createClass(ToKeyedSequence, KeyedSeq);
943
- function ToKeyedSequence(indexed, useKeys) {
944
- this._iter = indexed;
945
- this._useKeys = useKeys;
946
- this.size = indexed.size;
877
+ function Range(start, end, step) {
878
+ if (!(this instanceof Range)) {
879
+ return new Range(start, end, step);
880
+ }
881
+ invariant(step !== 0, 'Cannot step a Range by 0');
882
+ start = start || 0;
883
+ if (end === undefined) {
884
+ end = Infinity;
885
+ }
886
+ step = step === undefined ? 1 : Math.abs(step);
887
+ if (end < start) {
888
+ step = -step;
889
+ }
890
+ this._start = start;
891
+ this._end = end;
892
+ this._step = step;
893
+ this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
894
+ if (this.size === 0) {
895
+ if (EMPTY_RANGE) {
896
+ return EMPTY_RANGE;
897
+ }
898
+ EMPTY_RANGE = this;
899
+ }
947
900
  }
948
901
 
949
- ToKeyedSequence.prototype.get = function(key, notSetValue) {
950
- return this._iter.get(key, notSetValue);
902
+ Range.prototype.toString = function() {
903
+ if (this.size === 0) {
904
+ return 'Range []';
905
+ }
906
+ return 'Range [ ' +
907
+ this._start + '...' + this._end +
908
+ (this._step !== 1 ? ' by ' + this._step : '') +
909
+ ' ]';
951
910
  };
952
911
 
953
- ToKeyedSequence.prototype.has = function(key) {
954
- return this._iter.has(key);
912
+ Range.prototype.get = function(index, notSetValue) {
913
+ return this.has(index) ?
914
+ this._start + wrapIndex(this, index) * this._step :
915
+ notSetValue;
955
916
  };
956
917
 
957
- ToKeyedSequence.prototype.valueSeq = function() {
958
- return this._iter.valueSeq();
918
+ Range.prototype.includes = function(searchValue) {
919
+ var possibleIndex = (searchValue - this._start) / this._step;
920
+ return possibleIndex >= 0 &&
921
+ possibleIndex < this.size &&
922
+ possibleIndex === Math.floor(possibleIndex);
959
923
  };
960
924
 
961
- ToKeyedSequence.prototype.reverse = function() {var this$0 = this;
962
- var reversedSequence = reverseFactory(this, true);
963
- if (!this._useKeys) {
964
- reversedSequence.valueSeq = function() {return this$0._iter.toSeq().reverse()};
925
+ Range.prototype.slice = function(begin, end) {
926
+ if (wholeSlice(begin, end, this.size)) {
927
+ return this;
965
928
  }
966
- return reversedSequence;
929
+ begin = resolveBegin(begin, this.size);
930
+ end = resolveEnd(end, this.size);
931
+ if (end <= begin) {
932
+ return new Range(0, 0);
933
+ }
934
+ return new Range(this.get(begin, this._end), this.get(end, this._end), this._step);
967
935
  };
968
936
 
969
- ToKeyedSequence.prototype.map = function(mapper, context) {var this$0 = this;
970
- var mappedSequence = mapFactory(this, mapper, context);
971
- if (!this._useKeys) {
972
- mappedSequence.valueSeq = function() {return this$0._iter.toSeq().map(mapper, context)};
937
+ Range.prototype.indexOf = function(searchValue) {
938
+ var offsetValue = searchValue - this._start;
939
+ if (offsetValue % this._step === 0) {
940
+ var index = offsetValue / this._step;
941
+ if (index >= 0 && index < this.size) {
942
+ return index
943
+ }
973
944
  }
974
- return mappedSequence;
945
+ return -1;
975
946
  };
976
947
 
977
- ToKeyedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
978
- var ii;
979
- return this._iter.__iterate(
980
- this._useKeys ?
981
- function(v, k) {return fn(v, k, this$0)} :
982
- ((ii = reverse ? resolveSize(this) : 0),
983
- function(v ) {return fn(v, reverse ? --ii : ii++, this$0)}),
984
- reverse
985
- );
948
+ Range.prototype.lastIndexOf = function(searchValue) {
949
+ return this.indexOf(searchValue);
986
950
  };
987
951
 
988
- ToKeyedSequence.prototype.__iterator = function(type, reverse) {
989
- if (this._useKeys) {
990
- return this._iter.__iterator(type, reverse);
952
+ Range.prototype.__iterate = function(fn, reverse) {
953
+ var maxIndex = this.size - 1;
954
+ var step = this._step;
955
+ var value = reverse ? this._start + maxIndex * step : this._start;
956
+ for (var ii = 0; ii <= maxIndex; ii++) {
957
+ if (fn(value, ii, this) === false) {
958
+ return ii + 1;
959
+ }
960
+ value += reverse ? -step : step;
991
961
  }
992
- var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
993
- var ii = reverse ? resolveSize(this) : 0;
994
- return new src_Iterator__Iterator(function() {
995
- var step = iterator.next();
996
- return step.done ? step :
997
- iteratorValue(type, reverse ? --ii : ii++, step.value, step);
998
- });
999
- };
1000
-
1001
- ToKeyedSequence.prototype[IS_ORDERED_SENTINEL] = true;
1002
-
1003
-
1004
- createClass(ToIndexedSequence, IndexedSeq);
1005
- function ToIndexedSequence(iter) {
1006
- this._iter = iter;
1007
- this.size = iter.size;
1008
- }
1009
-
1010
- ToIndexedSequence.prototype.includes = function(value) {
1011
- return this._iter.includes(value);
962
+ return ii;
1012
963
  };
1013
964
 
1014
- ToIndexedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
1015
- var iterations = 0;
1016
- return this._iter.__iterate(function(v ) {return fn(v, iterations++, this$0)}, reverse);
965
+ Range.prototype.__iterator = function(type, reverse) {
966
+ var maxIndex = this.size - 1;
967
+ var step = this._step;
968
+ var value = reverse ? this._start + maxIndex * step : this._start;
969
+ var ii = 0;
970
+ return new Iterator(function() {
971
+ var v = value;
972
+ value += reverse ? -step : step;
973
+ return ii > maxIndex ? iteratorDone() : iteratorValue(type, ii++, v);
974
+ });
1017
975
  };
1018
976
 
1019
- ToIndexedSequence.prototype.__iterator = function(type, reverse) {
1020
- var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
1021
- var iterations = 0;
1022
- return new src_Iterator__Iterator(function() {
1023
- var step = iterator.next();
1024
- return step.done ? step :
1025
- iteratorValue(type, iterations++, step.value, step)
1026
- });
977
+ Range.prototype.equals = function(other) {
978
+ return other instanceof Range ?
979
+ this._start === other._start &&
980
+ this._end === other._end &&
981
+ this._step === other._step :
982
+ deepEqual(this, other);
1027
983
  };
1028
984
 
1029
985
 
986
+ var EMPTY_RANGE;
1030
987
 
1031
- createClass(ToSetSequence, SetSeq);
1032
- function ToSetSequence(iter) {
1033
- this._iter = iter;
1034
- this.size = iter.size;
988
+ createClass(Collection, Iterable);
989
+ function Collection() {
990
+ throw TypeError('Abstract');
1035
991
  }
1036
992
 
1037
- ToSetSequence.prototype.has = function(key) {
1038
- return this._iter.includes(key);
1039
- };
1040
-
1041
- ToSetSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
1042
- return this._iter.__iterate(function(v ) {return fn(v, v, this$0)}, reverse);
1043
- };
1044
-
1045
- ToSetSequence.prototype.__iterator = function(type, reverse) {
1046
- var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
1047
- return new src_Iterator__Iterator(function() {
1048
- var step = iterator.next();
1049
- return step.done ? step :
1050
- iteratorValue(type, step.value, step.value, step);
1051
- });
1052
- };
1053
993
 
994
+ createClass(KeyedCollection, Collection);function KeyedCollection() {}
1054
995
 
996
+ createClass(IndexedCollection, Collection);function IndexedCollection() {}
1055
997
 
1056
- createClass(FromEntriesSequence, KeyedSeq);
1057
- function FromEntriesSequence(entries) {
1058
- this._iter = entries;
1059
- this.size = entries.size;
1060
- }
998
+ createClass(SetCollection, Collection);function SetCollection() {}
1061
999
 
1062
- FromEntriesSequence.prototype.entrySeq = function() {
1063
- return this._iter.toSeq();
1064
- };
1065
1000
 
1066
- FromEntriesSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
1067
- return this._iter.__iterate(function(entry ) {
1068
- // Check if entry exists first so array access doesn't throw for holes
1069
- // in the parent iteration.
1070
- if (entry) {
1071
- validateEntry(entry);
1072
- var indexedIterable = isIterable(entry);
1073
- return fn(
1074
- indexedIterable ? entry.get(1) : entry[1],
1075
- indexedIterable ? entry.get(0) : entry[0],
1076
- this$0
1077
- );
1078
- }
1079
- }, reverse);
1080
- };
1001
+ Collection.Keyed = KeyedCollection;
1002
+ Collection.Indexed = IndexedCollection;
1003
+ Collection.Set = SetCollection;
1081
1004
 
1082
- FromEntriesSequence.prototype.__iterator = function(type, reverse) {
1083
- var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
1084
- return new src_Iterator__Iterator(function() {
1085
- while (true) {
1086
- var step = iterator.next();
1087
- if (step.done) {
1088
- return step;
1089
- }
1090
- var entry = step.value;
1091
- // Check if entry exists first so array access doesn't throw for holes
1092
- // in the parent iteration.
1093
- if (entry) {
1094
- validateEntry(entry);
1095
- var indexedIterable = isIterable(entry);
1096
- return iteratorValue(
1097
- type,
1098
- indexedIterable ? entry.get(0) : entry[0],
1099
- indexedIterable ? entry.get(1) : entry[1],
1100
- step
1101
- );
1102
- }
1103
- }
1104
- });
1005
+ var imul =
1006
+ typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2 ?
1007
+ Math.imul :
1008
+ function imul(a, b) {
1009
+ a = a | 0; // int
1010
+ b = b | 0; // int
1011
+ var c = a & 0xffff;
1012
+ var d = b & 0xffff;
1013
+ // Shift by 0 fixes the sign on the high part.
1014
+ return (c * d) + ((((a >>> 16) * d + c * (b >>> 16)) << 16) >>> 0) | 0; // int
1105
1015
  };
1106
1016
 
1017
+ // v8 has an optimization for storing 31-bit signed numbers.
1018
+ // Values which have either 00 or 11 as the high order bits qualify.
1019
+ // This function drops the highest order bit in a signed number, maintaining
1020
+ // the sign bit.
1021
+ function smi(i32) {
1022
+ return ((i32 >>> 1) & 0x40000000) | (i32 & 0xBFFFFFFF);
1023
+ }
1107
1024
 
1108
- ToIndexedSequence.prototype.cacheResult =
1109
- ToKeyedSequence.prototype.cacheResult =
1110
- ToSetSequence.prototype.cacheResult =
1111
- FromEntriesSequence.prototype.cacheResult =
1112
- cacheResultThrough;
1113
-
1114
-
1115
- function flipFactory(iterable) {
1116
- var flipSequence = makeSequence(iterable);
1117
- flipSequence._iter = iterable;
1118
- flipSequence.size = iterable.size;
1119
- flipSequence.flip = function() {return iterable};
1120
- flipSequence.reverse = function () {
1121
- var reversedSequence = iterable.reverse.apply(this); // super.reverse()
1122
- reversedSequence.flip = function() {return iterable.reverse()};
1123
- return reversedSequence;
1124
- };
1125
- flipSequence.has = function(key ) {return iterable.includes(key)};
1126
- flipSequence.includes = function(key ) {return iterable.has(key)};
1127
- flipSequence.cacheResult = cacheResultThrough;
1128
- flipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
1129
- return iterable.__iterate(function(v, k) {return fn(k, v, this$0) !== false}, reverse);
1025
+ function hash(o) {
1026
+ if (o === false || o === null || o === undefined) {
1027
+ return 0;
1130
1028
  }
1131
- flipSequence.__iteratorUncached = function(type, reverse) {
1132
- if (type === ITERATE_ENTRIES) {
1133
- var iterator = iterable.__iterator(type, reverse);
1134
- return new src_Iterator__Iterator(function() {
1135
- var step = iterator.next();
1136
- if (!step.done) {
1137
- var k = step.value[0];
1138
- step.value[0] = step.value[1];
1139
- step.value[1] = k;
1140
- }
1141
- return step;
1142
- });
1029
+ if (typeof o.valueOf === 'function') {
1030
+ o = o.valueOf();
1031
+ if (o === false || o === null || o === undefined) {
1032
+ return 0;
1143
1033
  }
1144
- return iterable.__iterator(
1145
- type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES,
1146
- reverse
1147
- );
1148
1034
  }
1149
- return flipSequence;
1035
+ if (o === true) {
1036
+ return 1;
1037
+ }
1038
+ var type = typeof o;
1039
+ if (type === 'number') {
1040
+ if (o !== o || o === Infinity) {
1041
+ return 0;
1042
+ }
1043
+ var h = o | 0;
1044
+ if (h !== o) {
1045
+ h ^= o * 0xFFFFFFFF;
1046
+ }
1047
+ while (o > 0xFFFFFFFF) {
1048
+ o /= 0xFFFFFFFF;
1049
+ h ^= o;
1050
+ }
1051
+ return smi(h);
1052
+ }
1053
+ if (type === 'string') {
1054
+ return o.length > STRING_HASH_CACHE_MIN_STRLEN ? cachedHashString(o) : hashString(o);
1055
+ }
1056
+ if (typeof o.hashCode === 'function') {
1057
+ return o.hashCode();
1058
+ }
1059
+ if (type === 'object') {
1060
+ return hashJSObj(o);
1061
+ }
1062
+ if (typeof o.toString === 'function') {
1063
+ return hashString(o.toString());
1064
+ }
1065
+ throw new Error('Value type ' + type + ' cannot be hashed.');
1150
1066
  }
1151
1067
 
1152
-
1153
- function mapFactory(iterable, mapper, context) {
1154
- var mappedSequence = makeSequence(iterable);
1155
- mappedSequence.size = iterable.size;
1156
- mappedSequence.has = function(key ) {return iterable.has(key)};
1157
- mappedSequence.get = function(key, notSetValue) {
1158
- var v = iterable.get(key, NOT_SET);
1159
- return v === NOT_SET ?
1160
- notSetValue :
1161
- mapper.call(context, v, key, iterable);
1162
- };
1163
- mappedSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
1164
- return iterable.__iterate(
1165
- function(v, k, c) {return fn(mapper.call(context, v, k, c), k, this$0) !== false},
1166
- reverse
1167
- );
1068
+ function cachedHashString(string) {
1069
+ var hash = stringHashCache[string];
1070
+ if (hash === undefined) {
1071
+ hash = hashString(string);
1072
+ if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
1073
+ STRING_HASH_CACHE_SIZE = 0;
1074
+ stringHashCache = {};
1075
+ }
1076
+ STRING_HASH_CACHE_SIZE++;
1077
+ stringHashCache[string] = hash;
1168
1078
  }
1169
- mappedSequence.__iteratorUncached = function (type, reverse) {
1170
- var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
1171
- return new src_Iterator__Iterator(function() {
1172
- var step = iterator.next();
1173
- if (step.done) {
1174
- return step;
1175
- }
1176
- var entry = step.value;
1177
- var key = entry[0];
1178
- return iteratorValue(
1179
- type,
1180
- key,
1181
- mapper.call(context, entry[1], key, iterable),
1182
- step
1183
- );
1184
- });
1079
+ return hash;
1080
+ }
1081
+
1082
+ // http://jsperf.com/hashing-strings
1083
+ function hashString(string) {
1084
+ // This is the hash from JVM
1085
+ // The hash code for a string is computed as
1086
+ // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
1087
+ // where s[i] is the ith character of the string and n is the length of
1088
+ // the string. We "mod" the result to make it between 0 (inclusive) and 2^31
1089
+ // (exclusive) by dropping high bits.
1090
+ var hash = 0;
1091
+ for (var ii = 0; ii < string.length; ii++) {
1092
+ hash = 31 * hash + string.charCodeAt(ii) | 0;
1185
1093
  }
1186
- return mappedSequence;
1094
+ return smi(hash);
1187
1095
  }
1188
1096
 
1097
+ function hashJSObj(obj) {
1098
+ var hash;
1099
+ if (usingWeakMap) {
1100
+ hash = weakMap.get(obj);
1101
+ if (hash !== undefined) {
1102
+ return hash;
1103
+ }
1104
+ }
1189
1105
 
1190
- function reverseFactory(iterable, useKeys) {
1191
- var reversedSequence = makeSequence(iterable);
1192
- reversedSequence._iter = iterable;
1193
- reversedSequence.size = iterable.size;
1194
- reversedSequence.reverse = function() {return iterable};
1195
- if (iterable.flip) {
1196
- reversedSequence.flip = function () {
1197
- var flipSequence = flipFactory(iterable);
1198
- flipSequence.reverse = function() {return iterable.flip()};
1199
- return flipSequence;
1200
- };
1106
+ hash = obj[UID_HASH_KEY];
1107
+ if (hash !== undefined) {
1108
+ return hash;
1201
1109
  }
1202
- reversedSequence.get = function(key, notSetValue)
1203
- {return iterable.get(useKeys ? key : -1 - key, notSetValue)};
1204
- reversedSequence.has = function(key )
1205
- {return iterable.has(useKeys ? key : -1 - key)};
1206
- reversedSequence.includes = function(value ) {return iterable.includes(value)};
1207
- reversedSequence.cacheResult = cacheResultThrough;
1208
- reversedSequence.__iterate = function (fn, reverse) {var this$0 = this;
1209
- return iterable.__iterate(function(v, k) {return fn(v, k, this$0)}, !reverse);
1210
- };
1211
- reversedSequence.__iterator =
1212
- function(type, reverse) {return iterable.__iterator(type, !reverse)};
1213
- return reversedSequence;
1214
- }
1215
1110
 
1111
+ if (!canDefineProperty) {
1112
+ hash = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
1113
+ if (hash !== undefined) {
1114
+ return hash;
1115
+ }
1216
1116
 
1217
- function filterFactory(iterable, predicate, context, useKeys) {
1218
- var filterSequence = makeSequence(iterable);
1219
- if (useKeys) {
1220
- filterSequence.has = function(key ) {
1221
- var v = iterable.get(key, NOT_SET);
1222
- return v !== NOT_SET && !!predicate.call(context, v, key, iterable);
1223
- };
1224
- filterSequence.get = function(key, notSetValue) {
1225
- var v = iterable.get(key, NOT_SET);
1226
- return v !== NOT_SET && predicate.call(context, v, key, iterable) ?
1227
- v : notSetValue;
1228
- };
1117
+ hash = getIENodeHash(obj);
1118
+ if (hash !== undefined) {
1119
+ return hash;
1120
+ }
1229
1121
  }
1230
- filterSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
1231
- var iterations = 0;
1232
- iterable.__iterate(function(v, k, c) {
1233
- if (predicate.call(context, v, k, c)) {
1234
- iterations++;
1235
- return fn(v, useKeys ? k : iterations - 1, this$0);
1236
- }
1237
- }, reverse);
1238
- return iterations;
1239
- };
1240
- filterSequence.__iteratorUncached = function (type, reverse) {
1241
- var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
1242
- var iterations = 0;
1243
- return new src_Iterator__Iterator(function() {
1244
- while (true) {
1245
- var step = iterator.next();
1246
- if (step.done) {
1247
- return step;
1248
- }
1249
- var entry = step.value;
1250
- var key = entry[0];
1251
- var value = entry[1];
1252
- if (predicate.call(context, value, key, iterable)) {
1253
- return iteratorValue(type, useKeys ? key : iterations++, value, step);
1254
- }
1255
- }
1122
+
1123
+ hash = ++objHashUID;
1124
+ if (objHashUID & 0x40000000) {
1125
+ objHashUID = 0;
1126
+ }
1127
+
1128
+ if (usingWeakMap) {
1129
+ weakMap.set(obj, hash);
1130
+ } else if (isExtensible !== undefined && isExtensible(obj) === false) {
1131
+ throw new Error('Non-extensible objects are not allowed as keys.');
1132
+ } else if (canDefineProperty) {
1133
+ Object.defineProperty(obj, UID_HASH_KEY, {
1134
+ 'enumerable': false,
1135
+ 'configurable': false,
1136
+ 'writable': false,
1137
+ 'value': hash
1256
1138
  });
1139
+ } else if (obj.propertyIsEnumerable !== undefined &&
1140
+ obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable) {
1141
+ // Since we can't define a non-enumerable property on the object
1142
+ // we'll hijack one of the less-used non-enumerable properties to
1143
+ // save our hash on it. Since this is a function it will not show up in
1144
+ // `JSON.stringify` which is what we want.
1145
+ obj.propertyIsEnumerable = function() {
1146
+ return this.constructor.prototype.propertyIsEnumerable.apply(this, arguments);
1147
+ };
1148
+ obj.propertyIsEnumerable[UID_HASH_KEY] = hash;
1149
+ } else if (obj.nodeType !== undefined) {
1150
+ // At this point we couldn't get the IE `uniqueID` to use as a hash
1151
+ // and we couldn't use a non-enumerable property to exploit the
1152
+ // dontEnum bug so we simply add the `UID_HASH_KEY` on the node
1153
+ // itself.
1154
+ obj[UID_HASH_KEY] = hash;
1155
+ } else {
1156
+ throw new Error('Unable to set a non-enumerable property on object.');
1257
1157
  }
1258
- return filterSequence;
1158
+
1159
+ return hash;
1259
1160
  }
1260
1161
 
1162
+ // Get references to ES5 object methods.
1163
+ var isExtensible = Object.isExtensible;
1261
1164
 
1262
- function countByFactory(iterable, grouper, context) {
1263
- var groups = src_Map__Map().asMutable();
1264
- iterable.__iterate(function(v, k) {
1265
- groups.update(
1266
- grouper.call(context, v, k, iterable),
1267
- 0,
1268
- function(a ) {return a + 1}
1269
- );
1270
- });
1271
- return groups.asImmutable();
1165
+ // True if Object.defineProperty works as expected. IE8 fails this test.
1166
+ var canDefineProperty = (function() {
1167
+ try {
1168
+ Object.defineProperty({}, '@', {});
1169
+ return true;
1170
+ } catch (e) {
1171
+ return false;
1172
+ }
1173
+ }());
1174
+
1175
+ // IE has a `uniqueID` property on DOM nodes. We can construct the hash from it
1176
+ // and avoid memory leaks from the IE cloneNode bug.
1177
+ function getIENodeHash(node) {
1178
+ if (node && node.nodeType > 0) {
1179
+ switch (node.nodeType) {
1180
+ case 1: // Element
1181
+ return node.uniqueID;
1182
+ case 9: // Document
1183
+ return node.documentElement && node.documentElement.uniqueID;
1184
+ }
1185
+ }
1186
+ }
1187
+
1188
+ // If possible, use a WeakMap.
1189
+ var usingWeakMap = typeof WeakMap === 'function';
1190
+ var weakMap;
1191
+ if (usingWeakMap) {
1192
+ weakMap = new WeakMap();
1272
1193
  }
1273
1194
 
1195
+ var objHashUID = 0;
1274
1196
 
1275
- function groupByFactory(iterable, grouper, context) {
1276
- var isKeyedIter = isKeyed(iterable);
1277
- var groups = (isOrdered(iterable) ? OrderedMap() : src_Map__Map()).asMutable();
1278
- iterable.__iterate(function(v, k) {
1279
- groups.update(
1280
- grouper.call(context, v, k, iterable),
1281
- function(a ) {return (a = a || [], a.push(isKeyedIter ? [k, v] : v), a)}
1282
- );
1283
- });
1284
- var coerce = iterableClass(iterable);
1285
- return groups.map(function(arr ) {return reify(iterable, coerce(arr))});
1197
+ var UID_HASH_KEY = '__immutablehash__';
1198
+ if (typeof Symbol === 'function') {
1199
+ UID_HASH_KEY = Symbol(UID_HASH_KEY);
1286
1200
  }
1287
1201
 
1202
+ var STRING_HASH_CACHE_MIN_STRLEN = 16;
1203
+ var STRING_HASH_CACHE_MAX_SIZE = 255;
1204
+ var STRING_HASH_CACHE_SIZE = 0;
1205
+ var stringHashCache = {};
1288
1206
 
1289
- function sliceFactory(iterable, begin, end, useKeys) {
1290
- var originalSize = iterable.size;
1207
+ function assertNotInfinite(size) {
1208
+ invariant(
1209
+ size !== Infinity,
1210
+ 'Cannot perform this action with an infinite size.'
1211
+ );
1212
+ }
1291
1213
 
1292
- if (wholeSlice(begin, end, originalSize)) {
1293
- return iterable;
1294
- }
1214
+ createClass(Map, KeyedCollection);
1295
1215
 
1296
- var resolvedBegin = resolveBegin(begin, originalSize);
1297
- var resolvedEnd = resolveEnd(end, originalSize);
1216
+ // @pragma Construction
1298
1217
 
1299
- // begin or end will be NaN if they were provided as negative numbers and
1300
- // this iterable's size is unknown. In that case, cache first so there is
1301
- // a known size and these do not resolve to NaN.
1302
- if (resolvedBegin !== resolvedBegin || resolvedEnd !== resolvedEnd) {
1303
- return sliceFactory(iterable.toSeq().cacheResult(), begin, end, useKeys);
1218
+ function Map(value) {
1219
+ return value === null || value === undefined ? emptyMap() :
1220
+ isMap(value) && !isOrdered(value) ? value :
1221
+ emptyMap().withMutations(function(map ) {
1222
+ var iter = KeyedIterable(value);
1223
+ assertNotInfinite(iter.size);
1224
+ iter.forEach(function(v, k) {return map.set(k, v)});
1225
+ });
1304
1226
  }
1305
1227
 
1306
- // Note: resolvedEnd is undefined when the original sequence's length is
1307
- // unknown and this slice did not supply an end and should contain all
1308
- // elements after resolvedBegin.
1309
- // In that case, resolvedSize will be NaN and sliceSize will remain undefined.
1310
- var resolvedSize = resolvedEnd - resolvedBegin;
1311
- var sliceSize;
1312
- if (resolvedSize === resolvedSize) {
1313
- sliceSize = resolvedSize < 0 ? 0 : resolvedSize;
1314
- }
1228
+ Map.of = function() {var keyValues = SLICE$0.call(arguments, 0);
1229
+ return emptyMap().withMutations(function(map ) {
1230
+ for (var i = 0; i < keyValues.length; i += 2) {
1231
+ if (i + 1 >= keyValues.length) {
1232
+ throw new Error('Missing value for key: ' + keyValues[i]);
1233
+ }
1234
+ map.set(keyValues[i], keyValues[i + 1]);
1235
+ }
1236
+ });
1237
+ };
1315
1238
 
1316
- var sliceSeq = makeSequence(iterable);
1239
+ Map.prototype.toString = function() {
1240
+ return this.__toString('Map {', '}');
1241
+ };
1317
1242
 
1318
- sliceSeq.size = sliceSize;
1243
+ // @pragma Access
1319
1244
 
1320
- if (!useKeys && isSeq(iterable) && sliceSize >= 0) {
1321
- sliceSeq.get = function (index, notSetValue) {
1322
- index = wrapIndex(this, index);
1323
- return index >= 0 && index < sliceSize ?
1324
- iterable.get(index + resolvedBegin, notSetValue) :
1325
- notSetValue;
1326
- }
1327
- }
1245
+ Map.prototype.get = function(k, notSetValue) {
1246
+ return this._root ?
1247
+ this._root.get(0, undefined, k, notSetValue) :
1248
+ notSetValue;
1249
+ };
1328
1250
 
1329
- sliceSeq.__iterateUncached = function(fn, reverse) {var this$0 = this;
1330
- if (sliceSize === 0) {
1331
- return 0;
1332
- }
1333
- if (reverse) {
1334
- return this.cacheResult().__iterate(fn, reverse);
1335
- }
1336
- var skipped = 0;
1337
- var isSkipping = true;
1338
- var iterations = 0;
1339
- iterable.__iterate(function(v, k) {
1340
- if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) {
1341
- iterations++;
1342
- return fn(v, useKeys ? k : iterations - 1, this$0) !== false &&
1343
- iterations !== sliceSize;
1344
- }
1345
- });
1346
- return iterations;
1251
+ // @pragma Modification
1252
+
1253
+ Map.prototype.set = function(k, v) {
1254
+ return updateMap(this, k, v);
1347
1255
  };
1348
1256
 
1349
- sliceSeq.__iteratorUncached = function(type, reverse) {
1350
- if (sliceSize !== 0 && reverse) {
1351
- return this.cacheResult().__iterator(type, reverse);
1352
- }
1353
- // Don't bother instantiating parent iterator if taking 0.
1354
- var iterator = sliceSize !== 0 && iterable.__iterator(type, reverse);
1355
- var skipped = 0;
1356
- var iterations = 0;
1357
- return new src_Iterator__Iterator(function() {
1358
- while (skipped++ < resolvedBegin) {
1359
- iterator.next();
1360
- }
1361
- if (++iterations > sliceSize) {
1362
- return iteratorDone();
1363
- }
1364
- var step = iterator.next();
1365
- if (useKeys || type === ITERATE_VALUES) {
1366
- return step;
1367
- } else if (type === ITERATE_KEYS) {
1368
- return iteratorValue(type, iterations - 1, undefined, step);
1369
- } else {
1370
- return iteratorValue(type, iterations - 1, step.value[1], step);
1371
- }
1372
- });
1373
- }
1257
+ Map.prototype.setIn = function(keyPath, v) {
1258
+ return this.updateIn(keyPath, NOT_SET, function() {return v});
1259
+ };
1374
1260
 
1375
- return sliceSeq;
1376
- }
1261
+ Map.prototype.remove = function(k) {
1262
+ return updateMap(this, k, NOT_SET);
1263
+ };
1264
+
1265
+ Map.prototype.deleteIn = function(keyPath) {
1266
+ return this.updateIn(keyPath, function() {return NOT_SET});
1267
+ };
1377
1268
 
1269
+ Map.prototype.update = function(k, notSetValue, updater) {
1270
+ return arguments.length === 1 ?
1271
+ k(this) :
1272
+ this.updateIn([k], notSetValue, updater);
1273
+ };
1378
1274
 
1379
- function takeWhileFactory(iterable, predicate, context) {
1380
- var takeSequence = makeSequence(iterable);
1381
- takeSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
1382
- if (reverse) {
1383
- return this.cacheResult().__iterate(fn, reverse);
1275
+ Map.prototype.updateIn = function(keyPath, notSetValue, updater) {
1276
+ if (!updater) {
1277
+ updater = notSetValue;
1278
+ notSetValue = undefined;
1384
1279
  }
1385
- var iterations = 0;
1386
- iterable.__iterate(function(v, k, c)
1387
- {return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$0)}
1280
+ var updatedValue = updateInDeepMap(
1281
+ this,
1282
+ forceIterator(keyPath),
1283
+ notSetValue,
1284
+ updater
1388
1285
  );
1389
- return iterations;
1286
+ return updatedValue === NOT_SET ? undefined : updatedValue;
1390
1287
  };
1391
- takeSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
1392
- if (reverse) {
1393
- return this.cacheResult().__iterator(type, reverse);
1288
+
1289
+ Map.prototype.clear = function() {
1290
+ if (this.size === 0) {
1291
+ return this;
1394
1292
  }
1395
- var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
1396
- var iterating = true;
1397
- return new src_Iterator__Iterator(function() {
1398
- if (!iterating) {
1399
- return iteratorDone();
1400
- }
1401
- var step = iterator.next();
1402
- if (step.done) {
1403
- return step;
1404
- }
1405
- var entry = step.value;
1406
- var k = entry[0];
1407
- var v = entry[1];
1408
- if (!predicate.call(context, v, k, this$0)) {
1409
- iterating = false;
1410
- return iteratorDone();
1411
- }
1412
- return type === ITERATE_ENTRIES ? step :
1413
- iteratorValue(type, k, v, step);
1414
- });
1293
+ if (this.__ownerID) {
1294
+ this.size = 0;
1295
+ this._root = null;
1296
+ this.__hash = undefined;
1297
+ this.__altered = true;
1298
+ return this;
1299
+ }
1300
+ return emptyMap();
1415
1301
  };
1416
- return takeSequence;
1417
- }
1418
1302
 
1303
+ // @pragma Composition
1419
1304
 
1420
- function skipWhileFactory(iterable, predicate, context, useKeys) {
1421
- var skipSequence = makeSequence(iterable);
1422
- skipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
1423
- if (reverse) {
1424
- return this.cacheResult().__iterate(fn, reverse);
1425
- }
1426
- var isSkipping = true;
1427
- var iterations = 0;
1428
- iterable.__iterate(function(v, k, c) {
1429
- if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) {
1430
- iterations++;
1431
- return fn(v, useKeys ? k : iterations - 1, this$0);
1432
- }
1433
- });
1434
- return iterations;
1305
+ Map.prototype.merge = function(/*...iters*/) {
1306
+ return mergeIntoMapWith(this, undefined, arguments);
1435
1307
  };
1436
- skipSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
1437
- if (reverse) {
1438
- return this.cacheResult().__iterator(type, reverse);
1439
- }
1440
- var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
1441
- var skipping = true;
1442
- var iterations = 0;
1443
- return new src_Iterator__Iterator(function() {
1444
- var step, k, v;
1445
- do {
1446
- step = iterator.next();
1447
- if (step.done) {
1448
- if (useKeys || type === ITERATE_VALUES) {
1449
- return step;
1450
- } else if (type === ITERATE_KEYS) {
1451
- return iteratorValue(type, iterations++, undefined, step);
1452
- } else {
1453
- return iteratorValue(type, iterations++, step.value[1], step);
1454
- }
1455
- }
1456
- var entry = step.value;
1457
- k = entry[0];
1458
- v = entry[1];
1459
- skipping && (skipping = predicate.call(context, v, k, this$0));
1460
- } while (skipping);
1461
- return type === ITERATE_ENTRIES ? step :
1462
- iteratorValue(type, k, v, step);
1463
- });
1308
+
1309
+ Map.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
1310
+ return mergeIntoMapWith(this, merger, iters);
1464
1311
  };
1465
- return skipSequence;
1466
- }
1467
1312
 
1313
+ Map.prototype.mergeIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
1314
+ return this.updateIn(
1315
+ keyPath,
1316
+ emptyMap(),
1317
+ function(m ) {return typeof m.merge === 'function' ?
1318
+ m.merge.apply(m, iters) :
1319
+ iters[iters.length - 1]}
1320
+ );
1321
+ };
1468
1322
 
1469
- function concatFactory(iterable, values) {
1470
- var isKeyedIterable = isKeyed(iterable);
1471
- var iters = [iterable].concat(values).map(function(v ) {
1472
- if (!isIterable(v)) {
1473
- v = isKeyedIterable ?
1474
- keyedSeqFromValue(v) :
1475
- indexedSeqFromValue(Array.isArray(v) ? v : [v]);
1476
- } else if (isKeyedIterable) {
1477
- v = KeyedIterable(v);
1478
- }
1479
- return v;
1480
- }).filter(function(v ) {return v.size !== 0});
1323
+ Map.prototype.mergeDeep = function(/*...iters*/) {
1324
+ return mergeIntoMapWith(this, deepMerger, arguments);
1325
+ };
1481
1326
 
1482
- if (iters.length === 0) {
1483
- return iterable;
1484
- }
1327
+ Map.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
1328
+ return mergeIntoMapWith(this, deepMergerWith(merger), iters);
1329
+ };
1485
1330
 
1486
- if (iters.length === 1) {
1487
- var singleton = iters[0];
1488
- if (singleton === iterable ||
1489
- isKeyedIterable && isKeyed(singleton) ||
1490
- isIndexed(iterable) && isIndexed(singleton)) {
1491
- return singleton;
1492
- }
1493
- }
1331
+ Map.prototype.mergeDeepIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
1332
+ return this.updateIn(
1333
+ keyPath,
1334
+ emptyMap(),
1335
+ function(m ) {return typeof m.mergeDeep === 'function' ?
1336
+ m.mergeDeep.apply(m, iters) :
1337
+ iters[iters.length - 1]}
1338
+ );
1339
+ };
1494
1340
 
1495
- var concatSeq = new ArraySeq(iters);
1496
- if (isKeyedIterable) {
1497
- concatSeq = concatSeq.toKeyedSeq();
1498
- } else if (!isIndexed(iterable)) {
1499
- concatSeq = concatSeq.toSetSeq();
1500
- }
1501
- concatSeq = concatSeq.flatten(true);
1502
- concatSeq.size = iters.reduce(
1503
- function(sum, seq) {
1504
- if (sum !== undefined) {
1505
- var size = seq.size;
1506
- if (size !== undefined) {
1507
- return sum + size;
1508
- }
1509
- }
1510
- },
1511
- 0
1512
- );
1513
- return concatSeq;
1514
- }
1341
+ Map.prototype.sort = function(comparator) {
1342
+ // Late binding
1343
+ return OrderedMap(sortFactory(this, comparator));
1344
+ };
1515
1345
 
1346
+ Map.prototype.sortBy = function(mapper, comparator) {
1347
+ // Late binding
1348
+ return OrderedMap(sortFactory(this, comparator, mapper));
1349
+ };
1516
1350
 
1517
- function flattenFactory(iterable, depth, useKeys) {
1518
- var flatSequence = makeSequence(iterable);
1519
- flatSequence.__iterateUncached = function(fn, reverse) {
1520
- var iterations = 0;
1521
- var stopped = false;
1522
- function flatDeep(iter, currentDepth) {var this$0 = this;
1523
- iter.__iterate(function(v, k) {
1524
- if ((!depth || currentDepth < depth) && isIterable(v)) {
1525
- flatDeep(v, currentDepth + 1);
1526
- } else if (fn(v, useKeys ? k : iterations++, this$0) === false) {
1527
- stopped = true;
1528
- }
1529
- return !stopped;
1530
- }, reverse);
1531
- }
1532
- flatDeep(iterable, 0);
1533
- return iterations;
1534
- }
1535
- flatSequence.__iteratorUncached = function(type, reverse) {
1536
- var iterator = iterable.__iterator(type, reverse);
1537
- var stack = [];
1538
- var iterations = 0;
1539
- return new src_Iterator__Iterator(function() {
1540
- while (iterator) {
1541
- var step = iterator.next();
1542
- if (step.done !== false) {
1543
- iterator = stack.pop();
1544
- continue;
1545
- }
1546
- var v = step.value;
1547
- if (type === ITERATE_ENTRIES) {
1548
- v = v[1];
1549
- }
1550
- if ((!depth || stack.length < depth) && isIterable(v)) {
1551
- stack.push(iterator);
1552
- iterator = v.__iterator(type, reverse);
1553
- } else {
1554
- return useKeys ? step : iteratorValue(type, iterations++, v, step);
1555
- }
1556
- }
1557
- return iteratorDone();
1558
- });
1559
- }
1560
- return flatSequence;
1561
- }
1351
+ // @pragma Mutability
1562
1352
 
1353
+ Map.prototype.withMutations = function(fn) {
1354
+ var mutable = this.asMutable();
1355
+ fn(mutable);
1356
+ return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
1357
+ };
1563
1358
 
1564
- function flatMapFactory(iterable, mapper, context) {
1565
- var coerce = iterableClass(iterable);
1566
- return iterable.toSeq().map(
1567
- function(v, k) {return coerce(mapper.call(context, v, k, iterable))}
1568
- ).flatten(true);
1569
- }
1359
+ Map.prototype.asMutable = function() {
1360
+ return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
1361
+ };
1362
+
1363
+ Map.prototype.asImmutable = function() {
1364
+ return this.__ensureOwner();
1365
+ };
1570
1366
 
1367
+ Map.prototype.wasAltered = function() {
1368
+ return this.__altered;
1369
+ };
1571
1370
 
1572
- function interposeFactory(iterable, separator) {
1573
- var interposedSequence = makeSequence(iterable);
1574
- interposedSequence.size = iterable.size && iterable.size * 2 -1;
1575
- interposedSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
1371
+ Map.prototype.__iterator = function(type, reverse) {
1372
+ return new MapIterator(this, type, reverse);
1373
+ };
1374
+
1375
+ Map.prototype.__iterate = function(fn, reverse) {var this$0 = this;
1576
1376
  var iterations = 0;
1577
- iterable.__iterate(function(v, k)
1578
- {return (!iterations || fn(separator, iterations++, this$0) !== false) &&
1579
- fn(v, iterations++, this$0) !== false},
1580
- reverse
1581
- );
1377
+ this._root && this._root.iterate(function(entry ) {
1378
+ iterations++;
1379
+ return fn(entry[1], entry[0], this$0);
1380
+ }, reverse);
1582
1381
  return iterations;
1583
1382
  };
1584
- interposedSequence.__iteratorUncached = function(type, reverse) {
1585
- var iterator = iterable.__iterator(ITERATE_VALUES, reverse);
1586
- var iterations = 0;
1587
- var step;
1588
- return new src_Iterator__Iterator(function() {
1589
- if (!step || iterations % 2) {
1590
- step = iterator.next();
1591
- if (step.done) {
1592
- return step;
1593
- }
1594
- }
1595
- return iterations % 2 ?
1596
- iteratorValue(type, iterations++, separator) :
1597
- iteratorValue(type, iterations++, step.value, step);
1598
- });
1383
+
1384
+ Map.prototype.__ensureOwner = function(ownerID) {
1385
+ if (ownerID === this.__ownerID) {
1386
+ return this;
1387
+ }
1388
+ if (!ownerID) {
1389
+ this.__ownerID = ownerID;
1390
+ this.__altered = false;
1391
+ return this;
1392
+ }
1393
+ return makeMap(this.size, this._root, ownerID, this.__hash);
1599
1394
  };
1600
- return interposedSequence;
1601
- }
1602
1395
 
1603
1396
 
1604
- function sortFactory(iterable, comparator, mapper) {
1605
- if (!comparator) {
1606
- comparator = defaultComparator;
1607
- }
1608
- var isKeyedIterable = isKeyed(iterable);
1609
- var index = 0;
1610
- var entries = iterable.toSeq().map(
1611
- function(v, k) {return [k, v, index++, mapper ? mapper(v, k, iterable) : v]}
1612
- ).toArray();
1613
- entries.sort(function(a, b) {return comparator(a[3], b[3]) || a[2] - b[2]}).forEach(
1614
- isKeyedIterable ?
1615
- function(v, i) { entries[i].length = 2; } :
1616
- function(v, i) { entries[i] = v[1]; }
1617
- );
1618
- return isKeyedIterable ? KeyedSeq(entries) :
1619
- isIndexed(iterable) ? IndexedSeq(entries) :
1620
- SetSeq(entries);
1397
+ function isMap(maybeMap) {
1398
+ return !!(maybeMap && maybeMap[IS_MAP_SENTINEL]);
1621
1399
  }
1622
1400
 
1401
+ Map.isMap = isMap;
1623
1402
 
1624
- function maxFactory(iterable, comparator, mapper) {
1625
- if (!comparator) {
1626
- comparator = defaultComparator;
1627
- }
1628
- if (mapper) {
1629
- var entry = iterable.toSeq()
1630
- .map(function(v, k) {return [v, mapper(v, k, iterable)]})
1631
- .reduce(function(a, b) {return maxCompare(comparator, a[1], b[1]) ? b : a});
1632
- return entry && entry[0];
1633
- } else {
1634
- return iterable.reduce(function(a, b) {return maxCompare(comparator, a, b) ? b : a});
1635
- }
1636
- }
1403
+ var IS_MAP_SENTINEL = '@@__IMMUTABLE_MAP__@@';
1637
1404
 
1638
- function maxCompare(comparator, a, b) {
1639
- var comp = comparator(b, a);
1640
- // b is considered the new max if the comparator declares them equal, but
1641
- // they are not equal and b is in fact a nullish value.
1642
- return (comp === 0 && b !== a && (b === undefined || b === null || b !== b)) || comp > 0;
1643
- }
1405
+ var MapPrototype = Map.prototype;
1406
+ MapPrototype[IS_MAP_SENTINEL] = true;
1407
+ MapPrototype[DELETE] = MapPrototype.remove;
1408
+ MapPrototype.removeIn = MapPrototype.deleteIn;
1644
1409
 
1645
1410
 
1646
- function zipWithFactory(keyIter, zipper, iters) {
1647
- var zipSequence = makeSequence(keyIter);
1648
- zipSequence.size = new ArraySeq(iters).map(function(i ) {return i.size}).min();
1649
- // Note: this a generic base implementation of __iterate in terms of
1650
- // __iterator which may be more generically useful in the future.
1651
- zipSequence.__iterate = function(fn, reverse) {
1652
- /* generic:
1653
- var iterator = this.__iterator(ITERATE_ENTRIES, reverse);
1654
- var step;
1655
- var iterations = 0;
1656
- while (!(step = iterator.next()).done) {
1657
- iterations++;
1658
- if (fn(step.value[1], step.value[0], this) === false) {
1659
- break;
1411
+ // #pragma Trie Nodes
1412
+
1413
+
1414
+
1415
+ function ArrayMapNode(ownerID, entries) {
1416
+ this.ownerID = ownerID;
1417
+ this.entries = entries;
1418
+ }
1419
+
1420
+ ArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
1421
+ var entries = this.entries;
1422
+ for (var ii = 0, len = entries.length; ii < len; ii++) {
1423
+ if (is(key, entries[ii][0])) {
1424
+ return entries[ii][1];
1660
1425
  }
1661
1426
  }
1662
- return iterations;
1663
- */
1664
- // indexed:
1665
- var iterator = this.__iterator(ITERATE_VALUES, reverse);
1666
- var step;
1667
- var iterations = 0;
1668
- while (!(step = iterator.next()).done) {
1669
- if (fn(step.value, iterations++, this) === false) {
1427
+ return notSetValue;
1428
+ };
1429
+
1430
+ ArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
1431
+ var removed = value === NOT_SET;
1432
+
1433
+ var entries = this.entries;
1434
+ var idx = 0;
1435
+ for (var len = entries.length; idx < len; idx++) {
1436
+ if (is(key, entries[idx][0])) {
1670
1437
  break;
1671
1438
  }
1672
1439
  }
1673
- return iterations;
1674
- };
1675
- zipSequence.__iteratorUncached = function(type, reverse) {
1676
- var iterators = iters.map(function(i )
1677
- {return (i = Iterable(i), getIterator(reverse ? i.reverse() : i))}
1678
- );
1679
- var iterations = 0;
1680
- var isDone = false;
1681
- return new src_Iterator__Iterator(function() {
1682
- var steps;
1683
- if (!isDone) {
1684
- steps = iterators.map(function(i ) {return i.next()});
1685
- isDone = steps.some(function(s ) {return s.done});
1686
- }
1687
- if (isDone) {
1688
- return iteratorDone();
1689
- }
1690
- return iteratorValue(
1691
- type,
1692
- iterations++,
1693
- zipper.apply(null, steps.map(function(s ) {return s.value}))
1694
- );
1695
- });
1696
- };
1697
- return zipSequence
1698
- }
1440
+ var exists = idx < len;
1699
1441
 
1442
+ if (exists ? entries[idx][1] === value : removed) {
1443
+ return this;
1444
+ }
1700
1445
 
1701
- // #pragma Helper Functions
1446
+ SetRef(didAlter);
1447
+ (removed || !exists) && SetRef(didChangeSize);
1702
1448
 
1703
- function reify(iter, seq) {
1704
- return isSeq(iter) ? seq : iter.constructor(seq);
1705
- }
1449
+ if (removed && entries.length === 1) {
1450
+ return; // undefined
1451
+ }
1706
1452
 
1707
- function validateEntry(entry) {
1708
- if (entry !== Object(entry)) {
1709
- throw new TypeError('Expected [K, V] tuple: ' + entry);
1710
- }
1711
- }
1453
+ if (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) {
1454
+ return createNodes(ownerID, entries, key, value);
1455
+ }
1712
1456
 
1713
- function resolveSize(iter) {
1714
- assertNotInfinite(iter.size);
1715
- return ensureSize(iter);
1716
- }
1457
+ var isEditable = ownerID && ownerID === this.ownerID;
1458
+ var newEntries = isEditable ? entries : arrCopy(entries);
1717
1459
 
1718
- function iterableClass(iterable) {
1719
- return isKeyed(iterable) ? KeyedIterable :
1720
- isIndexed(iterable) ? IndexedIterable :
1721
- SetIterable;
1722
- }
1723
-
1724
- function makeSequence(iterable) {
1725
- return Object.create(
1726
- (
1727
- isKeyed(iterable) ? KeyedSeq :
1728
- isIndexed(iterable) ? IndexedSeq :
1729
- SetSeq
1730
- ).prototype
1731
- );
1732
- }
1733
-
1734
- function cacheResultThrough() {
1735
- if (this._iter.cacheResult) {
1736
- this._iter.cacheResult();
1737
- this.size = this._iter.size;
1738
- return this;
1739
- } else {
1740
- return Seq.prototype.cacheResult.call(this);
1741
- }
1742
- }
1743
-
1744
- function defaultComparator(a, b) {
1745
- return a > b ? 1 : a < b ? -1 : 0;
1746
- }
1747
-
1748
- function forceIterator(keyPath) {
1749
- var iter = getIterator(keyPath);
1750
- if (!iter) {
1751
- // Array might not be iterable in this environment, so we need a fallback
1752
- // to our wrapped type.
1753
- if (!isArrayLike(keyPath)) {
1754
- throw new TypeError('Expected iterable or array-like: ' + keyPath);
1755
- }
1756
- iter = getIterator(Iterable(keyPath));
1757
- }
1758
- return iter;
1759
- }
1760
-
1761
- createClass(src_Map__Map, KeyedCollection);
1762
-
1763
- // @pragma Construction
1764
-
1765
- function src_Map__Map(value) {
1766
- return value === null || value === undefined ? emptyMap() :
1767
- isMap(value) ? value :
1768
- emptyMap().withMutations(function(map ) {
1769
- var iter = KeyedIterable(value);
1770
- assertNotInfinite(iter.size);
1771
- iter.forEach(function(v, k) {return map.set(k, v)});
1772
- });
1773
- }
1774
-
1775
- src_Map__Map.prototype.toString = function() {
1776
- return this.__toString('Map {', '}');
1777
- };
1778
-
1779
- // @pragma Access
1780
-
1781
- src_Map__Map.prototype.get = function(k, notSetValue) {
1782
- return this._root ?
1783
- this._root.get(0, undefined, k, notSetValue) :
1784
- notSetValue;
1785
- };
1786
-
1787
- // @pragma Modification
1788
-
1789
- src_Map__Map.prototype.set = function(k, v) {
1790
- return updateMap(this, k, v);
1791
- };
1792
-
1793
- src_Map__Map.prototype.setIn = function(keyPath, v) {
1794
- return this.updateIn(keyPath, NOT_SET, function() {return v});
1795
- };
1796
-
1797
- src_Map__Map.prototype.remove = function(k) {
1798
- return updateMap(this, k, NOT_SET);
1799
- };
1800
-
1801
- src_Map__Map.prototype.deleteIn = function(keyPath) {
1802
- return this.updateIn(keyPath, function() {return NOT_SET});
1803
- };
1804
-
1805
- src_Map__Map.prototype.update = function(k, notSetValue, updater) {
1806
- return arguments.length === 1 ?
1807
- k(this) :
1808
- this.updateIn([k], notSetValue, updater);
1809
- };
1810
-
1811
- src_Map__Map.prototype.updateIn = function(keyPath, notSetValue, updater) {
1812
- if (!updater) {
1813
- updater = notSetValue;
1814
- notSetValue = undefined;
1815
- }
1816
- var updatedValue = updateInDeepMap(
1817
- this,
1818
- forceIterator(keyPath),
1819
- notSetValue,
1820
- updater
1821
- );
1822
- return updatedValue === NOT_SET ? undefined : updatedValue;
1823
- };
1824
-
1825
- src_Map__Map.prototype.clear = function() {
1826
- if (this.size === 0) {
1827
- return this;
1828
- }
1829
- if (this.__ownerID) {
1830
- this.size = 0;
1831
- this._root = null;
1832
- this.__hash = undefined;
1833
- this.__altered = true;
1834
- return this;
1835
- }
1836
- return emptyMap();
1837
- };
1838
-
1839
- // @pragma Composition
1840
-
1841
- src_Map__Map.prototype.merge = function(/*...iters*/) {
1842
- return mergeIntoMapWith(this, undefined, arguments);
1843
- };
1844
-
1845
- src_Map__Map.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
1846
- return mergeIntoMapWith(this, merger, iters);
1847
- };
1848
-
1849
- src_Map__Map.prototype.mergeIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
1850
- return this.updateIn(
1851
- keyPath,
1852
- emptyMap(),
1853
- function(m ) {return typeof m.merge === 'function' ?
1854
- m.merge.apply(m, iters) :
1855
- iters[iters.length - 1]}
1856
- );
1857
- };
1858
-
1859
- src_Map__Map.prototype.mergeDeep = function(/*...iters*/) {
1860
- return mergeIntoMapWith(this, deepMerger(undefined), arguments);
1861
- };
1862
-
1863
- src_Map__Map.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
1864
- return mergeIntoMapWith(this, deepMerger(merger), iters);
1865
- };
1866
-
1867
- src_Map__Map.prototype.mergeDeepIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
1868
- return this.updateIn(
1869
- keyPath,
1870
- emptyMap(),
1871
- function(m ) {return typeof m.mergeDeep === 'function' ?
1872
- m.mergeDeep.apply(m, iters) :
1873
- iters[iters.length - 1]}
1874
- );
1875
- };
1876
-
1877
- src_Map__Map.prototype.sort = function(comparator) {
1878
- // Late binding
1879
- return OrderedMap(sortFactory(this, comparator));
1880
- };
1881
-
1882
- src_Map__Map.prototype.sortBy = function(mapper, comparator) {
1883
- // Late binding
1884
- return OrderedMap(sortFactory(this, comparator, mapper));
1885
- };
1886
-
1887
- // @pragma Mutability
1888
-
1889
- src_Map__Map.prototype.withMutations = function(fn) {
1890
- var mutable = this.asMutable();
1891
- fn(mutable);
1892
- return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
1893
- };
1894
-
1895
- src_Map__Map.prototype.asMutable = function() {
1896
- return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
1897
- };
1898
-
1899
- src_Map__Map.prototype.asImmutable = function() {
1900
- return this.__ensureOwner();
1901
- };
1902
-
1903
- src_Map__Map.prototype.wasAltered = function() {
1904
- return this.__altered;
1905
- };
1906
-
1907
- src_Map__Map.prototype.__iterator = function(type, reverse) {
1908
- return new MapIterator(this, type, reverse);
1909
- };
1910
-
1911
- src_Map__Map.prototype.__iterate = function(fn, reverse) {var this$0 = this;
1912
- var iterations = 0;
1913
- this._root && this._root.iterate(function(entry ) {
1914
- iterations++;
1915
- return fn(entry[1], entry[0], this$0);
1916
- }, reverse);
1917
- return iterations;
1918
- };
1919
-
1920
- src_Map__Map.prototype.__ensureOwner = function(ownerID) {
1921
- if (ownerID === this.__ownerID) {
1922
- return this;
1923
- }
1924
- if (!ownerID) {
1925
- this.__ownerID = ownerID;
1926
- this.__altered = false;
1927
- return this;
1928
- }
1929
- return makeMap(this.size, this._root, ownerID, this.__hash);
1930
- };
1931
-
1932
-
1933
- function isMap(maybeMap) {
1934
- return !!(maybeMap && maybeMap[IS_MAP_SENTINEL]);
1935
- }
1936
-
1937
- src_Map__Map.isMap = isMap;
1938
-
1939
- var IS_MAP_SENTINEL = '@@__IMMUTABLE_MAP__@@';
1940
-
1941
- var MapPrototype = src_Map__Map.prototype;
1942
- MapPrototype[IS_MAP_SENTINEL] = true;
1943
- MapPrototype[DELETE] = MapPrototype.remove;
1944
- MapPrototype.removeIn = MapPrototype.deleteIn;
1945
-
1946
-
1947
- // #pragma Trie Nodes
1948
-
1949
-
1950
-
1951
- function ArrayMapNode(ownerID, entries) {
1952
- this.ownerID = ownerID;
1953
- this.entries = entries;
1954
- }
1955
-
1956
- ArrayMapNode.prototype.get = function(shift, keyHash, key, notSetValue) {
1957
- var entries = this.entries;
1958
- for (var ii = 0, len = entries.length; ii < len; ii++) {
1959
- if (is(key, entries[ii][0])) {
1960
- return entries[ii][1];
1961
- }
1962
- }
1963
- return notSetValue;
1964
- };
1965
-
1966
- ArrayMapNode.prototype.update = function(ownerID, shift, keyHash, key, value, didChangeSize, didAlter) {
1967
- var removed = value === NOT_SET;
1968
-
1969
- var entries = this.entries;
1970
- var idx = 0;
1971
- for (var len = entries.length; idx < len; idx++) {
1972
- if (is(key, entries[idx][0])) {
1973
- break;
1974
- }
1975
- }
1976
- var exists = idx < len;
1977
-
1978
- if (exists ? entries[idx][1] === value : removed) {
1979
- return this;
1980
- }
1981
-
1982
- SetRef(didAlter);
1983
- (removed || !exists) && SetRef(didChangeSize);
1984
-
1985
- if (removed && entries.length === 1) {
1986
- return; // undefined
1987
- }
1988
-
1989
- if (!exists && !removed && entries.length >= MAX_ARRAY_MAP_SIZE) {
1990
- return createNodes(ownerID, entries, key, value);
1991
- }
1992
-
1993
- var isEditable = ownerID && ownerID === this.ownerID;
1994
- var newEntries = isEditable ? entries : arrCopy(entries);
1995
-
1996
- if (exists) {
1997
- if (removed) {
1998
- idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
1999
- } else {
2000
- newEntries[idx] = [key, value];
2001
- }
2002
- } else {
2003
- newEntries.push([key, value]);
2004
- }
1460
+ if (exists) {
1461
+ if (removed) {
1462
+ idx === len - 1 ? newEntries.pop() : (newEntries[idx] = newEntries.pop());
1463
+ } else {
1464
+ newEntries[idx] = [key, value];
1465
+ }
1466
+ } else {
1467
+ newEntries.push([key, value]);
1468
+ }
2005
1469
 
2006
1470
  if (isEditable) {
2007
1471
  this.entries = newEntries;
@@ -2282,7 +1746,7 @@
2282
1746
  return fn(this.entry);
2283
1747
  }
2284
1748
 
2285
- createClass(MapIterator, src_Iterator__Iterator);
1749
+ createClass(MapIterator, Iterator);
2286
1750
 
2287
1751
  function MapIterator(map, type, reverse) {
2288
1752
  this._type = type;
@@ -2461,11 +1925,20 @@
2461
1925
  return mergeIntoCollectionWith(map, merger, iters);
2462
1926
  }
2463
1927
 
2464
- function deepMerger(merger) {
2465
- return function(existing, value, key)
2466
- {return existing && existing.mergeDeepWith && isIterable(value) ?
2467
- existing.mergeDeepWith(merger, value) :
2468
- merger ? merger(existing, value, key) : value};
1928
+ function deepMerger(existing, value, key) {
1929
+ return existing && existing.mergeDeep && isIterable(value) ?
1930
+ existing.mergeDeep(value) :
1931
+ is(existing, value) ? existing : value;
1932
+ }
1933
+
1934
+ function deepMergerWith(merger) {
1935
+ return function(existing, value, key) {
1936
+ if (existing && existing.mergeDeepWith && isIterable(value)) {
1937
+ return existing.mergeDeepWith(merger, value);
1938
+ }
1939
+ var nextValue = merger(existing, value, key);
1940
+ return is(existing, nextValue) ? existing : nextValue;
1941
+ };
2469
1942
  }
2470
1943
 
2471
1944
  function mergeIntoCollectionWith(collection, merger, iters) {
@@ -2611,12 +2084,12 @@
2611
2084
 
2612
2085
  List.prototype.get = function(index, notSetValue) {
2613
2086
  index = wrapIndex(this, index);
2614
- if (index < 0 || index >= this.size) {
2615
- return notSetValue;
2087
+ if (index >= 0 && index < this.size) {
2088
+ index += this._origin;
2089
+ var node = listNodeFor(this, index);
2090
+ return node && node.array[index & MASK];
2616
2091
  }
2617
- index += this._origin;
2618
- var node = listNodeFor(this, index);
2619
- return node && node.array[index & MASK];
2092
+ return notSetValue;
2620
2093
  };
2621
2094
 
2622
2095
  // @pragma Modification
@@ -2632,6 +2105,10 @@
2632
2105
  this.splice(index, 1);
2633
2106
  };
2634
2107
 
2108
+ List.prototype.insert = function(index, value) {
2109
+ return this.splice(index, 0, value);
2110
+ };
2111
+
2635
2112
  List.prototype.clear = function() {
2636
2113
  if (this.size === 0) {
2637
2114
  return this;
@@ -2687,11 +2164,11 @@
2687
2164
  };
2688
2165
 
2689
2166
  List.prototype.mergeDeep = function(/*...iters*/) {
2690
- return mergeIntoListWith(this, deepMerger(undefined), arguments);
2167
+ return mergeIntoListWith(this, deepMerger, arguments);
2691
2168
  };
2692
2169
 
2693
2170
  List.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
2694
- return mergeIntoListWith(this, deepMerger(merger), iters);
2171
+ return mergeIntoListWith(this, deepMergerWith(merger), iters);
2695
2172
  };
2696
2173
 
2697
2174
  List.prototype.setSize = function(size) {
@@ -2715,7 +2192,7 @@
2715
2192
  List.prototype.__iterator = function(type, reverse) {
2716
2193
  var index = 0;
2717
2194
  var values = iterateList(this, reverse);
2718
- return new src_Iterator__Iterator(function() {
2195
+ return new Iterator(function() {
2719
2196
  var value = values();
2720
2197
  return value === DONE ?
2721
2198
  iteratorDone() :
@@ -2812,29 +2289,25 @@
2812
2289
  };
2813
2290
 
2814
2291
  VNode.prototype.removeAfter = function(ownerID, level, index) {
2815
- if (index === level ? 1 << level : 0 || this.array.length === 0) {
2292
+ if (index === (level ? 1 << level : 0) || this.array.length === 0) {
2816
2293
  return this;
2817
2294
  }
2818
2295
  var sizeIndex = ((index - 1) >>> level) & MASK;
2819
2296
  if (sizeIndex >= this.array.length) {
2820
2297
  return this;
2821
2298
  }
2822
- var removingLast = sizeIndex === this.array.length - 1;
2299
+
2823
2300
  var newChild;
2824
2301
  if (level > 0) {
2825
2302
  var oldChild = this.array[sizeIndex];
2826
2303
  newChild = oldChild && oldChild.removeAfter(ownerID, level - SHIFT, index);
2827
- if (newChild === oldChild && removingLast) {
2304
+ if (newChild === oldChild && sizeIndex === this.array.length - 1) {
2828
2305
  return this;
2829
2306
  }
2830
2307
  }
2831
- if (removingLast && !newChild) {
2832
- return this;
2833
- }
2308
+
2834
2309
  var editable = editableVNode(this, ownerID);
2835
- if (!removingLast) {
2836
- editable.array.pop();
2837
- }
2310
+ editable.array.splice(sizeIndex + 1);
2838
2311
  if (newChild) {
2839
2312
  editable.array[sizeIndex] = newChild;
2840
2313
  }
@@ -2926,6 +2399,10 @@
2926
2399
  function updateList(list, index, value) {
2927
2400
  index = wrapIndex(list, index);
2928
2401
 
2402
+ if (index !== index) {
2403
+ return list;
2404
+ }
2405
+
2929
2406
  if (index >= list.size || index < 0) {
2930
2407
  return list.withMutations(function(list ) {
2931
2408
  index < 0 ?
@@ -3017,6 +2494,14 @@
3017
2494
  }
3018
2495
 
3019
2496
  function setListBounds(list, begin, end) {
2497
+ // Sanitize begin & end using this shorthand for ToInt32(argument)
2498
+ // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
2499
+ if (begin !== undefined) {
2500
+ begin = begin | 0;
2501
+ }
2502
+ if (end !== undefined) {
2503
+ end = end | 0;
2504
+ }
3020
2505
  var owner = list.__ownerID || new OwnerID();
3021
2506
  var oldOrigin = list._origin;
3022
2507
  var oldCapacity = list._capacity;
@@ -3155,7 +2640,7 @@
3155
2640
  return size < SIZE ? 0 : (((size - 1) >>> SHIFT) << SHIFT);
3156
2641
  }
3157
2642
 
3158
- createClass(OrderedMap, src_Map__Map);
2643
+ createClass(OrderedMap, Map);
3159
2644
 
3160
2645
  // @pragma Construction
3161
2646
 
@@ -3307,453 +2792,838 @@
3307
2792
  return makeOrderedMap(newMap, newList);
3308
2793
  }
3309
2794
 
3310
- createClass(Stack, IndexedCollection);
3311
-
3312
- // @pragma Construction
3313
-
3314
- function Stack(value) {
3315
- return value === null || value === undefined ? emptyStack() :
3316
- isStack(value) ? value :
3317
- emptyStack().unshiftAll(value);
2795
+ createClass(ToKeyedSequence, KeyedSeq);
2796
+ function ToKeyedSequence(indexed, useKeys) {
2797
+ this._iter = indexed;
2798
+ this._useKeys = useKeys;
2799
+ this.size = indexed.size;
3318
2800
  }
3319
2801
 
3320
- Stack.of = function(/*...values*/) {
3321
- return this(arguments);
2802
+ ToKeyedSequence.prototype.get = function(key, notSetValue) {
2803
+ return this._iter.get(key, notSetValue);
3322
2804
  };
3323
2805
 
3324
- Stack.prototype.toString = function() {
3325
- return this.__toString('Stack [', ']');
2806
+ ToKeyedSequence.prototype.has = function(key) {
2807
+ return this._iter.has(key);
3326
2808
  };
3327
2809
 
3328
- // @pragma Access
2810
+ ToKeyedSequence.prototype.valueSeq = function() {
2811
+ return this._iter.valueSeq();
2812
+ };
3329
2813
 
3330
- Stack.prototype.get = function(index, notSetValue) {
3331
- var head = this._head;
3332
- index = wrapIndex(this, index);
3333
- while (head && index--) {
3334
- head = head.next;
2814
+ ToKeyedSequence.prototype.reverse = function() {var this$0 = this;
2815
+ var reversedSequence = reverseFactory(this, true);
2816
+ if (!this._useKeys) {
2817
+ reversedSequence.valueSeq = function() {return this$0._iter.toSeq().reverse()};
3335
2818
  }
3336
- return head ? head.value : notSetValue;
2819
+ return reversedSequence;
3337
2820
  };
3338
2821
 
3339
- Stack.prototype.peek = function() {
3340
- return this._head && this._head.value;
2822
+ ToKeyedSequence.prototype.map = function(mapper, context) {var this$0 = this;
2823
+ var mappedSequence = mapFactory(this, mapper, context);
2824
+ if (!this._useKeys) {
2825
+ mappedSequence.valueSeq = function() {return this$0._iter.toSeq().map(mapper, context)};
2826
+ }
2827
+ return mappedSequence;
3341
2828
  };
3342
2829
 
3343
- // @pragma Modification
3344
-
3345
- Stack.prototype.push = function(/*...values*/) {
3346
- if (arguments.length === 0) {
3347
- return this;
3348
- }
3349
- var newSize = this.size + arguments.length;
3350
- var head = this._head;
3351
- for (var ii = arguments.length - 1; ii >= 0; ii--) {
3352
- head = {
3353
- value: arguments[ii],
3354
- next: head
3355
- };
3356
- }
3357
- if (this.__ownerID) {
3358
- this.size = newSize;
3359
- this._head = head;
3360
- this.__hash = undefined;
3361
- this.__altered = true;
3362
- return this;
3363
- }
3364
- return makeStack(newSize, head);
2830
+ ToKeyedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
2831
+ var ii;
2832
+ return this._iter.__iterate(
2833
+ this._useKeys ?
2834
+ function(v, k) {return fn(v, k, this$0)} :
2835
+ ((ii = reverse ? resolveSize(this) : 0),
2836
+ function(v ) {return fn(v, reverse ? --ii : ii++, this$0)}),
2837
+ reverse
2838
+ );
3365
2839
  };
3366
2840
 
3367
- Stack.prototype.pushAll = function(iter) {
3368
- iter = IndexedIterable(iter);
3369
- if (iter.size === 0) {
3370
- return this;
2841
+ ToKeyedSequence.prototype.__iterator = function(type, reverse) {
2842
+ if (this._useKeys) {
2843
+ return this._iter.__iterator(type, reverse);
3371
2844
  }
3372
- assertNotInfinite(iter.size);
3373
- var newSize = this.size;
3374
- var head = this._head;
3375
- iter.reverse().forEach(function(value ) {
3376
- newSize++;
3377
- head = {
3378
- value: value,
3379
- next: head
3380
- };
2845
+ var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
2846
+ var ii = reverse ? resolveSize(this) : 0;
2847
+ return new Iterator(function() {
2848
+ var step = iterator.next();
2849
+ return step.done ? step :
2850
+ iteratorValue(type, reverse ? --ii : ii++, step.value, step);
3381
2851
  });
3382
- if (this.__ownerID) {
3383
- this.size = newSize;
3384
- this._head = head;
3385
- this.__hash = undefined;
3386
- this.__altered = true;
3387
- return this;
3388
- }
3389
- return makeStack(newSize, head);
3390
2852
  };
3391
2853
 
3392
- Stack.prototype.pop = function() {
3393
- return this.slice(1);
3394
- };
2854
+ ToKeyedSequence.prototype[IS_ORDERED_SENTINEL] = true;
3395
2855
 
3396
- Stack.prototype.unshift = function(/*...values*/) {
3397
- return this.push.apply(this, arguments);
3398
- };
3399
2856
 
3400
- Stack.prototype.unshiftAll = function(iter) {
3401
- return this.pushAll(iter);
3402
- };
2857
+ createClass(ToIndexedSequence, IndexedSeq);
2858
+ function ToIndexedSequence(iter) {
2859
+ this._iter = iter;
2860
+ this.size = iter.size;
2861
+ }
3403
2862
 
3404
- Stack.prototype.shift = function() {
3405
- return this.pop.apply(this, arguments);
2863
+ ToIndexedSequence.prototype.includes = function(value) {
2864
+ return this._iter.includes(value);
3406
2865
  };
3407
2866
 
3408
- Stack.prototype.clear = function() {
3409
- if (this.size === 0) {
3410
- return this;
3411
- }
3412
- if (this.__ownerID) {
3413
- this.size = 0;
3414
- this._head = undefined;
3415
- this.__hash = undefined;
3416
- this.__altered = true;
3417
- return this;
3418
- }
3419
- return emptyStack();
2867
+ ToIndexedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
2868
+ var iterations = 0;
2869
+ return this._iter.__iterate(function(v ) {return fn(v, iterations++, this$0)}, reverse);
3420
2870
  };
3421
2871
 
3422
- Stack.prototype.slice = function(begin, end) {
3423
- if (wholeSlice(begin, end, this.size)) {
3424
- return this;
3425
- }
3426
- var resolvedBegin = resolveBegin(begin, this.size);
3427
- var resolvedEnd = resolveEnd(end, this.size);
3428
- if (resolvedEnd !== this.size) {
3429
- // super.slice(begin, end);
3430
- return IndexedCollection.prototype.slice.call(this, begin, end);
3431
- }
3432
- var newSize = this.size - resolvedBegin;
3433
- var head = this._head;
3434
- while (resolvedBegin--) {
3435
- head = head.next;
3436
- }
3437
- if (this.__ownerID) {
3438
- this.size = newSize;
3439
- this._head = head;
3440
- this.__hash = undefined;
3441
- this.__altered = true;
3442
- return this;
3443
- }
3444
- return makeStack(newSize, head);
2872
+ ToIndexedSequence.prototype.__iterator = function(type, reverse) {
2873
+ var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
2874
+ var iterations = 0;
2875
+ return new Iterator(function() {
2876
+ var step = iterator.next();
2877
+ return step.done ? step :
2878
+ iteratorValue(type, iterations++, step.value, step)
2879
+ });
3445
2880
  };
3446
2881
 
3447
- // @pragma Mutability
3448
2882
 
3449
- Stack.prototype.__ensureOwner = function(ownerID) {
3450
- if (ownerID === this.__ownerID) {
3451
- return this;
3452
- }
3453
- if (!ownerID) {
3454
- this.__ownerID = ownerID;
3455
- this.__altered = false;
3456
- return this;
3457
- }
3458
- return makeStack(this.size, this._head, ownerID, this.__hash);
3459
- };
3460
2883
 
3461
- // @pragma Iteration
2884
+ createClass(ToSetSequence, SetSeq);
2885
+ function ToSetSequence(iter) {
2886
+ this._iter = iter;
2887
+ this.size = iter.size;
2888
+ }
3462
2889
 
3463
- Stack.prototype.__iterate = function(fn, reverse) {
3464
- if (reverse) {
3465
- return this.reverse().__iterate(fn);
3466
- }
3467
- var iterations = 0;
3468
- var node = this._head;
3469
- while (node) {
3470
- if (fn(node.value, iterations++, this) === false) {
3471
- break;
3472
- }
3473
- node = node.next;
3474
- }
3475
- return iterations;
2890
+ ToSetSequence.prototype.has = function(key) {
2891
+ return this._iter.includes(key);
3476
2892
  };
3477
2893
 
3478
- Stack.prototype.__iterator = function(type, reverse) {
3479
- if (reverse) {
3480
- return this.reverse().__iterator(type);
3481
- }
3482
- var iterations = 0;
3483
- var node = this._head;
3484
- return new src_Iterator__Iterator(function() {
3485
- if (node) {
3486
- var value = node.value;
3487
- node = node.next;
3488
- return iteratorValue(type, iterations++, value);
3489
- }
3490
- return iteratorDone();
3491
- });
2894
+ ToSetSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
2895
+ return this._iter.__iterate(function(v ) {return fn(v, v, this$0)}, reverse);
3492
2896
  };
3493
2897
 
2898
+ ToSetSequence.prototype.__iterator = function(type, reverse) {
2899
+ var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
2900
+ return new Iterator(function() {
2901
+ var step = iterator.next();
2902
+ return step.done ? step :
2903
+ iteratorValue(type, step.value, step.value, step);
2904
+ });
2905
+ };
3494
2906
 
3495
- function isStack(maybeStack) {
3496
- return !!(maybeStack && maybeStack[IS_STACK_SENTINEL]);
3497
- }
3498
2907
 
3499
- Stack.isStack = isStack;
3500
2908
 
3501
- var IS_STACK_SENTINEL = '@@__IMMUTABLE_STACK__@@';
2909
+ createClass(FromEntriesSequence, KeyedSeq);
2910
+ function FromEntriesSequence(entries) {
2911
+ this._iter = entries;
2912
+ this.size = entries.size;
2913
+ }
3502
2914
 
3503
- var StackPrototype = Stack.prototype;
3504
- StackPrototype[IS_STACK_SENTINEL] = true;
3505
- StackPrototype.withMutations = MapPrototype.withMutations;
3506
- StackPrototype.asMutable = MapPrototype.asMutable;
3507
- StackPrototype.asImmutable = MapPrototype.asImmutable;
3508
- StackPrototype.wasAltered = MapPrototype.wasAltered;
2915
+ FromEntriesSequence.prototype.entrySeq = function() {
2916
+ return this._iter.toSeq();
2917
+ };
3509
2918
 
2919
+ FromEntriesSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
2920
+ return this._iter.__iterate(function(entry ) {
2921
+ // Check if entry exists first so array access doesn't throw for holes
2922
+ // in the parent iteration.
2923
+ if (entry) {
2924
+ validateEntry(entry);
2925
+ var indexedIterable = isIterable(entry);
2926
+ return fn(
2927
+ indexedIterable ? entry.get(1) : entry[1],
2928
+ indexedIterable ? entry.get(0) : entry[0],
2929
+ this$0
2930
+ );
2931
+ }
2932
+ }, reverse);
2933
+ };
3510
2934
 
3511
- function makeStack(size, head, ownerID, hash) {
3512
- var map = Object.create(StackPrototype);
3513
- map.size = size;
3514
- map._head = head;
3515
- map.__ownerID = ownerID;
3516
- map.__hash = hash;
3517
- map.__altered = false;
3518
- return map;
3519
- }
2935
+ FromEntriesSequence.prototype.__iterator = function(type, reverse) {
2936
+ var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
2937
+ return new Iterator(function() {
2938
+ while (true) {
2939
+ var step = iterator.next();
2940
+ if (step.done) {
2941
+ return step;
2942
+ }
2943
+ var entry = step.value;
2944
+ // Check if entry exists first so array access doesn't throw for holes
2945
+ // in the parent iteration.
2946
+ if (entry) {
2947
+ validateEntry(entry);
2948
+ var indexedIterable = isIterable(entry);
2949
+ return iteratorValue(
2950
+ type,
2951
+ indexedIterable ? entry.get(0) : entry[0],
2952
+ indexedIterable ? entry.get(1) : entry[1],
2953
+ step
2954
+ );
2955
+ }
2956
+ }
2957
+ });
2958
+ };
3520
2959
 
3521
- var EMPTY_STACK;
3522
- function emptyStack() {
3523
- return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
3524
- }
3525
2960
 
3526
- createClass(src_Set__Set, SetCollection);
2961
+ ToIndexedSequence.prototype.cacheResult =
2962
+ ToKeyedSequence.prototype.cacheResult =
2963
+ ToSetSequence.prototype.cacheResult =
2964
+ FromEntriesSequence.prototype.cacheResult =
2965
+ cacheResultThrough;
3527
2966
 
3528
- // @pragma Construction
3529
2967
 
3530
- function src_Set__Set(value) {
3531
- return value === null || value === undefined ? emptySet() :
3532
- isSet(value) ? value :
3533
- emptySet().withMutations(function(set ) {
3534
- var iter = SetIterable(value);
3535
- assertNotInfinite(iter.size);
3536
- iter.forEach(function(v ) {return set.add(v)});
2968
+ function flipFactory(iterable) {
2969
+ var flipSequence = makeSequence(iterable);
2970
+ flipSequence._iter = iterable;
2971
+ flipSequence.size = iterable.size;
2972
+ flipSequence.flip = function() {return iterable};
2973
+ flipSequence.reverse = function () {
2974
+ var reversedSequence = iterable.reverse.apply(this); // super.reverse()
2975
+ reversedSequence.flip = function() {return iterable.reverse()};
2976
+ return reversedSequence;
2977
+ };
2978
+ flipSequence.has = function(key ) {return iterable.includes(key)};
2979
+ flipSequence.includes = function(key ) {return iterable.has(key)};
2980
+ flipSequence.cacheResult = cacheResultThrough;
2981
+ flipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
2982
+ return iterable.__iterate(function(v, k) {return fn(k, v, this$0) !== false}, reverse);
2983
+ }
2984
+ flipSequence.__iteratorUncached = function(type, reverse) {
2985
+ if (type === ITERATE_ENTRIES) {
2986
+ var iterator = iterable.__iterator(type, reverse);
2987
+ return new Iterator(function() {
2988
+ var step = iterator.next();
2989
+ if (!step.done) {
2990
+ var k = step.value[0];
2991
+ step.value[0] = step.value[1];
2992
+ step.value[1] = k;
2993
+ }
2994
+ return step;
3537
2995
  });
2996
+ }
2997
+ return iterable.__iterator(
2998
+ type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES,
2999
+ reverse
3000
+ );
3538
3001
  }
3002
+ return flipSequence;
3003
+ }
3539
3004
 
3540
- src_Set__Set.of = function(/*...values*/) {
3541
- return this(arguments);
3542
- };
3543
3005
 
3544
- src_Set__Set.fromKeys = function(value) {
3545
- return this(KeyedIterable(value).keySeq());
3006
+ function mapFactory(iterable, mapper, context) {
3007
+ var mappedSequence = makeSequence(iterable);
3008
+ mappedSequence.size = iterable.size;
3009
+ mappedSequence.has = function(key ) {return iterable.has(key)};
3010
+ mappedSequence.get = function(key, notSetValue) {
3011
+ var v = iterable.get(key, NOT_SET);
3012
+ return v === NOT_SET ?
3013
+ notSetValue :
3014
+ mapper.call(context, v, key, iterable);
3546
3015
  };
3016
+ mappedSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
3017
+ return iterable.__iterate(
3018
+ function(v, k, c) {return fn(mapper.call(context, v, k, c), k, this$0) !== false},
3019
+ reverse
3020
+ );
3021
+ }
3022
+ mappedSequence.__iteratorUncached = function (type, reverse) {
3023
+ var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
3024
+ return new Iterator(function() {
3025
+ var step = iterator.next();
3026
+ if (step.done) {
3027
+ return step;
3028
+ }
3029
+ var entry = step.value;
3030
+ var key = entry[0];
3031
+ return iteratorValue(
3032
+ type,
3033
+ key,
3034
+ mapper.call(context, entry[1], key, iterable),
3035
+ step
3036
+ );
3037
+ });
3038
+ }
3039
+ return mappedSequence;
3040
+ }
3547
3041
 
3548
- src_Set__Set.prototype.toString = function() {
3549
- return this.__toString('Set {', '}');
3042
+
3043
+ function reverseFactory(iterable, useKeys) {
3044
+ var reversedSequence = makeSequence(iterable);
3045
+ reversedSequence._iter = iterable;
3046
+ reversedSequence.size = iterable.size;
3047
+ reversedSequence.reverse = function() {return iterable};
3048
+ if (iterable.flip) {
3049
+ reversedSequence.flip = function () {
3050
+ var flipSequence = flipFactory(iterable);
3051
+ flipSequence.reverse = function() {return iterable.flip()};
3052
+ return flipSequence;
3053
+ };
3054
+ }
3055
+ reversedSequence.get = function(key, notSetValue)
3056
+ {return iterable.get(useKeys ? key : -1 - key, notSetValue)};
3057
+ reversedSequence.has = function(key )
3058
+ {return iterable.has(useKeys ? key : -1 - key)};
3059
+ reversedSequence.includes = function(value ) {return iterable.includes(value)};
3060
+ reversedSequence.cacheResult = cacheResultThrough;
3061
+ reversedSequence.__iterate = function (fn, reverse) {var this$0 = this;
3062
+ return iterable.__iterate(function(v, k) {return fn(v, k, this$0)}, !reverse);
3550
3063
  };
3064
+ reversedSequence.__iterator =
3065
+ function(type, reverse) {return iterable.__iterator(type, !reverse)};
3066
+ return reversedSequence;
3067
+ }
3551
3068
 
3552
- // @pragma Access
3553
3069
 
3554
- src_Set__Set.prototype.has = function(value) {
3555
- return this._map.has(value);
3070
+ function filterFactory(iterable, predicate, context, useKeys) {
3071
+ var filterSequence = makeSequence(iterable);
3072
+ if (useKeys) {
3073
+ filterSequence.has = function(key ) {
3074
+ var v = iterable.get(key, NOT_SET);
3075
+ return v !== NOT_SET && !!predicate.call(context, v, key, iterable);
3076
+ };
3077
+ filterSequence.get = function(key, notSetValue) {
3078
+ var v = iterable.get(key, NOT_SET);
3079
+ return v !== NOT_SET && predicate.call(context, v, key, iterable) ?
3080
+ v : notSetValue;
3081
+ };
3082
+ }
3083
+ filterSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
3084
+ var iterations = 0;
3085
+ iterable.__iterate(function(v, k, c) {
3086
+ if (predicate.call(context, v, k, c)) {
3087
+ iterations++;
3088
+ return fn(v, useKeys ? k : iterations - 1, this$0);
3089
+ }
3090
+ }, reverse);
3091
+ return iterations;
3556
3092
  };
3093
+ filterSequence.__iteratorUncached = function (type, reverse) {
3094
+ var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
3095
+ var iterations = 0;
3096
+ return new Iterator(function() {
3097
+ while (true) {
3098
+ var step = iterator.next();
3099
+ if (step.done) {
3100
+ return step;
3101
+ }
3102
+ var entry = step.value;
3103
+ var key = entry[0];
3104
+ var value = entry[1];
3105
+ if (predicate.call(context, value, key, iterable)) {
3106
+ return iteratorValue(type, useKeys ? key : iterations++, value, step);
3107
+ }
3108
+ }
3109
+ });
3110
+ }
3111
+ return filterSequence;
3112
+ }
3557
3113
 
3558
- // @pragma Modification
3559
3114
 
3560
- src_Set__Set.prototype.add = function(value) {
3561
- return updateSet(this, this._map.set(value, true));
3562
- };
3115
+ function countByFactory(iterable, grouper, context) {
3116
+ var groups = Map().asMutable();
3117
+ iterable.__iterate(function(v, k) {
3118
+ groups.update(
3119
+ grouper.call(context, v, k, iterable),
3120
+ 0,
3121
+ function(a ) {return a + 1}
3122
+ );
3123
+ });
3124
+ return groups.asImmutable();
3125
+ }
3563
3126
 
3564
- src_Set__Set.prototype.remove = function(value) {
3565
- return updateSet(this, this._map.remove(value));
3566
- };
3567
3127
 
3568
- src_Set__Set.prototype.clear = function() {
3569
- return updateSet(this, this._map.clear());
3570
- };
3128
+ function groupByFactory(iterable, grouper, context) {
3129
+ var isKeyedIter = isKeyed(iterable);
3130
+ var groups = (isOrdered(iterable) ? OrderedMap() : Map()).asMutable();
3131
+ iterable.__iterate(function(v, k) {
3132
+ groups.update(
3133
+ grouper.call(context, v, k, iterable),
3134
+ function(a ) {return (a = a || [], a.push(isKeyedIter ? [k, v] : v), a)}
3135
+ );
3136
+ });
3137
+ var coerce = iterableClass(iterable);
3138
+ return groups.map(function(arr ) {return reify(iterable, coerce(arr))});
3139
+ }
3571
3140
 
3572
- // @pragma Composition
3573
3141
 
3574
- src_Set__Set.prototype.union = function() {var iters = SLICE$0.call(arguments, 0);
3575
- iters = iters.filter(function(x ) {return x.size !== 0});
3576
- if (iters.length === 0) {
3577
- return this;
3578
- }
3579
- if (this.size === 0 && !this.__ownerID && iters.length === 1) {
3580
- return this.constructor(iters[0]);
3581
- }
3582
- return this.withMutations(function(set ) {
3583
- for (var ii = 0; ii < iters.length; ii++) {
3584
- SetIterable(iters[ii]).forEach(function(value ) {return set.add(value)});
3585
- }
3586
- });
3587
- };
3142
+ function sliceFactory(iterable, begin, end, useKeys) {
3143
+ var originalSize = iterable.size;
3588
3144
 
3589
- src_Set__Set.prototype.intersect = function() {var iters = SLICE$0.call(arguments, 0);
3590
- if (iters.length === 0) {
3591
- return this;
3145
+ // Sanitize begin & end using this shorthand for ToInt32(argument)
3146
+ // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
3147
+ if (begin !== undefined) {
3148
+ begin = begin | 0;
3149
+ }
3150
+ if (end !== undefined) {
3151
+ if (end === Infinity) {
3152
+ end = originalSize;
3153
+ } else {
3154
+ end = end | 0;
3592
3155
  }
3593
- iters = iters.map(function(iter ) {return SetIterable(iter)});
3594
- var originalSet = this;
3595
- return this.withMutations(function(set ) {
3596
- originalSet.forEach(function(value ) {
3597
- if (!iters.every(function(iter ) {return iter.includes(value)})) {
3598
- set.remove(value);
3599
- }
3600
- });
3156
+ }
3157
+
3158
+ if (wholeSlice(begin, end, originalSize)) {
3159
+ return iterable;
3160
+ }
3161
+
3162
+ var resolvedBegin = resolveBegin(begin, originalSize);
3163
+ var resolvedEnd = resolveEnd(end, originalSize);
3164
+
3165
+ // begin or end will be NaN if they were provided as negative numbers and
3166
+ // this iterable's size is unknown. In that case, cache first so there is
3167
+ // a known size and these do not resolve to NaN.
3168
+ if (resolvedBegin !== resolvedBegin || resolvedEnd !== resolvedEnd) {
3169
+ return sliceFactory(iterable.toSeq().cacheResult(), begin, end, useKeys);
3170
+ }
3171
+
3172
+ // Note: resolvedEnd is undefined when the original sequence's length is
3173
+ // unknown and this slice did not supply an end and should contain all
3174
+ // elements after resolvedBegin.
3175
+ // In that case, resolvedSize will be NaN and sliceSize will remain undefined.
3176
+ var resolvedSize = resolvedEnd - resolvedBegin;
3177
+ var sliceSize;
3178
+ if (resolvedSize === resolvedSize) {
3179
+ sliceSize = resolvedSize < 0 ? 0 : resolvedSize;
3180
+ }
3181
+
3182
+ var sliceSeq = makeSequence(iterable);
3183
+
3184
+ // If iterable.size is undefined, the size of the realized sliceSeq is
3185
+ // unknown at this point unless the number of items to slice is 0
3186
+ sliceSeq.size = sliceSize === 0 ? sliceSize : iterable.size && sliceSize || undefined;
3187
+
3188
+ if (!useKeys && isSeq(iterable) && sliceSize >= 0) {
3189
+ sliceSeq.get = function (index, notSetValue) {
3190
+ index = wrapIndex(this, index);
3191
+ return index >= 0 && index < sliceSize ?
3192
+ iterable.get(index + resolvedBegin, notSetValue) :
3193
+ notSetValue;
3194
+ }
3195
+ }
3196
+
3197
+ sliceSeq.__iterateUncached = function(fn, reverse) {var this$0 = this;
3198
+ if (sliceSize === 0) {
3199
+ return 0;
3200
+ }
3201
+ if (reverse) {
3202
+ return this.cacheResult().__iterate(fn, reverse);
3203
+ }
3204
+ var skipped = 0;
3205
+ var isSkipping = true;
3206
+ var iterations = 0;
3207
+ iterable.__iterate(function(v, k) {
3208
+ if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) {
3209
+ iterations++;
3210
+ return fn(v, useKeys ? k : iterations - 1, this$0) !== false &&
3211
+ iterations !== sliceSize;
3212
+ }
3601
3213
  });
3214
+ return iterations;
3602
3215
  };
3603
3216
 
3604
- src_Set__Set.prototype.subtract = function() {var iters = SLICE$0.call(arguments, 0);
3605
- if (iters.length === 0) {
3606
- return this;
3217
+ sliceSeq.__iteratorUncached = function(type, reverse) {
3218
+ if (sliceSize !== 0 && reverse) {
3219
+ return this.cacheResult().__iterator(type, reverse);
3607
3220
  }
3608
- iters = iters.map(function(iter ) {return SetIterable(iter)});
3609
- var originalSet = this;
3610
- return this.withMutations(function(set ) {
3611
- originalSet.forEach(function(value ) {
3612
- if (iters.some(function(iter ) {return iter.includes(value)})) {
3613
- set.remove(value);
3614
- }
3615
- });
3221
+ // Don't bother instantiating parent iterator if taking 0.
3222
+ var iterator = sliceSize !== 0 && iterable.__iterator(type, reverse);
3223
+ var skipped = 0;
3224
+ var iterations = 0;
3225
+ return new Iterator(function() {
3226
+ while (skipped++ < resolvedBegin) {
3227
+ iterator.next();
3228
+ }
3229
+ if (++iterations > sliceSize) {
3230
+ return iteratorDone();
3231
+ }
3232
+ var step = iterator.next();
3233
+ if (useKeys || type === ITERATE_VALUES) {
3234
+ return step;
3235
+ } else if (type === ITERATE_KEYS) {
3236
+ return iteratorValue(type, iterations - 1, undefined, step);
3237
+ } else {
3238
+ return iteratorValue(type, iterations - 1, step.value[1], step);
3239
+ }
3616
3240
  });
3617
- };
3241
+ }
3618
3242
 
3619
- src_Set__Set.prototype.merge = function() {
3620
- return this.union.apply(this, arguments);
3621
- };
3243
+ return sliceSeq;
3244
+ }
3622
3245
 
3623
- src_Set__Set.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
3624
- return this.union.apply(this, iters);
3625
- };
3626
3246
 
3627
- src_Set__Set.prototype.sort = function(comparator) {
3628
- // Late binding
3629
- return OrderedSet(sortFactory(this, comparator));
3247
+ function takeWhileFactory(iterable, predicate, context) {
3248
+ var takeSequence = makeSequence(iterable);
3249
+ takeSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
3250
+ if (reverse) {
3251
+ return this.cacheResult().__iterate(fn, reverse);
3252
+ }
3253
+ var iterations = 0;
3254
+ iterable.__iterate(function(v, k, c)
3255
+ {return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$0)}
3256
+ );
3257
+ return iterations;
3630
3258
  };
3631
-
3632
- src_Set__Set.prototype.sortBy = function(mapper, comparator) {
3633
- // Late binding
3634
- return OrderedSet(sortFactory(this, comparator, mapper));
3259
+ takeSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
3260
+ if (reverse) {
3261
+ return this.cacheResult().__iterator(type, reverse);
3262
+ }
3263
+ var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
3264
+ var iterating = true;
3265
+ return new Iterator(function() {
3266
+ if (!iterating) {
3267
+ return iteratorDone();
3268
+ }
3269
+ var step = iterator.next();
3270
+ if (step.done) {
3271
+ return step;
3272
+ }
3273
+ var entry = step.value;
3274
+ var k = entry[0];
3275
+ var v = entry[1];
3276
+ if (!predicate.call(context, v, k, this$0)) {
3277
+ iterating = false;
3278
+ return iteratorDone();
3279
+ }
3280
+ return type === ITERATE_ENTRIES ? step :
3281
+ iteratorValue(type, k, v, step);
3282
+ });
3635
3283
  };
3284
+ return takeSequence;
3285
+ }
3636
3286
 
3637
- src_Set__Set.prototype.wasAltered = function() {
3638
- return this._map.wasAltered();
3639
- };
3640
3287
 
3641
- src_Set__Set.prototype.__iterate = function(fn, reverse) {var this$0 = this;
3642
- return this._map.__iterate(function(_, k) {return fn(k, k, this$0)}, reverse);
3288
+ function skipWhileFactory(iterable, predicate, context, useKeys) {
3289
+ var skipSequence = makeSequence(iterable);
3290
+ skipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
3291
+ if (reverse) {
3292
+ return this.cacheResult().__iterate(fn, reverse);
3293
+ }
3294
+ var isSkipping = true;
3295
+ var iterations = 0;
3296
+ iterable.__iterate(function(v, k, c) {
3297
+ if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) {
3298
+ iterations++;
3299
+ return fn(v, useKeys ? k : iterations - 1, this$0);
3300
+ }
3301
+ });
3302
+ return iterations;
3643
3303
  };
3644
-
3645
- src_Set__Set.prototype.__iterator = function(type, reverse) {
3646
- return this._map.map(function(_, k) {return k}).__iterator(type, reverse);
3304
+ skipSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
3305
+ if (reverse) {
3306
+ return this.cacheResult().__iterator(type, reverse);
3307
+ }
3308
+ var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
3309
+ var skipping = true;
3310
+ var iterations = 0;
3311
+ return new Iterator(function() {
3312
+ var step, k, v;
3313
+ do {
3314
+ step = iterator.next();
3315
+ if (step.done) {
3316
+ if (useKeys || type === ITERATE_VALUES) {
3317
+ return step;
3318
+ } else if (type === ITERATE_KEYS) {
3319
+ return iteratorValue(type, iterations++, undefined, step);
3320
+ } else {
3321
+ return iteratorValue(type, iterations++, step.value[1], step);
3322
+ }
3323
+ }
3324
+ var entry = step.value;
3325
+ k = entry[0];
3326
+ v = entry[1];
3327
+ skipping && (skipping = predicate.call(context, v, k, this$0));
3328
+ } while (skipping);
3329
+ return type === ITERATE_ENTRIES ? step :
3330
+ iteratorValue(type, k, v, step);
3331
+ });
3647
3332
  };
3333
+ return skipSequence;
3334
+ }
3648
3335
 
3649
- src_Set__Set.prototype.__ensureOwner = function(ownerID) {
3650
- if (ownerID === this.__ownerID) {
3651
- return this;
3336
+
3337
+ function concatFactory(iterable, values) {
3338
+ var isKeyedIterable = isKeyed(iterable);
3339
+ var iters = [iterable].concat(values).map(function(v ) {
3340
+ if (!isIterable(v)) {
3341
+ v = isKeyedIterable ?
3342
+ keyedSeqFromValue(v) :
3343
+ indexedSeqFromValue(Array.isArray(v) ? v : [v]);
3344
+ } else if (isKeyedIterable) {
3345
+ v = KeyedIterable(v);
3652
3346
  }
3653
- var newMap = this._map.__ensureOwner(ownerID);
3654
- if (!ownerID) {
3655
- this.__ownerID = ownerID;
3656
- this._map = newMap;
3657
- return this;
3347
+ return v;
3348
+ }).filter(function(v ) {return v.size !== 0});
3349
+
3350
+ if (iters.length === 0) {
3351
+ return iterable;
3352
+ }
3353
+
3354
+ if (iters.length === 1) {
3355
+ var singleton = iters[0];
3356
+ if (singleton === iterable ||
3357
+ isKeyedIterable && isKeyed(singleton) ||
3358
+ isIndexed(iterable) && isIndexed(singleton)) {
3359
+ return singleton;
3658
3360
  }
3659
- return this.__make(newMap, ownerID);
3660
- };
3361
+ }
3661
3362
 
3363
+ var concatSeq = new ArraySeq(iters);
3364
+ if (isKeyedIterable) {
3365
+ concatSeq = concatSeq.toKeyedSeq();
3366
+ } else if (!isIndexed(iterable)) {
3367
+ concatSeq = concatSeq.toSetSeq();
3368
+ }
3369
+ concatSeq = concatSeq.flatten(true);
3370
+ concatSeq.size = iters.reduce(
3371
+ function(sum, seq) {
3372
+ if (sum !== undefined) {
3373
+ var size = seq.size;
3374
+ if (size !== undefined) {
3375
+ return sum + size;
3376
+ }
3377
+ }
3378
+ },
3379
+ 0
3380
+ );
3381
+ return concatSeq;
3382
+ }
3662
3383
 
3663
- function isSet(maybeSet) {
3664
- return !!(maybeSet && maybeSet[IS_SET_SENTINEL]);
3384
+
3385
+ function flattenFactory(iterable, depth, useKeys) {
3386
+ var flatSequence = makeSequence(iterable);
3387
+ flatSequence.__iterateUncached = function(fn, reverse) {
3388
+ var iterations = 0;
3389
+ var stopped = false;
3390
+ function flatDeep(iter, currentDepth) {var this$0 = this;
3391
+ iter.__iterate(function(v, k) {
3392
+ if ((!depth || currentDepth < depth) && isIterable(v)) {
3393
+ flatDeep(v, currentDepth + 1);
3394
+ } else if (fn(v, useKeys ? k : iterations++, this$0) === false) {
3395
+ stopped = true;
3396
+ }
3397
+ return !stopped;
3398
+ }, reverse);
3399
+ }
3400
+ flatDeep(iterable, 0);
3401
+ return iterations;
3402
+ }
3403
+ flatSequence.__iteratorUncached = function(type, reverse) {
3404
+ var iterator = iterable.__iterator(type, reverse);
3405
+ var stack = [];
3406
+ var iterations = 0;
3407
+ return new Iterator(function() {
3408
+ while (iterator) {
3409
+ var step = iterator.next();
3410
+ if (step.done !== false) {
3411
+ iterator = stack.pop();
3412
+ continue;
3413
+ }
3414
+ var v = step.value;
3415
+ if (type === ITERATE_ENTRIES) {
3416
+ v = v[1];
3417
+ }
3418
+ if ((!depth || stack.length < depth) && isIterable(v)) {
3419
+ stack.push(iterator);
3420
+ iterator = v.__iterator(type, reverse);
3421
+ } else {
3422
+ return useKeys ? step : iteratorValue(type, iterations++, v, step);
3423
+ }
3424
+ }
3425
+ return iteratorDone();
3426
+ });
3427
+ }
3428
+ return flatSequence;
3665
3429
  }
3666
3430
 
3667
- src_Set__Set.isSet = isSet;
3668
3431
 
3669
- var IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
3432
+ function flatMapFactory(iterable, mapper, context) {
3433
+ var coerce = iterableClass(iterable);
3434
+ return iterable.toSeq().map(
3435
+ function(v, k) {return coerce(mapper.call(context, v, k, iterable))}
3436
+ ).flatten(true);
3437
+ }
3670
3438
 
3671
- var SetPrototype = src_Set__Set.prototype;
3672
- SetPrototype[IS_SET_SENTINEL] = true;
3673
- SetPrototype[DELETE] = SetPrototype.remove;
3674
- SetPrototype.mergeDeep = SetPrototype.merge;
3675
- SetPrototype.mergeDeepWith = SetPrototype.mergeWith;
3676
- SetPrototype.withMutations = MapPrototype.withMutations;
3677
- SetPrototype.asMutable = MapPrototype.asMutable;
3678
- SetPrototype.asImmutable = MapPrototype.asImmutable;
3679
3439
 
3680
- SetPrototype.__empty = emptySet;
3681
- SetPrototype.__make = makeSet;
3440
+ function interposeFactory(iterable, separator) {
3441
+ var interposedSequence = makeSequence(iterable);
3442
+ interposedSequence.size = iterable.size && iterable.size * 2 -1;
3443
+ interposedSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
3444
+ var iterations = 0;
3445
+ iterable.__iterate(function(v, k)
3446
+ {return (!iterations || fn(separator, iterations++, this$0) !== false) &&
3447
+ fn(v, iterations++, this$0) !== false},
3448
+ reverse
3449
+ );
3450
+ return iterations;
3451
+ };
3452
+ interposedSequence.__iteratorUncached = function(type, reverse) {
3453
+ var iterator = iterable.__iterator(ITERATE_VALUES, reverse);
3454
+ var iterations = 0;
3455
+ var step;
3456
+ return new Iterator(function() {
3457
+ if (!step || iterations % 2) {
3458
+ step = iterator.next();
3459
+ if (step.done) {
3460
+ return step;
3461
+ }
3462
+ }
3463
+ return iterations % 2 ?
3464
+ iteratorValue(type, iterations++, separator) :
3465
+ iteratorValue(type, iterations++, step.value, step);
3466
+ });
3467
+ };
3468
+ return interposedSequence;
3469
+ }
3682
3470
 
3683
- function updateSet(set, newMap) {
3684
- if (set.__ownerID) {
3685
- set.size = newMap.size;
3686
- set._map = newMap;
3687
- return set;
3471
+
3472
+ function sortFactory(iterable, comparator, mapper) {
3473
+ if (!comparator) {
3474
+ comparator = defaultComparator;
3688
3475
  }
3689
- return newMap === set._map ? set :
3690
- newMap.size === 0 ? set.__empty() :
3691
- set.__make(newMap);
3476
+ var isKeyedIterable = isKeyed(iterable);
3477
+ var index = 0;
3478
+ var entries = iterable.toSeq().map(
3479
+ function(v, k) {return [k, v, index++, mapper ? mapper(v, k, iterable) : v]}
3480
+ ).toArray();
3481
+ entries.sort(function(a, b) {return comparator(a[3], b[3]) || a[2] - b[2]}).forEach(
3482
+ isKeyedIterable ?
3483
+ function(v, i) { entries[i].length = 2; } :
3484
+ function(v, i) { entries[i] = v[1]; }
3485
+ );
3486
+ return isKeyedIterable ? KeyedSeq(entries) :
3487
+ isIndexed(iterable) ? IndexedSeq(entries) :
3488
+ SetSeq(entries);
3692
3489
  }
3693
3490
 
3694
- function makeSet(map, ownerID) {
3695
- var set = Object.create(SetPrototype);
3696
- set.size = map ? map.size : 0;
3697
- set._map = map;
3698
- set.__ownerID = ownerID;
3699
- return set;
3491
+
3492
+ function maxFactory(iterable, comparator, mapper) {
3493
+ if (!comparator) {
3494
+ comparator = defaultComparator;
3495
+ }
3496
+ if (mapper) {
3497
+ var entry = iterable.toSeq()
3498
+ .map(function(v, k) {return [v, mapper(v, k, iterable)]})
3499
+ .reduce(function(a, b) {return maxCompare(comparator, a[1], b[1]) ? b : a});
3500
+ return entry && entry[0];
3501
+ } else {
3502
+ return iterable.reduce(function(a, b) {return maxCompare(comparator, a, b) ? b : a});
3503
+ }
3504
+ }
3505
+
3506
+ function maxCompare(comparator, a, b) {
3507
+ var comp = comparator(b, a);
3508
+ // b is considered the new max if the comparator declares them equal, but
3509
+ // they are not equal and b is in fact a nullish value.
3510
+ return (comp === 0 && b !== a && (b === undefined || b === null || b !== b)) || comp > 0;
3511
+ }
3512
+
3513
+
3514
+ function zipWithFactory(keyIter, zipper, iters) {
3515
+ var zipSequence = makeSequence(keyIter);
3516
+ zipSequence.size = new ArraySeq(iters).map(function(i ) {return i.size}).min();
3517
+ // Note: this a generic base implementation of __iterate in terms of
3518
+ // __iterator which may be more generically useful in the future.
3519
+ zipSequence.__iterate = function(fn, reverse) {
3520
+ /* generic:
3521
+ var iterator = this.__iterator(ITERATE_ENTRIES, reverse);
3522
+ var step;
3523
+ var iterations = 0;
3524
+ while (!(step = iterator.next()).done) {
3525
+ iterations++;
3526
+ if (fn(step.value[1], step.value[0], this) === false) {
3527
+ break;
3528
+ }
3529
+ }
3530
+ return iterations;
3531
+ */
3532
+ // indexed:
3533
+ var iterator = this.__iterator(ITERATE_VALUES, reverse);
3534
+ var step;
3535
+ var iterations = 0;
3536
+ while (!(step = iterator.next()).done) {
3537
+ if (fn(step.value, iterations++, this) === false) {
3538
+ break;
3539
+ }
3540
+ }
3541
+ return iterations;
3542
+ };
3543
+ zipSequence.__iteratorUncached = function(type, reverse) {
3544
+ var iterators = iters.map(function(i )
3545
+ {return (i = Iterable(i), getIterator(reverse ? i.reverse() : i))}
3546
+ );
3547
+ var iterations = 0;
3548
+ var isDone = false;
3549
+ return new Iterator(function() {
3550
+ var steps;
3551
+ if (!isDone) {
3552
+ steps = iterators.map(function(i ) {return i.next()});
3553
+ isDone = steps.some(function(s ) {return s.done});
3554
+ }
3555
+ if (isDone) {
3556
+ return iteratorDone();
3557
+ }
3558
+ return iteratorValue(
3559
+ type,
3560
+ iterations++,
3561
+ zipper.apply(null, steps.map(function(s ) {return s.value}))
3562
+ );
3563
+ });
3564
+ };
3565
+ return zipSequence
3700
3566
  }
3701
3567
 
3702
- var EMPTY_SET;
3703
- function emptySet() {
3704
- return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
3705
- }
3706
3568
 
3707
- createClass(OrderedSet, src_Set__Set);
3569
+ // #pragma Helper Functions
3708
3570
 
3709
- // @pragma Construction
3571
+ function reify(iter, seq) {
3572
+ return isSeq(iter) ? seq : iter.constructor(seq);
3573
+ }
3710
3574
 
3711
- function OrderedSet(value) {
3712
- return value === null || value === undefined ? emptyOrderedSet() :
3713
- isOrderedSet(value) ? value :
3714
- emptyOrderedSet().withMutations(function(set ) {
3715
- var iter = SetIterable(value);
3716
- assertNotInfinite(iter.size);
3717
- iter.forEach(function(v ) {return set.add(v)});
3718
- });
3575
+ function validateEntry(entry) {
3576
+ if (entry !== Object(entry)) {
3577
+ throw new TypeError('Expected [K, V] tuple: ' + entry);
3719
3578
  }
3579
+ }
3720
3580
 
3721
- OrderedSet.of = function(/*...values*/) {
3722
- return this(arguments);
3723
- };
3724
-
3725
- OrderedSet.fromKeys = function(value) {
3726
- return this(KeyedIterable(value).keySeq());
3727
- };
3728
-
3729
- OrderedSet.prototype.toString = function() {
3730
- return this.__toString('OrderedSet {', '}');
3731
- };
3732
-
3733
-
3734
- function isOrderedSet(maybeOrderedSet) {
3735
- return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
3581
+ function resolveSize(iter) {
3582
+ assertNotInfinite(iter.size);
3583
+ return ensureSize(iter);
3736
3584
  }
3737
3585
 
3738
- OrderedSet.isOrderedSet = isOrderedSet;
3586
+ function iterableClass(iterable) {
3587
+ return isKeyed(iterable) ? KeyedIterable :
3588
+ isIndexed(iterable) ? IndexedIterable :
3589
+ SetIterable;
3590
+ }
3739
3591
 
3740
- var OrderedSetPrototype = OrderedSet.prototype;
3741
- OrderedSetPrototype[IS_ORDERED_SENTINEL] = true;
3592
+ function makeSequence(iterable) {
3593
+ return Object.create(
3594
+ (
3595
+ isKeyed(iterable) ? KeyedSeq :
3596
+ isIndexed(iterable) ? IndexedSeq :
3597
+ SetSeq
3598
+ ).prototype
3599
+ );
3600
+ }
3742
3601
 
3743
- OrderedSetPrototype.__empty = emptyOrderedSet;
3744
- OrderedSetPrototype.__make = makeOrderedSet;
3602
+ function cacheResultThrough() {
3603
+ if (this._iter.cacheResult) {
3604
+ this._iter.cacheResult();
3605
+ this.size = this._iter.size;
3606
+ return this;
3607
+ } else {
3608
+ return Seq.prototype.cacheResult.call(this);
3609
+ }
3610
+ }
3745
3611
 
3746
- function makeOrderedSet(map, ownerID) {
3747
- var set = Object.create(OrderedSetPrototype);
3748
- set.size = map ? map.size : 0;
3749
- set._map = map;
3750
- set.__ownerID = ownerID;
3751
- return set;
3612
+ function defaultComparator(a, b) {
3613
+ return a > b ? 1 : a < b ? -1 : 0;
3752
3614
  }
3753
3615
 
3754
- var EMPTY_ORDERED_SET;
3755
- function emptyOrderedSet() {
3756
- return EMPTY_ORDERED_SET || (EMPTY_ORDERED_SET = makeOrderedSet(emptyOrderedMap()));
3616
+ function forceIterator(keyPath) {
3617
+ var iter = getIterator(keyPath);
3618
+ if (!iter) {
3619
+ // Array might not be iterable in this environment, so we need a fallback
3620
+ // to our wrapped type.
3621
+ if (!isArrayLike(keyPath)) {
3622
+ throw new TypeError('Expected iterable or array-like: ' + keyPath);
3623
+ }
3624
+ iter = getIterator(Iterable(keyPath));
3625
+ }
3626
+ return iter;
3757
3627
  }
3758
3628
 
3759
3629
  createClass(Record, KeyedCollection);
@@ -3777,7 +3647,7 @@
3777
3647
  RecordTypePrototype._keys = keys;
3778
3648
  RecordTypePrototype._defaultValues = defaultValues;
3779
3649
  }
3780
- this._map = src_Map__Map(values);
3650
+ this._map = Map(values);
3781
3651
  };
3782
3652
 
3783
3653
  var RecordTypePrototype = RecordType.prototype = Object.create(RecordPrototype);
@@ -3819,6 +3689,12 @@
3819
3689
  if (!this.has(k)) {
3820
3690
  throw new Error('Cannot set unknown key "' + k + '" on ' + recordName(this));
3821
3691
  }
3692
+ if (this._map && !this._map.has(k)) {
3693
+ var defaultVal = this._defaultValues[k];
3694
+ if (v === defaultVal) {
3695
+ return this;
3696
+ }
3697
+ }
3822
3698
  var newMap = this._map && this._map.set(k, v);
3823
3699
  if (this.__ownerID || newMap === this._map) {
3824
3700
  return this;
@@ -3888,279 +3764,478 @@
3888
3764
  return record;
3889
3765
  }
3890
3766
 
3891
- function recordName(record) {
3892
- return record._name || record.constructor.name || 'Record';
3767
+ function recordName(record) {
3768
+ return record._name || record.constructor.name || 'Record';
3769
+ }
3770
+
3771
+ function setProps(prototype, names) {
3772
+ try {
3773
+ names.forEach(setProp.bind(undefined, prototype));
3774
+ } catch (error) {
3775
+ // Object.defineProperty failed. Probably IE8.
3776
+ }
3777
+ }
3778
+
3779
+ function setProp(prototype, name) {
3780
+ Object.defineProperty(prototype, name, {
3781
+ get: function() {
3782
+ return this.get(name);
3783
+ },
3784
+ set: function(value) {
3785
+ invariant(this.__ownerID, 'Cannot set on an immutable record.');
3786
+ this.set(name, value);
3787
+ }
3788
+ });
3789
+ }
3790
+
3791
+ createClass(Set, SetCollection);
3792
+
3793
+ // @pragma Construction
3794
+
3795
+ function Set(value) {
3796
+ return value === null || value === undefined ? emptySet() :
3797
+ isSet(value) && !isOrdered(value) ? value :
3798
+ emptySet().withMutations(function(set ) {
3799
+ var iter = SetIterable(value);
3800
+ assertNotInfinite(iter.size);
3801
+ iter.forEach(function(v ) {return set.add(v)});
3802
+ });
3803
+ }
3804
+
3805
+ Set.of = function(/*...values*/) {
3806
+ return this(arguments);
3807
+ };
3808
+
3809
+ Set.fromKeys = function(value) {
3810
+ return this(KeyedIterable(value).keySeq());
3811
+ };
3812
+
3813
+ Set.prototype.toString = function() {
3814
+ return this.__toString('Set {', '}');
3815
+ };
3816
+
3817
+ // @pragma Access
3818
+
3819
+ Set.prototype.has = function(value) {
3820
+ return this._map.has(value);
3821
+ };
3822
+
3823
+ // @pragma Modification
3824
+
3825
+ Set.prototype.add = function(value) {
3826
+ return updateSet(this, this._map.set(value, true));
3827
+ };
3828
+
3829
+ Set.prototype.remove = function(value) {
3830
+ return updateSet(this, this._map.remove(value));
3831
+ };
3832
+
3833
+ Set.prototype.clear = function() {
3834
+ return updateSet(this, this._map.clear());
3835
+ };
3836
+
3837
+ // @pragma Composition
3838
+
3839
+ Set.prototype.union = function() {var iters = SLICE$0.call(arguments, 0);
3840
+ iters = iters.filter(function(x ) {return x.size !== 0});
3841
+ if (iters.length === 0) {
3842
+ return this;
3843
+ }
3844
+ if (this.size === 0 && !this.__ownerID && iters.length === 1) {
3845
+ return this.constructor(iters[0]);
3846
+ }
3847
+ return this.withMutations(function(set ) {
3848
+ for (var ii = 0; ii < iters.length; ii++) {
3849
+ SetIterable(iters[ii]).forEach(function(value ) {return set.add(value)});
3850
+ }
3851
+ });
3852
+ };
3853
+
3854
+ Set.prototype.intersect = function() {var iters = SLICE$0.call(arguments, 0);
3855
+ if (iters.length === 0) {
3856
+ return this;
3857
+ }
3858
+ iters = iters.map(function(iter ) {return SetIterable(iter)});
3859
+ var originalSet = this;
3860
+ return this.withMutations(function(set ) {
3861
+ originalSet.forEach(function(value ) {
3862
+ if (!iters.every(function(iter ) {return iter.includes(value)})) {
3863
+ set.remove(value);
3864
+ }
3865
+ });
3866
+ });
3867
+ };
3868
+
3869
+ Set.prototype.subtract = function() {var iters = SLICE$0.call(arguments, 0);
3870
+ if (iters.length === 0) {
3871
+ return this;
3872
+ }
3873
+ iters = iters.map(function(iter ) {return SetIterable(iter)});
3874
+ var originalSet = this;
3875
+ return this.withMutations(function(set ) {
3876
+ originalSet.forEach(function(value ) {
3877
+ if (iters.some(function(iter ) {return iter.includes(value)})) {
3878
+ set.remove(value);
3879
+ }
3880
+ });
3881
+ });
3882
+ };
3883
+
3884
+ Set.prototype.merge = function() {
3885
+ return this.union.apply(this, arguments);
3886
+ };
3887
+
3888
+ Set.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
3889
+ return this.union.apply(this, iters);
3890
+ };
3891
+
3892
+ Set.prototype.sort = function(comparator) {
3893
+ // Late binding
3894
+ return OrderedSet(sortFactory(this, comparator));
3895
+ };
3896
+
3897
+ Set.prototype.sortBy = function(mapper, comparator) {
3898
+ // Late binding
3899
+ return OrderedSet(sortFactory(this, comparator, mapper));
3900
+ };
3901
+
3902
+ Set.prototype.wasAltered = function() {
3903
+ return this._map.wasAltered();
3904
+ };
3905
+
3906
+ Set.prototype.__iterate = function(fn, reverse) {var this$0 = this;
3907
+ return this._map.__iterate(function(_, k) {return fn(k, k, this$0)}, reverse);
3908
+ };
3909
+
3910
+ Set.prototype.__iterator = function(type, reverse) {
3911
+ return this._map.map(function(_, k) {return k}).__iterator(type, reverse);
3912
+ };
3913
+
3914
+ Set.prototype.__ensureOwner = function(ownerID) {
3915
+ if (ownerID === this.__ownerID) {
3916
+ return this;
3917
+ }
3918
+ var newMap = this._map.__ensureOwner(ownerID);
3919
+ if (!ownerID) {
3920
+ this.__ownerID = ownerID;
3921
+ this._map = newMap;
3922
+ return this;
3923
+ }
3924
+ return this.__make(newMap, ownerID);
3925
+ };
3926
+
3927
+
3928
+ function isSet(maybeSet) {
3929
+ return !!(maybeSet && maybeSet[IS_SET_SENTINEL]);
3930
+ }
3931
+
3932
+ Set.isSet = isSet;
3933
+
3934
+ var IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
3935
+
3936
+ var SetPrototype = Set.prototype;
3937
+ SetPrototype[IS_SET_SENTINEL] = true;
3938
+ SetPrototype[DELETE] = SetPrototype.remove;
3939
+ SetPrototype.mergeDeep = SetPrototype.merge;
3940
+ SetPrototype.mergeDeepWith = SetPrototype.mergeWith;
3941
+ SetPrototype.withMutations = MapPrototype.withMutations;
3942
+ SetPrototype.asMutable = MapPrototype.asMutable;
3943
+ SetPrototype.asImmutable = MapPrototype.asImmutable;
3944
+
3945
+ SetPrototype.__empty = emptySet;
3946
+ SetPrototype.__make = makeSet;
3947
+
3948
+ function updateSet(set, newMap) {
3949
+ if (set.__ownerID) {
3950
+ set.size = newMap.size;
3951
+ set._map = newMap;
3952
+ return set;
3953
+ }
3954
+ return newMap === set._map ? set :
3955
+ newMap.size === 0 ? set.__empty() :
3956
+ set.__make(newMap);
3893
3957
  }
3894
3958
 
3895
- function setProps(prototype, names) {
3896
- try {
3897
- names.forEach(setProp.bind(undefined, prototype));
3898
- } catch (error) {
3899
- // Object.defineProperty failed. Probably IE8.
3900
- }
3959
+ function makeSet(map, ownerID) {
3960
+ var set = Object.create(SetPrototype);
3961
+ set.size = map ? map.size : 0;
3962
+ set._map = map;
3963
+ set.__ownerID = ownerID;
3964
+ return set;
3901
3965
  }
3902
3966
 
3903
- function setProp(prototype, name) {
3904
- Object.defineProperty(prototype, name, {
3905
- get: function() {
3906
- return this.get(name);
3907
- },
3908
- set: function(value) {
3909
- invariant(this.__ownerID, 'Cannot set on an immutable record.');
3910
- this.set(name, value);
3911
- }
3912
- });
3967
+ var EMPTY_SET;
3968
+ function emptySet() {
3969
+ return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
3913
3970
  }
3914
3971
 
3915
- function deepEqual(a, b) {
3916
- if (a === b) {
3917
- return true;
3918
- }
3972
+ createClass(OrderedSet, Set);
3919
3973
 
3920
- if (
3921
- !isIterable(b) ||
3922
- a.size !== undefined && b.size !== undefined && a.size !== b.size ||
3923
- a.__hash !== undefined && b.__hash !== undefined && a.__hash !== b.__hash ||
3924
- isKeyed(a) !== isKeyed(b) ||
3925
- isIndexed(a) !== isIndexed(b) ||
3926
- isOrdered(a) !== isOrdered(b)
3927
- ) {
3928
- return false;
3929
- }
3974
+ // @pragma Construction
3930
3975
 
3931
- if (a.size === 0 && b.size === 0) {
3932
- return true;
3976
+ function OrderedSet(value) {
3977
+ return value === null || value === undefined ? emptyOrderedSet() :
3978
+ isOrderedSet(value) ? value :
3979
+ emptyOrderedSet().withMutations(function(set ) {
3980
+ var iter = SetIterable(value);
3981
+ assertNotInfinite(iter.size);
3982
+ iter.forEach(function(v ) {return set.add(v)});
3983
+ });
3933
3984
  }
3934
3985
 
3935
- var notAssociative = !isAssociative(a);
3986
+ OrderedSet.of = function(/*...values*/) {
3987
+ return this(arguments);
3988
+ };
3936
3989
 
3937
- if (isOrdered(a)) {
3938
- var entries = a.entries();
3939
- return b.every(function(v, k) {
3940
- var entry = entries.next().value;
3941
- return entry && is(entry[1], v) && (notAssociative || is(entry[0], k));
3942
- }) && entries.next().done;
3943
- }
3990
+ OrderedSet.fromKeys = function(value) {
3991
+ return this(KeyedIterable(value).keySeq());
3992
+ };
3944
3993
 
3945
- var flipped = false;
3994
+ OrderedSet.prototype.toString = function() {
3995
+ return this.__toString('OrderedSet {', '}');
3996
+ };
3946
3997
 
3947
- if (a.size === undefined) {
3948
- if (b.size === undefined) {
3949
- if (typeof a.cacheResult === 'function') {
3950
- a.cacheResult();
3951
- }
3952
- } else {
3953
- flipped = true;
3954
- var _ = a;
3955
- a = b;
3956
- b = _;
3957
- }
3958
- }
3959
3998
 
3960
- var allEqual = true;
3961
- var bSize = b.__iterate(function(v, k) {
3962
- if (notAssociative ? !a.has(v) :
3963
- flipped ? !is(v, a.get(k, NOT_SET)) : !is(a.get(k, NOT_SET), v)) {
3964
- allEqual = false;
3965
- return false;
3966
- }
3967
- });
3999
+ function isOrderedSet(maybeOrderedSet) {
4000
+ return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
4001
+ }
3968
4002
 
3969
- return allEqual && a.size === bSize;
4003
+ OrderedSet.isOrderedSet = isOrderedSet;
4004
+
4005
+ var OrderedSetPrototype = OrderedSet.prototype;
4006
+ OrderedSetPrototype[IS_ORDERED_SENTINEL] = true;
4007
+
4008
+ OrderedSetPrototype.__empty = emptyOrderedSet;
4009
+ OrderedSetPrototype.__make = makeOrderedSet;
4010
+
4011
+ function makeOrderedSet(map, ownerID) {
4012
+ var set = Object.create(OrderedSetPrototype);
4013
+ set.size = map ? map.size : 0;
4014
+ set._map = map;
4015
+ set.__ownerID = ownerID;
4016
+ return set;
3970
4017
  }
3971
4018
 
3972
- createClass(Range, IndexedSeq);
4019
+ var EMPTY_ORDERED_SET;
4020
+ function emptyOrderedSet() {
4021
+ return EMPTY_ORDERED_SET || (EMPTY_ORDERED_SET = makeOrderedSet(emptyOrderedMap()));
4022
+ }
3973
4023
 
3974
- function Range(start, end, step) {
3975
- if (!(this instanceof Range)) {
3976
- return new Range(start, end, step);
3977
- }
3978
- invariant(step !== 0, 'Cannot step a Range by 0');
3979
- start = start || 0;
3980
- if (end === undefined) {
3981
- end = Infinity;
3982
- }
3983
- step = step === undefined ? 1 : Math.abs(step);
3984
- if (end < start) {
3985
- step = -step;
3986
- }
3987
- this._start = start;
3988
- this._end = end;
3989
- this._step = step;
3990
- this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
3991
- if (this.size === 0) {
3992
- if (EMPTY_RANGE) {
3993
- return EMPTY_RANGE;
3994
- }
3995
- EMPTY_RANGE = this;
3996
- }
4024
+ createClass(Stack, IndexedCollection);
4025
+
4026
+ // @pragma Construction
4027
+
4028
+ function Stack(value) {
4029
+ return value === null || value === undefined ? emptyStack() :
4030
+ isStack(value) ? value :
4031
+ emptyStack().unshiftAll(value);
3997
4032
  }
3998
4033
 
3999
- Range.prototype.toString = function() {
4000
- if (this.size === 0) {
4001
- return 'Range []';
4002
- }
4003
- return 'Range [ ' +
4004
- this._start + '...' + this._end +
4005
- (this._step > 1 ? ' by ' + this._step : '') +
4006
- ' ]';
4034
+ Stack.of = function(/*...values*/) {
4035
+ return this(arguments);
4007
4036
  };
4008
4037
 
4009
- Range.prototype.get = function(index, notSetValue) {
4010
- return this.has(index) ?
4011
- this._start + wrapIndex(this, index) * this._step :
4012
- notSetValue;
4038
+ Stack.prototype.toString = function() {
4039
+ return this.__toString('Stack [', ']');
4013
4040
  };
4014
4041
 
4015
- Range.prototype.includes = function(searchValue) {
4016
- var possibleIndex = (searchValue - this._start) / this._step;
4017
- return possibleIndex >= 0 &&
4018
- possibleIndex < this.size &&
4019
- possibleIndex === Math.floor(possibleIndex);
4020
- };
4042
+ // @pragma Access
4021
4043
 
4022
- Range.prototype.slice = function(begin, end) {
4023
- if (wholeSlice(begin, end, this.size)) {
4024
- return this;
4025
- }
4026
- begin = resolveBegin(begin, this.size);
4027
- end = resolveEnd(end, this.size);
4028
- if (end <= begin) {
4029
- return new Range(0, 0);
4044
+ Stack.prototype.get = function(index, notSetValue) {
4045
+ var head = this._head;
4046
+ index = wrapIndex(this, index);
4047
+ while (head && index--) {
4048
+ head = head.next;
4030
4049
  }
4031
- return new Range(this.get(begin, this._end), this.get(end, this._end), this._step);
4050
+ return head ? head.value : notSetValue;
4032
4051
  };
4033
4052
 
4034
- Range.prototype.indexOf = function(searchValue) {
4035
- var offsetValue = searchValue - this._start;
4036
- if (offsetValue % this._step === 0) {
4037
- var index = offsetValue / this._step;
4038
- if (index >= 0 && index < this.size) {
4039
- return index
4040
- }
4041
- }
4042
- return -1;
4053
+ Stack.prototype.peek = function() {
4054
+ return this._head && this._head.value;
4043
4055
  };
4044
4056
 
4045
- Range.prototype.lastIndexOf = function(searchValue) {
4046
- return this.indexOf(searchValue);
4047
- };
4057
+ // @pragma Modification
4048
4058
 
4049
- Range.prototype.__iterate = function(fn, reverse) {
4050
- var maxIndex = this.size - 1;
4051
- var step = this._step;
4052
- var value = reverse ? this._start + maxIndex * step : this._start;
4053
- for (var ii = 0; ii <= maxIndex; ii++) {
4054
- if (fn(value, ii, this) === false) {
4055
- return ii + 1;
4056
- }
4057
- value += reverse ? -step : step;
4059
+ Stack.prototype.push = function(/*...values*/) {
4060
+ if (arguments.length === 0) {
4061
+ return this;
4058
4062
  }
4059
- return ii;
4063
+ var newSize = this.size + arguments.length;
4064
+ var head = this._head;
4065
+ for (var ii = arguments.length - 1; ii >= 0; ii--) {
4066
+ head = {
4067
+ value: arguments[ii],
4068
+ next: head
4069
+ };
4070
+ }
4071
+ if (this.__ownerID) {
4072
+ this.size = newSize;
4073
+ this._head = head;
4074
+ this.__hash = undefined;
4075
+ this.__altered = true;
4076
+ return this;
4077
+ }
4078
+ return makeStack(newSize, head);
4060
4079
  };
4061
4080
 
4062
- Range.prototype.__iterator = function(type, reverse) {
4063
- var maxIndex = this.size - 1;
4064
- var step = this._step;
4065
- var value = reverse ? this._start + maxIndex * step : this._start;
4066
- var ii = 0;
4067
- return new src_Iterator__Iterator(function() {
4068
- var v = value;
4069
- value += reverse ? -step : step;
4070
- return ii > maxIndex ? iteratorDone() : iteratorValue(type, ii++, v);
4081
+ Stack.prototype.pushAll = function(iter) {
4082
+ iter = IndexedIterable(iter);
4083
+ if (iter.size === 0) {
4084
+ return this;
4085
+ }
4086
+ assertNotInfinite(iter.size);
4087
+ var newSize = this.size;
4088
+ var head = this._head;
4089
+ iter.reverse().forEach(function(value ) {
4090
+ newSize++;
4091
+ head = {
4092
+ value: value,
4093
+ next: head
4094
+ };
4071
4095
  });
4096
+ if (this.__ownerID) {
4097
+ this.size = newSize;
4098
+ this._head = head;
4099
+ this.__hash = undefined;
4100
+ this.__altered = true;
4101
+ return this;
4102
+ }
4103
+ return makeStack(newSize, head);
4072
4104
  };
4073
4105
 
4074
- Range.prototype.equals = function(other) {
4075
- return other instanceof Range ?
4076
- this._start === other._start &&
4077
- this._end === other._end &&
4078
- this._step === other._step :
4079
- deepEqual(this, other);
4106
+ Stack.prototype.pop = function() {
4107
+ return this.slice(1);
4080
4108
  };
4081
4109
 
4110
+ Stack.prototype.unshift = function(/*...values*/) {
4111
+ return this.push.apply(this, arguments);
4112
+ };
4082
4113
 
4083
- var EMPTY_RANGE;
4114
+ Stack.prototype.unshiftAll = function(iter) {
4115
+ return this.pushAll(iter);
4116
+ };
4084
4117
 
4085
- createClass(Repeat, IndexedSeq);
4118
+ Stack.prototype.shift = function() {
4119
+ return this.pop.apply(this, arguments);
4120
+ };
4086
4121
 
4087
- function Repeat(value, times) {
4088
- if (!(this instanceof Repeat)) {
4089
- return new Repeat(value, times);
4090
- }
4091
- this._value = value;
4092
- this.size = times === undefined ? Infinity : Math.max(0, times);
4122
+ Stack.prototype.clear = function() {
4093
4123
  if (this.size === 0) {
4094
- if (EMPTY_REPEAT) {
4095
- return EMPTY_REPEAT;
4096
- }
4097
- EMPTY_REPEAT = this;
4124
+ return this;
4098
4125
  }
4099
- }
4100
-
4101
- Repeat.prototype.toString = function() {
4102
- if (this.size === 0) {
4103
- return 'Repeat []';
4126
+ if (this.__ownerID) {
4127
+ this.size = 0;
4128
+ this._head = undefined;
4129
+ this.__hash = undefined;
4130
+ this.__altered = true;
4131
+ return this;
4104
4132
  }
4105
- return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]';
4133
+ return emptyStack();
4106
4134
  };
4107
4135
 
4108
- Repeat.prototype.get = function(index, notSetValue) {
4109
- return this.has(index) ? this._value : notSetValue;
4136
+ Stack.prototype.slice = function(begin, end) {
4137
+ if (wholeSlice(begin, end, this.size)) {
4138
+ return this;
4139
+ }
4140
+ var resolvedBegin = resolveBegin(begin, this.size);
4141
+ var resolvedEnd = resolveEnd(end, this.size);
4142
+ if (resolvedEnd !== this.size) {
4143
+ // super.slice(begin, end);
4144
+ return IndexedCollection.prototype.slice.call(this, begin, end);
4145
+ }
4146
+ var newSize = this.size - resolvedBegin;
4147
+ var head = this._head;
4148
+ while (resolvedBegin--) {
4149
+ head = head.next;
4150
+ }
4151
+ if (this.__ownerID) {
4152
+ this.size = newSize;
4153
+ this._head = head;
4154
+ this.__hash = undefined;
4155
+ this.__altered = true;
4156
+ return this;
4157
+ }
4158
+ return makeStack(newSize, head);
4110
4159
  };
4111
4160
 
4112
- Repeat.prototype.includes = function(searchValue) {
4113
- return is(this._value, searchValue);
4114
- };
4161
+ // @pragma Mutability
4115
4162
 
4116
- Repeat.prototype.slice = function(begin, end) {
4117
- var size = this.size;
4118
- return wholeSlice(begin, end, size) ? this :
4119
- new Repeat(this._value, resolveEnd(end, size) - resolveBegin(begin, size));
4163
+ Stack.prototype.__ensureOwner = function(ownerID) {
4164
+ if (ownerID === this.__ownerID) {
4165
+ return this;
4166
+ }
4167
+ if (!ownerID) {
4168
+ this.__ownerID = ownerID;
4169
+ this.__altered = false;
4170
+ return this;
4171
+ }
4172
+ return makeStack(this.size, this._head, ownerID, this.__hash);
4120
4173
  };
4121
4174
 
4122
- Repeat.prototype.reverse = function() {
4123
- return this;
4124
- };
4175
+ // @pragma Iteration
4125
4176
 
4126
- Repeat.prototype.indexOf = function(searchValue) {
4127
- if (is(this._value, searchValue)) {
4128
- return 0;
4177
+ Stack.prototype.__iterate = function(fn, reverse) {
4178
+ if (reverse) {
4179
+ return this.reverse().__iterate(fn);
4129
4180
  }
4130
- return -1;
4131
- };
4132
-
4133
- Repeat.prototype.lastIndexOf = function(searchValue) {
4134
- if (is(this._value, searchValue)) {
4135
- return this.size;
4181
+ var iterations = 0;
4182
+ var node = this._head;
4183
+ while (node) {
4184
+ if (fn(node.value, iterations++, this) === false) {
4185
+ break;
4186
+ }
4187
+ node = node.next;
4136
4188
  }
4137
- return -1;
4189
+ return iterations;
4138
4190
  };
4139
4191
 
4140
- Repeat.prototype.__iterate = function(fn, reverse) {
4141
- for (var ii = 0; ii < this.size; ii++) {
4142
- if (fn(this._value, ii, this) === false) {
4143
- return ii + 1;
4144
- }
4192
+ Stack.prototype.__iterator = function(type, reverse) {
4193
+ if (reverse) {
4194
+ return this.reverse().__iterator(type);
4145
4195
  }
4146
- return ii;
4196
+ var iterations = 0;
4197
+ var node = this._head;
4198
+ return new Iterator(function() {
4199
+ if (node) {
4200
+ var value = node.value;
4201
+ node = node.next;
4202
+ return iteratorValue(type, iterations++, value);
4203
+ }
4204
+ return iteratorDone();
4205
+ });
4147
4206
  };
4148
4207
 
4149
- Repeat.prototype.__iterator = function(type, reverse) {var this$0 = this;
4150
- var ii = 0;
4151
- return new src_Iterator__Iterator(function()
4152
- {return ii < this$0.size ? iteratorValue(type, ii++, this$0._value) : iteratorDone()}
4153
- );
4154
- };
4155
4208
 
4156
- Repeat.prototype.equals = function(other) {
4157
- return other instanceof Repeat ?
4158
- is(this._value, other._value) :
4159
- deepEqual(other);
4160
- };
4209
+ function isStack(maybeStack) {
4210
+ return !!(maybeStack && maybeStack[IS_STACK_SENTINEL]);
4211
+ }
4161
4212
 
4213
+ Stack.isStack = isStack;
4162
4214
 
4163
- var EMPTY_REPEAT;
4215
+ var IS_STACK_SENTINEL = '@@__IMMUTABLE_STACK__@@';
4216
+
4217
+ var StackPrototype = Stack.prototype;
4218
+ StackPrototype[IS_STACK_SENTINEL] = true;
4219
+ StackPrototype.withMutations = MapPrototype.withMutations;
4220
+ StackPrototype.asMutable = MapPrototype.asMutable;
4221
+ StackPrototype.asImmutable = MapPrototype.asImmutable;
4222
+ StackPrototype.wasAltered = MapPrototype.wasAltered;
4223
+
4224
+
4225
+ function makeStack(size, head, ownerID, hash) {
4226
+ var map = Object.create(StackPrototype);
4227
+ map.size = size;
4228
+ map._head = head;
4229
+ map.__ownerID = ownerID;
4230
+ map.__hash = hash;
4231
+ map.__altered = false;
4232
+ return map;
4233
+ }
4234
+
4235
+ var EMPTY_STACK;
4236
+ function emptyStack() {
4237
+ return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
4238
+ }
4164
4239
 
4165
4240
  /**
4166
4241
  * Contributes additional methods to a constructor
@@ -4173,7 +4248,7 @@
4173
4248
  return ctor;
4174
4249
  }
4175
4250
 
4176
- Iterable.Iterator = src_Iterator__Iterator;
4251
+ Iterable.Iterator = Iterator;
4177
4252
 
4178
4253
  mixin(Iterable, {
4179
4254
 
@@ -4208,7 +4283,7 @@
4208
4283
 
4209
4284
  toMap: function() {
4210
4285
  // Use Late Binding here to solve the circular dependency.
4211
- return src_Map__Map(this.toKeyedSeq());
4286
+ return Map(this.toKeyedSeq());
4212
4287
  },
4213
4288
 
4214
4289
  toObject: function() {
@@ -4230,7 +4305,7 @@
4230
4305
 
4231
4306
  toSet: function() {
4232
4307
  // Use Late Binding here to solve the circular dependency.
4233
- return src_Set__Set(isKeyed(this) ? this.valueSeq() : this);
4308
+ return Set(isKeyed(this) ? this.valueSeq() : this);
4234
4309
  },
4235
4310
 
4236
4311
  toSetSeq: function() {
@@ -4274,10 +4349,6 @@
4274
4349
  return reify(this, concatFactory(this, values));
4275
4350
  },
4276
4351
 
4277
- contains: function(searchValue) {
4278
- return this.includes(searchValue);
4279
- },
4280
-
4281
4352
  includes: function(searchValue) {
4282
4353
  return this.some(function(value ) {return is(value, searchValue)});
4283
4354
  },
@@ -4307,21 +4378,6 @@
4307
4378
  return entry ? entry[1] : notSetValue;
4308
4379
  },
4309
4380
 
4310
- findEntry: function(predicate, context) {
4311
- var found;
4312
- this.__iterate(function(v, k, c) {
4313
- if (predicate.call(context, v, k, c)) {
4314
- found = [k, v];
4315
- return false;
4316
- }
4317
- });
4318
- return found;
4319
- },
4320
-
4321
- findLastEntry: function(predicate, context) {
4322
- return this.toSeq().reverse().findEntry(predicate, context);
4323
- },
4324
-
4325
4381
  forEach: function(sideEffect, context) {
4326
4382
  assertNotInfinite(this.size);
4327
4383
  return this.__iterate(context ? sideEffect.bind(context) : sideEffect);
@@ -4432,10 +4488,34 @@
4432
4488
  return this.filter(not(predicate), context);
4433
4489
  },
4434
4490
 
4491
+ findEntry: function(predicate, context, notSetValue) {
4492
+ var found = notSetValue;
4493
+ this.__iterate(function(v, k, c) {
4494
+ if (predicate.call(context, v, k, c)) {
4495
+ found = [k, v];
4496
+ return false;
4497
+ }
4498
+ });
4499
+ return found;
4500
+ },
4501
+
4502
+ findKey: function(predicate, context) {
4503
+ var entry = this.findEntry(predicate, context);
4504
+ return entry && entry[0];
4505
+ },
4506
+
4435
4507
  findLast: function(predicate, context, notSetValue) {
4436
4508
  return this.toKeyedSeq().reverse().find(predicate, context, notSetValue);
4437
4509
  },
4438
4510
 
4511
+ findLastEntry: function(predicate, context, notSetValue) {
4512
+ return this.toKeyedSeq().reverse().findEntry(predicate, context, notSetValue);
4513
+ },
4514
+
4515
+ findLastKey: function(predicate, context) {
4516
+ return this.toKeyedSeq().reverse().findKey(predicate, context);
4517
+ },
4518
+
4439
4519
  first: function() {
4440
4520
  return this.find(returnTrue);
4441
4521
  },
@@ -4494,6 +4574,10 @@
4494
4574
  return iter.isSubset(this);
4495
4575
  },
4496
4576
 
4577
+ keyOf: function(searchValue) {
4578
+ return this.findKey(function(value ) {return is(value, searchValue)});
4579
+ },
4580
+
4497
4581
  keySeq: function() {
4498
4582
  return this.toSeq().map(keyMapper).toIndexedSeq();
4499
4583
  },
@@ -4502,6 +4586,10 @@
4502
4586
  return this.toSeq().reverse().first();
4503
4587
  },
4504
4588
 
4589
+ lastKeyOf: function(searchValue) {
4590
+ return this.toKeyedSeq().reverse().keyOf(searchValue);
4591
+ },
4592
+
4505
4593
  max: function(comparator) {
4506
4594
  return maxFactory(this, comparator);
4507
4595
  },
@@ -4567,7 +4655,7 @@
4567
4655
 
4568
4656
  hashCode: function() {
4569
4657
  return this.__hash || (this.__hash = hashIterable(this));
4570
- },
4658
+ }
4571
4659
 
4572
4660
 
4573
4661
  // ### Internal
@@ -4590,35 +4678,7 @@
4590
4678
  IterablePrototype.inspect =
4591
4679
  IterablePrototype.toSource = function() { return this.toString(); };
4592
4680
  IterablePrototype.chain = IterablePrototype.flatMap;
4593
-
4594
- // Temporary warning about using length
4595
- (function () {
4596
- try {
4597
- Object.defineProperty(IterablePrototype, 'length', {
4598
- get: function () {
4599
- if (!Iterable.noLengthWarning) {
4600
- var stack;
4601
- try {
4602
- throw new Error();
4603
- } catch (error) {
4604
- stack = error.stack;
4605
- }
4606
- if (stack.indexOf('_wrapObject') === -1) {
4607
- console && console.warn && console.warn(
4608
- 'iterable.length has been deprecated, '+
4609
- 'use iterable.size or iterable.count(). '+
4610
- 'This warning will become a silent error in a future version. ' +
4611
- stack
4612
- );
4613
- return this.size;
4614
- }
4615
- }
4616
- }
4617
- });
4618
- } catch (e) {}
4619
- })();
4620
-
4621
-
4681
+ IterablePrototype.contains = IterablePrototype.includes;
4622
4682
 
4623
4683
  mixin(KeyedIterable, {
4624
4684
 
@@ -4628,23 +4688,6 @@
4628
4688
  return reify(this, flipFactory(this));
4629
4689
  },
4630
4690
 
4631
- findKey: function(predicate, context) {
4632
- var entry = this.findEntry(predicate, context);
4633
- return entry && entry[0];
4634
- },
4635
-
4636
- findLastKey: function(predicate, context) {
4637
- return this.toSeq().reverse().findKey(predicate, context);
4638
- },
4639
-
4640
- keyOf: function(searchValue) {
4641
- return this.findKey(function(value ) {return is(value, searchValue)});
4642
- },
4643
-
4644
- lastKeyOf: function(searchValue) {
4645
- return this.findLastKey(function(value ) {return is(value, searchValue)});
4646
- },
4647
-
4648
4691
  mapEntries: function(mapper, context) {var this$0 = this;
4649
4692
  var iterations = 0;
4650
4693
  return reify(this,
@@ -4660,7 +4703,7 @@
4660
4703
  function(k, v) {return mapper.call(context, k, v, this$0)}
4661
4704
  ).flip()
4662
4705
  );
4663
- },
4706
+ }
4664
4707
 
4665
4708
  });
4666
4709
 
@@ -4693,12 +4736,13 @@
4693
4736
  },
4694
4737
 
4695
4738
  indexOf: function(searchValue) {
4696
- var key = this.toKeyedSeq().keyOf(searchValue);
4739
+ var key = this.keyOf(searchValue);
4697
4740
  return key === undefined ? -1 : key;
4698
4741
  },
4699
4742
 
4700
4743
  lastIndexOf: function(searchValue) {
4701
- return this.toSeq().reverse().indexOf(searchValue);
4744
+ var key = this.lastKeyOf(searchValue);
4745
+ return key === undefined ? -1 : key;
4702
4746
  },
4703
4747
 
4704
4748
  reverse: function() {
@@ -4715,7 +4759,10 @@
4715
4759
  if (numArgs === 0 || (numArgs === 2 && !removeNum)) {
4716
4760
  return this;
4717
4761
  }
4718
- index = resolveBegin(index, this.size);
4762
+ // If index is negative, it should resolve relative to the size of the
4763
+ // collection. However size may be expensive to compute if not cached, so
4764
+ // only call count() if the number is in fact negative.
4765
+ index = resolveBegin(index, index < 0 ? this.count() : this.size);
4719
4766
  var spliced = this.slice(0, index);
4720
4767
  return reify(
4721
4768
  this,
@@ -4729,8 +4776,8 @@
4729
4776
  // ### More collection methods
4730
4777
 
4731
4778
  findLastIndex: function(predicate, context) {
4732
- var key = this.toKeyedSeq().findLastKey(predicate, context);
4733
- return key === undefined ? -1 : key;
4779
+ var entry = this.findLastEntry(predicate, context);
4780
+ return entry ? entry[0] : -1;
4734
4781
  },
4735
4782
 
4736
4783
  first: function() {
@@ -4771,6 +4818,10 @@
4771
4818
  return reify(this, interleaved);
4772
4819
  },
4773
4820
 
4821
+ keySeq: function() {
4822
+ return Range(0, this.size);
4823
+ },
4824
+
4774
4825
  last: function() {
4775
4826
  return this.get(-1);
4776
4827
  },
@@ -4788,7 +4839,7 @@
4788
4839
  var iterables = arrCopy(arguments);
4789
4840
  iterables[0] = this;
4790
4841
  return reify(this, zipWithFactory(this, zipper, iterables));
4791
- },
4842
+ }
4792
4843
 
4793
4844
  });
4794
4845
 
@@ -4814,11 +4865,12 @@
4814
4865
 
4815
4866
  keySeq: function() {
4816
4867
  return this.valueSeq();
4817
- },
4868
+ }
4818
4869
 
4819
4870
  });
4820
4871
 
4821
4872
  SetIterable.prototype.has = IterablePrototype.includes;
4873
+ SetIterable.prototype.contains = SetIterable.prototype.includes;
4822
4874
 
4823
4875
 
4824
4876
  // Mixin subclasses
@@ -4855,7 +4907,7 @@
4855
4907
  }
4856
4908
 
4857
4909
  function quoteString(value) {
4858
- return typeof value === 'string' ? JSON.stringify(value) : value;
4910
+ return typeof value === 'string' ? JSON.stringify(value) : String(value);
4859
4911
  }
4860
4912
 
4861
4913
  function defaultZipper() {
@@ -4886,12 +4938,12 @@
4886
4938
  }
4887
4939
 
4888
4940
  function murmurHashOfSize(size, h) {
4889
- h = src_Math__imul(h, 0xCC9E2D51);
4890
- h = src_Math__imul(h << 15 | h >>> -15, 0x1B873593);
4891
- h = src_Math__imul(h << 13 | h >>> -13, 5);
4941
+ h = imul(h, 0xCC9E2D51);
4942
+ h = imul(h << 15 | h >>> -15, 0x1B873593);
4943
+ h = imul(h << 13 | h >>> -13, 5);
4892
4944
  h = (h + 0xE6546B64 | 0) ^ size;
4893
- h = src_Math__imul(h ^ h >>> 16, 0x85EBCA6B);
4894
- h = src_Math__imul(h ^ h >>> 13, 0xC2B2AE35);
4945
+ h = imul(h ^ h >>> 16, 0x85EBCA6B);
4946
+ h = imul(h ^ h >>> 13, 0xC2B2AE35);
4895
4947
  h = smi(h ^ h >>> 16);
4896
4948
  return h;
4897
4949
  }
@@ -4906,11 +4958,11 @@
4906
4958
 
4907
4959
  Seq: Seq,
4908
4960
  Collection: Collection,
4909
- Map: src_Map__Map,
4961
+ Map: Map,
4910
4962
  OrderedMap: OrderedMap,
4911
4963
  List: List,
4912
4964
  Stack: Stack,
4913
- Set: src_Set__Set,
4965
+ Set: Set,
4914
4966
  OrderedSet: OrderedSet,
4915
4967
 
4916
4968
  Record: Record,
@@ -4918,7 +4970,7 @@
4918
4970
  Repeat: Repeat,
4919
4971
 
4920
4972
  is: is,
4921
- fromJS: fromJS,
4973
+ fromJS: fromJS
4922
4974
 
4923
4975
  };
4924
4976