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.
@@ -1,10 +1,8 @@
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
  */
9
7
 
10
8
  /**
@@ -57,7 +55,7 @@ declare module Immutable {
57
55
  *
58
56
  * `reviver` acts similarly to the [same parameter in `JSON.parse`][1].
59
57
  *
60
- * `Immutable.fromJS` is conservative in it's conversion. It will only convert
58
+ * `Immutable.fromJS` is conservative in its conversion. It will only convert
61
59
  * arrays which pass `Array.isArray` to Lists, and only raw objects (no custom
62
60
  * prototype) to Map.
63
61
  *
@@ -121,7 +119,7 @@ declare module Immutable {
121
119
  *
122
120
  * Unlike a JavaScript Array, there is no distinction between an
123
121
  * "unset" index and an index set to `undefined`. `List#forEach` visits all
124
- * indices from 0 to size, regardless of if they where explicitly defined.
122
+ * indices from 0 to size, regardless of whether they were explicitly defined.
125
123
  */
126
124
  export module List {
127
125
 
@@ -141,15 +139,15 @@ declare module Immutable {
141
139
  * iterable-like.
142
140
  */
143
141
  export function List<T>(): List<T>;
144
- export function List<T>(iter: IndexedIterable<T>): List<T>;
145
- export function List<T>(iter: SetIterable<T>): List<T>;
146
- export function List<K, V>(iter: KeyedIterable<K, V>): List</*[K,V]*/any>;
142
+ export function List<T>(iter: Iterable.Indexed<T>): List<T>;
143
+ export function List<T>(iter: Iterable.Set<T>): List<T>;
144
+ export function List<K, V>(iter: Iterable.Keyed<K, V>): List</*[K,V]*/any>;
147
145
  export function List<T>(array: Array<T>): List<T>;
148
146
  export function List<T>(iterator: Iterator<T>): List<T>;
149
147
  export function List<T>(iterable: /*Iterable<T>*/Object): List<T>;
150
148
 
151
149
 
152
- export interface List<T> extends IndexedCollection<T> {
150
+ export interface List<T> extends Collection.Indexed<T> {
153
151
 
154
152
  // Persistent changes
155
153
 
@@ -181,6 +179,14 @@ declare module Immutable {
181
179
  delete(index: number): List<T>;
182
180
  remove(index: number): List<T>;
183
181
 
182
+ /**
183
+ * Returns a new List with `value` at `index` with a size 1 more than this
184
+ * List. Values at indices above `index` are shifted over by 1.
185
+ *
186
+ * This is synonymous with `list.splice(index, 0, value)
187
+ */
188
+ insert(index: number, value: T): List<T>;
189
+
184
190
  /**
185
191
  * Returns a new List with 0 size and no values.
186
192
  */
@@ -236,7 +242,7 @@ declare module Immutable {
236
242
  /**
237
243
  * @see `Map#merge`
238
244
  */
239
- merge(...iterables: IndexedIterable<T>[]): List<T>;
245
+ merge(...iterables: Iterable.Indexed<T>[]): List<T>;
240
246
  merge(...iterables: Array<T>[]): List<T>;
241
247
 
242
248
  /**
@@ -244,7 +250,7 @@ declare module Immutable {
244
250
  */
245
251
  mergeWith(
246
252
  merger: (previous?: T, next?: T, key?: number) => T,
247
- ...iterables: IndexedIterable<T>[]
253
+ ...iterables: Iterable.Indexed<T>[]
248
254
  ): List<T>;
249
255
  mergeWith(
250
256
  merger: (previous?: T, next?: T, key?: number) => T,
@@ -254,7 +260,7 @@ declare module Immutable {
254
260
  /**
255
261
  * @see `Map#mergeDeep`
256
262
  */
257
- mergeDeep(...iterables: IndexedIterable<T>[]): List<T>;
263
+ mergeDeep(...iterables: Iterable.Indexed<T>[]): List<T>;
258
264
  mergeDeep(...iterables: Array<T>[]): List<T>;
259
265
 
260
266
  /**
@@ -262,7 +268,7 @@ declare module Immutable {
262
268
  */
263
269
  mergeDeepWith(
264
270
  merger: (previous?: T, next?: T, key?: number) => T,
265
- ...iterables: IndexedIterable<T>[]
271
+ ...iterables: Iterable.Indexed<T>[]
266
272
  ): List<T>;
267
273
  mergeDeepWith(
268
274
  merger: (previous?: T, next?: T, key?: number) => T,
@@ -332,11 +338,11 @@ declare module Immutable {
332
338
  */
333
339
  mergeIn(
334
340
  keyPath: Iterable<any, any>,
335
- ...iterables: IndexedIterable<T>[]
341
+ ...iterables: Iterable.Indexed<T>[]
336
342
  ): List<T>;
337
343
  mergeIn(
338
344
  keyPath: Array<any>,
339
- ...iterables: IndexedIterable<T>[]
345
+ ...iterables: Iterable.Indexed<T>[]
340
346
  ): List<T>;
341
347
  mergeIn(
342
348
  keyPath: Array<any>,
@@ -348,11 +354,11 @@ declare module Immutable {
348
354
  */
349
355
  mergeDeepIn(
350
356
  keyPath: Iterable<any, any>,
351
- ...iterables: IndexedIterable<T>[]
357
+ ...iterables: Iterable.Indexed<T>[]
352
358
  ): List<T>;
353
359
  mergeDeepIn(
354
360
  keyPath: Array<any>,
355
- ...iterables: IndexedIterable<T>[]
361
+ ...iterables: Iterable.Indexed<T>[]
356
362
  ): List<T>;
357
363
  mergeDeepIn(
358
364
  keyPath: Array<any>,
@@ -384,7 +390,7 @@ declare module Immutable {
384
390
 
385
391
 
386
392
  /**
387
- * Immutable Map is an unordered KeyedIterable of (key, value) pairs with
393
+ * Immutable Map is an unordered Iterable.Keyed of (key, value) pairs with
388
394
  * `O(log32 N)` gets and `O(log32 N)` persistent sets.
389
395
  *
390
396
  * Iteration order of a Map is undefined, however is stable. Multiple
@@ -412,12 +418,17 @@ declare module Immutable {
412
418
  * True if the provided value is a Map
413
419
  */
414
420
  function isMap(maybeMap: any): boolean;
421
+
422
+ /**
423
+ * Creates a new Map from alternating keys and values
424
+ */
425
+ function of(...keyValues: any[]): Map<any, any>;
415
426
  }
416
427
 
417
428
  /**
418
429
  * Creates a new Immutable Map.
419
430
  *
420
- * Created with the same key value pairs as the provided KeyedIterable or
431
+ * Created with the same key value pairs as the provided Iterable.Keyed or
421
432
  * JavaScript Object or expects an Iterable of [K, V] tuple entries.
422
433
  *
423
434
  * var newMap = Map({key: "value"});
@@ -443,14 +454,14 @@ declare module Immutable {
443
454
  * not altered.
444
455
  */
445
456
  export function Map<K, V>(): Map<K, V>;
446
- export function Map<K, V>(iter: KeyedIterable<K, V>): Map<K, V>;
457
+ export function Map<K, V>(iter: Iterable.Keyed<K, V>): Map<K, V>;
447
458
  export function Map<K, V>(iter: Iterable<any, /*[K,V]*/Array<any>>): Map<K, V>;
448
459
  export function Map<K, V>(array: Array</*[K,V]*/Array<any>>): Map<K, V>;
449
460
  export function Map<V>(obj: {[key: string]: V}): Map<string, V>;
450
461
  export function Map<K, V>(iterator: Iterator</*[K,V]*/Array<any>>): Map<K, V>;
451
462
  export function Map<K, V>(iterable: /*Iterable<[K,V]>*/Object): Map<K, V>;
452
463
 
453
- export interface Map<K, V> extends KeyedCollection<K, V> {
464
+ export interface Map<K, V> extends Collection.Keyed<K, V> {
454
465
 
455
466
  // Persistent changes
456
467
 
@@ -739,7 +750,7 @@ declare module Immutable {
739
750
  /**
740
751
  * Creates a new Immutable OrderedMap.
741
752
  *
742
- * Created with the same key value pairs as the provided KeyedIterable or
753
+ * Created with the same key value pairs as the provided Iterable.Keyed or
743
754
  * JavaScript Object or expects an Iterable of [K, V] tuple entries.
744
755
  *
745
756
  * The iteration order of key-value pairs provided to this constructor will
@@ -750,7 +761,7 @@ declare module Immutable {
750
761
  *
751
762
  */
752
763
  export function OrderedMap<K, V>(): OrderedMap<K, V>;
753
- export function OrderedMap<K, V>(iter: KeyedIterable<K, V>): OrderedMap<K, V>;
764
+ export function OrderedMap<K, V>(iter: Iterable.Keyed<K, V>): OrderedMap<K, V>;
754
765
  export function OrderedMap<K, V>(iter: Iterable<any, /*[K,V]*/Array<any>>): OrderedMap<K, V>;
755
766
  export function OrderedMap<K, V>(array: Array</*[K,V]*/Array<any>>): OrderedMap<K, V>;
756
767
  export function OrderedMap<V>(obj: {[key: string]: V}): OrderedMap<string, V>;
@@ -796,14 +807,14 @@ declare module Immutable {
796
807
  * iterable-like.
797
808
  */
798
809
  export function Set<T>(): Set<T>;
799
- export function Set<T>(iter: SetIterable<T>): Set<T>;
800
- export function Set<T>(iter: IndexedIterable<T>): Set<T>;
801
- export function Set<K, V>(iter: KeyedIterable<K, V>): Set</*[K,V]*/any>;
810
+ export function Set<T>(iter: Iterable.Set<T>): Set<T>;
811
+ export function Set<T>(iter: Iterable.Indexed<T>): Set<T>;
812
+ export function Set<K, V>(iter: Iterable.Keyed<K, V>): Set</*[K,V]*/any>;
802
813
  export function Set<T>(array: Array<T>): Set<T>;
803
814
  export function Set<T>(iterator: Iterator<T>): Set<T>;
804
815
  export function Set<T>(iterable: /*Iterable<T>*/Object): Set<T>;
805
816
 
806
- export interface Set<T> extends SetCollection<T> {
817
+ export interface Set<T> extends Collection.Set<T> {
807
818
 
808
819
  // Persistent changes
809
820
 
@@ -908,9 +919,9 @@ declare module Immutable {
908
919
  * iterable-like.
909
920
  */
910
921
  export function OrderedSet<T>(): OrderedSet<T>;
911
- export function OrderedSet<T>(iter: SetIterable<T>): OrderedSet<T>;
912
- export function OrderedSet<T>(iter: IndexedIterable<T>): OrderedSet<T>;
913
- export function OrderedSet<K, V>(iter: KeyedIterable<K, V>): OrderedSet</*[K,V]*/any>;
922
+ export function OrderedSet<T>(iter: Iterable.Set<T>): OrderedSet<T>;
923
+ export function OrderedSet<T>(iter: Iterable.Indexed<T>): OrderedSet<T>;
924
+ export function OrderedSet<K, V>(iter: Iterable.Keyed<K, V>): OrderedSet</*[K,V]*/any>;
914
925
  export function OrderedSet<T>(array: Array<T>): OrderedSet<T>;
915
926
  export function OrderedSet<T>(iterator: Iterator<T>): OrderedSet<T>;
916
927
  export function OrderedSet<T>(iterable: /*Iterable<T>*/Object): OrderedSet<T>;
@@ -952,14 +963,14 @@ declare module Immutable {
952
963
  * resulting `Stack`.
953
964
  */
954
965
  export function Stack<T>(): Stack<T>;
955
- export function Stack<T>(iter: IndexedIterable<T>): Stack<T>;
956
- export function Stack<T>(iter: SetIterable<T>): Stack<T>;
957
- export function Stack<K, V>(iter: KeyedIterable<K, V>): Stack</*[K,V]*/any>;
966
+ export function Stack<T>(iter: Iterable.Indexed<T>): Stack<T>;
967
+ export function Stack<T>(iter: Iterable.Set<T>): Stack<T>;
968
+ export function Stack<K, V>(iter: Iterable.Keyed<K, V>): Stack</*[K,V]*/any>;
958
969
  export function Stack<T>(array: Array<T>): Stack<T>;
959
970
  export function Stack<T>(iterator: Iterator<T>): Stack<T>;
960
971
  export function Stack<T>(iterable: /*Iterable<T>*/Object): Stack<T>;
961
972
 
962
- export interface Stack<T> extends IndexedCollection<T> {
973
+ export interface Stack<T> extends Collection.Indexed<T> {
963
974
 
964
975
  // Reading values
965
976
 
@@ -1040,7 +1051,7 @@ declare module Immutable {
1040
1051
 
1041
1052
 
1042
1053
  /**
1043
- * Returns a IndexedSeq of numbers from `start` (inclusive) to `end`
1054
+ * Returns a Seq.Indexed of numbers from `start` (inclusive) to `end`
1044
1055
  * (exclusive), by `step`, where `start` defaults to 0, `step` to 1, and `end` to
1045
1056
  * infinity. When `start` is equal to `end`, returns empty range.
1046
1057
  *
@@ -1052,18 +1063,18 @@ declare module Immutable {
1052
1063
  * Range(30,30,5) // []
1053
1064
  *
1054
1065
  */
1055
- export function Range(start?: number, end?: number, step?: number): IndexedSeq<number>;
1066
+ export function Range(start?: number, end?: number, step?: number): Seq.Indexed<number>;
1056
1067
 
1057
1068
 
1058
1069
  /**
1059
- * Returns a IndexedSeq of `value` repeated `times` times. When `times` is
1070
+ * Returns a Seq.Indexed of `value` repeated `times` times. When `times` is
1060
1071
  * not defined, returns an infinite `Seq` of `value`.
1061
1072
  *
1062
1073
  * Repeat('foo') // ['foo','foo','foo',...]
1063
1074
  * Repeat('bar',4) // ['bar','bar','bar','bar']
1064
1075
  *
1065
1076
  */
1066
- export function Repeat<T>(value: T, times?: number): IndexedSeq<T>;
1077
+ export function Repeat<T>(value: T, times?: number): Seq.Indexed<T>;
1067
1078
 
1068
1079
 
1069
1080
  /**
@@ -1085,7 +1096,9 @@ declare module Immutable {
1085
1096
  * myRecordWithoutB.size // 2
1086
1097
  *
1087
1098
  * Values provided to the constructor not found in the Record type will
1088
- * be ignored:
1099
+ * be ignored. For example, in this case, ABRecord is provided a key "x" even
1100
+ * though only "a" and "b" have been defined. The value for "x" will be
1101
+ * ignored for this record.
1089
1102
  *
1090
1103
  * var myRecord = new ABRecord({b:3, x:10})
1091
1104
  * myRecord.get('x') // undefined
@@ -1116,7 +1129,7 @@ declare module Immutable {
1116
1129
  *
1117
1130
  */
1118
1131
  export module Record {
1119
- interface Class {
1132
+ export interface Class {
1120
1133
  new (): Map<string, any>;
1121
1134
  new (values: {[key: string]: any}): Map<string, any>;
1122
1135
  new (values: Iterable<string, any>): Map<string, any>; // deprecated
@@ -1153,9 +1166,9 @@ declare module Immutable {
1153
1166
  *
1154
1167
  * Once the Seq is used, it performs only the work necessary. In this
1155
1168
  * example, no intermediate data structures are ever created, filter is only
1156
- * called three times, and map is only called twice:
1169
+ * called three times, and map is only called once:
1157
1170
  *
1158
- * console.log(evenSquares.get(1)); // 9
1171
+ * console.log(oddSquares.get(1)); // 9
1159
1172
  *
1160
1173
  * Seq allows for the efficient chaining of operations,
1161
1174
  * allowing for the expression of logic that can otherwise be very tedious:
@@ -1188,9 +1201,102 @@ declare module Immutable {
1188
1201
  function isSeq(maybeSeq: any): boolean;
1189
1202
 
1190
1203
  /**
1191
- * Returns a Seq of the values provided. Alias for `IndexedSeq.of()`.
1204
+ * Returns a Seq of the values provided. Alias for `Seq.Indexed.of()`.
1205
+ */
1206
+ function of<T>(...values: T[]): Seq.Indexed<T>;
1207
+
1208
+
1209
+ /**
1210
+ * `Seq` which represents key-value pairs.
1211
+ */
1212
+ export module Keyed {}
1213
+
1214
+ /**
1215
+ * Always returns a Seq.Keyed, if input is not keyed, expects an
1216
+ * iterable of [K, V] tuples.
1217
+ */
1218
+ export function Keyed<K, V>(): Seq.Keyed<K, V>;
1219
+ export function Keyed<K, V>(seq: Iterable.Keyed<K, V>): Seq.Keyed<K, V>;
1220
+ export function Keyed<K, V>(seq: Iterable<any, /*[K,V]*/any>): Seq.Keyed<K, V>;
1221
+ export function Keyed<K, V>(array: Array</*[K,V]*/any>): Seq.Keyed<K, V>;
1222
+ export function Keyed<V>(obj: {[key: string]: V}): Seq.Keyed<string, V>;
1223
+ export function Keyed<K, V>(iterator: Iterator</*[K,V]*/any>): Seq.Keyed<K, V>;
1224
+ export function Keyed<K, V>(iterable: /*Iterable<[K,V]>*/Object): Seq.Keyed<K, V>;
1225
+
1226
+ export interface Keyed<K, V> extends Seq<K, V>, Iterable.Keyed<K, V> {
1227
+
1228
+ /**
1229
+ * Returns itself
1230
+ */
1231
+ toSeq(): /*this*/Seq.Keyed<K, V>
1232
+ }
1233
+
1234
+
1235
+ /**
1236
+ * `Seq` which represents an ordered indexed list of values.
1237
+ */
1238
+ module Indexed {
1239
+
1240
+ /**
1241
+ * Provides an Seq.Indexed of the values provided.
1242
+ */
1243
+ function of<T>(...values: T[]): Seq.Indexed<T>;
1244
+ }
1245
+
1246
+ /**
1247
+ * Always returns Seq.Indexed, discarding associated keys and
1248
+ * supplying incrementing indices.
1249
+ */
1250
+ export function Indexed<T>(): Seq.Indexed<T>;
1251
+ export function Indexed<T>(seq: Iterable.Indexed<T>): Seq.Indexed<T>;
1252
+ export function Indexed<T>(seq: Iterable.Set<T>): Seq.Indexed<T>;
1253
+ export function Indexed<K, V>(seq: Iterable.Keyed<K, V>): Seq.Indexed</*[K,V]*/any>;
1254
+ export function Indexed<T>(array: Array<T>): Seq.Indexed<T>;
1255
+ export function Indexed<T>(iterator: Iterator<T>): Seq.Indexed<T>;
1256
+ export function Indexed<T>(iterable: /*Iterable<T>*/Object): Seq.Indexed<T>;
1257
+
1258
+ export interface Indexed<T> extends Seq<number, T>, Iterable.Indexed<T> {
1259
+
1260
+ /**
1261
+ * Returns itself
1262
+ */
1263
+ toSeq(): /*this*/Seq.Indexed<T>
1264
+ }
1265
+
1266
+
1267
+ /**
1268
+ * `Seq` which represents a set of values.
1269
+ *
1270
+ * Because `Seq` are often lazy, `Seq.Set` does not provide the same guarantee
1271
+ * of value uniqueness as the concrete `Set`.
1272
+ */
1273
+ export module Set {
1274
+
1275
+ /**
1276
+ * Returns a Seq.Set of the provided values
1277
+ */
1278
+ function of<T>(...values: T[]): Seq.Set<T>;
1279
+ }
1280
+
1281
+ /**
1282
+ * Always returns a Seq.Set, discarding associated indices or keys.
1192
1283
  */
1193
- function of<T>(...values: T[]): IndexedSeq<T>;
1284
+ export function Set<T>(): Seq.Set<T>;
1285
+ export function Set<T>(seq: Iterable.Set<T>): Seq.Set<T>;
1286
+ export function Set<T>(seq: Iterable.Indexed<T>): Seq.Set<T>;
1287
+ export function Set<K, V>(seq: Iterable.Keyed<K, V>): Seq.Set</*[K,V]*/any>;
1288
+ export function Set<T>(array: Array<T>): Seq.Set<T>;
1289
+ export function Set<T>(iterator: Iterator<T>): Seq.Set<T>;
1290
+ export function Set<T>(iterable: /*Iterable<T>*/Object): Seq.Set<T>;
1291
+
1292
+ export interface Set<T> extends Seq<T, T>, Iterable.Set<T> {
1293
+
1294
+ /**
1295
+ * Returns itself
1296
+ */
1297
+ toSeq(): /*this*/Seq.Set<T>
1298
+ }
1299
+
1194
1300
  }
1195
1301
 
1196
1302
  /**
@@ -1200,19 +1306,19 @@ declare module Immutable {
1200
1306
  *
1201
1307
  * * If a `Seq`, that same `Seq`.
1202
1308
  * * If an `Iterable`, a `Seq` of the same kind (Keyed, Indexed, or Set).
1203
- * * If an Array-like, an `IndexedSeq`.
1204
- * * If an Object with an Iterator, an `IndexedSeq`.
1205
- * * If an Iterator, an `IndexedSeq`.
1206
- * * If an Object, a `KeyedSeq`.
1309
+ * * If an Array-like, an `Seq.Indexed`.
1310
+ * * If an Object with an Iterator, an `Seq.Indexed`.
1311
+ * * If an Iterator, an `Seq.Indexed`.
1312
+ * * If an Object, a `Seq.Keyed`.
1207
1313
  *
1208
1314
  */
1209
1315
  export function Seq<K, V>(): Seq<K, V>;
1210
1316
  export function Seq<K, V>(seq: Seq<K, V>): Seq<K, V>;
1211
1317
  export function Seq<K, V>(iterable: Iterable<K, V>): Seq<K, V>;
1212
- export function Seq<T>(array: Array<T>): IndexedSeq<T>;
1213
- export function Seq<V>(obj: {[key: string]: V}): KeyedSeq<string, V>;
1214
- export function Seq<T>(iterator: Iterator<T>): IndexedSeq<T>;
1215
- export function Seq<T>(iterable: /*ES6Iterable<T>*/Object): IndexedSeq<T>;
1318
+ export function Seq<T>(array: Array<T>): Seq.Indexed<T>;
1319
+ export function Seq<V>(obj: {[key: string]: V}): Seq.Keyed<string, V>;
1320
+ export function Seq<T>(iterator: Iterator<T>): Seq.Indexed<T>;
1321
+ export function Seq<T>(iterable: /*ES6Iterable<T>*/Object): Seq.Indexed<T>;
1216
1322
 
1217
1323
  export interface Seq<K, V> extends Iterable<K, V> {
1218
1324
 
@@ -1254,98 +1360,6 @@ declare module Immutable {
1254
1360
  cacheResult(): /*this*/Seq<K, V>;
1255
1361
  }
1256
1362
 
1257
-
1258
- /**
1259
- * `Seq` which represents key-value pairs.
1260
- */
1261
- export module KeyedSeq {}
1262
-
1263
- /**
1264
- * Always returns a KeyedSeq, if input is not keyed, expects an
1265
- * iterable of [K, V] tuples.
1266
- */
1267
- export function KeyedSeq<K, V>(): KeyedSeq<K, V>;
1268
- export function KeyedSeq<K, V>(seq: KeyedIterable<K, V>): KeyedSeq<K, V>;
1269
- export function KeyedSeq<K, V>(seq: Iterable<any, /*[K,V]*/any>): KeyedSeq<K, V>;
1270
- export function KeyedSeq<K, V>(array: Array</*[K,V]*/any>): KeyedSeq<K, V>;
1271
- export function KeyedSeq<V>(obj: {[key: string]: V}): KeyedSeq<string, V>;
1272
- export function KeyedSeq<K, V>(iterator: Iterator</*[K,V]*/any>): KeyedSeq<K, V>;
1273
- export function KeyedSeq<K, V>(iterable: /*Iterable<[K,V]>*/Object): KeyedSeq<K, V>;
1274
-
1275
- export interface KeyedSeq<K, V> extends Seq<K, V>, KeyedIterable<K, V> {
1276
-
1277
- /**
1278
- * Returns itself
1279
- */
1280
- toSeq(): /*this*/KeyedSeq<K, V>
1281
- }
1282
-
1283
-
1284
- /**
1285
- * `Seq` which represents an ordered indexed list of values.
1286
- */
1287
- export module IndexedSeq {
1288
-
1289
- /**
1290
- * Provides an IndexedSeq of the values provided.
1291
- */
1292
- function of<T>(...values: T[]): IndexedSeq<T>;
1293
- }
1294
-
1295
- /**
1296
- * Always returns IndexedSeq, discarding associated keys and
1297
- * supplying incrementing indices.
1298
- */
1299
- export function IndexedSeq<T>(): IndexedSeq<T>;
1300
- export function IndexedSeq<T>(seq: IndexedIterable<T>): IndexedSeq<T>;
1301
- export function IndexedSeq<T>(seq: SetIterable<T>): IndexedSeq<T>;
1302
- export function IndexedSeq<K, V>(seq: KeyedIterable<K, V>): IndexedSeq</*[K,V]*/any>;
1303
- export function IndexedSeq<T>(array: Array<T>): IndexedSeq<T>;
1304
- export function IndexedSeq<T>(iterator: Iterator<T>): IndexedSeq<T>;
1305
- export function IndexedSeq<T>(iterable: /*Iterable<T>*/Object): IndexedSeq<T>;
1306
-
1307
- export interface IndexedSeq<T> extends Seq<number, T>, IndexedIterable<T> {
1308
-
1309
- /**
1310
- * Returns itself
1311
- */
1312
- toSeq(): /*this*/IndexedSeq<T>
1313
- }
1314
-
1315
- /**
1316
- * `Seq` which represents a set of values.
1317
- *
1318
- * Because `Seq` are often lazy, `SetSeq` does not provide the same guarantee
1319
- * of value uniqueness as the concrete `Set`.
1320
- */
1321
- export module SetSeq {
1322
-
1323
- /**
1324
- * Returns a SetSeq of the provided values
1325
- */
1326
- function of<T>(...values: T[]): SetSeq<T>;
1327
- }
1328
-
1329
- /**
1330
- * Always returns a SetSeq, discarding associated indices or keys.
1331
- */
1332
- export function SetSeq<T>(): SetSeq<T>;
1333
- export function SetSeq<T>(seq: SetIterable<T>): SetSeq<T>;
1334
- export function SetSeq<T>(seq: IndexedIterable<T>): SetSeq<T>;
1335
- export function SetSeq<K, V>(seq: KeyedIterable<K, V>): SetSeq</*[K,V]*/any>;
1336
- export function SetSeq<T>(array: Array<T>): SetSeq<T>;
1337
- export function SetSeq<T>(iterator: Iterator<T>): SetSeq<T>;
1338
- export function SetSeq<T>(iterable: /*Iterable<T>*/Object): SetSeq<T>;
1339
-
1340
- export interface SetSeq<T> extends Seq<T, T>, SetIterable<T> {
1341
-
1342
- /**
1343
- * Returns itself
1344
- */
1345
- toSeq(): /*this*/SetSeq<T>
1346
- }
1347
-
1348
-
1349
1363
  /**
1350
1364
  * The `Iterable` is a set of (key, value) entries which can be iterated, and
1351
1365
  * is the base class for all collections in `immutable`, allowing them to
@@ -1361,12 +1375,12 @@ declare module Immutable {
1361
1375
  function isIterable(maybeIterable: any): boolean;
1362
1376
 
1363
1377
  /**
1364
- * True if `maybeKeyed` is a KeyedIterable, or any of its subclasses.
1378
+ * True if `maybeKeyed` is an Iterable.Keyed, or any of its subclasses.
1365
1379
  */
1366
1380
  function isKeyed(maybeKeyed: any): boolean;
1367
1381
 
1368
1382
  /**
1369
- * True if `maybeIndexed` is a IndexedIterable, or any of its subclasses.
1383
+ * True if `maybeIndexed` is a Iterable.Indexed, or any of its subclasses.
1370
1384
  */
1371
1385
  function isIndexed(maybeIndexed: any): boolean;
1372
1386
 
@@ -1377,9 +1391,293 @@ declare module Immutable {
1377
1391
 
1378
1392
  /**
1379
1393
  * True if `maybeOrdered` is an Iterable where iteration order is well
1380
- * defined. True for IndexedIterable as well as OrderedMap and OrderedSet.
1394
+ * defined. True for Iterable.Indexed as well as OrderedMap and OrderedSet.
1381
1395
  */
1382
1396
  function isOrdered(maybeOrdered: any): boolean;
1397
+
1398
+
1399
+ /**
1400
+ * Keyed Iterables have discrete keys tied to each value.
1401
+ *
1402
+ * When iterating `Iterable.Keyed`, each iteration will yield a `[K, V]`
1403
+ * tuple, in other words, `Iterable#entries` is the default iterator for
1404
+ * Keyed Iterables.
1405
+ */
1406
+ export module Keyed {}
1407
+
1408
+ /**
1409
+ * Creates an Iterable.Keyed
1410
+ *
1411
+ * Similar to `Iterable()`, however it expects iterable-likes of [K, V]
1412
+ * tuples if not constructed from a Iterable.Keyed or JS Object.
1413
+ */
1414
+ export function Keyed<K, V>(iter: Iterable.Keyed<K, V>): Iterable.Keyed<K, V>;
1415
+ export function Keyed<K, V>(iter: Iterable<any, /*[K,V]*/any>): Iterable.Keyed<K, V>;
1416
+ export function Keyed<K, V>(array: Array</*[K,V]*/any>): Iterable.Keyed<K, V>;
1417
+ export function Keyed<V>(obj: {[key: string]: V}): Iterable.Keyed<string, V>;
1418
+ export function Keyed<K, V>(iterator: Iterator</*[K,V]*/any>): Iterable.Keyed<K, V>;
1419
+ export function Keyed<K, V>(iterable: /*Iterable<[K,V]>*/Object): Iterable.Keyed<K, V>;
1420
+
1421
+ export interface Keyed<K, V> extends Iterable<K, V> {
1422
+
1423
+ /**
1424
+ * Returns Seq.Keyed.
1425
+ * @override
1426
+ */
1427
+ toSeq(): Seq.Keyed<K, V>;
1428
+
1429
+
1430
+ // Sequence functions
1431
+
1432
+ /**
1433
+ * Returns a new Iterable.Keyed of the same type where the keys and values
1434
+ * have been flipped.
1435
+ *
1436
+ * Seq({ a: 'z', b: 'y' }).flip() // { z: 'a', y: 'b' }
1437
+ *
1438
+ */
1439
+ flip(): /*this*/Iterable.Keyed<V, K>;
1440
+
1441
+ /**
1442
+ * Returns a new Iterable.Keyed of the same type with keys passed through
1443
+ * a `mapper` function.
1444
+ *
1445
+ * Seq({ a: 1, b: 2 })
1446
+ * .mapKeys(x => x.toUpperCase())
1447
+ * // Seq { A: 1, B: 2 }
1448
+ *
1449
+ */
1450
+ mapKeys<M>(
1451
+ mapper: (key?: K, value?: V, iter?: /*this*/Iterable.Keyed<K, V>) => M,
1452
+ context?: any
1453
+ ): /*this*/Iterable.Keyed<M, V>;
1454
+
1455
+ /**
1456
+ * Returns a new Iterable.Keyed of the same type with entries
1457
+ * ([key, value] tuples) passed through a `mapper` function.
1458
+ *
1459
+ * Seq({ a: 1, b: 2 })
1460
+ * .mapEntries(([k, v]) => [k.toUpperCase(), v * 2])
1461
+ * // Seq { A: 2, B: 4 }
1462
+ *
1463
+ */
1464
+ mapEntries<KM, VM>(
1465
+ mapper: (
1466
+ entry?: /*(K, V)*/Array<any>,
1467
+ index?: number,
1468
+ iter?: /*this*/Iterable.Keyed<K, V>
1469
+ ) => /*[KM, VM]*/Array<any>,
1470
+ context?: any
1471
+ ): /*this*/Iterable.Keyed<KM, VM>;
1472
+ }
1473
+
1474
+
1475
+ /**
1476
+ * Indexed Iterables have incrementing numeric keys. They exhibit
1477
+ * slightly different behavior than `Iterable.Keyed` for some methods in order
1478
+ * to better mirror the behavior of JavaScript's `Array`, and add methods
1479
+ * which do not make sense on non-indexed Iterables such as `indexOf`.
1480
+ *
1481
+ * Unlike JavaScript arrays, `Iterable.Indexed`s are always dense. "Unset"
1482
+ * indices and `undefined` indices are indistinguishable, and all indices from
1483
+ * 0 to `size` are visited when iterated.
1484
+ *
1485
+ * All Iterable.Indexed methods return re-indexed Iterables. In other words,
1486
+ * indices always start at 0 and increment until size. If you wish to
1487
+ * preserve indices, using them as keys, convert to a Iterable.Keyed by
1488
+ * calling `toKeyedSeq`.
1489
+ */
1490
+ export module Indexed {}
1491
+
1492
+ /**
1493
+ * Creates a new Iterable.Indexed.
1494
+ */
1495
+ export function Indexed<T>(iter: Iterable.Indexed<T>): Iterable.Indexed<T>;
1496
+ export function Indexed<T>(iter: Iterable.Set<T>): Iterable.Indexed<T>;
1497
+ export function Indexed<K, V>(iter: Iterable.Keyed<K, V>): Iterable.Indexed</*[K,V]*/any>;
1498
+ export function Indexed<T>(array: Array<T>): Iterable.Indexed<T>;
1499
+ export function Indexed<T>(iterator: Iterator<T>): Iterable.Indexed<T>;
1500
+ export function Indexed<T>(iterable: /*Iterable<T>*/Object): Iterable.Indexed<T>;
1501
+
1502
+ export interface Indexed<T> extends Iterable<number, T> {
1503
+
1504
+ // Reading values
1505
+
1506
+ /**
1507
+ * Returns the value associated with the provided index, or notSetValue if
1508
+ * the index is beyond the bounds of the Iterable.
1509
+ *
1510
+ * `index` may be a negative number, which indexes back from the end of the
1511
+ * Iterable. `s.get(-1)` gets the last item in the Iterable.
1512
+ */
1513
+ get(index: number, notSetValue?: T): T;
1514
+
1515
+
1516
+ // Conversion to Seq
1517
+
1518
+ /**
1519
+ * Returns Seq.Indexed.
1520
+ * @override
1521
+ */
1522
+ toSeq(): Seq.Indexed<T>;
1523
+
1524
+ /**
1525
+ * If this is an iterable of [key, value] entry tuples, it will return a
1526
+ * Seq.Keyed of those entries.
1527
+ */
1528
+ fromEntrySeq(): Seq.Keyed<any, any>;
1529
+
1530
+
1531
+ // Combination
1532
+
1533
+ /**
1534
+ * Returns an Iterable of the same type with `separator` between each item
1535
+ * in this Iterable.
1536
+ */
1537
+ interpose(separator: T): /*this*/Iterable.Indexed<T>;
1538
+
1539
+ /**
1540
+ * Returns an Iterable of the same type with the provided `iterables`
1541
+ * interleaved into this iterable.
1542
+ *
1543
+ * The resulting Iterable includes the first item from each, then the
1544
+ * second from each, etc.
1545
+ *
1546
+ * I.Seq.of(1,2,3).interleave(I.Seq.of('A','B','C'))
1547
+ * // Seq [ 1, 'A', 2, 'B', 3, 'C' ]
1548
+ *
1549
+ * The shortest Iterable stops interleave.
1550
+ *
1551
+ * I.Seq.of(1,2,3).interleave(
1552
+ * I.Seq.of('A','B'),
1553
+ * I.Seq.of('X','Y','Z')
1554
+ * )
1555
+ * // Seq [ 1, 'A', 'X', 2, 'B', 'Y' ]
1556
+ */
1557
+ interleave(...iterables: Array<Iterable<any, T>>): /*this*/Iterable.Indexed<T>;
1558
+
1559
+ /**
1560
+ * Splice returns a new indexed Iterable by replacing a region of this
1561
+ * Iterable with new values. If values are not provided, it only skips the
1562
+ * region to be removed.
1563
+ *
1564
+ * `index` may be a negative number, which indexes back from the end of the
1565
+ * Iterable. `s.splice(-2)` splices after the second to last item.
1566
+ *
1567
+ * Seq(['a','b','c','d']).splice(1, 2, 'q', 'r', 's')
1568
+ * // Seq ['a', 'q', 'r', 's', 'd']
1569
+ *
1570
+ */
1571
+ splice(
1572
+ index: number,
1573
+ removeNum: number,
1574
+ ...values: /*Array<Iterable.Indexed<T> | T>*/any[]
1575
+ ): /*this*/Iterable.Indexed<T>;
1576
+
1577
+ /**
1578
+ * Returns an Iterable of the same type "zipped" with the provided
1579
+ * iterables.
1580
+ *
1581
+ * Like `zipWith`, but using the default `zipper`: creating an `Array`.
1582
+ *
1583
+ * var a = Seq.of(1, 2, 3);
1584
+ * var b = Seq.of(4, 5, 6);
1585
+ * var c = a.zip(b); // Seq [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]
1586
+ *
1587
+ */
1588
+ zip(...iterables: Array<Iterable<any, any>>): /*this*/Iterable.Indexed<any>;
1589
+
1590
+ /**
1591
+ * Returns an Iterable of the same type "zipped" with the provided
1592
+ * iterables by using a custom `zipper` function.
1593
+ *
1594
+ * var a = Seq.of(1, 2, 3);
1595
+ * var b = Seq.of(4, 5, 6);
1596
+ * var c = a.zipWith((a, b) => a + b, b); // Seq [ 5, 7, 9 ]
1597
+ *
1598
+ */
1599
+ zipWith<U, Z>(
1600
+ zipper: (value: T, otherValue: U) => Z,
1601
+ otherIterable: Iterable<any, U>
1602
+ ): Iterable.Indexed<Z>;
1603
+ zipWith<U, V, Z>(
1604
+ zipper: (value: T, otherValue: U, thirdValue: V) => Z,
1605
+ otherIterable: Iterable<any, U>,
1606
+ thirdIterable: Iterable<any, V>
1607
+ ): Iterable.Indexed<Z>;
1608
+ zipWith<Z>(
1609
+ zipper: (...any: Array<any>) => Z,
1610
+ ...iterables: Array<Iterable<any, any>>
1611
+ ): Iterable.Indexed<Z>;
1612
+
1613
+
1614
+ // Search for value
1615
+
1616
+ /**
1617
+ * Returns the first index at which a given value can be found in the
1618
+ * Iterable, or -1 if it is not present.
1619
+ */
1620
+ indexOf(searchValue: T): number;
1621
+
1622
+ /**
1623
+ * Returns the last index at which a given value can be found in the
1624
+ * Iterable, or -1 if it is not present.
1625
+ */
1626
+ lastIndexOf(searchValue: T): number;
1627
+
1628
+ /**
1629
+ * Returns the first index in the Iterable where a value satisfies the
1630
+ * provided predicate function. Otherwise -1 is returned.
1631
+ */
1632
+ findIndex(
1633
+ predicate: (value?: T, index?: number, iter?: /*this*/Iterable.Indexed<T>) => boolean,
1634
+ context?: any
1635
+ ): number;
1636
+
1637
+ /**
1638
+ * Returns the last index in the Iterable where a value satisfies the
1639
+ * provided predicate function. Otherwise -1 is returned.
1640
+ */
1641
+ findLastIndex(
1642
+ predicate: (value?: T, index?: number, iter?: /*this*/Iterable.Indexed<T>) => boolean,
1643
+ context?: any
1644
+ ): number;
1645
+ }
1646
+
1647
+
1648
+ /**
1649
+ * Set Iterables only represent values. They have no associated keys or
1650
+ * indices. Duplicate values are possible in Seq.Sets, however the
1651
+ * concrete `Set` does not allow duplicate values.
1652
+ *
1653
+ * Iterable methods on Iterable.Set such as `map` and `forEach` will provide
1654
+ * the value as both the first and second arguments to the provided function.
1655
+ *
1656
+ * var seq = Seq.Set.of('A', 'B', 'C');
1657
+ * assert.equal(seq.every((v, k) => v === k), true);
1658
+ *
1659
+ */
1660
+ export module Set {}
1661
+
1662
+ /**
1663
+ * Similar to `Iterable()`, but always returns a Iterable.Set.
1664
+ */
1665
+ export function Set<T>(iter: Iterable.Set<T>): Iterable.Set<T>;
1666
+ export function Set<T>(iter: Iterable.Indexed<T>): Iterable.Set<T>;
1667
+ export function Set<K, V>(iter: Iterable.Keyed<K, V>): Iterable.Set</*[K,V]*/any>;
1668
+ export function Set<T>(array: Array<T>): Iterable.Set<T>;
1669
+ export function Set<T>(iterator: Iterator<T>): Iterable.Set<T>;
1670
+ export function Set<T>(iterable: /*Iterable<T>*/Object): Iterable.Set<T>;
1671
+
1672
+ export interface Set<T> extends Iterable<T, T> {
1673
+
1674
+ /**
1675
+ * Returns Seq.Set.
1676
+ * @override
1677
+ */
1678
+ toSeq(): Seq.Set<T>;
1679
+ }
1680
+
1383
1681
  }
1384
1682
 
1385
1683
  /**
@@ -1388,21 +1686,21 @@ declare module Immutable {
1388
1686
  * The type of Iterable created is based on the input.
1389
1687
  *
1390
1688
  * * If an `Iterable`, that same `Iterable`.
1391
- * * If an Array-like, an `IndexedIterable`.
1392
- * * If an Object with an Iterator, an `IndexedIterable`.
1393
- * * If an Iterator, an `IndexedIterable`.
1394
- * * If an Object, a `KeyedIterable`.
1689
+ * * If an Array-like, an `Iterable.Indexed`.
1690
+ * * If an Object with an Iterator, an `Iterable.Indexed`.
1691
+ * * If an Iterator, an `Iterable.Indexed`.
1692
+ * * If an Object, an `Iterable.Keyed`.
1395
1693
  *
1396
1694
  * This methods forces the conversion of Objects and Strings to Iterables.
1397
1695
  * If you want to ensure that a Iterable of one item is returned, use
1398
1696
  * `Seq.of`.
1399
1697
  */
1400
1698
  export function Iterable<K, V>(iterable: Iterable<K, V>): Iterable<K, V>;
1401
- export function Iterable<T>(array: Array<T>): IndexedIterable<T>;
1402
- export function Iterable<V>(obj: {[key: string]: V}): KeyedIterable<string, V>;
1403
- export function Iterable<T>(iterator: Iterator<T>): IndexedIterable<T>;
1404
- export function Iterable<T>(iterable: /*ES6Iterable<T>*/Object): IndexedIterable<T>;
1405
- export function Iterable<V>(value: V): IndexedIterable<V>;
1699
+ export function Iterable<T>(array: Array<T>): Iterable.Indexed<T>;
1700
+ export function Iterable<V>(obj: {[key: string]: V}): Iterable.Keyed<string, V>;
1701
+ export function Iterable<T>(iterator: Iterator<T>): Iterable.Indexed<T>;
1702
+ export function Iterable<T>(iterable: /*ES6Iterable<T>*/Object): Iterable.Indexed<T>;
1703
+ export function Iterable<V>(value: V): Iterable.Indexed<V>;
1406
1704
 
1407
1705
  export interface Iterable<K, V> {
1408
1706
 
@@ -1452,12 +1750,12 @@ declare module Immutable {
1452
1750
  get(key: K, notSetValue?: V): V;
1453
1751
 
1454
1752
  /**
1455
- * True if a key exists within this `Iterable`.
1753
+ * True if a key exists within this `Iterable`, using `Immutable.is` to determine equality
1456
1754
  */
1457
1755
  has(key: K): boolean;
1458
1756
 
1459
1757
  /**
1460
- * True if a value exists within this `Iterable`.
1758
+ * True if a value exists within this `Iterable`, using `Immutable.is` to determine equality
1461
1759
  * @alias contains
1462
1760
  */
1463
1761
  includes(value: V): boolean;
@@ -1496,8 +1794,8 @@ declare module Immutable {
1496
1794
  /**
1497
1795
  * Deeply converts this Iterable to equivalent JS.
1498
1796
  *
1499
- * `IndexedIterables`, and `SetIterables` become Arrays, while
1500
- * `KeyedIterables` become Objects.
1797
+ * `Iterable.Indexeds`, and `Iterable.Sets` become Arrays, while
1798
+ * `Iterable.Keyeds` become Objects.
1501
1799
  *
1502
1800
  * @alias toJSON
1503
1801
  */
@@ -1532,7 +1830,7 @@ declare module Immutable {
1532
1830
  * Note: This is equivalent to `OrderedMap(this.toKeyedSeq())`, but
1533
1831
  * provided for convenience and to allow for chained expressions.
1534
1832
  */
1535
- toOrderedMap(): Map<K, V>;
1833
+ toOrderedMap(): OrderedMap<K, V>;
1536
1834
 
1537
1835
  /**
1538
1836
  * Converts this Iterable to a Set, discarding keys. Throws if values
@@ -1550,7 +1848,7 @@ declare module Immutable {
1550
1848
  * Note: This is equivalent to `OrderedSet(this.valueSeq())`, but provided
1551
1849
  * for convenience and to allow for chained expressions.
1552
1850
  */
1553
- toOrderedSet(): Set<V>;
1851
+ toOrderedSet(): OrderedSet<V>;
1554
1852
 
1555
1853
  /**
1556
1854
  * Converts this Iterable to a List, discarding keys.
@@ -1579,10 +1877,10 @@ declare module Immutable {
1579
1877
  toSeq(): Seq<K, V>;
1580
1878
 
1581
1879
  /**
1582
- * Returns a KeyedSeq from this Iterable where indices are treated as keys.
1880
+ * Returns a Seq.Keyed from this Iterable where indices are treated as keys.
1583
1881
  *
1584
1882
  * This is useful if you want to operate on an
1585
- * IndexedIterable and preserve the [index, value] pairs.
1883
+ * Iterable.Indexed and preserve the [index, value] pairs.
1586
1884
  *
1587
1885
  * The returned Seq will have identical iteration order as
1588
1886
  * this Iterable.
@@ -1595,33 +1893,39 @@ declare module Immutable {
1595
1893
  * keyedSeq.filter(v => v === 'B').toString() // Seq { 1: 'B' }
1596
1894
  *
1597
1895
  */
1598
- toKeyedSeq(): KeyedSeq<K, V>;
1896
+ toKeyedSeq(): Seq.Keyed<K, V>;
1599
1897
 
1600
1898
  /**
1601
- * Returns an IndexedSeq of the values of this Iterable, discarding keys.
1899
+ * Returns an Seq.Indexed of the values of this Iterable, discarding keys.
1602
1900
  */
1603
- toIndexedSeq(): IndexedSeq<V>;
1901
+ toIndexedSeq(): Seq.Indexed<V>;
1604
1902
 
1605
1903
  /**
1606
- * Returns a SetSeq of the values of this Iterable, discarding keys.
1904
+ * Returns a Seq.Set of the values of this Iterable, discarding keys.
1607
1905
  */
1608
- toSetSeq(): SetSeq<V>;
1906
+ toSetSeq(): Seq.Set<V>;
1609
1907
 
1610
1908
 
1611
1909
  // Iterators
1612
1910
 
1613
1911
  /**
1614
1912
  * An iterator of this `Iterable`'s keys.
1913
+ *
1914
+ * Note: this will return an ES6 iterator which does not support Immutable JS sequence algorithms. Use `keySeq` instead, if this is what you want.
1615
1915
  */
1616
1916
  keys(): Iterator<K>;
1617
1917
 
1618
1918
  /**
1619
1919
  * An iterator of this `Iterable`'s values.
1920
+ *
1921
+ * Note: this will return an ES6 iterator which does not support Immutable JS sequence algorithms. Use `valueSeq` instead, if this is what you want.
1620
1922
  */
1621
1923
  values(): Iterator<V>;
1622
1924
 
1623
1925
  /**
1624
1926
  * An iterator of this `Iterable`'s entries as `[key, value]` tuples.
1927
+ *
1928
+ * Note: this will return an ES6 iterator which does not support Immutable JS sequence algorithms. Use `entrySeq` instead, if this is what you want.
1625
1929
  */
1626
1930
  entries(): Iterator</*[K, V]*/Array<any>>;
1627
1931
 
@@ -1629,20 +1933,20 @@ declare module Immutable {
1629
1933
  // Iterables (Seq)
1630
1934
 
1631
1935
  /**
1632
- * Returns a new IndexedSeq of the keys of this Iterable,
1936
+ * Returns a new Seq.Indexed of the keys of this Iterable,
1633
1937
  * discarding values.
1634
1938
  */
1635
- keySeq(): IndexedSeq<K>;
1939
+ keySeq(): Seq.Indexed<K>;
1636
1940
 
1637
1941
  /**
1638
- * Returns an IndexedSeq of the values of this Iterable, discarding keys.
1942
+ * Returns an Seq.Indexed of the values of this Iterable, discarding keys.
1639
1943
  */
1640
- valueSeq(): IndexedSeq<V>;
1944
+ valueSeq(): Seq.Indexed<V>;
1641
1945
 
1642
1946
  /**
1643
- * Returns a new IndexedSeq of [key, value] tuples.
1947
+ * Returns a new Seq.Indexed of [key, value] tuples.
1644
1948
  */
1645
- entrySeq(): IndexedSeq</*(K, V)*/Array<any>>;
1949
+ entrySeq(): Seq.Indexed</*(K, V)*/Array<any>>;
1646
1950
 
1647
1951
 
1648
1952
  // Sequence algorithms
@@ -1723,7 +2027,7 @@ declare module Immutable {
1723
2027
  ): /*this*/Iterable<K, V>;
1724
2028
 
1725
2029
  /**
1726
- * Returns a `KeyedIterable` of `KeyedIterables`, grouped by the return
2030
+ * Returns a `Iterable.Keyed` of `Iterable.Keyeds`, grouped by the return
1727
2031
  * value of the `grouper` function.
1728
2032
  *
1729
2033
  * Note: This is always an eager operation.
@@ -1731,7 +2035,7 @@ declare module Immutable {
1731
2035
  groupBy<G>(
1732
2036
  grouper: (value?: V, key?: K, iter?: /*this*/Iterable<K, V>) => G,
1733
2037
  context?: any
1734
- ): /*Map*/KeyedSeq<G, /*this*/Iterable<K, V>>;
2038
+ ): /*Map*/Seq.Keyed<G, /*this*/Iterable<K, V>>;
1735
2039
 
1736
2040
 
1737
2041
  // Side effects
@@ -1979,7 +2283,7 @@ declare module Immutable {
1979
2283
  ): number;
1980
2284
 
1981
2285
  /**
1982
- * Returns a `KeyedSeq` of counts, grouped by the return value of
2286
+ * Returns a `Seq.Keyed` of counts, grouped by the return value of
1983
2287
  * the `grouper` function.
1984
2288
  *
1985
2289
  * Note: This is not a lazy operation.
@@ -1993,7 +2297,7 @@ declare module Immutable {
1993
2297
  // Search for value
1994
2298
 
1995
2299
  /**
1996
- * Returns the value for which the `predicate` returns true.
2300
+ * Returns the first value for which the `predicate` returns true.
1997
2301
  */
1998
2302
  find(
1999
2303
  predicate: (value?: V, key?: K, iter?: /*this*/Iterable<K, V>) => boolean,
@@ -2013,7 +2317,7 @@ declare module Immutable {
2013
2317
  ): V;
2014
2318
 
2015
2319
  /**
2016
- * Returns the [key, value] entry for which the `predicate` returns true.
2320
+ * Returns the first [key, value] entry for which the `predicate` returns true.
2017
2321
  */
2018
2322
  findEntry(
2019
2323
  predicate: (value?: V, key?: K, iter?: /*this*/Iterable<K, V>) => boolean,
@@ -2033,6 +2337,34 @@ declare module Immutable {
2033
2337
  notSetValue?: V
2034
2338
  ): /*[K, V]*/Array<any>;
2035
2339
 
2340
+ /**
2341
+ * Returns the key for which the `predicate` returns true.
2342
+ */
2343
+ findKey(
2344
+ predicate: (value?: V, key?: K, iter?: /*this*/Iterable.Keyed<K, V>) => boolean,
2345
+ context?: any
2346
+ ): K;
2347
+
2348
+ /**
2349
+ * Returns the last key for which the `predicate` returns true.
2350
+ *
2351
+ * Note: `predicate` will be called for each entry in reverse.
2352
+ */
2353
+ findLastKey(
2354
+ predicate: (value?: V, key?: K, iter?: /*this*/Iterable.Keyed<K, V>) => boolean,
2355
+ context?: any
2356
+ ): K;
2357
+
2358
+ /**
2359
+ * Returns the key associated with the search value, or undefined.
2360
+ */
2361
+ keyOf(searchValue: V): K;
2362
+
2363
+ /**
2364
+ * Returns the last key associated with the search value, or undefined.
2365
+ */
2366
+ lastKeyOf(searchValue: V): K;
2367
+
2036
2368
  /**
2037
2369
  * Returns the maximum value in this collection. If any values are
2038
2370
  * comparatively equivalent, the first one found will be returned.
@@ -2120,328 +2452,63 @@ declare module Immutable {
2120
2452
 
2121
2453
 
2122
2454
  /**
2123
- * Keyed Iterables have discrete keys tied to each value.
2124
- *
2125
- * When iterating `KeyedIterable`, each iteration will yield a `[K, V]` tuple,
2126
- * in other words, `Iterable#entries` is the default iterator for Keyed
2127
- * Iterables.
2128
- */
2129
- export module KeyedIterable {}
2130
-
2131
- /**
2132
- * Creates a KeyedIterable
2455
+ * Collection is the abstract base class for concrete data structures. It
2456
+ * cannot be constructed directly.
2133
2457
  *
2134
- * Similar to `Iterable()`, however it expects iterable-likes of [K, V]
2135
- * tuples if not constructed from a KeyedIterable or JS Object.
2136
- */
2137
- export function KeyedIterable<K, V>(iter: KeyedIterable<K, V>): KeyedIterable<K, V>;
2138
- export function KeyedIterable<K, V>(iter: Iterable<any, /*[K,V]*/any>): KeyedIterable<K, V>;
2139
- export function KeyedIterable<K, V>(array: Array</*[K,V]*/any>): KeyedIterable<K, V>;
2140
- export function KeyedIterable<V>(obj: {[key: string]: V}): KeyedIterable<string, V>;
2141
- export function KeyedIterable<K, V>(iterator: Iterator</*[K,V]*/any>): KeyedIterable<K, V>;
2142
- export function KeyedIterable<K, V>(iterable: /*Iterable<[K,V]>*/Object): KeyedIterable<K, V>;
2143
-
2144
- export interface KeyedIterable<K, V> extends Iterable<K, V> {
2145
-
2146
- /**
2147
- * Returns KeyedSeq.
2148
- * @override
2149
- */
2150
- toSeq(): KeyedSeq<K, V>;
2151
-
2152
-
2153
- // Sequence functions
2154
-
2155
- /**
2156
- * Returns a new KeyedIterable of the same type where the keys and values
2157
- * have been flipped.
2158
- *
2159
- * Seq({ a: 'z', b: 'y' }).flip() // { z: 'a', y: 'b' }
2160
- *
2161
- */
2162
- flip(): /*this*/KeyedIterable<V, K>;
2163
-
2164
- /**
2165
- * Returns a new KeyedIterable of the same type with keys passed through a
2166
- * `mapper` function.
2167
- *
2168
- * Seq({ a: 1, b: 2 })
2169
- * .mapKeys(x => x.toUpperCase())
2170
- * // Seq { A: 1, B: 2 }
2171
- *
2172
- */
2173
- mapKeys<M>(
2174
- mapper: (key?: K, value?: V, iter?: /*this*/KeyedIterable<K, V>) => M,
2175
- context?: any
2176
- ): /*this*/KeyedIterable<M, V>;
2177
-
2178
- /**
2179
- * Returns a new KeyedIterable of the same type with entries
2180
- * ([key, value] tuples) passed through a `mapper` function.
2181
- *
2182
- * Seq({ a: 1, b: 2 })
2183
- * .mapEntries(([k, v]) => [k.toUpperCase(), v * 2])
2184
- * // Seq { A: 2, B: 4 }
2185
- *
2186
- */
2187
- mapEntries<KM, VM>(
2188
- mapper: (
2189
- entry?: /*(K, V)*/Array<any>,
2190
- index?: number,
2191
- iter?: /*this*/KeyedIterable<K, V>
2192
- ) => /*[KM, VM]*/Array<any>,
2193
- context?: any
2194
- ): /*this*/KeyedIterable<KM, VM>;
2195
-
2196
-
2197
- // Search for value
2198
-
2199
- /**
2200
- * Returns the key associated with the search value, or undefined.
2201
- */
2202
- keyOf(searchValue: V): K;
2203
-
2204
- /**
2205
- * Returns the last key associated with the search value, or undefined.
2206
- */
2207
- lastKeyOf(searchValue: V): K;
2208
-
2209
- /**
2210
- * Returns the key for which the `predicate` returns true.
2211
- */
2212
- findKey(
2213
- predicate: (value?: V, key?: K, iter?: /*this*/KeyedIterable<K, V>) => boolean,
2214
- context?: any
2215
- ): K;
2216
-
2217
- /**
2218
- * Returns the last key for which the `predicate` returns true.
2219
- *
2220
- * Note: `predicate` will be called for each entry in reverse.
2221
- */
2222
- findLastKey(
2223
- predicate: (value?: V, key?: K, iter?: /*this*/KeyedIterable<K, V>) => boolean,
2224
- context?: any
2225
- ): K;
2226
- }
2227
-
2228
-
2229
- /**
2230
- * Indexed Iterables have incrementing numeric keys. They exhibit
2231
- * slightly different behavior than `KeyedIterable` for some methods in order
2232
- * to better mirror the behavior of JavaScript's `Array`, and add methods
2233
- * which do not make sense on non-indexed Iterables such as `indexOf`.
2234
- *
2235
- * Unlike JavaScript arrays, `IndexedIterable`s are always dense. "Unset"
2236
- * indices and `undefined` indices are indistinguishable, and all indices from
2237
- * 0 to `size` are visited when iterated.
2238
- *
2239
- * All IndexedIterable methods return re-indexed Iterables. In other words,
2240
- * indices always start at 0 and increment until size. If you wish to
2241
- * preserve indices, using them as keys, convert to a KeyedIterable by calling
2242
- * `toKeyedSeq`.
2458
+ * Implementations should extend one of the subclasses, `Collection.Keyed`,
2459
+ * `Collection.Indexed`, or `Collection.Set`.
2243
2460
  */
2244
- export module IndexedIterable {}
2245
-
2246
- /**
2247
- * Creates a new IndexedIterable.
2248
- */
2249
- export function IndexedIterable<T>(iter: IndexedIterable<T>): IndexedIterable<T>;
2250
- export function IndexedIterable<T>(iter: SetIterable<T>): IndexedIterable<T>;
2251
- export function IndexedIterable<K, V>(iter: KeyedIterable<K, V>): IndexedIterable</*[K,V]*/any>;
2252
- export function IndexedIterable<T>(array: Array<T>): IndexedIterable<T>;
2253
- export function IndexedIterable<T>(iterator: Iterator<T>): IndexedIterable<T>;
2254
- export function IndexedIterable<T>(iterable: /*Iterable<T>*/Object): IndexedIterable<T>;
2255
-
2256
- export interface IndexedIterable<T> extends Iterable<number, T> {
2257
-
2258
- // Reading values
2259
-
2260
- /**
2261
- * Returns the value associated with the provided index, or notSetValue if
2262
- * the index is beyond the bounds of the Iterable.
2263
- *
2264
- * `index` may be a negative number, which indexes back from the end of the
2265
- * Iterable. `s.get(-1)` gets the last item in the Iterable.
2266
- */
2267
- get(index: number, notSetValue?: T): T;
2461
+ export module Collection {
2268
2462
 
2269
2463
 
2270
- // Conversion to Seq
2271
-
2272
2464
  /**
2273
- * Returns IndexedSeq.
2274
- * @override
2465
+ * `Collection` which represents key-value pairs.
2275
2466
  */
2276
- toSeq(): IndexedSeq<T>;
2467
+ export module Keyed {}
2277
2468
 
2278
- /**
2279
- * If this is an iterable of [key, value] entry tuples, it will return a
2280
- * KeyedSeq of those entries.
2281
- */
2282
- fromEntrySeq(): KeyedSeq<any, any>;
2469
+ export interface Keyed<K, V> extends Collection<K, V>, Iterable.Keyed<K, V> {
2283
2470
 
2471
+ /**
2472
+ * Returns Seq.Keyed.
2473
+ * @override
2474
+ */
2475
+ toSeq(): Seq.Keyed<K, V>;
2476
+ }
2284
2477
 
2285
- // Combination
2286
2478
 
2287
2479
  /**
2288
- * Returns an Iterable of the same type with `separator` between each item
2289
- * in this Iterable.
2480
+ * `Collection` which represents ordered indexed values.
2290
2481
  */
2291
- interpose(separator: T): /*this*/IndexedIterable<T>;
2482
+ export module Indexed {}
2292
2483
 
2293
- /**
2294
- * Returns an Iterable of the same type with the provided `iterables`
2295
- * interleaved into this iterable.
2296
- *
2297
- * The resulting Iterable includes the first item from each, then the
2298
- * second from each, etc.
2299
- *
2300
- * I.Seq.of(1,2,3).interleave(I.Seq.of('A','B','C'))
2301
- * // Seq [ 1, 'A', 2, 'B', 3, 'C' ]
2302
- *
2303
- * The shortest Iterable stops interleave.
2304
- *
2305
- * I.Seq.of(1,2,3).interleave(
2306
- * I.Seq.of('A','B'),
2307
- * I.Seq.of('X','Y','Z')
2308
- * )
2309
- * // Seq [ 1, 'A', 'X', 2, 'B', 'Y' ]
2310
- */
2311
- interleave(...iterables: Array<Iterable<any, T>>): /*this*/IndexedIterable<T>;
2484
+ export interface Indexed<T> extends Collection<number, T>, Iterable.Indexed<T> {
2312
2485
 
2313
- /**
2314
- * Splice returns a new indexed Iterable by replacing a region of this
2315
- * Iterable with new values. If values are not provided, it only skips the
2316
- * region to be removed.
2317
- *
2318
- * `index` may be a negative number, which indexes back from the end of the
2319
- * Iterable. `s.splice(-2)` splices after the second to last item.
2320
- *
2321
- * Seq(['a','b','c','d']).splice(1, 2, 'q', 'r', 's')
2322
- * // Seq ['a', 'q', 'r', 's', 'd']
2323
- *
2324
- */
2325
- splice(
2326
- index: number,
2327
- removeNum: number,
2328
- ...values: /*Array<IndexedIterable<T> | T>*/any[]
2329
- ): /*this*/IndexedIterable<T>;
2486
+ /**
2487
+ * Returns Seq.Indexed.
2488
+ * @override
2489
+ */
2490
+ toSeq(): Seq.Indexed<T>;
2491
+ }
2330
2492
 
2331
- /**
2332
- * Returns an Iterable of the same type "zipped" with the provided
2333
- * iterables.
2334
- *
2335
- * Like `zipWith`, but using the default `zipper`: creating an `Array`.
2336
- *
2337
- * var a = Seq.of(1, 2, 3);
2338
- * var b = Seq.of(4, 5, 6);
2339
- * var c = a.zip(b); // Seq [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]
2340
- *
2341
- */
2342
- zip(...iterables: Array<Iterable<any, any>>): /*this*/IndexedIterable<any>;
2343
2493
 
2344
2494
  /**
2345
- * Returns an Iterable of the same type "zipped" with the provided
2346
- * iterables by using a custom `zipper` function.
2495
+ * `Collection` which represents values, unassociated with keys or indices.
2347
2496
  *
2348
- * var a = Seq.of(1, 2, 3);
2349
- * var b = Seq.of(4, 5, 6);
2350
- * var c = a.zipWith((a, b) => a + b, b); // Seq [ 5, 7, 9 ]
2351
- *
2352
- */
2353
- zipWith<U, Z>(
2354
- zipper: (value: T, otherValue: U) => Z,
2355
- otherIterable: Iterable<any, U>
2356
- ): IndexedIterable<Z>;
2357
- zipWith<U, V, Z>(
2358
- zipper: (value: T, otherValue: U, thirdValue: V) => Z,
2359
- otherIterable: Iterable<any, U>,
2360
- thirdIterable: Iterable<any, V>
2361
- ): IndexedIterable<Z>;
2362
- zipWith<Z>(
2363
- zipper: (...any: Array<any>) => Z,
2364
- ...iterables: Array<Iterable<any, any>>
2365
- ): IndexedIterable<Z>;
2366
-
2367
-
2368
- // Search for value
2369
-
2370
- /**
2371
- * Returns the first index at which a given value can be found in the
2372
- * Iterable, or -1 if it is not present.
2373
- */
2374
- indexOf(searchValue: T): number;
2375
-
2376
- /**
2377
- * Returns the last index at which a given value can be found in the
2378
- * Iterable, or -1 if it is not present.
2379
- */
2380
- lastIndexOf(searchValue: T): number;
2381
-
2382
- /**
2383
- * Returns the first index in the Iterable where a value satisfies the
2384
- * provided predicate function. Otherwise -1 is returned.
2385
- */
2386
- findIndex(
2387
- predicate: (value?: T, index?: number, iter?: /*this*/IndexedIterable<T>) => boolean,
2388
- context?: any
2389
- ): number;
2390
-
2391
- /**
2392
- * Returns the last index in the Iterable where a value satisfies the
2393
- * provided predicate function. Otherwise -1 is returned.
2497
+ * `Collection.Set` implementations should guarantee value uniqueness.
2394
2498
  */
2395
- findLastIndex(
2396
- predicate: (value?: T, index?: number, iter?: /*this*/IndexedIterable<T>) => boolean,
2397
- context?: any
2398
- ): number;
2399
- }
2499
+ export module Set {}
2400
2500
 
2501
+ export interface Set<T> extends Collection<T, T>, Iterable.Set<T> {
2401
2502
 
2402
- /**
2403
- * Set Iterables only represent values. They have no associated keys or
2404
- * indices. Duplicate values are possible in SetSeqs, however the
2405
- * concrete `Set` does not allow duplicate values.
2406
- *
2407
- * Iterable methods on SetIterable such as `map` and `forEach` will provide
2408
- * the value as both the first and second arguments to the provided function.
2409
- *
2410
- * var seq = SetSeq.of('A', 'B', 'C');
2411
- * assert.equal(seq.every((v, k) => v === k), true);
2412
- *
2413
- */
2414
- export module SetIterable {}
2415
-
2416
- /**
2417
- * Similar to `Iterable()`, but always returns a SetIterable.
2418
- */
2419
- export function SetIterable<T>(iter: SetIterable<T>): SetIterable<T>;
2420
- export function SetIterable<T>(iter: IndexedIterable<T>): SetIterable<T>;
2421
- export function SetIterable<K, V>(iter: KeyedIterable<K, V>): SetIterable</*[K,V]*/any>;
2422
- export function SetIterable<T>(array: Array<T>): SetIterable<T>;
2423
- export function SetIterable<T>(iterator: Iterator<T>): SetIterable<T>;
2424
- export function SetIterable<T>(iterable: /*Iterable<T>*/Object): SetIterable<T>;
2425
-
2426
- export interface SetIterable<T> extends Iterable<T, T> {
2503
+ /**
2504
+ * Returns Seq.Set.
2505
+ * @override
2506
+ */
2507
+ toSeq(): Seq.Set<T>;
2508
+ }
2427
2509
 
2428
- /**
2429
- * Returns SetSeq.
2430
- * @override
2431
- */
2432
- toSeq(): SetSeq<T>;
2433
2510
  }
2434
2511
 
2435
-
2436
- /**
2437
- * Collection is the abstract base class for concrete data structures. It
2438
- * cannot be constructed directly.
2439
- *
2440
- * Implementations should extend one of the subclasses, `KeyedCollection`,
2441
- * `IndexedCollection`, or `SetCollection`.
2442
- */
2443
- export module Collection {}
2444
-
2445
2512
  export interface Collection<K, V> extends Iterable<K, V> {
2446
2513
 
2447
2514
  /**
@@ -2451,53 +2518,6 @@ declare module Immutable {
2451
2518
  }
2452
2519
 
2453
2520
 
2454
- /**
2455
- * `Collection` which represents key-value pairs.
2456
- */
2457
- export module KeyedCollection {}
2458
-
2459
- export interface KeyedCollection<K, V> extends Collection<K, V>, KeyedIterable<K, V> {
2460
-
2461
- /**
2462
- * Returns KeyedSeq.
2463
- * @override
2464
- */
2465
- toSeq(): KeyedSeq<K, V>;
2466
- }
2467
-
2468
-
2469
- /**
2470
- * `Collection` which represents ordered indexed values.
2471
- */
2472
- export module IndexedCollection {}
2473
-
2474
- export interface IndexedCollection<T> extends Collection<number, T>, IndexedIterable<T> {
2475
-
2476
- /**
2477
- * Returns IndexedSeq.
2478
- * @override
2479
- */
2480
- toSeq(): IndexedSeq<T>;
2481
- }
2482
-
2483
-
2484
- /**
2485
- * `Collection` which represents values, unassociated with keys or indices.
2486
- *
2487
- * `SetCollection` implementations should guarantee value uniqueness.
2488
- */
2489
- export module SetCollection {}
2490
-
2491
- export interface SetCollection<T> extends Collection<T, T>, SetIterable<T> {
2492
-
2493
- /**
2494
- * Returns SetSeq.
2495
- * @override
2496
- */
2497
- toSeq(): SetSeq<T>;
2498
- }
2499
-
2500
-
2501
2521
  /**
2502
2522
  * ES6 Iterator.
2503
2523
  *