immutable 3.7.5 → 3.8.2

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