immutable 3.7.2 → 3.7.6

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,1105 +731,534 @@
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 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
- }
829
-
830
- hash = obj[UID_HASH_KEY];
831
- if (hash !== undefined) {
832
- return hash;
833
- }
791
+ createClass(Repeat, IndexedSeq);
834
792
 
835
- if (!canDefineProperty) {
836
- hash = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
837
- if (hash !== undefined) {
838
- return hash;
793
+ function Repeat(value, times) {
794
+ if (!(this instanceof Repeat)) {
795
+ return new Repeat(value, times);
839
796
  }
840
-
841
- hash = getIENodeHash(obj);
842
- if (hash !== undefined) {
843
- return hash;
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;
844
804
  }
845
805
  }
846
806
 
847
- hash = ++objHashUID;
848
- if (objHashUID & 0x40000000) {
849
- objHashUID = 0;
850
- }
851
-
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
- }
882
-
883
- return hash;
884
- }
885
-
886
- // Get references to ES5 object methods.
887
- var isExtensible = Object.isExtensible;
888
-
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
- }());
898
-
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;
807
+ Repeat.prototype.toString = function() {
808
+ if (this.size === 0) {
809
+ return 'Repeat []';
908
810
  }
909
- }
910
- }
911
-
912
- // If possible, use a WeakMap.
913
- var usingWeakMap = typeof WeakMap === 'function';
914
- var weakMap;
915
- if (usingWeakMap) {
916
- weakMap = new WeakMap();
917
- }
918
-
919
- var objHashUID = 0;
920
-
921
- var UID_HASH_KEY = '__immutablehash__';
922
- if (typeof Symbol === 'function') {
923
- UID_HASH_KEY = Symbol(UID_HASH_KEY);
924
- }
925
-
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 = {};
930
-
931
- function invariant(condition, error) {
932
- if (!condition) throw new Error(error);
933
- }
811
+ return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]';
812
+ };
934
813
 
935
- function assertNotInfinite(size) {
936
- invariant(
937
- size !== Infinity,
938
- 'Cannot perform this action with an infinite size.'
939
- );
940
- }
814
+ Repeat.prototype.get = function(index, notSetValue) {
815
+ return this.has(index) ? this._value : notSetValue;
816
+ };
941
817
 
942
- createClass(ToKeyedSequence, KeyedSeq);
943
- function ToKeyedSequence(indexed, useKeys) {
944
- this._iter = indexed;
945
- this._useKeys = useKeys;
946
- this.size = indexed.size;
947
- }
818
+ Repeat.prototype.includes = function(searchValue) {
819
+ return is(this._value, searchValue);
820
+ };
948
821
 
949
- ToKeyedSequence.prototype.get = function(key, notSetValue) {
950
- return this._iter.get(key, notSetValue);
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));
951
826
  };
952
827
 
953
- ToKeyedSequence.prototype.has = function(key) {
954
- return this._iter.has(key);
828
+ Repeat.prototype.reverse = function() {
829
+ return this;
955
830
  };
956
831
 
957
- ToKeyedSequence.prototype.valueSeq = function() {
958
- return this._iter.valueSeq();
832
+ Repeat.prototype.indexOf = function(searchValue) {
833
+ if (is(this._value, searchValue)) {
834
+ return 0;
835
+ }
836
+ return -1;
959
837
  };
960
838
 
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()};
839
+ Repeat.prototype.lastIndexOf = function(searchValue) {
840
+ if (is(this._value, searchValue)) {
841
+ return this.size;
965
842
  }
966
- return reversedSequence;
843
+ return -1;
967
844
  };
968
845
 
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)};
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
+ }
973
851
  }
974
- return mappedSequence;
852
+ return ii;
975
853
  };
976
854
 
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
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()}
985
859
  );
986
860
  };
987
861
 
988
- ToKeyedSequence.prototype.__iterator = function(type, reverse) {
989
- if (this._useKeys) {
990
- return this._iter.__iterator(type, reverse);
991
- }
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
- });
862
+ Repeat.prototype.equals = function(other) {
863
+ return other instanceof Repeat ?
864
+ is(this._value, other._value) :
865
+ deepEqual(other);
999
866
  };
1000
867
 
1001
- ToKeyedSequence.prototype[IS_ORDERED_SENTINEL] = true;
1002
-
1003
868
 
1004
- createClass(ToIndexedSequence, IndexedSeq);
1005
- function ToIndexedSequence(iter) {
1006
- this._iter = iter;
1007
- this.size = iter.size;
1008
- }
869
+ var EMPTY_REPEAT;
1009
870
 
1010
- ToIndexedSequence.prototype.includes = function(value) {
1011
- return this._iter.includes(value);
1012
- };
871
+ function invariant(condition, error) {
872
+ if (!condition) throw new Error(error);
873
+ }
1013
874
 
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);
875
+ createClass(Range, IndexedSeq);
876
+
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
+ }
900
+ }
901
+
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
+ ' ]';
1017
910
  };
1018
911
 
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
- });
912
+ Range.prototype.get = function(index, notSetValue) {
913
+ return this.has(index) ?
914
+ this._start + wrapIndex(this, index) * this._step :
915
+ notSetValue;
1027
916
  };
1028
917
 
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);
923
+ };
1029
924
 
925
+ Range.prototype.slice = function(begin, end) {
926
+ if (wholeSlice(begin, end, this.size)) {
927
+ return this;
928
+ }
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);
935
+ };
1030
936
 
1031
- createClass(ToSetSequence, SetSeq);
1032
- function ToSetSequence(iter) {
1033
- this._iter = iter;
1034
- this.size = iter.size;
1035
- }
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
+ }
944
+ }
945
+ return -1;
946
+ };
1036
947
 
1037
- ToSetSequence.prototype.has = function(key) {
1038
- return this._iter.includes(key);
948
+ Range.prototype.lastIndexOf = function(searchValue) {
949
+ return this.indexOf(searchValue);
1039
950
  };
1040
951
 
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);
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;
961
+ }
962
+ return ii;
1043
963
  };
1044
964
 
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);
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);
1051
974
  });
1052
975
  };
1053
976
 
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);
983
+ };
1054
984
 
1055
985
 
1056
- createClass(FromEntriesSequence, KeyedSeq);
1057
- function FromEntriesSequence(entries) {
1058
- this._iter = entries;
1059
- this.size = entries.size;
986
+ var EMPTY_RANGE;
987
+
988
+ createClass(Collection, Iterable);
989
+ function Collection() {
990
+ throw TypeError('Abstract');
1060
991
  }
1061
992
 
1062
- FromEntriesSequence.prototype.entrySeq = function() {
1063
- return this._iter.toSeq();
1064
- };
1065
993
 
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
- };
994
+ createClass(KeyedCollection, Collection);function KeyedCollection() {}
1081
995
 
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
- });
1105
- };
996
+ createClass(IndexedCollection, Collection);function IndexedCollection() {}
1106
997
 
998
+ createClass(SetCollection, Collection);function SetCollection() {}
1107
999
 
1108
- ToIndexedSequence.prototype.cacheResult =
1109
- ToKeyedSequence.prototype.cacheResult =
1110
- ToSetSequence.prototype.cacheResult =
1111
- FromEntriesSequence.prototype.cacheResult =
1112
- cacheResultThrough;
1113
1000
 
1001
+ Collection.Keyed = KeyedCollection;
1002
+ Collection.Indexed = IndexedCollection;
1003
+ Collection.Set = SetCollection;
1114
1004
 
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;
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
1124
1015
  };
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);
1130
- }
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
- });
1143
- }
1144
- return iterable.__iterator(
1145
- type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES,
1146
- reverse
1147
- );
1148
- }
1149
- return flipSequence;
1150
- }
1151
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
+ }
1152
1024
 
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
- );
1025
+ function hash(o) {
1026
+ if (o === false || o === null || o === undefined) {
1027
+ return 0;
1168
1028
  }
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
- });
1029
+ if (typeof o.valueOf === 'function') {
1030
+ o = o.valueOf();
1031
+ if (o === false || o === null || o === undefined) {
1032
+ return 0;
1033
+ }
1185
1034
  }
1186
- return mappedSequence;
1187
- }
1188
-
1189
-
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
- };
1035
+ if (o === true) {
1036
+ return 1;
1201
1037
  }
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
-
1216
-
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
- };
1038
+ var type = typeof o;
1039
+ if (type === 'number') {
1040
+ var h = o | 0;
1041
+ if (h !== o) {
1042
+ h ^= o * 0xFFFFFFFF;
1043
+ }
1044
+ while (o > 0xFFFFFFFF) {
1045
+ o /= 0xFFFFFFFF;
1046
+ h ^= o;
1047
+ }
1048
+ return smi(h);
1229
1049
  }
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
- }
1256
- });
1050
+ if (type === 'string') {
1051
+ return o.length > STRING_HASH_CACHE_MIN_STRLEN ? cachedHashString(o) : hashString(o);
1257
1052
  }
1258
- return filterSequence;
1053
+ if (typeof o.hashCode === 'function') {
1054
+ return o.hashCode();
1055
+ }
1056
+ if (type === 'object') {
1057
+ return hashJSObj(o);
1058
+ }
1059
+ if (typeof o.toString === 'function') {
1060
+ return hashString(o.toString());
1061
+ }
1062
+ throw new Error('Value type ' + type + ' cannot be hashed.');
1259
1063
  }
1260
1064
 
1261
-
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();
1065
+ function cachedHashString(string) {
1066
+ var hash = stringHashCache[string];
1067
+ if (hash === undefined) {
1068
+ hash = hashString(string);
1069
+ if (STRING_HASH_CACHE_SIZE === STRING_HASH_CACHE_MAX_SIZE) {
1070
+ STRING_HASH_CACHE_SIZE = 0;
1071
+ stringHashCache = {};
1072
+ }
1073
+ STRING_HASH_CACHE_SIZE++;
1074
+ stringHashCache[string] = hash;
1075
+ }
1076
+ return hash;
1272
1077
  }
1273
1078
 
1274
-
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))});
1079
+ // http://jsperf.com/hashing-strings
1080
+ function hashString(string) {
1081
+ // This is the hash from JVM
1082
+ // The hash code for a string is computed as
1083
+ // s[0] * 31 ^ (n - 1) + s[1] * 31 ^ (n - 2) + ... + s[n - 1],
1084
+ // where s[i] is the ith character of the string and n is the length of
1085
+ // the string. We "mod" the result to make it between 0 (inclusive) and 2^31
1086
+ // (exclusive) by dropping high bits.
1087
+ var hash = 0;
1088
+ for (var ii = 0; ii < string.length; ii++) {
1089
+ hash = 31 * hash + string.charCodeAt(ii) | 0;
1090
+ }
1091
+ return smi(hash);
1286
1092
  }
1287
1093
 
1094
+ function hashJSObj(obj) {
1095
+ var hash;
1096
+ if (usingWeakMap) {
1097
+ hash = weakMap.get(obj);
1098
+ if (hash !== undefined) {
1099
+ return hash;
1100
+ }
1101
+ }
1288
1102
 
1289
- function sliceFactory(iterable, begin, end, useKeys) {
1290
- var originalSize = iterable.size;
1291
-
1292
- if (wholeSlice(begin, end, originalSize)) {
1293
- return iterable;
1103
+ hash = obj[UID_HASH_KEY];
1104
+ if (hash !== undefined) {
1105
+ return hash;
1294
1106
  }
1295
1107
 
1296
- var resolvedBegin = resolveBegin(begin, originalSize);
1297
- var resolvedEnd = resolveEnd(end, originalSize);
1108
+ if (!canDefineProperty) {
1109
+ hash = obj.propertyIsEnumerable && obj.propertyIsEnumerable[UID_HASH_KEY];
1110
+ if (hash !== undefined) {
1111
+ return hash;
1112
+ }
1298
1113
 
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.
1302
- if (resolvedBegin !== resolvedBegin || resolvedEnd !== resolvedEnd) {
1303
- return sliceFactory(iterable.toSeq().cacheResult(), begin, end, useKeys);
1114
+ hash = getIENodeHash(obj);
1115
+ if (hash !== undefined) {
1116
+ return hash;
1117
+ }
1304
1118
  }
1305
1119
 
1306
- var sliceSize = resolvedEnd - resolvedBegin;
1307
- if (sliceSize < 0) {
1308
- sliceSize = 0;
1120
+ hash = ++objHashUID;
1121
+ if (objHashUID & 0x40000000) {
1122
+ objHashUID = 0;
1309
1123
  }
1310
1124
 
1311
- var sliceSeq = makeSequence(iterable);
1125
+ if (usingWeakMap) {
1126
+ weakMap.set(obj, hash);
1127
+ } else if (isExtensible !== undefined && isExtensible(obj) === false) {
1128
+ throw new Error('Non-extensible objects are not allowed as keys.');
1129
+ } else if (canDefineProperty) {
1130
+ Object.defineProperty(obj, UID_HASH_KEY, {
1131
+ 'enumerable': false,
1132
+ 'configurable': false,
1133
+ 'writable': false,
1134
+ 'value': hash
1135
+ });
1136
+ } else if (obj.propertyIsEnumerable !== undefined &&
1137
+ obj.propertyIsEnumerable === obj.constructor.prototype.propertyIsEnumerable) {
1138
+ // Since we can't define a non-enumerable property on the object
1139
+ // we'll hijack one of the less-used non-enumerable properties to
1140
+ // save our hash on it. Since this is a function it will not show up in
1141
+ // `JSON.stringify` which is what we want.
1142
+ obj.propertyIsEnumerable = function() {
1143
+ return this.constructor.prototype.propertyIsEnumerable.apply(this, arguments);
1144
+ };
1145
+ obj.propertyIsEnumerable[UID_HASH_KEY] = hash;
1146
+ } else if (obj.nodeType !== undefined) {
1147
+ // At this point we couldn't get the IE `uniqueID` to use as a hash
1148
+ // and we couldn't use a non-enumerable property to exploit the
1149
+ // dontEnum bug so we simply add the `UID_HASH_KEY` on the node
1150
+ // itself.
1151
+ obj[UID_HASH_KEY] = hash;
1152
+ } else {
1153
+ throw new Error('Unable to set a non-enumerable property on object.');
1154
+ }
1312
1155
 
1313
- sliceSeq.size = sliceSize === 0 ? sliceSize : iterable.size && sliceSize || undefined;
1156
+ return hash;
1157
+ }
1314
1158
 
1315
- if (!useKeys && isSeq(iterable) && sliceSize >= 0) {
1316
- sliceSeq.get = function (index, notSetValue) {
1317
- index = wrapIndex(this, index);
1318
- return index >= 0 && index < sliceSize ?
1319
- iterable.get(index + resolvedBegin, notSetValue) :
1320
- notSetValue;
1321
- }
1159
+ // Get references to ES5 object methods.
1160
+ var isExtensible = Object.isExtensible;
1161
+
1162
+ // True if Object.defineProperty works as expected. IE8 fails this test.
1163
+ var canDefineProperty = (function() {
1164
+ try {
1165
+ Object.defineProperty({}, '@', {});
1166
+ return true;
1167
+ } catch (e) {
1168
+ return false;
1322
1169
  }
1170
+ }());
1323
1171
 
1324
- sliceSeq.__iterateUncached = function(fn, reverse) {var this$0 = this;
1325
- if (sliceSize === 0) {
1326
- return 0;
1327
- }
1328
- if (reverse) {
1329
- return this.cacheResult().__iterate(fn, reverse);
1172
+ // IE has a `uniqueID` property on DOM nodes. We can construct the hash from it
1173
+ // and avoid memory leaks from the IE cloneNode bug.
1174
+ function getIENodeHash(node) {
1175
+ if (node && node.nodeType > 0) {
1176
+ switch (node.nodeType) {
1177
+ case 1: // Element
1178
+ return node.uniqueID;
1179
+ case 9: // Document
1180
+ return node.documentElement && node.documentElement.uniqueID;
1330
1181
  }
1331
- var skipped = 0;
1332
- var isSkipping = true;
1333
- var iterations = 0;
1334
- iterable.__iterate(function(v, k) {
1335
- if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) {
1336
- iterations++;
1337
- return fn(v, useKeys ? k : iterations - 1, this$0) !== false &&
1338
- iterations !== sliceSize;
1339
- }
1340
- });
1341
- return iterations;
1342
- };
1343
-
1344
- sliceSeq.__iteratorUncached = function(type, reverse) {
1345
- if (sliceSize && reverse) {
1346
- return this.cacheResult().__iterator(type, reverse);
1347
- }
1348
- // Don't bother instantiating parent iterator if taking 0.
1349
- var iterator = sliceSize && iterable.__iterator(type, reverse);
1350
- var skipped = 0;
1351
- var iterations = 0;
1352
- return new src_Iterator__Iterator(function() {
1353
- while (skipped++ < resolvedBegin) {
1354
- iterator.next();
1355
- }
1356
- if (++iterations > sliceSize) {
1357
- return iteratorDone();
1358
- }
1359
- var step = iterator.next();
1360
- if (useKeys || type === ITERATE_VALUES) {
1361
- return step;
1362
- } else if (type === ITERATE_KEYS) {
1363
- return iteratorValue(type, iterations - 1, undefined, step);
1364
- } else {
1365
- return iteratorValue(type, iterations - 1, step.value[1], step);
1366
- }
1367
- });
1368
1182
  }
1183
+ }
1369
1184
 
1370
- return sliceSeq;
1185
+ // If possible, use a WeakMap.
1186
+ var usingWeakMap = typeof WeakMap === 'function';
1187
+ var weakMap;
1188
+ if (usingWeakMap) {
1189
+ weakMap = new WeakMap();
1371
1190
  }
1372
1191
 
1192
+ var objHashUID = 0;
1373
1193
 
1374
- function takeWhileFactory(iterable, predicate, context) {
1375
- var takeSequence = makeSequence(iterable);
1376
- takeSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
1377
- if (reverse) {
1378
- return this.cacheResult().__iterate(fn, reverse);
1379
- }
1380
- var iterations = 0;
1381
- iterable.__iterate(function(v, k, c)
1382
- {return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$0)}
1383
- );
1384
- return iterations;
1385
- };
1386
- takeSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
1387
- if (reverse) {
1388
- return this.cacheResult().__iterator(type, reverse);
1389
- }
1390
- var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
1391
- var iterating = true;
1392
- return new src_Iterator__Iterator(function() {
1393
- if (!iterating) {
1394
- return iteratorDone();
1395
- }
1396
- var step = iterator.next();
1397
- if (step.done) {
1398
- return step;
1399
- }
1400
- var entry = step.value;
1401
- var k = entry[0];
1402
- var v = entry[1];
1403
- if (!predicate.call(context, v, k, this$0)) {
1404
- iterating = false;
1405
- return iteratorDone();
1406
- }
1407
- return type === ITERATE_ENTRIES ? step :
1408
- iteratorValue(type, k, v, step);
1409
- });
1410
- };
1411
- return takeSequence;
1194
+ var UID_HASH_KEY = '__immutablehash__';
1195
+ if (typeof Symbol === 'function') {
1196
+ UID_HASH_KEY = Symbol(UID_HASH_KEY);
1412
1197
  }
1413
1198
 
1199
+ var STRING_HASH_CACHE_MIN_STRLEN = 16;
1200
+ var STRING_HASH_CACHE_MAX_SIZE = 255;
1201
+ var STRING_HASH_CACHE_SIZE = 0;
1202
+ var stringHashCache = {};
1414
1203
 
1415
- function skipWhileFactory(iterable, predicate, context, useKeys) {
1416
- var skipSequence = makeSequence(iterable);
1417
- skipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
1418
- if (reverse) {
1419
- return this.cacheResult().__iterate(fn, reverse);
1420
- }
1421
- var isSkipping = true;
1422
- var iterations = 0;
1423
- iterable.__iterate(function(v, k, c) {
1424
- if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) {
1425
- iterations++;
1426
- return fn(v, useKeys ? k : iterations - 1, this$0);
1427
- }
1428
- });
1429
- return iterations;
1430
- };
1431
- skipSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
1432
- if (reverse) {
1433
- return this.cacheResult().__iterator(type, reverse);
1434
- }
1435
- var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
1436
- var skipping = true;
1437
- var iterations = 0;
1438
- return new src_Iterator__Iterator(function() {
1439
- var step, k, v;
1440
- do {
1441
- step = iterator.next();
1442
- if (step.done) {
1443
- if (useKeys || type === ITERATE_VALUES) {
1444
- return step;
1445
- } else if (type === ITERATE_KEYS) {
1446
- return iteratorValue(type, iterations++, undefined, step);
1447
- } else {
1448
- return iteratorValue(type, iterations++, step.value[1], step);
1449
- }
1450
- }
1451
- var entry = step.value;
1452
- k = entry[0];
1453
- v = entry[1];
1454
- skipping && (skipping = predicate.call(context, v, k, this$0));
1455
- } while (skipping);
1456
- return type === ITERATE_ENTRIES ? step :
1457
- iteratorValue(type, k, v, step);
1458
- });
1459
- };
1460
- return skipSequence;
1204
+ function assertNotInfinite(size) {
1205
+ invariant(
1206
+ size !== Infinity,
1207
+ 'Cannot perform this action with an infinite size.'
1208
+ );
1461
1209
  }
1462
1210
 
1211
+ createClass(Map, KeyedCollection);
1463
1212
 
1464
- function concatFactory(iterable, values) {
1465
- var isKeyedIterable = isKeyed(iterable);
1466
- var iters = [iterable].concat(values).map(function(v ) {
1467
- if (!isIterable(v)) {
1468
- v = isKeyedIterable ?
1469
- keyedSeqFromValue(v) :
1470
- indexedSeqFromValue(Array.isArray(v) ? v : [v]);
1471
- } else if (isKeyedIterable) {
1472
- v = KeyedIterable(v);
1473
- }
1474
- return v;
1475
- }).filter(function(v ) {return v.size !== 0});
1213
+ // @pragma Construction
1476
1214
 
1477
- if (iters.length === 0) {
1478
- return iterable;
1215
+ function Map(value) {
1216
+ return value === null || value === undefined ? emptyMap() :
1217
+ isMap(value) && !isOrdered(value) ? value :
1218
+ emptyMap().withMutations(function(map ) {
1219
+ var iter = KeyedIterable(value);
1220
+ assertNotInfinite(iter.size);
1221
+ iter.forEach(function(v, k) {return map.set(k, v)});
1222
+ });
1479
1223
  }
1480
1224
 
1481
- if (iters.length === 1) {
1482
- var singleton = iters[0];
1483
- if (singleton === iterable ||
1484
- isKeyedIterable && isKeyed(singleton) ||
1485
- isIndexed(iterable) && isIndexed(singleton)) {
1486
- return singleton;
1487
- }
1488
- }
1225
+ Map.prototype.toString = function() {
1226
+ return this.__toString('Map {', '}');
1227
+ };
1489
1228
 
1490
- var concatSeq = new ArraySeq(iters);
1491
- if (isKeyedIterable) {
1492
- concatSeq = concatSeq.toKeyedSeq();
1493
- } else if (!isIndexed(iterable)) {
1494
- concatSeq = concatSeq.toSetSeq();
1495
- }
1496
- concatSeq = concatSeq.flatten(true);
1497
- concatSeq.size = iters.reduce(
1498
- function(sum, seq) {
1499
- if (sum !== undefined) {
1500
- var size = seq.size;
1501
- if (size !== undefined) {
1502
- return sum + size;
1503
- }
1504
- }
1505
- },
1506
- 0
1507
- );
1508
- return concatSeq;
1509
- }
1229
+ // @pragma Access
1510
1230
 
1231
+ Map.prototype.get = function(k, notSetValue) {
1232
+ return this._root ?
1233
+ this._root.get(0, undefined, k, notSetValue) :
1234
+ notSetValue;
1235
+ };
1511
1236
 
1512
- function flattenFactory(iterable, depth, useKeys) {
1513
- var flatSequence = makeSequence(iterable);
1514
- flatSequence.__iterateUncached = function(fn, reverse) {
1515
- var iterations = 0;
1516
- var stopped = false;
1517
- function flatDeep(iter, currentDepth) {var this$0 = this;
1518
- iter.__iterate(function(v, k) {
1519
- if ((!depth || currentDepth < depth) && isIterable(v)) {
1520
- flatDeep(v, currentDepth + 1);
1521
- } else if (fn(v, useKeys ? k : iterations++, this$0) === false) {
1522
- stopped = true;
1523
- }
1524
- return !stopped;
1525
- }, reverse);
1526
- }
1527
- flatDeep(iterable, 0);
1528
- return iterations;
1529
- }
1530
- flatSequence.__iteratorUncached = function(type, reverse) {
1531
- var iterator = iterable.__iterator(type, reverse);
1532
- var stack = [];
1533
- var iterations = 0;
1534
- return new src_Iterator__Iterator(function() {
1535
- while (iterator) {
1536
- var step = iterator.next();
1537
- if (step.done !== false) {
1538
- iterator = stack.pop();
1539
- continue;
1540
- }
1541
- var v = step.value;
1542
- if (type === ITERATE_ENTRIES) {
1543
- v = v[1];
1544
- }
1545
- if ((!depth || stack.length < depth) && isIterable(v)) {
1546
- stack.push(iterator);
1547
- iterator = v.__iterator(type, reverse);
1548
- } else {
1549
- return useKeys ? step : iteratorValue(type, iterations++, v, step);
1550
- }
1551
- }
1552
- return iteratorDone();
1553
- });
1554
- }
1555
- return flatSequence;
1556
- }
1237
+ // @pragma Modification
1557
1238
 
1239
+ Map.prototype.set = function(k, v) {
1240
+ return updateMap(this, k, v);
1241
+ };
1558
1242
 
1559
- function flatMapFactory(iterable, mapper, context) {
1560
- var coerce = iterableClass(iterable);
1561
- return iterable.toSeq().map(
1562
- function(v, k) {return coerce(mapper.call(context, v, k, iterable))}
1563
- ).flatten(true);
1564
- }
1243
+ Map.prototype.setIn = function(keyPath, v) {
1244
+ return this.updateIn(keyPath, NOT_SET, function() {return v});
1245
+ };
1565
1246
 
1247
+ Map.prototype.remove = function(k) {
1248
+ return updateMap(this, k, NOT_SET);
1249
+ };
1566
1250
 
1567
- function interposeFactory(iterable, separator) {
1568
- var interposedSequence = makeSequence(iterable);
1569
- interposedSequence.size = iterable.size && iterable.size * 2 -1;
1570
- interposedSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
1571
- var iterations = 0;
1572
- iterable.__iterate(function(v, k)
1573
- {return (!iterations || fn(separator, iterations++, this$0) !== false) &&
1574
- fn(v, iterations++, this$0) !== false},
1575
- reverse
1576
- );
1577
- return iterations;
1578
- };
1579
- interposedSequence.__iteratorUncached = function(type, reverse) {
1580
- var iterator = iterable.__iterator(ITERATE_VALUES, reverse);
1581
- var iterations = 0;
1582
- var step;
1583
- return new src_Iterator__Iterator(function() {
1584
- if (!step || iterations % 2) {
1585
- step = iterator.next();
1586
- if (step.done) {
1587
- return step;
1588
- }
1589
- }
1590
- return iterations % 2 ?
1591
- iteratorValue(type, iterations++, separator) :
1592
- iteratorValue(type, iterations++, step.value, step);
1593
- });
1594
- };
1595
- return interposedSequence;
1596
- }
1597
-
1598
-
1599
- function sortFactory(iterable, comparator, mapper) {
1600
- if (!comparator) {
1601
- comparator = defaultComparator;
1602
- }
1603
- var isKeyedIterable = isKeyed(iterable);
1604
- var index = 0;
1605
- var entries = iterable.toSeq().map(
1606
- function(v, k) {return [k, v, index++, mapper ? mapper(v, k, iterable) : v]}
1607
- ).toArray();
1608
- entries.sort(function(a, b) {return comparator(a[3], b[3]) || a[2] - b[2]}).forEach(
1609
- isKeyedIterable ?
1610
- function(v, i) { entries[i].length = 2; } :
1611
- function(v, i) { entries[i] = v[1]; }
1612
- );
1613
- return isKeyedIterable ? KeyedSeq(entries) :
1614
- isIndexed(iterable) ? IndexedSeq(entries) :
1615
- SetSeq(entries);
1616
- }
1617
-
1618
-
1619
- function maxFactory(iterable, comparator, mapper) {
1620
- if (!comparator) {
1621
- comparator = defaultComparator;
1622
- }
1623
- if (mapper) {
1624
- var entry = iterable.toSeq()
1625
- .map(function(v, k) {return [v, mapper(v, k, iterable)]})
1626
- .reduce(function(a, b) {return maxCompare(comparator, a[1], b[1]) ? b : a});
1627
- return entry && entry[0];
1628
- } else {
1629
- return iterable.reduce(function(a, b) {return maxCompare(comparator, a, b) ? b : a});
1630
- }
1631
- }
1632
-
1633
- function maxCompare(comparator, a, b) {
1634
- var comp = comparator(b, a);
1635
- // b is considered the new max if the comparator declares them equal, but
1636
- // they are not equal and b is in fact a nullish value.
1637
- return (comp === 0 && b !== a && (b === undefined || b === null || b !== b)) || comp > 0;
1638
- }
1639
-
1640
-
1641
- function zipWithFactory(keyIter, zipper, iters) {
1642
- var zipSequence = makeSequence(keyIter);
1643
- zipSequence.size = new ArraySeq(iters).map(function(i ) {return i.size}).min();
1644
- // Note: this a generic base implementation of __iterate in terms of
1645
- // __iterator which may be more generically useful in the future.
1646
- zipSequence.__iterate = function(fn, reverse) {
1647
- /* generic:
1648
- var iterator = this.__iterator(ITERATE_ENTRIES, reverse);
1649
- var step;
1650
- var iterations = 0;
1651
- while (!(step = iterator.next()).done) {
1652
- iterations++;
1653
- if (fn(step.value[1], step.value[0], this) === false) {
1654
- break;
1655
- }
1656
- }
1657
- return iterations;
1658
- */
1659
- // indexed:
1660
- var iterator = this.__iterator(ITERATE_VALUES, reverse);
1661
- var step;
1662
- var iterations = 0;
1663
- while (!(step = iterator.next()).done) {
1664
- if (fn(step.value, iterations++, this) === false) {
1665
- break;
1666
- }
1667
- }
1668
- return iterations;
1669
- };
1670
- zipSequence.__iteratorUncached = function(type, reverse) {
1671
- var iterators = iters.map(function(i )
1672
- {return (i = Iterable(i), getIterator(reverse ? i.reverse() : i))}
1673
- );
1674
- var iterations = 0;
1675
- var isDone = false;
1676
- return new src_Iterator__Iterator(function() {
1677
- var steps;
1678
- if (!isDone) {
1679
- steps = iterators.map(function(i ) {return i.next()});
1680
- isDone = steps.some(function(s ) {return s.done});
1681
- }
1682
- if (isDone) {
1683
- return iteratorDone();
1684
- }
1685
- return iteratorValue(
1686
- type,
1687
- iterations++,
1688
- zipper.apply(null, steps.map(function(s ) {return s.value}))
1689
- );
1690
- });
1691
- };
1692
- return zipSequence
1693
- }
1694
-
1695
-
1696
- // #pragma Helper Functions
1697
-
1698
- function reify(iter, seq) {
1699
- return isSeq(iter) ? seq : iter.constructor(seq);
1700
- }
1701
-
1702
- function validateEntry(entry) {
1703
- if (entry !== Object(entry)) {
1704
- throw new TypeError('Expected [K, V] tuple: ' + entry);
1705
- }
1706
- }
1707
-
1708
- function resolveSize(iter) {
1709
- assertNotInfinite(iter.size);
1710
- return ensureSize(iter);
1711
- }
1712
-
1713
- function iterableClass(iterable) {
1714
- return isKeyed(iterable) ? KeyedIterable :
1715
- isIndexed(iterable) ? IndexedIterable :
1716
- SetIterable;
1717
- }
1718
-
1719
- function makeSequence(iterable) {
1720
- return Object.create(
1721
- (
1722
- isKeyed(iterable) ? KeyedSeq :
1723
- isIndexed(iterable) ? IndexedSeq :
1724
- SetSeq
1725
- ).prototype
1726
- );
1727
- }
1728
-
1729
- function cacheResultThrough() {
1730
- if (this._iter.cacheResult) {
1731
- this._iter.cacheResult();
1732
- this.size = this._iter.size;
1733
- return this;
1734
- } else {
1735
- return Seq.prototype.cacheResult.call(this);
1736
- }
1737
- }
1738
-
1739
- function defaultComparator(a, b) {
1740
- return a > b ? 1 : a < b ? -1 : 0;
1741
- }
1742
-
1743
- function forceIterator(keyPath) {
1744
- var iter = getIterator(keyPath);
1745
- if (!iter) {
1746
- // Array might not be iterable in this environment, so we need a fallback
1747
- // to our wrapped type.
1748
- if (!isArrayLike(keyPath)) {
1749
- throw new TypeError('Expected iterable or array-like: ' + keyPath);
1750
- }
1751
- iter = getIterator(Iterable(keyPath));
1752
- }
1753
- return iter;
1754
- }
1755
-
1756
- createClass(src_Map__Map, KeyedCollection);
1757
-
1758
- // @pragma Construction
1759
-
1760
- function src_Map__Map(value) {
1761
- return value === null || value === undefined ? emptyMap() :
1762
- isMap(value) ? value :
1763
- emptyMap().withMutations(function(map ) {
1764
- var iter = KeyedIterable(value);
1765
- assertNotInfinite(iter.size);
1766
- iter.forEach(function(v, k) {return map.set(k, v)});
1767
- });
1768
- }
1769
-
1770
- src_Map__Map.prototype.toString = function() {
1771
- return this.__toString('Map {', '}');
1772
- };
1773
-
1774
- // @pragma Access
1775
-
1776
- src_Map__Map.prototype.get = function(k, notSetValue) {
1777
- return this._root ?
1778
- this._root.get(0, undefined, k, notSetValue) :
1779
- notSetValue;
1780
- };
1781
-
1782
- // @pragma Modification
1783
-
1784
- src_Map__Map.prototype.set = function(k, v) {
1785
- return updateMap(this, k, v);
1786
- };
1787
-
1788
- src_Map__Map.prototype.setIn = function(keyPath, v) {
1789
- return this.updateIn(keyPath, NOT_SET, function() {return v});
1790
- };
1791
-
1792
- src_Map__Map.prototype.remove = function(k) {
1793
- return updateMap(this, k, NOT_SET);
1794
- };
1795
-
1796
- src_Map__Map.prototype.deleteIn = function(keyPath) {
1251
+ Map.prototype.deleteIn = function(keyPath) {
1797
1252
  return this.updateIn(keyPath, function() {return NOT_SET});
1798
1253
  };
1799
1254
 
1800
- src_Map__Map.prototype.update = function(k, notSetValue, updater) {
1255
+ Map.prototype.update = function(k, notSetValue, updater) {
1801
1256
  return arguments.length === 1 ?
1802
1257
  k(this) :
1803
1258
  this.updateIn([k], notSetValue, updater);
1804
1259
  };
1805
1260
 
1806
- src_Map__Map.prototype.updateIn = function(keyPath, notSetValue, updater) {
1261
+ Map.prototype.updateIn = function(keyPath, notSetValue, updater) {
1807
1262
  if (!updater) {
1808
1263
  updater = notSetValue;
1809
1264
  notSetValue = undefined;
@@ -1817,7 +1272,7 @@
1817
1272
  return updatedValue === NOT_SET ? undefined : updatedValue;
1818
1273
  };
1819
1274
 
1820
- src_Map__Map.prototype.clear = function() {
1275
+ Map.prototype.clear = function() {
1821
1276
  if (this.size === 0) {
1822
1277
  return this;
1823
1278
  }
@@ -1833,65 +1288,77 @@
1833
1288
 
1834
1289
  // @pragma Composition
1835
1290
 
1836
- src_Map__Map.prototype.merge = function(/*...iters*/) {
1291
+ Map.prototype.merge = function(/*...iters*/) {
1837
1292
  return mergeIntoMapWith(this, undefined, arguments);
1838
1293
  };
1839
1294
 
1840
- src_Map__Map.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
1295
+ Map.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
1841
1296
  return mergeIntoMapWith(this, merger, iters);
1842
1297
  };
1843
1298
 
1844
- src_Map__Map.prototype.mergeIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
1845
- return this.updateIn(keyPath, emptyMap(), function(m ) {return m.merge.apply(m, iters)});
1299
+ Map.prototype.mergeIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
1300
+ return this.updateIn(
1301
+ keyPath,
1302
+ emptyMap(),
1303
+ function(m ) {return typeof m.merge === 'function' ?
1304
+ m.merge.apply(m, iters) :
1305
+ iters[iters.length - 1]}
1306
+ );
1846
1307
  };
1847
1308
 
1848
- src_Map__Map.prototype.mergeDeep = function(/*...iters*/) {
1849
- return mergeIntoMapWith(this, deepMerger(undefined), arguments);
1309
+ Map.prototype.mergeDeep = function(/*...iters*/) {
1310
+ return mergeIntoMapWith(this, deepMerger, arguments);
1850
1311
  };
1851
1312
 
1852
- src_Map__Map.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
1853
- return mergeIntoMapWith(this, deepMerger(merger), iters);
1313
+ Map.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
1314
+ return mergeIntoMapWith(this, deepMergerWith(merger), iters);
1854
1315
  };
1855
1316
 
1856
- src_Map__Map.prototype.mergeDeepIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
1857
- return this.updateIn(keyPath, emptyMap(), function(m ) {return m.mergeDeep.apply(m, iters)});
1317
+ Map.prototype.mergeDeepIn = function(keyPath) {var iters = SLICE$0.call(arguments, 1);
1318
+ return this.updateIn(
1319
+ keyPath,
1320
+ emptyMap(),
1321
+ function(m ) {return typeof m.mergeDeep === 'function' ?
1322
+ m.mergeDeep.apply(m, iters) :
1323
+ iters[iters.length - 1]}
1324
+ );
1858
1325
  };
1859
1326
 
1860
- src_Map__Map.prototype.sort = function(comparator) {
1327
+ Map.prototype.sort = function(comparator) {
1861
1328
  // Late binding
1862
1329
  return OrderedMap(sortFactory(this, comparator));
1863
1330
  };
1864
1331
 
1865
- src_Map__Map.prototype.sortBy = function(mapper, comparator) {
1332
+ Map.prototype.sortBy = function(mapper, comparator) {
1866
1333
  // Late binding
1867
1334
  return OrderedMap(sortFactory(this, comparator, mapper));
1868
1335
  };
1869
1336
 
1870
1337
  // @pragma Mutability
1871
1338
 
1872
- src_Map__Map.prototype.withMutations = function(fn) {
1339
+ Map.prototype.withMutations = function(fn) {
1873
1340
  var mutable = this.asMutable();
1874
1341
  fn(mutable);
1875
1342
  return mutable.wasAltered() ? mutable.__ensureOwner(this.__ownerID) : this;
1876
1343
  };
1877
1344
 
1878
- src_Map__Map.prototype.asMutable = function() {
1345
+ Map.prototype.asMutable = function() {
1879
1346
  return this.__ownerID ? this : this.__ensureOwner(new OwnerID());
1880
1347
  };
1881
1348
 
1882
- src_Map__Map.prototype.asImmutable = function() {
1349
+ Map.prototype.asImmutable = function() {
1883
1350
  return this.__ensureOwner();
1884
1351
  };
1885
1352
 
1886
- src_Map__Map.prototype.wasAltered = function() {
1353
+ Map.prototype.wasAltered = function() {
1887
1354
  return this.__altered;
1888
1355
  };
1889
1356
 
1890
- src_Map__Map.prototype.__iterator = function(type, reverse) {
1357
+ Map.prototype.__iterator = function(type, reverse) {
1891
1358
  return new MapIterator(this, type, reverse);
1892
1359
  };
1893
1360
 
1894
- src_Map__Map.prototype.__iterate = function(fn, reverse) {var this$0 = this;
1361
+ Map.prototype.__iterate = function(fn, reverse) {var this$0 = this;
1895
1362
  var iterations = 0;
1896
1363
  this._root && this._root.iterate(function(entry ) {
1897
1364
  iterations++;
@@ -1900,7 +1367,7 @@
1900
1367
  return iterations;
1901
1368
  };
1902
1369
 
1903
- src_Map__Map.prototype.__ensureOwner = function(ownerID) {
1370
+ Map.prototype.__ensureOwner = function(ownerID) {
1904
1371
  if (ownerID === this.__ownerID) {
1905
1372
  return this;
1906
1373
  }
@@ -1917,11 +1384,11 @@
1917
1384
  return !!(maybeMap && maybeMap[IS_MAP_SENTINEL]);
1918
1385
  }
1919
1386
 
1920
- src_Map__Map.isMap = isMap;
1387
+ Map.isMap = isMap;
1921
1388
 
1922
1389
  var IS_MAP_SENTINEL = '@@__IMMUTABLE_MAP__@@';
1923
1390
 
1924
- var MapPrototype = src_Map__Map.prototype;
1391
+ var MapPrototype = Map.prototype;
1925
1392
  MapPrototype[IS_MAP_SENTINEL] = true;
1926
1393
  MapPrototype[DELETE] = MapPrototype.remove;
1927
1394
  MapPrototype.removeIn = MapPrototype.deleteIn;
@@ -2265,7 +1732,7 @@
2265
1732
  return fn(this.entry);
2266
1733
  }
2267
1734
 
2268
- createClass(MapIterator, src_Iterator__Iterator);
1735
+ createClass(MapIterator, Iterator);
2269
1736
 
2270
1737
  function MapIterator(map, type, reverse) {
2271
1738
  this._type = type;
@@ -2444,11 +1911,20 @@
2444
1911
  return mergeIntoCollectionWith(map, merger, iters);
2445
1912
  }
2446
1913
 
2447
- function deepMerger(merger) {
2448
- return function(existing, value, key)
2449
- {return existing && existing.mergeDeepWith && isIterable(value) ?
2450
- existing.mergeDeepWith(merger, value) :
2451
- merger ? merger(existing, value, key) : value};
1914
+ function deepMerger(existing, value, key) {
1915
+ return existing && existing.mergeDeep && isIterable(value) ?
1916
+ existing.mergeDeep(value) :
1917
+ is(existing, value) ? existing : value;
1918
+ }
1919
+
1920
+ function deepMergerWith(merger) {
1921
+ return function(existing, value, key) {
1922
+ if (existing && existing.mergeDeepWith && isIterable(value)) {
1923
+ return existing.mergeDeepWith(merger, value);
1924
+ }
1925
+ var nextValue = merger(existing, value, key);
1926
+ return is(existing, nextValue) ? existing : nextValue;
1927
+ };
2452
1928
  }
2453
1929
 
2454
1930
  function mergeIntoCollectionWith(collection, merger, iters) {
@@ -2594,12 +2070,12 @@
2594
2070
 
2595
2071
  List.prototype.get = function(index, notSetValue) {
2596
2072
  index = wrapIndex(this, index);
2597
- if (index < 0 || index >= this.size) {
2598
- return notSetValue;
2073
+ if (index >= 0 && index < this.size) {
2074
+ index += this._origin;
2075
+ var node = listNodeFor(this, index);
2076
+ return node && node.array[index & MASK];
2599
2077
  }
2600
- index += this._origin;
2601
- var node = listNodeFor(this, index);
2602
- return node && node.array[index & MASK];
2078
+ return notSetValue;
2603
2079
  };
2604
2080
 
2605
2081
  // @pragma Modification
@@ -2615,6 +2091,10 @@
2615
2091
  this.splice(index, 1);
2616
2092
  };
2617
2093
 
2094
+ List.prototype.insert = function(index, value) {
2095
+ return this.splice(index, 0, value);
2096
+ };
2097
+
2618
2098
  List.prototype.clear = function() {
2619
2099
  if (this.size === 0) {
2620
2100
  return this;
@@ -2670,11 +2150,11 @@
2670
2150
  };
2671
2151
 
2672
2152
  List.prototype.mergeDeep = function(/*...iters*/) {
2673
- return mergeIntoListWith(this, deepMerger(undefined), arguments);
2153
+ return mergeIntoListWith(this, deepMerger, arguments);
2674
2154
  };
2675
2155
 
2676
2156
  List.prototype.mergeDeepWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
2677
- return mergeIntoListWith(this, deepMerger(merger), iters);
2157
+ return mergeIntoListWith(this, deepMergerWith(merger), iters);
2678
2158
  };
2679
2159
 
2680
2160
  List.prototype.setSize = function(size) {
@@ -2698,7 +2178,7 @@
2698
2178
  List.prototype.__iterator = function(type, reverse) {
2699
2179
  var index = 0;
2700
2180
  var values = iterateList(this, reverse);
2701
- return new src_Iterator__Iterator(function() {
2181
+ return new Iterator(function() {
2702
2182
  var value = values();
2703
2183
  return value === DONE ?
2704
2184
  iteratorDone() :
@@ -2795,29 +2275,25 @@
2795
2275
  };
2796
2276
 
2797
2277
  VNode.prototype.removeAfter = function(ownerID, level, index) {
2798
- if (index === level ? 1 << level : 0 || this.array.length === 0) {
2278
+ if (index === (level ? 1 << level : 0) || this.array.length === 0) {
2799
2279
  return this;
2800
2280
  }
2801
2281
  var sizeIndex = ((index - 1) >>> level) & MASK;
2802
2282
  if (sizeIndex >= this.array.length) {
2803
2283
  return this;
2804
2284
  }
2805
- var removingLast = sizeIndex === this.array.length - 1;
2285
+
2806
2286
  var newChild;
2807
2287
  if (level > 0) {
2808
2288
  var oldChild = this.array[sizeIndex];
2809
2289
  newChild = oldChild && oldChild.removeAfter(ownerID, level - SHIFT, index);
2810
- if (newChild === oldChild && removingLast) {
2290
+ if (newChild === oldChild && sizeIndex === this.array.length - 1) {
2811
2291
  return this;
2812
2292
  }
2813
2293
  }
2814
- if (removingLast && !newChild) {
2815
- return this;
2816
- }
2294
+
2817
2295
  var editable = editableVNode(this, ownerID);
2818
- if (!removingLast) {
2819
- editable.array.pop();
2820
- }
2296
+ editable.array.splice(sizeIndex + 1);
2821
2297
  if (newChild) {
2822
2298
  editable.array[sizeIndex] = newChild;
2823
2299
  }
@@ -2909,6 +2385,10 @@
2909
2385
  function updateList(list, index, value) {
2910
2386
  index = wrapIndex(list, index);
2911
2387
 
2388
+ if (index !== index) {
2389
+ return list;
2390
+ }
2391
+
2912
2392
  if (index >= list.size || index < 0) {
2913
2393
  return list.withMutations(function(list ) {
2914
2394
  index < 0 ?
@@ -3000,6 +2480,14 @@
3000
2480
  }
3001
2481
 
3002
2482
  function setListBounds(list, begin, end) {
2483
+ // Sanitize begin & end using this shorthand for ToInt32(argument)
2484
+ // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
2485
+ if (begin !== undefined) {
2486
+ begin = begin | 0;
2487
+ }
2488
+ if (end !== undefined) {
2489
+ end = end | 0;
2490
+ }
3003
2491
  var owner = list.__ownerID || new OwnerID();
3004
2492
  var oldOrigin = list._origin;
3005
2493
  var oldCapacity = list._capacity;
@@ -3017,7 +2505,7 @@
3017
2505
  var newLevel = list._level;
3018
2506
  var newRoot = list._root;
3019
2507
 
3020
- // New origin might require creating a higher root.
2508
+ // New origin might need creating a higher root.
3021
2509
  var offsetShift = 0;
3022
2510
  while (newOrigin + offsetShift < 0) {
3023
2511
  newRoot = new VNode(newRoot && newRoot.array.length ? [undefined, newRoot] : [], owner);
@@ -3034,7 +2522,7 @@
3034
2522
  var oldTailOffset = getTailOffset(oldCapacity);
3035
2523
  var newTailOffset = getTailOffset(newCapacity);
3036
2524
 
3037
- // New size might require creating a higher root.
2525
+ // New size might need creating a higher root.
3038
2526
  while (newTailOffset >= 1 << (newLevel + SHIFT)) {
3039
2527
  newRoot = new VNode(newRoot && newRoot.array.length ? [newRoot] : [], owner);
3040
2528
  newLevel += SHIFT;
@@ -3131,388 +2619,1158 @@
3131
2619
  if (maxSize > list.size) {
3132
2620
  list = list.setSize(maxSize);
3133
2621
  }
3134
- return mergeIntoCollectionWith(list, merger, iters);
3135
- }
3136
-
3137
- function getTailOffset(size) {
3138
- return size < SIZE ? 0 : (((size - 1) >>> SHIFT) << SHIFT);
2622
+ return mergeIntoCollectionWith(list, merger, iters);
2623
+ }
2624
+
2625
+ function getTailOffset(size) {
2626
+ return size < SIZE ? 0 : (((size - 1) >>> SHIFT) << SHIFT);
2627
+ }
2628
+
2629
+ createClass(OrderedMap, Map);
2630
+
2631
+ // @pragma Construction
2632
+
2633
+ function OrderedMap(value) {
2634
+ return value === null || value === undefined ? emptyOrderedMap() :
2635
+ isOrderedMap(value) ? value :
2636
+ emptyOrderedMap().withMutations(function(map ) {
2637
+ var iter = KeyedIterable(value);
2638
+ assertNotInfinite(iter.size);
2639
+ iter.forEach(function(v, k) {return map.set(k, v)});
2640
+ });
2641
+ }
2642
+
2643
+ OrderedMap.of = function(/*...values*/) {
2644
+ return this(arguments);
2645
+ };
2646
+
2647
+ OrderedMap.prototype.toString = function() {
2648
+ return this.__toString('OrderedMap {', '}');
2649
+ };
2650
+
2651
+ // @pragma Access
2652
+
2653
+ OrderedMap.prototype.get = function(k, notSetValue) {
2654
+ var index = this._map.get(k);
2655
+ return index !== undefined ? this._list.get(index)[1] : notSetValue;
2656
+ };
2657
+
2658
+ // @pragma Modification
2659
+
2660
+ OrderedMap.prototype.clear = function() {
2661
+ if (this.size === 0) {
2662
+ return this;
2663
+ }
2664
+ if (this.__ownerID) {
2665
+ this.size = 0;
2666
+ this._map.clear();
2667
+ this._list.clear();
2668
+ return this;
2669
+ }
2670
+ return emptyOrderedMap();
2671
+ };
2672
+
2673
+ OrderedMap.prototype.set = function(k, v) {
2674
+ return updateOrderedMap(this, k, v);
2675
+ };
2676
+
2677
+ OrderedMap.prototype.remove = function(k) {
2678
+ return updateOrderedMap(this, k, NOT_SET);
2679
+ };
2680
+
2681
+ OrderedMap.prototype.wasAltered = function() {
2682
+ return this._map.wasAltered() || this._list.wasAltered();
2683
+ };
2684
+
2685
+ OrderedMap.prototype.__iterate = function(fn, reverse) {var this$0 = this;
2686
+ return this._list.__iterate(
2687
+ function(entry ) {return entry && fn(entry[1], entry[0], this$0)},
2688
+ reverse
2689
+ );
2690
+ };
2691
+
2692
+ OrderedMap.prototype.__iterator = function(type, reverse) {
2693
+ return this._list.fromEntrySeq().__iterator(type, reverse);
2694
+ };
2695
+
2696
+ OrderedMap.prototype.__ensureOwner = function(ownerID) {
2697
+ if (ownerID === this.__ownerID) {
2698
+ return this;
2699
+ }
2700
+ var newMap = this._map.__ensureOwner(ownerID);
2701
+ var newList = this._list.__ensureOwner(ownerID);
2702
+ if (!ownerID) {
2703
+ this.__ownerID = ownerID;
2704
+ this._map = newMap;
2705
+ this._list = newList;
2706
+ return this;
2707
+ }
2708
+ return makeOrderedMap(newMap, newList, ownerID, this.__hash);
2709
+ };
2710
+
2711
+
2712
+ function isOrderedMap(maybeOrderedMap) {
2713
+ return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
2714
+ }
2715
+
2716
+ OrderedMap.isOrderedMap = isOrderedMap;
2717
+
2718
+ OrderedMap.prototype[IS_ORDERED_SENTINEL] = true;
2719
+ OrderedMap.prototype[DELETE] = OrderedMap.prototype.remove;
2720
+
2721
+
2722
+
2723
+ function makeOrderedMap(map, list, ownerID, hash) {
2724
+ var omap = Object.create(OrderedMap.prototype);
2725
+ omap.size = map ? map.size : 0;
2726
+ omap._map = map;
2727
+ omap._list = list;
2728
+ omap.__ownerID = ownerID;
2729
+ omap.__hash = hash;
2730
+ return omap;
2731
+ }
2732
+
2733
+ var EMPTY_ORDERED_MAP;
2734
+ function emptyOrderedMap() {
2735
+ return EMPTY_ORDERED_MAP || (EMPTY_ORDERED_MAP = makeOrderedMap(emptyMap(), emptyList()));
2736
+ }
2737
+
2738
+ function updateOrderedMap(omap, k, v) {
2739
+ var map = omap._map;
2740
+ var list = omap._list;
2741
+ var i = map.get(k);
2742
+ var has = i !== undefined;
2743
+ var newMap;
2744
+ var newList;
2745
+ if (v === NOT_SET) { // removed
2746
+ if (!has) {
2747
+ return omap;
2748
+ }
2749
+ if (list.size >= SIZE && list.size >= map.size * 2) {
2750
+ newList = list.filter(function(entry, idx) {return entry !== undefined && i !== idx});
2751
+ newMap = newList.toKeyedSeq().map(function(entry ) {return entry[0]}).flip().toMap();
2752
+ if (omap.__ownerID) {
2753
+ newMap.__ownerID = newList.__ownerID = omap.__ownerID;
2754
+ }
2755
+ } else {
2756
+ newMap = map.remove(k);
2757
+ newList = i === list.size - 1 ? list.pop() : list.set(i, undefined);
2758
+ }
2759
+ } else {
2760
+ if (has) {
2761
+ if (v === list.get(i)[1]) {
2762
+ return omap;
2763
+ }
2764
+ newMap = map;
2765
+ newList = list.set(i, [k, v]);
2766
+ } else {
2767
+ newMap = map.set(k, list.size);
2768
+ newList = list.set(list.size, [k, v]);
2769
+ }
2770
+ }
2771
+ if (omap.__ownerID) {
2772
+ omap.size = newMap.size;
2773
+ omap._map = newMap;
2774
+ omap._list = newList;
2775
+ omap.__hash = undefined;
2776
+ return omap;
2777
+ }
2778
+ return makeOrderedMap(newMap, newList);
2779
+ }
2780
+
2781
+ createClass(ToKeyedSequence, KeyedSeq);
2782
+ function ToKeyedSequence(indexed, useKeys) {
2783
+ this._iter = indexed;
2784
+ this._useKeys = useKeys;
2785
+ this.size = indexed.size;
2786
+ }
2787
+
2788
+ ToKeyedSequence.prototype.get = function(key, notSetValue) {
2789
+ return this._iter.get(key, notSetValue);
2790
+ };
2791
+
2792
+ ToKeyedSequence.prototype.has = function(key) {
2793
+ return this._iter.has(key);
2794
+ };
2795
+
2796
+ ToKeyedSequence.prototype.valueSeq = function() {
2797
+ return this._iter.valueSeq();
2798
+ };
2799
+
2800
+ ToKeyedSequence.prototype.reverse = function() {var this$0 = this;
2801
+ var reversedSequence = reverseFactory(this, true);
2802
+ if (!this._useKeys) {
2803
+ reversedSequence.valueSeq = function() {return this$0._iter.toSeq().reverse()};
2804
+ }
2805
+ return reversedSequence;
2806
+ };
2807
+
2808
+ ToKeyedSequence.prototype.map = function(mapper, context) {var this$0 = this;
2809
+ var mappedSequence = mapFactory(this, mapper, context);
2810
+ if (!this._useKeys) {
2811
+ mappedSequence.valueSeq = function() {return this$0._iter.toSeq().map(mapper, context)};
2812
+ }
2813
+ return mappedSequence;
2814
+ };
2815
+
2816
+ ToKeyedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
2817
+ var ii;
2818
+ return this._iter.__iterate(
2819
+ this._useKeys ?
2820
+ function(v, k) {return fn(v, k, this$0)} :
2821
+ ((ii = reverse ? resolveSize(this) : 0),
2822
+ function(v ) {return fn(v, reverse ? --ii : ii++, this$0)}),
2823
+ reverse
2824
+ );
2825
+ };
2826
+
2827
+ ToKeyedSequence.prototype.__iterator = function(type, reverse) {
2828
+ if (this._useKeys) {
2829
+ return this._iter.__iterator(type, reverse);
2830
+ }
2831
+ var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
2832
+ var ii = reverse ? resolveSize(this) : 0;
2833
+ return new Iterator(function() {
2834
+ var step = iterator.next();
2835
+ return step.done ? step :
2836
+ iteratorValue(type, reverse ? --ii : ii++, step.value, step);
2837
+ });
2838
+ };
2839
+
2840
+ ToKeyedSequence.prototype[IS_ORDERED_SENTINEL] = true;
2841
+
2842
+
2843
+ createClass(ToIndexedSequence, IndexedSeq);
2844
+ function ToIndexedSequence(iter) {
2845
+ this._iter = iter;
2846
+ this.size = iter.size;
2847
+ }
2848
+
2849
+ ToIndexedSequence.prototype.includes = function(value) {
2850
+ return this._iter.includes(value);
2851
+ };
2852
+
2853
+ ToIndexedSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
2854
+ var iterations = 0;
2855
+ return this._iter.__iterate(function(v ) {return fn(v, iterations++, this$0)}, reverse);
2856
+ };
2857
+
2858
+ ToIndexedSequence.prototype.__iterator = function(type, reverse) {
2859
+ var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
2860
+ var iterations = 0;
2861
+ return new Iterator(function() {
2862
+ var step = iterator.next();
2863
+ return step.done ? step :
2864
+ iteratorValue(type, iterations++, step.value, step)
2865
+ });
2866
+ };
2867
+
2868
+
2869
+
2870
+ createClass(ToSetSequence, SetSeq);
2871
+ function ToSetSequence(iter) {
2872
+ this._iter = iter;
2873
+ this.size = iter.size;
2874
+ }
2875
+
2876
+ ToSetSequence.prototype.has = function(key) {
2877
+ return this._iter.includes(key);
2878
+ };
2879
+
2880
+ ToSetSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
2881
+ return this._iter.__iterate(function(v ) {return fn(v, v, this$0)}, reverse);
2882
+ };
2883
+
2884
+ ToSetSequence.prototype.__iterator = function(type, reverse) {
2885
+ var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
2886
+ return new Iterator(function() {
2887
+ var step = iterator.next();
2888
+ return step.done ? step :
2889
+ iteratorValue(type, step.value, step.value, step);
2890
+ });
2891
+ };
2892
+
2893
+
2894
+
2895
+ createClass(FromEntriesSequence, KeyedSeq);
2896
+ function FromEntriesSequence(entries) {
2897
+ this._iter = entries;
2898
+ this.size = entries.size;
2899
+ }
2900
+
2901
+ FromEntriesSequence.prototype.entrySeq = function() {
2902
+ return this._iter.toSeq();
2903
+ };
2904
+
2905
+ FromEntriesSequence.prototype.__iterate = function(fn, reverse) {var this$0 = this;
2906
+ return this._iter.__iterate(function(entry ) {
2907
+ // Check if entry exists first so array access doesn't throw for holes
2908
+ // in the parent iteration.
2909
+ if (entry) {
2910
+ validateEntry(entry);
2911
+ var indexedIterable = isIterable(entry);
2912
+ return fn(
2913
+ indexedIterable ? entry.get(1) : entry[1],
2914
+ indexedIterable ? entry.get(0) : entry[0],
2915
+ this$0
2916
+ );
2917
+ }
2918
+ }, reverse);
2919
+ };
2920
+
2921
+ FromEntriesSequence.prototype.__iterator = function(type, reverse) {
2922
+ var iterator = this._iter.__iterator(ITERATE_VALUES, reverse);
2923
+ return new Iterator(function() {
2924
+ while (true) {
2925
+ var step = iterator.next();
2926
+ if (step.done) {
2927
+ return step;
2928
+ }
2929
+ var entry = step.value;
2930
+ // Check if entry exists first so array access doesn't throw for holes
2931
+ // in the parent iteration.
2932
+ if (entry) {
2933
+ validateEntry(entry);
2934
+ var indexedIterable = isIterable(entry);
2935
+ return iteratorValue(
2936
+ type,
2937
+ indexedIterable ? entry.get(0) : entry[0],
2938
+ indexedIterable ? entry.get(1) : entry[1],
2939
+ step
2940
+ );
2941
+ }
2942
+ }
2943
+ });
2944
+ };
2945
+
2946
+
2947
+ ToIndexedSequence.prototype.cacheResult =
2948
+ ToKeyedSequence.prototype.cacheResult =
2949
+ ToSetSequence.prototype.cacheResult =
2950
+ FromEntriesSequence.prototype.cacheResult =
2951
+ cacheResultThrough;
2952
+
2953
+
2954
+ function flipFactory(iterable) {
2955
+ var flipSequence = makeSequence(iterable);
2956
+ flipSequence._iter = iterable;
2957
+ flipSequence.size = iterable.size;
2958
+ flipSequence.flip = function() {return iterable};
2959
+ flipSequence.reverse = function () {
2960
+ var reversedSequence = iterable.reverse.apply(this); // super.reverse()
2961
+ reversedSequence.flip = function() {return iterable.reverse()};
2962
+ return reversedSequence;
2963
+ };
2964
+ flipSequence.has = function(key ) {return iterable.includes(key)};
2965
+ flipSequence.includes = function(key ) {return iterable.has(key)};
2966
+ flipSequence.cacheResult = cacheResultThrough;
2967
+ flipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
2968
+ return iterable.__iterate(function(v, k) {return fn(k, v, this$0) !== false}, reverse);
2969
+ }
2970
+ flipSequence.__iteratorUncached = function(type, reverse) {
2971
+ if (type === ITERATE_ENTRIES) {
2972
+ var iterator = iterable.__iterator(type, reverse);
2973
+ return new Iterator(function() {
2974
+ var step = iterator.next();
2975
+ if (!step.done) {
2976
+ var k = step.value[0];
2977
+ step.value[0] = step.value[1];
2978
+ step.value[1] = k;
2979
+ }
2980
+ return step;
2981
+ });
2982
+ }
2983
+ return iterable.__iterator(
2984
+ type === ITERATE_VALUES ? ITERATE_KEYS : ITERATE_VALUES,
2985
+ reverse
2986
+ );
2987
+ }
2988
+ return flipSequence;
2989
+ }
2990
+
2991
+
2992
+ function mapFactory(iterable, mapper, context) {
2993
+ var mappedSequence = makeSequence(iterable);
2994
+ mappedSequence.size = iterable.size;
2995
+ mappedSequence.has = function(key ) {return iterable.has(key)};
2996
+ mappedSequence.get = function(key, notSetValue) {
2997
+ var v = iterable.get(key, NOT_SET);
2998
+ return v === NOT_SET ?
2999
+ notSetValue :
3000
+ mapper.call(context, v, key, iterable);
3001
+ };
3002
+ mappedSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
3003
+ return iterable.__iterate(
3004
+ function(v, k, c) {return fn(mapper.call(context, v, k, c), k, this$0) !== false},
3005
+ reverse
3006
+ );
3007
+ }
3008
+ mappedSequence.__iteratorUncached = function (type, reverse) {
3009
+ var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
3010
+ return new Iterator(function() {
3011
+ var step = iterator.next();
3012
+ if (step.done) {
3013
+ return step;
3014
+ }
3015
+ var entry = step.value;
3016
+ var key = entry[0];
3017
+ return iteratorValue(
3018
+ type,
3019
+ key,
3020
+ mapper.call(context, entry[1], key, iterable),
3021
+ step
3022
+ );
3023
+ });
3024
+ }
3025
+ return mappedSequence;
3026
+ }
3027
+
3028
+
3029
+ function reverseFactory(iterable, useKeys) {
3030
+ var reversedSequence = makeSequence(iterable);
3031
+ reversedSequence._iter = iterable;
3032
+ reversedSequence.size = iterable.size;
3033
+ reversedSequence.reverse = function() {return iterable};
3034
+ if (iterable.flip) {
3035
+ reversedSequence.flip = function () {
3036
+ var flipSequence = flipFactory(iterable);
3037
+ flipSequence.reverse = function() {return iterable.flip()};
3038
+ return flipSequence;
3039
+ };
3040
+ }
3041
+ reversedSequence.get = function(key, notSetValue)
3042
+ {return iterable.get(useKeys ? key : -1 - key, notSetValue)};
3043
+ reversedSequence.has = function(key )
3044
+ {return iterable.has(useKeys ? key : -1 - key)};
3045
+ reversedSequence.includes = function(value ) {return iterable.includes(value)};
3046
+ reversedSequence.cacheResult = cacheResultThrough;
3047
+ reversedSequence.__iterate = function (fn, reverse) {var this$0 = this;
3048
+ return iterable.__iterate(function(v, k) {return fn(v, k, this$0)}, !reverse);
3049
+ };
3050
+ reversedSequence.__iterator =
3051
+ function(type, reverse) {return iterable.__iterator(type, !reverse)};
3052
+ return reversedSequence;
3053
+ }
3054
+
3055
+
3056
+ function filterFactory(iterable, predicate, context, useKeys) {
3057
+ var filterSequence = makeSequence(iterable);
3058
+ if (useKeys) {
3059
+ filterSequence.has = function(key ) {
3060
+ var v = iterable.get(key, NOT_SET);
3061
+ return v !== NOT_SET && !!predicate.call(context, v, key, iterable);
3062
+ };
3063
+ filterSequence.get = function(key, notSetValue) {
3064
+ var v = iterable.get(key, NOT_SET);
3065
+ return v !== NOT_SET && predicate.call(context, v, key, iterable) ?
3066
+ v : notSetValue;
3067
+ };
3068
+ }
3069
+ filterSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
3070
+ var iterations = 0;
3071
+ iterable.__iterate(function(v, k, c) {
3072
+ if (predicate.call(context, v, k, c)) {
3073
+ iterations++;
3074
+ return fn(v, useKeys ? k : iterations - 1, this$0);
3075
+ }
3076
+ }, reverse);
3077
+ return iterations;
3078
+ };
3079
+ filterSequence.__iteratorUncached = function (type, reverse) {
3080
+ var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
3081
+ var iterations = 0;
3082
+ return new Iterator(function() {
3083
+ while (true) {
3084
+ var step = iterator.next();
3085
+ if (step.done) {
3086
+ return step;
3087
+ }
3088
+ var entry = step.value;
3089
+ var key = entry[0];
3090
+ var value = entry[1];
3091
+ if (predicate.call(context, value, key, iterable)) {
3092
+ return iteratorValue(type, useKeys ? key : iterations++, value, step);
3093
+ }
3094
+ }
3095
+ });
3096
+ }
3097
+ return filterSequence;
3098
+ }
3099
+
3100
+
3101
+ function countByFactory(iterable, grouper, context) {
3102
+ var groups = Map().asMutable();
3103
+ iterable.__iterate(function(v, k) {
3104
+ groups.update(
3105
+ grouper.call(context, v, k, iterable),
3106
+ 0,
3107
+ function(a ) {return a + 1}
3108
+ );
3109
+ });
3110
+ return groups.asImmutable();
3111
+ }
3112
+
3113
+
3114
+ function groupByFactory(iterable, grouper, context) {
3115
+ var isKeyedIter = isKeyed(iterable);
3116
+ var groups = (isOrdered(iterable) ? OrderedMap() : Map()).asMutable();
3117
+ iterable.__iterate(function(v, k) {
3118
+ groups.update(
3119
+ grouper.call(context, v, k, iterable),
3120
+ function(a ) {return (a = a || [], a.push(isKeyedIter ? [k, v] : v), a)}
3121
+ );
3122
+ });
3123
+ var coerce = iterableClass(iterable);
3124
+ return groups.map(function(arr ) {return reify(iterable, coerce(arr))});
3125
+ }
3126
+
3127
+
3128
+ function sliceFactory(iterable, begin, end, useKeys) {
3129
+ var originalSize = iterable.size;
3130
+
3131
+ // Sanitize begin & end using this shorthand for ToInt32(argument)
3132
+ // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32
3133
+ if (begin !== undefined) {
3134
+ begin = begin | 0;
3135
+ }
3136
+ if (end !== undefined) {
3137
+ end = end | 0;
3138
+ }
3139
+
3140
+ if (wholeSlice(begin, end, originalSize)) {
3141
+ return iterable;
3142
+ }
3143
+
3144
+ var resolvedBegin = resolveBegin(begin, originalSize);
3145
+ var resolvedEnd = resolveEnd(end, originalSize);
3146
+
3147
+ // begin or end will be NaN if they were provided as negative numbers and
3148
+ // this iterable's size is unknown. In that case, cache first so there is
3149
+ // a known size and these do not resolve to NaN.
3150
+ if (resolvedBegin !== resolvedBegin || resolvedEnd !== resolvedEnd) {
3151
+ return sliceFactory(iterable.toSeq().cacheResult(), begin, end, useKeys);
3152
+ }
3153
+
3154
+ // Note: resolvedEnd is undefined when the original sequence's length is
3155
+ // unknown and this slice did not supply an end and should contain all
3156
+ // elements after resolvedBegin.
3157
+ // In that case, resolvedSize will be NaN and sliceSize will remain undefined.
3158
+ var resolvedSize = resolvedEnd - resolvedBegin;
3159
+ var sliceSize;
3160
+ if (resolvedSize === resolvedSize) {
3161
+ sliceSize = resolvedSize < 0 ? 0 : resolvedSize;
3162
+ }
3163
+
3164
+ var sliceSeq = makeSequence(iterable);
3165
+
3166
+ // If iterable.size is undefined, the size of the realized sliceSeq is
3167
+ // unknown at this point unless the number of items to slice is 0
3168
+ sliceSeq.size = sliceSize === 0 ? sliceSize : iterable.size && sliceSize || undefined;
3169
+
3170
+ if (!useKeys && isSeq(iterable) && sliceSize >= 0) {
3171
+ sliceSeq.get = function (index, notSetValue) {
3172
+ index = wrapIndex(this, index);
3173
+ return index >= 0 && index < sliceSize ?
3174
+ iterable.get(index + resolvedBegin, notSetValue) :
3175
+ notSetValue;
3176
+ }
3177
+ }
3178
+
3179
+ sliceSeq.__iterateUncached = function(fn, reverse) {var this$0 = this;
3180
+ if (sliceSize === 0) {
3181
+ return 0;
3182
+ }
3183
+ if (reverse) {
3184
+ return this.cacheResult().__iterate(fn, reverse);
3185
+ }
3186
+ var skipped = 0;
3187
+ var isSkipping = true;
3188
+ var iterations = 0;
3189
+ iterable.__iterate(function(v, k) {
3190
+ if (!(isSkipping && (isSkipping = skipped++ < resolvedBegin))) {
3191
+ iterations++;
3192
+ return fn(v, useKeys ? k : iterations - 1, this$0) !== false &&
3193
+ iterations !== sliceSize;
3194
+ }
3195
+ });
3196
+ return iterations;
3197
+ };
3198
+
3199
+ sliceSeq.__iteratorUncached = function(type, reverse) {
3200
+ if (sliceSize !== 0 && reverse) {
3201
+ return this.cacheResult().__iterator(type, reverse);
3202
+ }
3203
+ // Don't bother instantiating parent iterator if taking 0.
3204
+ var iterator = sliceSize !== 0 && iterable.__iterator(type, reverse);
3205
+ var skipped = 0;
3206
+ var iterations = 0;
3207
+ return new Iterator(function() {
3208
+ while (skipped++ < resolvedBegin) {
3209
+ iterator.next();
3210
+ }
3211
+ if (++iterations > sliceSize) {
3212
+ return iteratorDone();
3213
+ }
3214
+ var step = iterator.next();
3215
+ if (useKeys || type === ITERATE_VALUES) {
3216
+ return step;
3217
+ } else if (type === ITERATE_KEYS) {
3218
+ return iteratorValue(type, iterations - 1, undefined, step);
3219
+ } else {
3220
+ return iteratorValue(type, iterations - 1, step.value[1], step);
3221
+ }
3222
+ });
3223
+ }
3224
+
3225
+ return sliceSeq;
3226
+ }
3227
+
3228
+
3229
+ function takeWhileFactory(iterable, predicate, context) {
3230
+ var takeSequence = makeSequence(iterable);
3231
+ takeSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
3232
+ if (reverse) {
3233
+ return this.cacheResult().__iterate(fn, reverse);
3234
+ }
3235
+ var iterations = 0;
3236
+ iterable.__iterate(function(v, k, c)
3237
+ {return predicate.call(context, v, k, c) && ++iterations && fn(v, k, this$0)}
3238
+ );
3239
+ return iterations;
3240
+ };
3241
+ takeSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
3242
+ if (reverse) {
3243
+ return this.cacheResult().__iterator(type, reverse);
3244
+ }
3245
+ var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
3246
+ var iterating = true;
3247
+ return new Iterator(function() {
3248
+ if (!iterating) {
3249
+ return iteratorDone();
3250
+ }
3251
+ var step = iterator.next();
3252
+ if (step.done) {
3253
+ return step;
3254
+ }
3255
+ var entry = step.value;
3256
+ var k = entry[0];
3257
+ var v = entry[1];
3258
+ if (!predicate.call(context, v, k, this$0)) {
3259
+ iterating = false;
3260
+ return iteratorDone();
3261
+ }
3262
+ return type === ITERATE_ENTRIES ? step :
3263
+ iteratorValue(type, k, v, step);
3264
+ });
3265
+ };
3266
+ return takeSequence;
3267
+ }
3268
+
3269
+
3270
+ function skipWhileFactory(iterable, predicate, context, useKeys) {
3271
+ var skipSequence = makeSequence(iterable);
3272
+ skipSequence.__iterateUncached = function (fn, reverse) {var this$0 = this;
3273
+ if (reverse) {
3274
+ return this.cacheResult().__iterate(fn, reverse);
3275
+ }
3276
+ var isSkipping = true;
3277
+ var iterations = 0;
3278
+ iterable.__iterate(function(v, k, c) {
3279
+ if (!(isSkipping && (isSkipping = predicate.call(context, v, k, c)))) {
3280
+ iterations++;
3281
+ return fn(v, useKeys ? k : iterations - 1, this$0);
3282
+ }
3283
+ });
3284
+ return iterations;
3285
+ };
3286
+ skipSequence.__iteratorUncached = function(type, reverse) {var this$0 = this;
3287
+ if (reverse) {
3288
+ return this.cacheResult().__iterator(type, reverse);
3289
+ }
3290
+ var iterator = iterable.__iterator(ITERATE_ENTRIES, reverse);
3291
+ var skipping = true;
3292
+ var iterations = 0;
3293
+ return new Iterator(function() {
3294
+ var step, k, v;
3295
+ do {
3296
+ step = iterator.next();
3297
+ if (step.done) {
3298
+ if (useKeys || type === ITERATE_VALUES) {
3299
+ return step;
3300
+ } else if (type === ITERATE_KEYS) {
3301
+ return iteratorValue(type, iterations++, undefined, step);
3302
+ } else {
3303
+ return iteratorValue(type, iterations++, step.value[1], step);
3304
+ }
3305
+ }
3306
+ var entry = step.value;
3307
+ k = entry[0];
3308
+ v = entry[1];
3309
+ skipping && (skipping = predicate.call(context, v, k, this$0));
3310
+ } while (skipping);
3311
+ return type === ITERATE_ENTRIES ? step :
3312
+ iteratorValue(type, k, v, step);
3313
+ });
3314
+ };
3315
+ return skipSequence;
3316
+ }
3317
+
3318
+
3319
+ function concatFactory(iterable, values) {
3320
+ var isKeyedIterable = isKeyed(iterable);
3321
+ var iters = [iterable].concat(values).map(function(v ) {
3322
+ if (!isIterable(v)) {
3323
+ v = isKeyedIterable ?
3324
+ keyedSeqFromValue(v) :
3325
+ indexedSeqFromValue(Array.isArray(v) ? v : [v]);
3326
+ } else if (isKeyedIterable) {
3327
+ v = KeyedIterable(v);
3328
+ }
3329
+ return v;
3330
+ }).filter(function(v ) {return v.size !== 0});
3331
+
3332
+ if (iters.length === 0) {
3333
+ return iterable;
3334
+ }
3335
+
3336
+ if (iters.length === 1) {
3337
+ var singleton = iters[0];
3338
+ if (singleton === iterable ||
3339
+ isKeyedIterable && isKeyed(singleton) ||
3340
+ isIndexed(iterable) && isIndexed(singleton)) {
3341
+ return singleton;
3342
+ }
3343
+ }
3344
+
3345
+ var concatSeq = new ArraySeq(iters);
3346
+ if (isKeyedIterable) {
3347
+ concatSeq = concatSeq.toKeyedSeq();
3348
+ } else if (!isIndexed(iterable)) {
3349
+ concatSeq = concatSeq.toSetSeq();
3350
+ }
3351
+ concatSeq = concatSeq.flatten(true);
3352
+ concatSeq.size = iters.reduce(
3353
+ function(sum, seq) {
3354
+ if (sum !== undefined) {
3355
+ var size = seq.size;
3356
+ if (size !== undefined) {
3357
+ return sum + size;
3358
+ }
3359
+ }
3360
+ },
3361
+ 0
3362
+ );
3363
+ return concatSeq;
3364
+ }
3365
+
3366
+
3367
+ function flattenFactory(iterable, depth, useKeys) {
3368
+ var flatSequence = makeSequence(iterable);
3369
+ flatSequence.__iterateUncached = function(fn, reverse) {
3370
+ var iterations = 0;
3371
+ var stopped = false;
3372
+ function flatDeep(iter, currentDepth) {var this$0 = this;
3373
+ iter.__iterate(function(v, k) {
3374
+ if ((!depth || currentDepth < depth) && isIterable(v)) {
3375
+ flatDeep(v, currentDepth + 1);
3376
+ } else if (fn(v, useKeys ? k : iterations++, this$0) === false) {
3377
+ stopped = true;
3378
+ }
3379
+ return !stopped;
3380
+ }, reverse);
3381
+ }
3382
+ flatDeep(iterable, 0);
3383
+ return iterations;
3384
+ }
3385
+ flatSequence.__iteratorUncached = function(type, reverse) {
3386
+ var iterator = iterable.__iterator(type, reverse);
3387
+ var stack = [];
3388
+ var iterations = 0;
3389
+ return new Iterator(function() {
3390
+ while (iterator) {
3391
+ var step = iterator.next();
3392
+ if (step.done !== false) {
3393
+ iterator = stack.pop();
3394
+ continue;
3395
+ }
3396
+ var v = step.value;
3397
+ if (type === ITERATE_ENTRIES) {
3398
+ v = v[1];
3399
+ }
3400
+ if ((!depth || stack.length < depth) && isIterable(v)) {
3401
+ stack.push(iterator);
3402
+ iterator = v.__iterator(type, reverse);
3403
+ } else {
3404
+ return useKeys ? step : iteratorValue(type, iterations++, v, step);
3405
+ }
3406
+ }
3407
+ return iteratorDone();
3408
+ });
3409
+ }
3410
+ return flatSequence;
3139
3411
  }
3140
3412
 
3141
- createClass(OrderedMap, src_Map__Map);
3142
3413
 
3143
- // @pragma Construction
3414
+ function flatMapFactory(iterable, mapper, context) {
3415
+ var coerce = iterableClass(iterable);
3416
+ return iterable.toSeq().map(
3417
+ function(v, k) {return coerce(mapper.call(context, v, k, iterable))}
3418
+ ).flatten(true);
3419
+ }
3144
3420
 
3145
- function OrderedMap(value) {
3146
- return value === null || value === undefined ? emptyOrderedMap() :
3147
- isOrderedMap(value) ? value :
3148
- emptyOrderedMap().withMutations(function(map ) {
3149
- var iter = KeyedIterable(value);
3150
- assertNotInfinite(iter.size);
3151
- iter.forEach(function(v, k) {return map.set(k, v)});
3152
- });
3153
- }
3154
3421
 
3155
- OrderedMap.of = function(/*...values*/) {
3156
- return this(arguments);
3422
+ function interposeFactory(iterable, separator) {
3423
+ var interposedSequence = makeSequence(iterable);
3424
+ interposedSequence.size = iterable.size && iterable.size * 2 -1;
3425
+ interposedSequence.__iterateUncached = function(fn, reverse) {var this$0 = this;
3426
+ var iterations = 0;
3427
+ iterable.__iterate(function(v, k)
3428
+ {return (!iterations || fn(separator, iterations++, this$0) !== false) &&
3429
+ fn(v, iterations++, this$0) !== false},
3430
+ reverse
3431
+ );
3432
+ return iterations;
3157
3433
  };
3158
-
3159
- OrderedMap.prototype.toString = function() {
3160
- return this.__toString('OrderedMap {', '}');
3434
+ interposedSequence.__iteratorUncached = function(type, reverse) {
3435
+ var iterator = iterable.__iterator(ITERATE_VALUES, reverse);
3436
+ var iterations = 0;
3437
+ var step;
3438
+ return new Iterator(function() {
3439
+ if (!step || iterations % 2) {
3440
+ step = iterator.next();
3441
+ if (step.done) {
3442
+ return step;
3443
+ }
3444
+ }
3445
+ return iterations % 2 ?
3446
+ iteratorValue(type, iterations++, separator) :
3447
+ iteratorValue(type, iterations++, step.value, step);
3448
+ });
3161
3449
  };
3450
+ return interposedSequence;
3451
+ }
3162
3452
 
3163
- // @pragma Access
3164
3453
 
3165
- OrderedMap.prototype.get = function(k, notSetValue) {
3166
- var index = this._map.get(k);
3167
- return index !== undefined ? this._list.get(index)[1] : notSetValue;
3168
- };
3454
+ function sortFactory(iterable, comparator, mapper) {
3455
+ if (!comparator) {
3456
+ comparator = defaultComparator;
3457
+ }
3458
+ var isKeyedIterable = isKeyed(iterable);
3459
+ var index = 0;
3460
+ var entries = iterable.toSeq().map(
3461
+ function(v, k) {return [k, v, index++, mapper ? mapper(v, k, iterable) : v]}
3462
+ ).toArray();
3463
+ entries.sort(function(a, b) {return comparator(a[3], b[3]) || a[2] - b[2]}).forEach(
3464
+ isKeyedIterable ?
3465
+ function(v, i) { entries[i].length = 2; } :
3466
+ function(v, i) { entries[i] = v[1]; }
3467
+ );
3468
+ return isKeyedIterable ? KeyedSeq(entries) :
3469
+ isIndexed(iterable) ? IndexedSeq(entries) :
3470
+ SetSeq(entries);
3471
+ }
3169
3472
 
3170
- // @pragma Modification
3171
3473
 
3172
- OrderedMap.prototype.clear = function() {
3173
- if (this.size === 0) {
3174
- return this;
3175
- }
3176
- if (this.__ownerID) {
3177
- this.size = 0;
3178
- this._map.clear();
3179
- this._list.clear();
3180
- return this;
3181
- }
3182
- return emptyOrderedMap();
3183
- };
3474
+ function maxFactory(iterable, comparator, mapper) {
3475
+ if (!comparator) {
3476
+ comparator = defaultComparator;
3477
+ }
3478
+ if (mapper) {
3479
+ var entry = iterable.toSeq()
3480
+ .map(function(v, k) {return [v, mapper(v, k, iterable)]})
3481
+ .reduce(function(a, b) {return maxCompare(comparator, a[1], b[1]) ? b : a});
3482
+ return entry && entry[0];
3483
+ } else {
3484
+ return iterable.reduce(function(a, b) {return maxCompare(comparator, a, b) ? b : a});
3485
+ }
3486
+ }
3184
3487
 
3185
- OrderedMap.prototype.set = function(k, v) {
3186
- return updateOrderedMap(this, k, v);
3187
- };
3488
+ function maxCompare(comparator, a, b) {
3489
+ var comp = comparator(b, a);
3490
+ // b is considered the new max if the comparator declares them equal, but
3491
+ // they are not equal and b is in fact a nullish value.
3492
+ return (comp === 0 && b !== a && (b === undefined || b === null || b !== b)) || comp > 0;
3493
+ }
3188
3494
 
3189
- OrderedMap.prototype.remove = function(k) {
3190
- return updateOrderedMap(this, k, NOT_SET);
3191
- };
3192
3495
 
3193
- OrderedMap.prototype.wasAltered = function() {
3194
- return this._map.wasAltered() || this._list.wasAltered();
3496
+ function zipWithFactory(keyIter, zipper, iters) {
3497
+ var zipSequence = makeSequence(keyIter);
3498
+ zipSequence.size = new ArraySeq(iters).map(function(i ) {return i.size}).min();
3499
+ // Note: this a generic base implementation of __iterate in terms of
3500
+ // __iterator which may be more generically useful in the future.
3501
+ zipSequence.__iterate = function(fn, reverse) {
3502
+ /* generic:
3503
+ var iterator = this.__iterator(ITERATE_ENTRIES, reverse);
3504
+ var step;
3505
+ var iterations = 0;
3506
+ while (!(step = iterator.next()).done) {
3507
+ iterations++;
3508
+ if (fn(step.value[1], step.value[0], this) === false) {
3509
+ break;
3510
+ }
3511
+ }
3512
+ return iterations;
3513
+ */
3514
+ // indexed:
3515
+ var iterator = this.__iterator(ITERATE_VALUES, reverse);
3516
+ var step;
3517
+ var iterations = 0;
3518
+ while (!(step = iterator.next()).done) {
3519
+ if (fn(step.value, iterations++, this) === false) {
3520
+ break;
3521
+ }
3522
+ }
3523
+ return iterations;
3195
3524
  };
3196
-
3197
- OrderedMap.prototype.__iterate = function(fn, reverse) {var this$0 = this;
3198
- return this._list.__iterate(
3199
- function(entry ) {return entry && fn(entry[1], entry[0], this$0)},
3200
- reverse
3525
+ zipSequence.__iteratorUncached = function(type, reverse) {
3526
+ var iterators = iters.map(function(i )
3527
+ {return (i = Iterable(i), getIterator(reverse ? i.reverse() : i))}
3201
3528
  );
3529
+ var iterations = 0;
3530
+ var isDone = false;
3531
+ return new Iterator(function() {
3532
+ var steps;
3533
+ if (!isDone) {
3534
+ steps = iterators.map(function(i ) {return i.next()});
3535
+ isDone = steps.some(function(s ) {return s.done});
3536
+ }
3537
+ if (isDone) {
3538
+ return iteratorDone();
3539
+ }
3540
+ return iteratorValue(
3541
+ type,
3542
+ iterations++,
3543
+ zipper.apply(null, steps.map(function(s ) {return s.value}))
3544
+ );
3545
+ });
3202
3546
  };
3547
+ return zipSequence
3548
+ }
3203
3549
 
3204
- OrderedMap.prototype.__iterator = function(type, reverse) {
3205
- return this._list.fromEntrySeq().__iterator(type, reverse);
3206
- };
3207
-
3208
- OrderedMap.prototype.__ensureOwner = function(ownerID) {
3209
- if (ownerID === this.__ownerID) {
3210
- return this;
3211
- }
3212
- var newMap = this._map.__ensureOwner(ownerID);
3213
- var newList = this._list.__ensureOwner(ownerID);
3214
- if (!ownerID) {
3215
- this.__ownerID = ownerID;
3216
- this._map = newMap;
3217
- this._list = newList;
3218
- return this;
3219
- }
3220
- return makeOrderedMap(newMap, newList, ownerID, this.__hash);
3221
- };
3222
3550
 
3551
+ // #pragma Helper Functions
3223
3552
 
3224
- function isOrderedMap(maybeOrderedMap) {
3225
- return isMap(maybeOrderedMap) && isOrdered(maybeOrderedMap);
3553
+ function reify(iter, seq) {
3554
+ return isSeq(iter) ? seq : iter.constructor(seq);
3226
3555
  }
3227
3556
 
3228
- OrderedMap.isOrderedMap = isOrderedMap;
3229
-
3230
- OrderedMap.prototype[IS_ORDERED_SENTINEL] = true;
3231
- OrderedMap.prototype[DELETE] = OrderedMap.prototype.remove;
3557
+ function validateEntry(entry) {
3558
+ if (entry !== Object(entry)) {
3559
+ throw new TypeError('Expected [K, V] tuple: ' + entry);
3560
+ }
3561
+ }
3232
3562
 
3563
+ function resolveSize(iter) {
3564
+ assertNotInfinite(iter.size);
3565
+ return ensureSize(iter);
3566
+ }
3233
3567
 
3568
+ function iterableClass(iterable) {
3569
+ return isKeyed(iterable) ? KeyedIterable :
3570
+ isIndexed(iterable) ? IndexedIterable :
3571
+ SetIterable;
3572
+ }
3234
3573
 
3235
- function makeOrderedMap(map, list, ownerID, hash) {
3236
- var omap = Object.create(OrderedMap.prototype);
3237
- omap.size = map ? map.size : 0;
3238
- omap._map = map;
3239
- omap._list = list;
3240
- omap.__ownerID = ownerID;
3241
- omap.__hash = hash;
3242
- return omap;
3574
+ function makeSequence(iterable) {
3575
+ return Object.create(
3576
+ (
3577
+ isKeyed(iterable) ? KeyedSeq :
3578
+ isIndexed(iterable) ? IndexedSeq :
3579
+ SetSeq
3580
+ ).prototype
3581
+ );
3243
3582
  }
3244
3583
 
3245
- var EMPTY_ORDERED_MAP;
3246
- function emptyOrderedMap() {
3247
- return EMPTY_ORDERED_MAP || (EMPTY_ORDERED_MAP = makeOrderedMap(emptyMap(), emptyList()));
3584
+ function cacheResultThrough() {
3585
+ if (this._iter.cacheResult) {
3586
+ this._iter.cacheResult();
3587
+ this.size = this._iter.size;
3588
+ return this;
3589
+ } else {
3590
+ return Seq.prototype.cacheResult.call(this);
3591
+ }
3248
3592
  }
3249
3593
 
3250
- function updateOrderedMap(omap, k, v) {
3251
- var map = omap._map;
3252
- var list = omap._list;
3253
- var i = map.get(k);
3254
- var has = i !== undefined;
3255
- var newMap;
3256
- var newList;
3257
- if (v === NOT_SET) { // removed
3258
- if (!has) {
3259
- return omap;
3260
- }
3261
- if (list.size >= SIZE && list.size >= map.size * 2) {
3262
- newList = list.filter(function(entry, idx) {return entry !== undefined && i !== idx});
3263
- newMap = newList.toKeyedSeq().map(function(entry ) {return entry[0]}).flip().toMap();
3264
- if (omap.__ownerID) {
3265
- newMap.__ownerID = newList.__ownerID = omap.__ownerID;
3266
- }
3267
- } else {
3268
- newMap = map.remove(k);
3269
- newList = i === list.size - 1 ? list.pop() : list.set(i, undefined);
3270
- }
3271
- } else {
3272
- if (has) {
3273
- if (v === list.get(i)[1]) {
3274
- return omap;
3275
- }
3276
- newMap = map;
3277
- newList = list.set(i, [k, v]);
3278
- } else {
3279
- newMap = map.set(k, list.size);
3280
- newList = list.set(list.size, [k, v]);
3594
+ function defaultComparator(a, b) {
3595
+ return a > b ? 1 : a < b ? -1 : 0;
3596
+ }
3597
+
3598
+ function forceIterator(keyPath) {
3599
+ var iter = getIterator(keyPath);
3600
+ if (!iter) {
3601
+ // Array might not be iterable in this environment, so we need a fallback
3602
+ // to our wrapped type.
3603
+ if (!isArrayLike(keyPath)) {
3604
+ throw new TypeError('Expected iterable or array-like: ' + keyPath);
3281
3605
  }
3606
+ iter = getIterator(Iterable(keyPath));
3282
3607
  }
3283
- if (omap.__ownerID) {
3284
- omap.size = newMap.size;
3285
- omap._map = newMap;
3286
- omap._list = newList;
3287
- omap.__hash = undefined;
3288
- return omap;
3289
- }
3290
- return makeOrderedMap(newMap, newList);
3608
+ return iter;
3291
3609
  }
3292
3610
 
3293
- createClass(Stack, IndexedCollection);
3611
+ createClass(Record, KeyedCollection);
3294
3612
 
3295
- // @pragma Construction
3613
+ function Record(defaultValues, name) {
3614
+ var hasInitialized;
3296
3615
 
3297
- function Stack(value) {
3298
- return value === null || value === undefined ? emptyStack() :
3299
- isStack(value) ? value :
3300
- emptyStack().unshiftAll(value);
3301
- }
3616
+ var RecordType = function Record(values) {
3617
+ if (values instanceof RecordType) {
3618
+ return values;
3619
+ }
3620
+ if (!(this instanceof RecordType)) {
3621
+ return new RecordType(values);
3622
+ }
3623
+ if (!hasInitialized) {
3624
+ hasInitialized = true;
3625
+ var keys = Object.keys(defaultValues);
3626
+ setProps(RecordTypePrototype, keys);
3627
+ RecordTypePrototype.size = keys.length;
3628
+ RecordTypePrototype._name = name;
3629
+ RecordTypePrototype._keys = keys;
3630
+ RecordTypePrototype._defaultValues = defaultValues;
3631
+ }
3632
+ this._map = Map(values);
3633
+ };
3302
3634
 
3303
- Stack.of = function(/*...values*/) {
3304
- return this(arguments);
3305
- };
3635
+ var RecordTypePrototype = RecordType.prototype = Object.create(RecordPrototype);
3636
+ RecordTypePrototype.constructor = RecordType;
3306
3637
 
3307
- Stack.prototype.toString = function() {
3308
- return this.__toString('Stack [', ']');
3638
+ return RecordType;
3639
+ }
3640
+
3641
+ Record.prototype.toString = function() {
3642
+ return this.__toString(recordName(this) + ' {', '}');
3309
3643
  };
3310
3644
 
3311
3645
  // @pragma Access
3312
3646
 
3313
- Stack.prototype.get = function(index, notSetValue) {
3314
- var head = this._head;
3315
- index = wrapIndex(this, index);
3316
- while (head && index--) {
3317
- head = head.next;
3318
- }
3319
- return head ? head.value : notSetValue;
3647
+ Record.prototype.has = function(k) {
3648
+ return this._defaultValues.hasOwnProperty(k);
3320
3649
  };
3321
3650
 
3322
- Stack.prototype.peek = function() {
3323
- return this._head && this._head.value;
3651
+ Record.prototype.get = function(k, notSetValue) {
3652
+ if (!this.has(k)) {
3653
+ return notSetValue;
3654
+ }
3655
+ var defaultVal = this._defaultValues[k];
3656
+ return this._map ? this._map.get(k, defaultVal) : defaultVal;
3324
3657
  };
3325
3658
 
3326
3659
  // @pragma Modification
3327
3660
 
3328
- Stack.prototype.push = function(/*...values*/) {
3329
- if (arguments.length === 0) {
3330
- return this;
3331
- }
3332
- var newSize = this.size + arguments.length;
3333
- var head = this._head;
3334
- for (var ii = arguments.length - 1; ii >= 0; ii--) {
3335
- head = {
3336
- value: arguments[ii],
3337
- next: head
3338
- };
3339
- }
3661
+ Record.prototype.clear = function() {
3340
3662
  if (this.__ownerID) {
3341
- this.size = newSize;
3342
- this._head = head;
3343
- this.__hash = undefined;
3344
- this.__altered = true;
3663
+ this._map && this._map.clear();
3345
3664
  return this;
3346
3665
  }
3347
- return makeStack(newSize, head);
3666
+ var RecordType = this.constructor;
3667
+ return RecordType._empty || (RecordType._empty = makeRecord(this, emptyMap()));
3348
3668
  };
3349
3669
 
3350
- Stack.prototype.pushAll = function(iter) {
3351
- iter = IndexedIterable(iter);
3352
- if (iter.size === 0) {
3353
- return this;
3670
+ Record.prototype.set = function(k, v) {
3671
+ if (!this.has(k)) {
3672
+ throw new Error('Cannot set unknown key "' + k + '" on ' + recordName(this));
3354
3673
  }
3355
- assertNotInfinite(iter.size);
3356
- var newSize = this.size;
3357
- var head = this._head;
3358
- iter.reverse().forEach(function(value ) {
3359
- newSize++;
3360
- head = {
3361
- value: value,
3362
- next: head
3363
- };
3364
- });
3365
- if (this.__ownerID) {
3366
- this.size = newSize;
3367
- this._head = head;
3368
- this.__hash = undefined;
3369
- this.__altered = true;
3674
+ var newMap = this._map && this._map.set(k, v);
3675
+ if (this.__ownerID || newMap === this._map) {
3370
3676
  return this;
3371
3677
  }
3372
- return makeStack(newSize, head);
3373
- };
3374
-
3375
- Stack.prototype.pop = function() {
3376
- return this.slice(1);
3377
- };
3378
-
3379
- Stack.prototype.unshift = function(/*...values*/) {
3380
- return this.push.apply(this, arguments);
3381
- };
3382
-
3383
- Stack.prototype.unshiftAll = function(iter) {
3384
- return this.pushAll(iter);
3385
- };
3386
-
3387
- Stack.prototype.shift = function() {
3388
- return this.pop.apply(this, arguments);
3678
+ return makeRecord(this, newMap);
3389
3679
  };
3390
3680
 
3391
- Stack.prototype.clear = function() {
3392
- if (this.size === 0) {
3681
+ Record.prototype.remove = function(k) {
3682
+ if (!this.has(k)) {
3393
3683
  return this;
3394
3684
  }
3395
- if (this.__ownerID) {
3396
- this.size = 0;
3397
- this._head = undefined;
3398
- this.__hash = undefined;
3399
- this.__altered = true;
3685
+ var newMap = this._map && this._map.remove(k);
3686
+ if (this.__ownerID || newMap === this._map) {
3400
3687
  return this;
3401
3688
  }
3402
- return emptyStack();
3689
+ return makeRecord(this, newMap);
3403
3690
  };
3404
3691
 
3405
- Stack.prototype.slice = function(begin, end) {
3406
- if (wholeSlice(begin, end, this.size)) {
3407
- return this;
3408
- }
3409
- var resolvedBegin = resolveBegin(begin, this.size);
3410
- var resolvedEnd = resolveEnd(end, this.size);
3411
- if (resolvedEnd !== this.size) {
3412
- // super.slice(begin, end);
3413
- return IndexedCollection.prototype.slice.call(this, begin, end);
3414
- }
3415
- var newSize = this.size - resolvedBegin;
3416
- var head = this._head;
3417
- while (resolvedBegin--) {
3418
- head = head.next;
3419
- }
3420
- if (this.__ownerID) {
3421
- this.size = newSize;
3422
- this._head = head;
3423
- this.__hash = undefined;
3424
- this.__altered = true;
3425
- return this;
3426
- }
3427
- return makeStack(newSize, head);
3692
+ Record.prototype.wasAltered = function() {
3693
+ return this._map.wasAltered();
3428
3694
  };
3429
3695
 
3430
- // @pragma Mutability
3696
+ Record.prototype.__iterator = function(type, reverse) {var this$0 = this;
3697
+ return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterator(type, reverse);
3698
+ };
3431
3699
 
3432
- Stack.prototype.__ensureOwner = function(ownerID) {
3700
+ Record.prototype.__iterate = function(fn, reverse) {var this$0 = this;
3701
+ return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterate(fn, reverse);
3702
+ };
3703
+
3704
+ Record.prototype.__ensureOwner = function(ownerID) {
3433
3705
  if (ownerID === this.__ownerID) {
3434
3706
  return this;
3435
3707
  }
3708
+ var newMap = this._map && this._map.__ensureOwner(ownerID);
3436
3709
  if (!ownerID) {
3437
3710
  this.__ownerID = ownerID;
3438
- this.__altered = false;
3439
- return this;
3440
- }
3441
- return makeStack(this.size, this._head, ownerID, this.__hash);
3442
- };
3443
-
3444
- // @pragma Iteration
3445
-
3446
- Stack.prototype.__iterate = function(fn, reverse) {
3447
- if (reverse) {
3448
- return this.reverse().__iterate(fn);
3449
- }
3450
- var iterations = 0;
3451
- var node = this._head;
3452
- while (node) {
3453
- if (fn(node.value, iterations++, this) === false) {
3454
- break;
3455
- }
3456
- node = node.next;
3457
- }
3458
- return iterations;
3459
- };
3460
-
3461
- Stack.prototype.__iterator = function(type, reverse) {
3462
- if (reverse) {
3463
- return this.reverse().__iterator(type);
3464
- }
3465
- var iterations = 0;
3466
- var node = this._head;
3467
- return new src_Iterator__Iterator(function() {
3468
- if (node) {
3469
- var value = node.value;
3470
- node = node.next;
3471
- return iteratorValue(type, iterations++, value);
3472
- }
3473
- return iteratorDone();
3474
- });
3711
+ this._map = newMap;
3712
+ return this;
3713
+ }
3714
+ return makeRecord(this, newMap, ownerID);
3475
3715
  };
3476
3716
 
3477
3717
 
3478
- function isStack(maybeStack) {
3479
- return !!(maybeStack && maybeStack[IS_STACK_SENTINEL]);
3480
- }
3481
-
3482
- Stack.isStack = isStack;
3718
+ var RecordPrototype = Record.prototype;
3719
+ RecordPrototype[DELETE] = RecordPrototype.remove;
3720
+ RecordPrototype.deleteIn =
3721
+ RecordPrototype.removeIn = MapPrototype.removeIn;
3722
+ RecordPrototype.merge = MapPrototype.merge;
3723
+ RecordPrototype.mergeWith = MapPrototype.mergeWith;
3724
+ RecordPrototype.mergeIn = MapPrototype.mergeIn;
3725
+ RecordPrototype.mergeDeep = MapPrototype.mergeDeep;
3726
+ RecordPrototype.mergeDeepWith = MapPrototype.mergeDeepWith;
3727
+ RecordPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
3728
+ RecordPrototype.setIn = MapPrototype.setIn;
3729
+ RecordPrototype.update = MapPrototype.update;
3730
+ RecordPrototype.updateIn = MapPrototype.updateIn;
3731
+ RecordPrototype.withMutations = MapPrototype.withMutations;
3732
+ RecordPrototype.asMutable = MapPrototype.asMutable;
3733
+ RecordPrototype.asImmutable = MapPrototype.asImmutable;
3483
3734
 
3484
- var IS_STACK_SENTINEL = '@@__IMMUTABLE_STACK__@@';
3485
3735
 
3486
- var StackPrototype = Stack.prototype;
3487
- StackPrototype[IS_STACK_SENTINEL] = true;
3488
- StackPrototype.withMutations = MapPrototype.withMutations;
3489
- StackPrototype.asMutable = MapPrototype.asMutable;
3490
- StackPrototype.asImmutable = MapPrototype.asImmutable;
3491
- StackPrototype.wasAltered = MapPrototype.wasAltered;
3736
+ function makeRecord(likeRecord, map, ownerID) {
3737
+ var record = Object.create(Object.getPrototypeOf(likeRecord));
3738
+ record._map = map;
3739
+ record.__ownerID = ownerID;
3740
+ return record;
3741
+ }
3492
3742
 
3743
+ function recordName(record) {
3744
+ return record._name || record.constructor.name || 'Record';
3745
+ }
3493
3746
 
3494
- function makeStack(size, head, ownerID, hash) {
3495
- var map = Object.create(StackPrototype);
3496
- map.size = size;
3497
- map._head = head;
3498
- map.__ownerID = ownerID;
3499
- map.__hash = hash;
3500
- map.__altered = false;
3501
- return map;
3747
+ function setProps(prototype, names) {
3748
+ try {
3749
+ names.forEach(setProp.bind(undefined, prototype));
3750
+ } catch (error) {
3751
+ // Object.defineProperty failed. Probably IE8.
3752
+ }
3502
3753
  }
3503
3754
 
3504
- var EMPTY_STACK;
3505
- function emptyStack() {
3506
- return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
3755
+ function setProp(prototype, name) {
3756
+ Object.defineProperty(prototype, name, {
3757
+ get: function() {
3758
+ return this.get(name);
3759
+ },
3760
+ set: function(value) {
3761
+ invariant(this.__ownerID, 'Cannot set on an immutable record.');
3762
+ this.set(name, value);
3763
+ }
3764
+ });
3507
3765
  }
3508
3766
 
3509
- createClass(src_Set__Set, SetCollection);
3767
+ createClass(Set, SetCollection);
3510
3768
 
3511
3769
  // @pragma Construction
3512
3770
 
3513
- function src_Set__Set(value) {
3771
+ function Set(value) {
3514
3772
  return value === null || value === undefined ? emptySet() :
3515
- isSet(value) ? value :
3773
+ isSet(value) && !isOrdered(value) ? value :
3516
3774
  emptySet().withMutations(function(set ) {
3517
3775
  var iter = SetIterable(value);
3518
3776
  assertNotInfinite(iter.size);
@@ -3520,41 +3778,41 @@
3520
3778
  });
3521
3779
  }
3522
3780
 
3523
- src_Set__Set.of = function(/*...values*/) {
3781
+ Set.of = function(/*...values*/) {
3524
3782
  return this(arguments);
3525
3783
  };
3526
3784
 
3527
- src_Set__Set.fromKeys = function(value) {
3785
+ Set.fromKeys = function(value) {
3528
3786
  return this(KeyedIterable(value).keySeq());
3529
3787
  };
3530
3788
 
3531
- src_Set__Set.prototype.toString = function() {
3789
+ Set.prototype.toString = function() {
3532
3790
  return this.__toString('Set {', '}');
3533
3791
  };
3534
3792
 
3535
3793
  // @pragma Access
3536
3794
 
3537
- src_Set__Set.prototype.has = function(value) {
3795
+ Set.prototype.has = function(value) {
3538
3796
  return this._map.has(value);
3539
3797
  };
3540
3798
 
3541
3799
  // @pragma Modification
3542
3800
 
3543
- src_Set__Set.prototype.add = function(value) {
3801
+ Set.prototype.add = function(value) {
3544
3802
  return updateSet(this, this._map.set(value, true));
3545
3803
  };
3546
3804
 
3547
- src_Set__Set.prototype.remove = function(value) {
3805
+ Set.prototype.remove = function(value) {
3548
3806
  return updateSet(this, this._map.remove(value));
3549
3807
  };
3550
3808
 
3551
- src_Set__Set.prototype.clear = function() {
3809
+ Set.prototype.clear = function() {
3552
3810
  return updateSet(this, this._map.clear());
3553
3811
  };
3554
3812
 
3555
3813
  // @pragma Composition
3556
3814
 
3557
- src_Set__Set.prototype.union = function() {var iters = SLICE$0.call(arguments, 0);
3815
+ Set.prototype.union = function() {var iters = SLICE$0.call(arguments, 0);
3558
3816
  iters = iters.filter(function(x ) {return x.size !== 0});
3559
3817
  if (iters.length === 0) {
3560
3818
  return this;
@@ -3569,7 +3827,7 @@
3569
3827
  });
3570
3828
  };
3571
3829
 
3572
- src_Set__Set.prototype.intersect = function() {var iters = SLICE$0.call(arguments, 0);
3830
+ Set.prototype.intersect = function() {var iters = SLICE$0.call(arguments, 0);
3573
3831
  if (iters.length === 0) {
3574
3832
  return this;
3575
3833
  }
@@ -3584,7 +3842,7 @@
3584
3842
  });
3585
3843
  };
3586
3844
 
3587
- src_Set__Set.prototype.subtract = function() {var iters = SLICE$0.call(arguments, 0);
3845
+ Set.prototype.subtract = function() {var iters = SLICE$0.call(arguments, 0);
3588
3846
  if (iters.length === 0) {
3589
3847
  return this;
3590
3848
  }
@@ -3599,551 +3857,361 @@
3599
3857
  });
3600
3858
  };
3601
3859
 
3602
- src_Set__Set.prototype.merge = function() {
3860
+ Set.prototype.merge = function() {
3603
3861
  return this.union.apply(this, arguments);
3604
3862
  };
3605
3863
 
3606
- src_Set__Set.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
3864
+ Set.prototype.mergeWith = function(merger) {var iters = SLICE$0.call(arguments, 1);
3607
3865
  return this.union.apply(this, iters);
3608
3866
  };
3609
3867
 
3610
- src_Set__Set.prototype.sort = function(comparator) {
3868
+ Set.prototype.sort = function(comparator) {
3611
3869
  // Late binding
3612
3870
  return OrderedSet(sortFactory(this, comparator));
3613
3871
  };
3614
3872
 
3615
- src_Set__Set.prototype.sortBy = function(mapper, comparator) {
3616
- // Late binding
3617
- return OrderedSet(sortFactory(this, comparator, mapper));
3618
- };
3619
-
3620
- src_Set__Set.prototype.wasAltered = function() {
3621
- return this._map.wasAltered();
3622
- };
3623
-
3624
- src_Set__Set.prototype.__iterate = function(fn, reverse) {var this$0 = this;
3625
- return this._map.__iterate(function(_, k) {return fn(k, k, this$0)}, reverse);
3626
- };
3627
-
3628
- src_Set__Set.prototype.__iterator = function(type, reverse) {
3629
- return this._map.map(function(_, k) {return k}).__iterator(type, reverse);
3630
- };
3631
-
3632
- src_Set__Set.prototype.__ensureOwner = function(ownerID) {
3633
- if (ownerID === this.__ownerID) {
3634
- return this;
3635
- }
3636
- var newMap = this._map.__ensureOwner(ownerID);
3637
- if (!ownerID) {
3638
- this.__ownerID = ownerID;
3639
- this._map = newMap;
3640
- return this;
3641
- }
3642
- return this.__make(newMap, ownerID);
3643
- };
3644
-
3645
-
3646
- function isSet(maybeSet) {
3647
- return !!(maybeSet && maybeSet[IS_SET_SENTINEL]);
3648
- }
3649
-
3650
- src_Set__Set.isSet = isSet;
3651
-
3652
- var IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
3653
-
3654
- var SetPrototype = src_Set__Set.prototype;
3655
- SetPrototype[IS_SET_SENTINEL] = true;
3656
- SetPrototype[DELETE] = SetPrototype.remove;
3657
- SetPrototype.mergeDeep = SetPrototype.merge;
3658
- SetPrototype.mergeDeepWith = SetPrototype.mergeWith;
3659
- SetPrototype.withMutations = MapPrototype.withMutations;
3660
- SetPrototype.asMutable = MapPrototype.asMutable;
3661
- SetPrototype.asImmutable = MapPrototype.asImmutable;
3662
-
3663
- SetPrototype.__empty = emptySet;
3664
- SetPrototype.__make = makeSet;
3665
-
3666
- function updateSet(set, newMap) {
3667
- if (set.__ownerID) {
3668
- set.size = newMap.size;
3669
- set._map = newMap;
3670
- return set;
3671
- }
3672
- return newMap === set._map ? set :
3673
- newMap.size === 0 ? set.__empty() :
3674
- set.__make(newMap);
3675
- }
3676
-
3677
- function makeSet(map, ownerID) {
3678
- var set = Object.create(SetPrototype);
3679
- set.size = map ? map.size : 0;
3680
- set._map = map;
3681
- set.__ownerID = ownerID;
3682
- return set;
3683
- }
3684
-
3685
- var EMPTY_SET;
3686
- function emptySet() {
3687
- return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
3688
- }
3689
-
3690
- createClass(OrderedSet, src_Set__Set);
3691
-
3692
- // @pragma Construction
3693
-
3694
- function OrderedSet(value) {
3695
- return value === null || value === undefined ? emptyOrderedSet() :
3696
- isOrderedSet(value) ? value :
3697
- emptyOrderedSet().withMutations(function(set ) {
3698
- var iter = SetIterable(value);
3699
- assertNotInfinite(iter.size);
3700
- iter.forEach(function(v ) {return set.add(v)});
3701
- });
3702
- }
3703
-
3704
- OrderedSet.of = function(/*...values*/) {
3705
- return this(arguments);
3706
- };
3707
-
3708
- OrderedSet.fromKeys = function(value) {
3709
- return this(KeyedIterable(value).keySeq());
3710
- };
3711
-
3712
- OrderedSet.prototype.toString = function() {
3713
- return this.__toString('OrderedSet {', '}');
3714
- };
3715
-
3716
-
3717
- function isOrderedSet(maybeOrderedSet) {
3718
- return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
3719
- }
3720
-
3721
- OrderedSet.isOrderedSet = isOrderedSet;
3722
-
3723
- var OrderedSetPrototype = OrderedSet.prototype;
3724
- OrderedSetPrototype[IS_ORDERED_SENTINEL] = true;
3725
-
3726
- OrderedSetPrototype.__empty = emptyOrderedSet;
3727
- OrderedSetPrototype.__make = makeOrderedSet;
3728
-
3729
- function makeOrderedSet(map, ownerID) {
3730
- var set = Object.create(OrderedSetPrototype);
3731
- set.size = map ? map.size : 0;
3732
- set._map = map;
3733
- set.__ownerID = ownerID;
3734
- return set;
3735
- }
3736
-
3737
- var EMPTY_ORDERED_SET;
3738
- function emptyOrderedSet() {
3739
- return EMPTY_ORDERED_SET || (EMPTY_ORDERED_SET = makeOrderedSet(emptyOrderedMap()));
3740
- }
3741
-
3742
- createClass(Record, KeyedCollection);
3743
-
3744
- function Record(defaultValues, name) {
3745
- var hasInitialized;
3746
-
3747
- var RecordType = function Record(values) {
3748
- if (values instanceof RecordType) {
3749
- return values;
3750
- }
3751
- if (!(this instanceof RecordType)) {
3752
- return new RecordType(values);
3753
- }
3754
- if (!hasInitialized) {
3755
- hasInitialized = true;
3756
- var keys = Object.keys(defaultValues);
3757
- setProps(RecordTypePrototype, keys);
3758
- RecordTypePrototype.size = keys.length;
3759
- RecordTypePrototype._name = name;
3760
- RecordTypePrototype._keys = keys;
3761
- RecordTypePrototype._defaultValues = defaultValues;
3762
- }
3763
- this._map = src_Map__Map(values);
3764
- };
3765
-
3766
- var RecordTypePrototype = RecordType.prototype = Object.create(RecordPrototype);
3767
- RecordTypePrototype.constructor = RecordType;
3768
-
3769
- return RecordType;
3770
- }
3771
-
3772
- Record.prototype.toString = function() {
3773
- return this.__toString(recordName(this) + ' {', '}');
3774
- };
3775
-
3776
- // @pragma Access
3777
-
3778
- Record.prototype.has = function(k) {
3779
- return this._defaultValues.hasOwnProperty(k);
3780
- };
3781
-
3782
- Record.prototype.get = function(k, notSetValue) {
3783
- if (!this.has(k)) {
3784
- return notSetValue;
3785
- }
3786
- var defaultVal = this._defaultValues[k];
3787
- return this._map ? this._map.get(k, defaultVal) : defaultVal;
3788
- };
3789
-
3790
- // @pragma Modification
3791
-
3792
- Record.prototype.clear = function() {
3793
- if (this.__ownerID) {
3794
- this._map && this._map.clear();
3795
- return this;
3796
- }
3797
- var RecordType = this.constructor;
3798
- return RecordType._empty || (RecordType._empty = makeRecord(this, emptyMap()));
3799
- };
3800
-
3801
- Record.prototype.set = function(k, v) {
3802
- if (!this.has(k)) {
3803
- throw new Error('Cannot set unknown key "' + k + '" on ' + recordName(this));
3804
- }
3805
- var newMap = this._map && this._map.set(k, v);
3806
- if (this.__ownerID || newMap === this._map) {
3807
- return this;
3808
- }
3809
- return makeRecord(this, newMap);
3810
- };
3811
-
3812
- Record.prototype.remove = function(k) {
3813
- if (!this.has(k)) {
3814
- return this;
3815
- }
3816
- var newMap = this._map && this._map.remove(k);
3817
- if (this.__ownerID || newMap === this._map) {
3818
- return this;
3819
- }
3820
- return makeRecord(this, newMap);
3873
+ Set.prototype.sortBy = function(mapper, comparator) {
3874
+ // Late binding
3875
+ return OrderedSet(sortFactory(this, comparator, mapper));
3821
3876
  };
3822
3877
 
3823
- Record.prototype.wasAltered = function() {
3878
+ Set.prototype.wasAltered = function() {
3824
3879
  return this._map.wasAltered();
3825
3880
  };
3826
3881
 
3827
- Record.prototype.__iterator = function(type, reverse) {var this$0 = this;
3828
- return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterator(type, reverse);
3882
+ Set.prototype.__iterate = function(fn, reverse) {var this$0 = this;
3883
+ return this._map.__iterate(function(_, k) {return fn(k, k, this$0)}, reverse);
3829
3884
  };
3830
3885
 
3831
- Record.prototype.__iterate = function(fn, reverse) {var this$0 = this;
3832
- return KeyedIterable(this._defaultValues).map(function(_, k) {return this$0.get(k)}).__iterate(fn, reverse);
3886
+ Set.prototype.__iterator = function(type, reverse) {
3887
+ return this._map.map(function(_, k) {return k}).__iterator(type, reverse);
3833
3888
  };
3834
3889
 
3835
- Record.prototype.__ensureOwner = function(ownerID) {
3890
+ Set.prototype.__ensureOwner = function(ownerID) {
3836
3891
  if (ownerID === this.__ownerID) {
3837
3892
  return this;
3838
3893
  }
3839
- var newMap = this._map && this._map.__ensureOwner(ownerID);
3894
+ var newMap = this._map.__ensureOwner(ownerID);
3840
3895
  if (!ownerID) {
3841
3896
  this.__ownerID = ownerID;
3842
3897
  this._map = newMap;
3843
3898
  return this;
3844
3899
  }
3845
- return makeRecord(this, newMap, ownerID);
3900
+ return this.__make(newMap, ownerID);
3846
3901
  };
3847
3902
 
3848
3903
 
3849
- var RecordPrototype = Record.prototype;
3850
- RecordPrototype[DELETE] = RecordPrototype.remove;
3851
- RecordPrototype.deleteIn =
3852
- RecordPrototype.removeIn = MapPrototype.removeIn;
3853
- RecordPrototype.merge = MapPrototype.merge;
3854
- RecordPrototype.mergeWith = MapPrototype.mergeWith;
3855
- RecordPrototype.mergeIn = MapPrototype.mergeIn;
3856
- RecordPrototype.mergeDeep = MapPrototype.mergeDeep;
3857
- RecordPrototype.mergeDeepWith = MapPrototype.mergeDeepWith;
3858
- RecordPrototype.mergeDeepIn = MapPrototype.mergeDeepIn;
3859
- RecordPrototype.setIn = MapPrototype.setIn;
3860
- RecordPrototype.update = MapPrototype.update;
3861
- RecordPrototype.updateIn = MapPrototype.updateIn;
3862
- RecordPrototype.withMutations = MapPrototype.withMutations;
3863
- RecordPrototype.asMutable = MapPrototype.asMutable;
3864
- RecordPrototype.asImmutable = MapPrototype.asImmutable;
3904
+ function isSet(maybeSet) {
3905
+ return !!(maybeSet && maybeSet[IS_SET_SENTINEL]);
3906
+ }
3865
3907
 
3908
+ Set.isSet = isSet;
3866
3909
 
3867
- function makeRecord(likeRecord, map, ownerID) {
3868
- var record = Object.create(Object.getPrototypeOf(likeRecord));
3869
- record._map = map;
3870
- record.__ownerID = ownerID;
3871
- return record;
3872
- }
3910
+ var IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
3873
3911
 
3874
- function recordName(record) {
3875
- return record._name || record.constructor.name || 'Record';
3876
- }
3912
+ var SetPrototype = Set.prototype;
3913
+ SetPrototype[IS_SET_SENTINEL] = true;
3914
+ SetPrototype[DELETE] = SetPrototype.remove;
3915
+ SetPrototype.mergeDeep = SetPrototype.merge;
3916
+ SetPrototype.mergeDeepWith = SetPrototype.mergeWith;
3917
+ SetPrototype.withMutations = MapPrototype.withMutations;
3918
+ SetPrototype.asMutable = MapPrototype.asMutable;
3919
+ SetPrototype.asImmutable = MapPrototype.asImmutable;
3877
3920
 
3878
- function setProps(prototype, names) {
3879
- try {
3880
- names.forEach(setProp.bind(undefined, prototype));
3881
- } catch (error) {
3882
- // Object.defineProperty failed. Probably IE8.
3921
+ SetPrototype.__empty = emptySet;
3922
+ SetPrototype.__make = makeSet;
3923
+
3924
+ function updateSet(set, newMap) {
3925
+ if (set.__ownerID) {
3926
+ set.size = newMap.size;
3927
+ set._map = newMap;
3928
+ return set;
3883
3929
  }
3930
+ return newMap === set._map ? set :
3931
+ newMap.size === 0 ? set.__empty() :
3932
+ set.__make(newMap);
3884
3933
  }
3885
3934
 
3886
- function setProp(prototype, name) {
3887
- Object.defineProperty(prototype, name, {
3888
- get: function() {
3889
- return this.get(name);
3890
- },
3891
- set: function(value) {
3892
- invariant(this.__ownerID, 'Cannot set on an immutable record.');
3893
- this.set(name, value);
3894
- }
3895
- });
3935
+ function makeSet(map, ownerID) {
3936
+ var set = Object.create(SetPrototype);
3937
+ set.size = map ? map.size : 0;
3938
+ set._map = map;
3939
+ set.__ownerID = ownerID;
3940
+ return set;
3896
3941
  }
3897
3942
 
3898
- function deepEqual(a, b) {
3899
- if (a === b) {
3900
- return true;
3901
- }
3902
-
3903
- if (
3904
- !isIterable(b) ||
3905
- a.size !== undefined && b.size !== undefined && a.size !== b.size ||
3906
- a.__hash !== undefined && b.__hash !== undefined && a.__hash !== b.__hash ||
3907
- isKeyed(a) !== isKeyed(b) ||
3908
- isIndexed(a) !== isIndexed(b) ||
3909
- isOrdered(a) !== isOrdered(b)
3910
- ) {
3911
- return false;
3912
- }
3943
+ var EMPTY_SET;
3944
+ function emptySet() {
3945
+ return EMPTY_SET || (EMPTY_SET = makeSet(emptyMap()));
3946
+ }
3913
3947
 
3914
- if (a.size === 0 && b.size === 0) {
3915
- return true;
3916
- }
3948
+ createClass(OrderedSet, Set);
3917
3949
 
3918
- var notAssociative = !isAssociative(a);
3950
+ // @pragma Construction
3919
3951
 
3920
- if (isOrdered(a)) {
3921
- var entries = a.entries();
3922
- return b.every(function(v, k) {
3923
- var entry = entries.next().value;
3924
- return entry && is(entry[1], v) && (notAssociative || is(entry[0], k));
3925
- }) && entries.next().done;
3952
+ function OrderedSet(value) {
3953
+ return value === null || value === undefined ? emptyOrderedSet() :
3954
+ isOrderedSet(value) ? value :
3955
+ emptyOrderedSet().withMutations(function(set ) {
3956
+ var iter = SetIterable(value);
3957
+ assertNotInfinite(iter.size);
3958
+ iter.forEach(function(v ) {return set.add(v)});
3959
+ });
3926
3960
  }
3927
3961
 
3928
- var flipped = false;
3962
+ OrderedSet.of = function(/*...values*/) {
3963
+ return this(arguments);
3964
+ };
3929
3965
 
3930
- if (a.size === undefined) {
3931
- if (b.size === undefined) {
3932
- if (typeof a.cacheResult === 'function') {
3933
- a.cacheResult();
3934
- }
3935
- } else {
3936
- flipped = true;
3937
- var _ = a;
3938
- a = b;
3939
- b = _;
3940
- }
3941
- }
3966
+ OrderedSet.fromKeys = function(value) {
3967
+ return this(KeyedIterable(value).keySeq());
3968
+ };
3942
3969
 
3943
- var allEqual = true;
3944
- var bSize = b.__iterate(function(v, k) {
3945
- if (notAssociative ? !a.has(v) :
3946
- flipped ? !is(v, a.get(k, NOT_SET)) : !is(a.get(k, NOT_SET), v)) {
3947
- allEqual = false;
3948
- return false;
3949
- }
3950
- });
3970
+ OrderedSet.prototype.toString = function() {
3971
+ return this.__toString('OrderedSet {', '}');
3972
+ };
3951
3973
 
3952
- return allEqual && a.size === bSize;
3974
+
3975
+ function isOrderedSet(maybeOrderedSet) {
3976
+ return isSet(maybeOrderedSet) && isOrdered(maybeOrderedSet);
3953
3977
  }
3954
3978
 
3955
- createClass(Range, IndexedSeq);
3979
+ OrderedSet.isOrderedSet = isOrderedSet;
3956
3980
 
3957
- function Range(start, end, step) {
3958
- if (!(this instanceof Range)) {
3959
- return new Range(start, end, step);
3960
- }
3961
- invariant(step !== 0, 'Cannot step a Range by 0');
3962
- start = start || 0;
3963
- if (end === undefined) {
3964
- end = Infinity;
3965
- }
3966
- step = step === undefined ? 1 : Math.abs(step);
3967
- if (end < start) {
3968
- step = -step;
3969
- }
3970
- this._start = start;
3971
- this._end = end;
3972
- this._step = step;
3973
- this.size = Math.max(0, Math.ceil((end - start) / step - 1) + 1);
3974
- if (this.size === 0) {
3975
- if (EMPTY_RANGE) {
3976
- return EMPTY_RANGE;
3977
- }
3978
- EMPTY_RANGE = this;
3979
- }
3980
- }
3981
+ var OrderedSetPrototype = OrderedSet.prototype;
3982
+ OrderedSetPrototype[IS_ORDERED_SENTINEL] = true;
3981
3983
 
3982
- Range.prototype.toString = function() {
3983
- if (this.size === 0) {
3984
- return 'Range []';
3985
- }
3986
- return 'Range [ ' +
3987
- this._start + '...' + this._end +
3988
- (this._step > 1 ? ' by ' + this._step : '') +
3989
- ' ]';
3990
- };
3984
+ OrderedSetPrototype.__empty = emptyOrderedSet;
3985
+ OrderedSetPrototype.__make = makeOrderedSet;
3991
3986
 
3992
- Range.prototype.get = function(index, notSetValue) {
3993
- return this.has(index) ?
3994
- this._start + wrapIndex(this, index) * this._step :
3995
- notSetValue;
3996
- };
3987
+ function makeOrderedSet(map, ownerID) {
3988
+ var set = Object.create(OrderedSetPrototype);
3989
+ set.size = map ? map.size : 0;
3990
+ set._map = map;
3991
+ set.__ownerID = ownerID;
3992
+ return set;
3993
+ }
3997
3994
 
3998
- Range.prototype.includes = function(searchValue) {
3999
- var possibleIndex = (searchValue - this._start) / this._step;
4000
- return possibleIndex >= 0 &&
4001
- possibleIndex < this.size &&
4002
- possibleIndex === Math.floor(possibleIndex);
4003
- };
3995
+ var EMPTY_ORDERED_SET;
3996
+ function emptyOrderedSet() {
3997
+ return EMPTY_ORDERED_SET || (EMPTY_ORDERED_SET = makeOrderedSet(emptyOrderedMap()));
3998
+ }
4004
3999
 
4005
- Range.prototype.slice = function(begin, end) {
4006
- if (wholeSlice(begin, end, this.size)) {
4007
- return this;
4008
- }
4009
- begin = resolveBegin(begin, this.size);
4010
- end = resolveEnd(end, this.size);
4011
- if (end <= begin) {
4012
- return new Range(0, 0);
4013
- }
4014
- return new Range(this.get(begin, this._end), this.get(end, this._end), this._step);
4015
- };
4000
+ createClass(Stack, IndexedCollection);
4016
4001
 
4017
- Range.prototype.indexOf = function(searchValue) {
4018
- var offsetValue = searchValue - this._start;
4019
- if (offsetValue % this._step === 0) {
4020
- var index = offsetValue / this._step;
4021
- if (index >= 0 && index < this.size) {
4022
- return index
4023
- }
4024
- }
4025
- return -1;
4026
- };
4002
+ // @pragma Construction
4027
4003
 
4028
- Range.prototype.lastIndexOf = function(searchValue) {
4029
- return this.indexOf(searchValue);
4004
+ function Stack(value) {
4005
+ return value === null || value === undefined ? emptyStack() :
4006
+ isStack(value) ? value :
4007
+ emptyStack().unshiftAll(value);
4008
+ }
4009
+
4010
+ Stack.of = function(/*...values*/) {
4011
+ return this(arguments);
4030
4012
  };
4031
4013
 
4032
- Range.prototype.__iterate = function(fn, reverse) {
4033
- var maxIndex = this.size - 1;
4034
- var step = this._step;
4035
- var value = reverse ? this._start + maxIndex * step : this._start;
4036
- for (var ii = 0; ii <= maxIndex; ii++) {
4037
- if (fn(value, ii, this) === false) {
4038
- return ii + 1;
4039
- }
4040
- value += reverse ? -step : step;
4041
- }
4042
- return ii;
4014
+ Stack.prototype.toString = function() {
4015
+ return this.__toString('Stack [', ']');
4043
4016
  };
4044
4017
 
4045
- Range.prototype.__iterator = function(type, reverse) {
4046
- var maxIndex = this.size - 1;
4047
- var step = this._step;
4048
- var value = reverse ? this._start + maxIndex * step : this._start;
4049
- var ii = 0;
4050
- return new src_Iterator__Iterator(function() {
4051
- var v = value;
4052
- value += reverse ? -step : step;
4053
- return ii > maxIndex ? iteratorDone() : iteratorValue(type, ii++, v);
4054
- });
4055
- };
4018
+ // @pragma Access
4056
4019
 
4057
- Range.prototype.equals = function(other) {
4058
- return other instanceof Range ?
4059
- this._start === other._start &&
4060
- this._end === other._end &&
4061
- this._step === other._step :
4062
- deepEqual(this, other);
4020
+ Stack.prototype.get = function(index, notSetValue) {
4021
+ var head = this._head;
4022
+ index = wrapIndex(this, index);
4023
+ while (head && index--) {
4024
+ head = head.next;
4025
+ }
4026
+ return head ? head.value : notSetValue;
4063
4027
  };
4064
4028
 
4029
+ Stack.prototype.peek = function() {
4030
+ return this._head && this._head.value;
4031
+ };
4065
4032
 
4066
- var EMPTY_RANGE;
4067
-
4068
- createClass(Repeat, IndexedSeq);
4033
+ // @pragma Modification
4069
4034
 
4070
- function Repeat(value, times) {
4071
- if (!(this instanceof Repeat)) {
4072
- return new Repeat(value, times);
4035
+ Stack.prototype.push = function(/*...values*/) {
4036
+ if (arguments.length === 0) {
4037
+ return this;
4073
4038
  }
4074
- this._value = value;
4075
- this.size = times === undefined ? Infinity : Math.max(0, times);
4076
- if (this.size === 0) {
4077
- if (EMPTY_REPEAT) {
4078
- return EMPTY_REPEAT;
4079
- }
4080
- EMPTY_REPEAT = this;
4039
+ var newSize = this.size + arguments.length;
4040
+ var head = this._head;
4041
+ for (var ii = arguments.length - 1; ii >= 0; ii--) {
4042
+ head = {
4043
+ value: arguments[ii],
4044
+ next: head
4045
+ };
4081
4046
  }
4082
- }
4047
+ if (this.__ownerID) {
4048
+ this.size = newSize;
4049
+ this._head = head;
4050
+ this.__hash = undefined;
4051
+ this.__altered = true;
4052
+ return this;
4053
+ }
4054
+ return makeStack(newSize, head);
4055
+ };
4083
4056
 
4084
- Repeat.prototype.toString = function() {
4085
- if (this.size === 0) {
4086
- return 'Repeat []';
4057
+ Stack.prototype.pushAll = function(iter) {
4058
+ iter = IndexedIterable(iter);
4059
+ if (iter.size === 0) {
4060
+ return this;
4087
4061
  }
4088
- return 'Repeat [ ' + this._value + ' ' + this.size + ' times ]';
4062
+ assertNotInfinite(iter.size);
4063
+ var newSize = this.size;
4064
+ var head = this._head;
4065
+ iter.reverse().forEach(function(value ) {
4066
+ newSize++;
4067
+ head = {
4068
+ value: value,
4069
+ next: head
4070
+ };
4071
+ });
4072
+ if (this.__ownerID) {
4073
+ this.size = newSize;
4074
+ this._head = head;
4075
+ this.__hash = undefined;
4076
+ this.__altered = true;
4077
+ return this;
4078
+ }
4079
+ return makeStack(newSize, head);
4089
4080
  };
4090
4081
 
4091
- Repeat.prototype.get = function(index, notSetValue) {
4092
- return this.has(index) ? this._value : notSetValue;
4082
+ Stack.prototype.pop = function() {
4083
+ return this.slice(1);
4093
4084
  };
4094
4085
 
4095
- Repeat.prototype.includes = function(searchValue) {
4096
- return is(this._value, searchValue);
4086
+ Stack.prototype.unshift = function(/*...values*/) {
4087
+ return this.push.apply(this, arguments);
4097
4088
  };
4098
4089
 
4099
- Repeat.prototype.slice = function(begin, end) {
4100
- var size = this.size;
4101
- return wholeSlice(begin, end, size) ? this :
4102
- new Repeat(this._value, resolveEnd(end, size) - resolveBegin(begin, size));
4090
+ Stack.prototype.unshiftAll = function(iter) {
4091
+ return this.pushAll(iter);
4103
4092
  };
4104
4093
 
4105
- Repeat.prototype.reverse = function() {
4106
- return this;
4094
+ Stack.prototype.shift = function() {
4095
+ return this.pop.apply(this, arguments);
4107
4096
  };
4108
4097
 
4109
- Repeat.prototype.indexOf = function(searchValue) {
4110
- if (is(this._value, searchValue)) {
4111
- return 0;
4098
+ Stack.prototype.clear = function() {
4099
+ if (this.size === 0) {
4100
+ return this;
4112
4101
  }
4113
- return -1;
4102
+ if (this.__ownerID) {
4103
+ this.size = 0;
4104
+ this._head = undefined;
4105
+ this.__hash = undefined;
4106
+ this.__altered = true;
4107
+ return this;
4108
+ }
4109
+ return emptyStack();
4114
4110
  };
4115
4111
 
4116
- Repeat.prototype.lastIndexOf = function(searchValue) {
4117
- if (is(this._value, searchValue)) {
4118
- return this.size;
4112
+ Stack.prototype.slice = function(begin, end) {
4113
+ if (wholeSlice(begin, end, this.size)) {
4114
+ return this;
4119
4115
  }
4120
- return -1;
4116
+ var resolvedBegin = resolveBegin(begin, this.size);
4117
+ var resolvedEnd = resolveEnd(end, this.size);
4118
+ if (resolvedEnd !== this.size) {
4119
+ // super.slice(begin, end);
4120
+ return IndexedCollection.prototype.slice.call(this, begin, end);
4121
+ }
4122
+ var newSize = this.size - resolvedBegin;
4123
+ var head = this._head;
4124
+ while (resolvedBegin--) {
4125
+ head = head.next;
4126
+ }
4127
+ if (this.__ownerID) {
4128
+ this.size = newSize;
4129
+ this._head = head;
4130
+ this.__hash = undefined;
4131
+ this.__altered = true;
4132
+ return this;
4133
+ }
4134
+ return makeStack(newSize, head);
4121
4135
  };
4122
4136
 
4123
- Repeat.prototype.__iterate = function(fn, reverse) {
4124
- for (var ii = 0; ii < this.size; ii++) {
4125
- if (fn(this._value, ii, this) === false) {
4126
- return ii + 1;
4127
- }
4137
+ // @pragma Mutability
4138
+
4139
+ Stack.prototype.__ensureOwner = function(ownerID) {
4140
+ if (ownerID === this.__ownerID) {
4141
+ return this;
4128
4142
  }
4129
- return ii;
4143
+ if (!ownerID) {
4144
+ this.__ownerID = ownerID;
4145
+ this.__altered = false;
4146
+ return this;
4147
+ }
4148
+ return makeStack(this.size, this._head, ownerID, this.__hash);
4130
4149
  };
4131
4150
 
4132
- Repeat.prototype.__iterator = function(type, reverse) {var this$0 = this;
4133
- var ii = 0;
4134
- return new src_Iterator__Iterator(function()
4135
- {return ii < this$0.size ? iteratorValue(type, ii++, this$0._value) : iteratorDone()}
4136
- );
4151
+ // @pragma Iteration
4152
+
4153
+ Stack.prototype.__iterate = function(fn, reverse) {
4154
+ if (reverse) {
4155
+ return this.reverse().__iterate(fn);
4156
+ }
4157
+ var iterations = 0;
4158
+ var node = this._head;
4159
+ while (node) {
4160
+ if (fn(node.value, iterations++, this) === false) {
4161
+ break;
4162
+ }
4163
+ node = node.next;
4164
+ }
4165
+ return iterations;
4137
4166
  };
4138
4167
 
4139
- Repeat.prototype.equals = function(other) {
4140
- return other instanceof Repeat ?
4141
- is(this._value, other._value) :
4142
- deepEqual(other);
4168
+ Stack.prototype.__iterator = function(type, reverse) {
4169
+ if (reverse) {
4170
+ return this.reverse().__iterator(type);
4171
+ }
4172
+ var iterations = 0;
4173
+ var node = this._head;
4174
+ return new Iterator(function() {
4175
+ if (node) {
4176
+ var value = node.value;
4177
+ node = node.next;
4178
+ return iteratorValue(type, iterations++, value);
4179
+ }
4180
+ return iteratorDone();
4181
+ });
4143
4182
  };
4144
4183
 
4145
4184
 
4146
- var EMPTY_REPEAT;
4185
+ function isStack(maybeStack) {
4186
+ return !!(maybeStack && maybeStack[IS_STACK_SENTINEL]);
4187
+ }
4188
+
4189
+ Stack.isStack = isStack;
4190
+
4191
+ var IS_STACK_SENTINEL = '@@__IMMUTABLE_STACK__@@';
4192
+
4193
+ var StackPrototype = Stack.prototype;
4194
+ StackPrototype[IS_STACK_SENTINEL] = true;
4195
+ StackPrototype.withMutations = MapPrototype.withMutations;
4196
+ StackPrototype.asMutable = MapPrototype.asMutable;
4197
+ StackPrototype.asImmutable = MapPrototype.asImmutable;
4198
+ StackPrototype.wasAltered = MapPrototype.wasAltered;
4199
+
4200
+
4201
+ function makeStack(size, head, ownerID, hash) {
4202
+ var map = Object.create(StackPrototype);
4203
+ map.size = size;
4204
+ map._head = head;
4205
+ map.__ownerID = ownerID;
4206
+ map.__hash = hash;
4207
+ map.__altered = false;
4208
+ return map;
4209
+ }
4210
+
4211
+ var EMPTY_STACK;
4212
+ function emptyStack() {
4213
+ return EMPTY_STACK || (EMPTY_STACK = makeStack(0));
4214
+ }
4147
4215
 
4148
4216
  /**
4149
4217
  * Contributes additional methods to a constructor
@@ -4156,7 +4224,7 @@
4156
4224
  return ctor;
4157
4225
  }
4158
4226
 
4159
- Iterable.Iterator = src_Iterator__Iterator;
4227
+ Iterable.Iterator = Iterator;
4160
4228
 
4161
4229
  mixin(Iterable, {
4162
4230
 
@@ -4191,7 +4259,7 @@
4191
4259
 
4192
4260
  toMap: function() {
4193
4261
  // Use Late Binding here to solve the circular dependency.
4194
- return src_Map__Map(this.toKeyedSeq());
4262
+ return Map(this.toKeyedSeq());
4195
4263
  },
4196
4264
 
4197
4265
  toObject: function() {
@@ -4213,7 +4281,7 @@
4213
4281
 
4214
4282
  toSet: function() {
4215
4283
  // Use Late Binding here to solve the circular dependency.
4216
- return src_Set__Set(isKeyed(this) ? this.valueSeq() : this);
4284
+ return Set(isKeyed(this) ? this.valueSeq() : this);
4217
4285
  },
4218
4286
 
4219
4287
  toSetSeq: function() {
@@ -4257,10 +4325,6 @@
4257
4325
  return reify(this, concatFactory(this, values));
4258
4326
  },
4259
4327
 
4260
- contains: function(searchValue) {
4261
- return this.includes(searchValue);
4262
- },
4263
-
4264
4328
  includes: function(searchValue) {
4265
4329
  return this.some(function(value ) {return is(value, searchValue)});
4266
4330
  },
@@ -4473,6 +4537,7 @@
4473
4537
  },
4474
4538
 
4475
4539
  isSuperset: function(iter) {
4540
+ iter = typeof iter.isSubset === 'function' ? iter : Iterable(iter);
4476
4541
  return iter.isSubset(this);
4477
4542
  },
4478
4543
 
@@ -4549,7 +4614,7 @@
4549
4614
 
4550
4615
  hashCode: function() {
4551
4616
  return this.__hash || (this.__hash = hashIterable(this));
4552
- },
4617
+ }
4553
4618
 
4554
4619
 
4555
4620
  // ### Internal
@@ -4572,6 +4637,7 @@
4572
4637
  IterablePrototype.inspect =
4573
4638
  IterablePrototype.toSource = function() { return this.toString(); };
4574
4639
  IterablePrototype.chain = IterablePrototype.flatMap;
4640
+ IterablePrototype.contains = IterablePrototype.includes;
4575
4641
 
4576
4642
  // Temporary warning about using length
4577
4643
  (function () {
@@ -4642,7 +4708,7 @@
4642
4708
  function(k, v) {return mapper.call(context, k, v, this$0)}
4643
4709
  ).flip()
4644
4710
  );
4645
- },
4711
+ }
4646
4712
 
4647
4713
  });
4648
4714
 
@@ -4680,7 +4746,11 @@
4680
4746
  },
4681
4747
 
4682
4748
  lastIndexOf: function(searchValue) {
4683
- return this.toSeq().reverse().indexOf(searchValue);
4749
+ var key = this.toKeyedSeq().reverse().keyOf(searchValue);
4750
+ return key === undefined ? -1 : key;
4751
+
4752
+ // var index =
4753
+ // return this.toSeq().reverse().indexOf(searchValue);
4684
4754
  },
4685
4755
 
4686
4756
  reverse: function() {
@@ -4697,7 +4767,10 @@
4697
4767
  if (numArgs === 0 || (numArgs === 2 && !removeNum)) {
4698
4768
  return this;
4699
4769
  }
4700
- index = resolveBegin(index, this.size);
4770
+ // If index is negative, it should resolve relative to the size of the
4771
+ // collection. However size may be expensive to compute if not cached, so
4772
+ // only call count() if the number is in fact negative.
4773
+ index = resolveBegin(index, index < 0 ? this.count() : this.size);
4701
4774
  var spliced = this.slice(0, index);
4702
4775
  return reify(
4703
4776
  this,
@@ -4770,7 +4843,7 @@
4770
4843
  var iterables = arrCopy(arguments);
4771
4844
  iterables[0] = this;
4772
4845
  return reify(this, zipWithFactory(this, zipper, iterables));
4773
- },
4846
+ }
4774
4847
 
4775
4848
  });
4776
4849
 
@@ -4796,7 +4869,7 @@
4796
4869
 
4797
4870
  keySeq: function() {
4798
4871
  return this.valueSeq();
4799
- },
4872
+ }
4800
4873
 
4801
4874
  });
4802
4875
 
@@ -4868,12 +4941,12 @@
4868
4941
  }
4869
4942
 
4870
4943
  function murmurHashOfSize(size, h) {
4871
- h = src_Math__imul(h, 0xCC9E2D51);
4872
- h = src_Math__imul(h << 15 | h >>> -15, 0x1B873593);
4873
- h = src_Math__imul(h << 13 | h >>> -13, 5);
4944
+ h = imul(h, 0xCC9E2D51);
4945
+ h = imul(h << 15 | h >>> -15, 0x1B873593);
4946
+ h = imul(h << 13 | h >>> -13, 5);
4874
4947
  h = (h + 0xE6546B64 | 0) ^ size;
4875
- h = src_Math__imul(h ^ h >>> 16, 0x85EBCA6B);
4876
- h = src_Math__imul(h ^ h >>> 13, 0xC2B2AE35);
4948
+ h = imul(h ^ h >>> 16, 0x85EBCA6B);
4949
+ h = imul(h ^ h >>> 13, 0xC2B2AE35);
4877
4950
  h = smi(h ^ h >>> 16);
4878
4951
  return h;
4879
4952
  }
@@ -4888,11 +4961,11 @@
4888
4961
 
4889
4962
  Seq: Seq,
4890
4963
  Collection: Collection,
4891
- Map: src_Map__Map,
4964
+ Map: Map,
4892
4965
  OrderedMap: OrderedMap,
4893
4966
  List: List,
4894
4967
  Stack: Stack,
4895
- Set: src_Set__Set,
4968
+ Set: Set,
4896
4969
  OrderedSet: OrderedSet,
4897
4970
 
4898
4971
  Record: Record,
@@ -4900,7 +4973,7 @@
4900
4973
  Repeat: Repeat,
4901
4974
 
4902
4975
  is: is,
4903
- fromJS: fromJS,
4976
+ fromJS: fromJS
4904
4977
 
4905
4978
  };
4906
4979