immutable 3.7.4 → 3.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2535 @@
1
+ /**
2
+ * Copyright (c) 2014-2015, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
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.
8
+ */
9
+
10
+ /**
11
+ * Immutable data encourages pure functions (data-in, data-out) and lends itself
12
+ * to much simpler application development and enabling techniques from
13
+ * functional programming such as lazy evaluation.
14
+ *
15
+ * While designed to bring these powerful functional concepts to JavaScript, it
16
+ * presents an Object-Oriented API familiar to Javascript engineers and closely
17
+ * mirroring that of Array, Map, and Set. It is easy and efficient to convert to
18
+ * and from plain Javascript types.
19
+
20
+ * Note: all examples are presented in [ES6][]. To run in all browsers, they
21
+ * need to be translated to ES3. For example:
22
+ *
23
+ * // ES6
24
+ * foo.map(x => x * x);
25
+ * // ES3
26
+ * foo.map(function (x) { return x * x; });
27
+ *
28
+ * [ES6]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/New_in_JavaScript/ECMAScript_6_support_in_Mozilla
29
+ */
30
+
31
+
32
+
33
+ /**
34
+ * Deeply converts plain JS objects and arrays to Immutable Maps and Lists.
35
+ *
36
+ * If a `reviver` is optionally provided, it will be called with every
37
+ * collection as a Seq (beginning with the most nested collections
38
+ * and proceeding to the top-level collection itself), along with the key
39
+ * refering to each collection and the parent JS object provided as `this`.
40
+ * For the top level, object, the key will be `""`. This `reviver` is expected
41
+ * to return a new Immutable Iterable, allowing for custom conversions from
42
+ * deep JS objects.
43
+ *
44
+ * This example converts JSON to List and OrderedMap:
45
+ *
46
+ * Immutable.fromJS({a: {b: [10, 20, 30]}, c: 40}, function (key, value) {
47
+ * var isIndexed = Immutable.Iterable.isIndexed(value);
48
+ * return isIndexed ? value.toList() : value.toOrderedMap();
49
+ * });
50
+ *
51
+ * // true, "b", {b: [10, 20, 30]}
52
+ * // false, "a", {a: {b: [10, 20, 30]}, c: 40}
53
+ * // false, "", {"": {a: {b: [10, 20, 30]}, c: 40}}
54
+ *
55
+ * If `reviver` is not provided, the default behavior will convert Arrays into
56
+ * Lists and Objects into Maps.
57
+ *
58
+ * `reviver` acts similarly to the [same parameter in `JSON.parse`][1].
59
+ *
60
+ * `Immutable.fromJS` is conservative in its conversion. It will only convert
61
+ * arrays which pass `Array.isArray` to Lists, and only raw objects (no custom
62
+ * prototype) to Map.
63
+ *
64
+ * Keep in mind, when using JS objects to construct Immutable Maps, that
65
+ * JavaScript Object properties are always strings, even if written in a
66
+ * quote-less shorthand, while Immutable Maps accept keys of any type.
67
+ *
68
+ * ```js
69
+ * var obj = { 1: "one" };
70
+ * Object.keys(obj); // [ "1" ]
71
+ * obj["1"]; // "one"
72
+ * obj[1]; // "one"
73
+ *
74
+ * var map = Map(obj);
75
+ * map.get("1"); // "one"
76
+ * map.get(1); // undefined
77
+ * ```
78
+ *
79
+ * Property access for JavaScript Objects first converts the key to a string,
80
+ * but since Immutable Map keys can be of any type the argument to `get()` is
81
+ * not altered.
82
+ *
83
+ * [1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Example.3A_Using_the_reviver_parameter
84
+ * "Using the reviver parameter"
85
+ */
86
+ export function fromJS(
87
+ json: any,
88
+ reviver?: (k: any, v: Iterable<any, any>) => any
89
+ ): any;
90
+
91
+
92
+ /**
93
+ * Value equality check with semantics similar to `Object.is`, but treats
94
+ * Immutable `Iterable`s as values, equal if the second `Iterable` includes
95
+ * equivalent values.
96
+ *
97
+ * It's used throughout Immutable when checking for equality, including `Map`
98
+ * key equality and `Set` membership.
99
+ *
100
+ * var map1 = Immutable.Map({a:1, b:1, c:1});
101
+ * var map2 = Immutable.Map({a:1, b:1, c:1});
102
+ * assert(map1 !== map2);
103
+ * assert(Object.is(map1, map2) === false);
104
+ * assert(Immutable.is(map1, map2) === true);
105
+ *
106
+ * Note: Unlike `Object.is`, `Immutable.is` assumes `0` and `-0` are the same
107
+ * value, matching the behavior of ES6 Map key equality.
108
+ */
109
+ export function is(first: any, second: any): boolean;
110
+
111
+
112
+ /**
113
+ * Lists are ordered indexed dense collections, much like a JavaScript
114
+ * Array.
115
+ *
116
+ * Lists are immutable and fully persistent with O(log32 N) gets and sets,
117
+ * and O(1) push and pop.
118
+ *
119
+ * Lists implement Deque, with efficient addition and removal from both the
120
+ * end (`push`, `pop`) and beginning (`unshift`, `shift`).
121
+ *
122
+ * Unlike a JavaScript Array, there is no distinction between an
123
+ * "unset" index and an index set to `undefined`. `List#forEach` visits all
124
+ * indices from 0 to size, regardless of whether they were explicitly defined.
125
+ */
126
+ export module List {
127
+
128
+ /**
129
+ * True if the provided value is a List
130
+ */
131
+ function isList(maybeList: any): boolean;
132
+
133
+ /**
134
+ * Creates a new List containing `values`.
135
+ */
136
+ function of<T>(...values: T[]): List<T>;
137
+ }
138
+
139
+ /**
140
+ * Create a new immutable List containing the values of the provided
141
+ * iterable-like.
142
+ */
143
+ export function List<T>(): List<T>;
144
+ export function List<T>(iter: Iterable.Indexed<T>): List<T>;
145
+ export function List<T>(iter: Iterable.Set<T>): List<T>;
146
+ export function List<K, V>(iter: Iterable.Keyed<K, V>): List</*[K,V]*/any>;
147
+ export function List<T>(array: Array<T>): List<T>;
148
+ export function List<T>(iterator: Iterator<T>): List<T>;
149
+ export function List<T>(iterable: /*Iterable<T>*/Object): List<T>;
150
+
151
+
152
+ export interface List<T> extends Collection.Indexed<T> {
153
+
154
+ // Persistent changes
155
+
156
+ /**
157
+ * Returns a new List which includes `value` at `index`. If `index` already
158
+ * exists in this List, it will be replaced.
159
+ *
160
+ * `index` may be a negative number, which indexes back from the end of the
161
+ * List. `v.set(-1, "value")` sets the last item in the List.
162
+ *
163
+ * If `index` larger than `size`, the returned List's `size` will be large
164
+ * enough to include the `index`.
165
+ */
166
+ set(index: number, value: T): List<T>;
167
+
168
+ /**
169
+ * Returns a new List which excludes this `index` and with a size 1 less
170
+ * than this List. Values at indices above `index` are shifted down by 1 to
171
+ * fill the position.
172
+ *
173
+ * This is synonymous with `list.splice(index, 1)`.
174
+ *
175
+ * `index` may be a negative number, which indexes back from the end of the
176
+ * List. `v.delete(-1)` deletes the last item in the List.
177
+ *
178
+ * Note: `delete` cannot be safely used in IE8
179
+ * @alias remove
180
+ */
181
+ delete(index: number): List<T>;
182
+ remove(index: number): List<T>;
183
+
184
+ /**
185
+ * Returns a new List with `value` at `index` with a size 1 more than this
186
+ * List. Values at indices above `index` are shifted over by 1.
187
+ *
188
+ * This is synonymous with `list.splice(index, 0, value)
189
+ */
190
+ insert(index: number, value: T): List<T>;
191
+
192
+ /**
193
+ * Returns a new List with 0 size and no values.
194
+ */
195
+ clear(): List<T>;
196
+
197
+ /**
198
+ * Returns a new List with the provided `values` appended, starting at this
199
+ * List's `size`.
200
+ */
201
+ push(...values: T[]): List<T>;
202
+
203
+ /**
204
+ * Returns a new List with a size ones less than this List, excluding
205
+ * the last index in this List.
206
+ *
207
+ * Note: this differs from `Array#pop` because it returns a new
208
+ * List rather than the removed value. Use `last()` to get the last value
209
+ * in this List.
210
+ */
211
+ pop(): List<T>;
212
+
213
+ /**
214
+ * Returns a new List with the provided `values` prepended, shifting other
215
+ * values ahead to higher indices.
216
+ */
217
+ unshift(...values: T[]): List<T>;
218
+
219
+ /**
220
+ * Returns a new List with a size ones less than this List, excluding
221
+ * the first index in this List, shifting all other values to a lower index.
222
+ *
223
+ * Note: this differs from `Array#shift` because it returns a new
224
+ * List rather than the removed value. Use `first()` to get the first
225
+ * value in this List.
226
+ */
227
+ shift(): List<T>;
228
+
229
+ /**
230
+ * Returns a new List with an updated value at `index` with the return
231
+ * value of calling `updater` with the existing value, or `notSetValue` if
232
+ * `index` was not set. If called with a single argument, `updater` is
233
+ * called with the List itself.
234
+ *
235
+ * `index` may be a negative number, which indexes back from the end of the
236
+ * List. `v.update(-1)` updates the last item in the List.
237
+ *
238
+ * @see `Map#update`
239
+ */
240
+ update(updater: (value: List<T>) => List<T>): List<T>;
241
+ update(index: number, updater: (value: T) => T): List<T>;
242
+ update(index: number, notSetValue: T, updater: (value: T) => T): List<T>;
243
+
244
+ /**
245
+ * @see `Map#merge`
246
+ */
247
+ merge(...iterables: Iterable.Indexed<T>[]): List<T>;
248
+ merge(...iterables: Array<T>[]): List<T>;
249
+
250
+ /**
251
+ * @see `Map#mergeWith`
252
+ */
253
+ mergeWith(
254
+ merger: (previous?: T, next?: T, key?: number) => T,
255
+ ...iterables: Iterable.Indexed<T>[]
256
+ ): List<T>;
257
+ mergeWith(
258
+ merger: (previous?: T, next?: T, key?: number) => T,
259
+ ...iterables: Array<T>[]
260
+ ): List<T>;
261
+
262
+ /**
263
+ * @see `Map#mergeDeep`
264
+ */
265
+ mergeDeep(...iterables: Iterable.Indexed<T>[]): List<T>;
266
+ mergeDeep(...iterables: Array<T>[]): List<T>;
267
+
268
+ /**
269
+ * @see `Map#mergeDeepWith`
270
+ */
271
+ mergeDeepWith(
272
+ merger: (previous?: T, next?: T, key?: number) => T,
273
+ ...iterables: Iterable.Indexed<T>[]
274
+ ): List<T>;
275
+ mergeDeepWith(
276
+ merger: (previous?: T, next?: T, key?: number) => T,
277
+ ...iterables: Array<T>[]
278
+ ): List<T>;
279
+
280
+ /**
281
+ * Returns a new List with size `size`. If `size` is less than this
282
+ * List's size, the new List will exclude values at the higher indices.
283
+ * If `size` is greater than this List's size, the new List will have
284
+ * undefined values for the newly available indices.
285
+ *
286
+ * When building a new List and the final size is known up front, `setSize`
287
+ * used in conjunction with `withMutations` may result in the more
288
+ * performant construction.
289
+ */
290
+ setSize(size: number): List<T>;
291
+
292
+
293
+ // Deep persistent changes
294
+
295
+ /**
296
+ * Returns a new List having set `value` at this `keyPath`. If any keys in
297
+ * `keyPath` do not exist, a new immutable Map will be created at that key.
298
+ *
299
+ * Index numbers are used as keys to determine the path to follow in
300
+ * the List.
301
+ */
302
+ setIn(keyPath: Array<any>, value: any): List<T>;
303
+ setIn(keyPath: Iterable<any, any>, value: any): List<T>;
304
+
305
+ /**
306
+ * Returns a new List having removed the value at this `keyPath`. If any
307
+ * keys in `keyPath` do not exist, no change will occur.
308
+ *
309
+ * @alias removeIn
310
+ */
311
+ deleteIn(keyPath: Array<any>): List<T>;
312
+ deleteIn(keyPath: Iterable<any, any>): List<T>;
313
+ removeIn(keyPath: Array<any>): List<T>;
314
+ removeIn(keyPath: Iterable<any, any>): List<T>;
315
+
316
+ /**
317
+ * @see `Map#updateIn`
318
+ */
319
+ updateIn(
320
+ keyPath: Array<any>,
321
+ updater: (value: any) => any
322
+ ): List<T>;
323
+ updateIn(
324
+ keyPath: Array<any>,
325
+ notSetValue: any,
326
+ updater: (value: any) => any
327
+ ): List<T>;
328
+ updateIn(
329
+ keyPath: Iterable<any, any>,
330
+ updater: (value: any) => any
331
+ ): List<T>;
332
+ updateIn(
333
+ keyPath: Iterable<any, any>,
334
+ notSetValue: any,
335
+ updater: (value: any) => any
336
+ ): List<T>;
337
+
338
+ /**
339
+ * @see `Map#mergeIn`
340
+ */
341
+ mergeIn(
342
+ keyPath: Iterable<any, any>,
343
+ ...iterables: Iterable.Indexed<T>[]
344
+ ): List<T>;
345
+ mergeIn(
346
+ keyPath: Array<any>,
347
+ ...iterables: Iterable.Indexed<T>[]
348
+ ): List<T>;
349
+ mergeIn(
350
+ keyPath: Array<any>,
351
+ ...iterables: Array<T>[]
352
+ ): List<T>;
353
+
354
+ /**
355
+ * @see `Map#mergeDeepIn`
356
+ */
357
+ mergeDeepIn(
358
+ keyPath: Iterable<any, any>,
359
+ ...iterables: Iterable.Indexed<T>[]
360
+ ): List<T>;
361
+ mergeDeepIn(
362
+ keyPath: Array<any>,
363
+ ...iterables: Iterable.Indexed<T>[]
364
+ ): List<T>;
365
+ mergeDeepIn(
366
+ keyPath: Array<any>,
367
+ ...iterables: Array<T>[]
368
+ ): List<T>;
369
+
370
+
371
+ // Transient changes
372
+
373
+ /**
374
+ * Note: Not all methods can be used on a mutable collection or within
375
+ * `withMutations`! Only `set`, `push`, `pop`, `shift`, `unshift` and
376
+ * `merge` may be used mutatively.
377
+ *
378
+ * @see `Map#withMutations`
379
+ */
380
+ withMutations(mutator: (mutable: List<T>) => any): List<T>;
381
+
382
+ /**
383
+ * @see `Map#asMutable`
384
+ */
385
+ asMutable(): List<T>;
386
+
387
+ /**
388
+ * @see `Map#asImmutable`
389
+ */
390
+ asImmutable(): List<T>;
391
+ }
392
+
393
+
394
+ /**
395
+ * Immutable Map is an unordered Iterable.Keyed of (key, value) pairs with
396
+ * `O(log32 N)` gets and `O(log32 N)` persistent sets.
397
+ *
398
+ * Iteration order of a Map is undefined, however is stable. Multiple
399
+ * iterations of the same Map will iterate in the same order.
400
+ *
401
+ * Map's keys can be of any type, and use `Immutable.is` to determine key
402
+ * equality. This allows the use of any value (including NaN) as a key.
403
+ *
404
+ * Because `Immutable.is` returns equality based on value semantics, and
405
+ * Immutable collections are treated as values, any Immutable collection may
406
+ * be used as a key.
407
+ *
408
+ * Map().set(List.of(1), 'listofone').get(List.of(1));
409
+ * // 'listofone'
410
+ *
411
+ * Any JavaScript object may be used as a key, however strict identity is used
412
+ * to evaluate key equality. Two similar looking objects will represent two
413
+ * different keys.
414
+ *
415
+ * Implemented by a hash-array mapped trie.
416
+ */
417
+ export module Map {
418
+
419
+ /**
420
+ * True if the provided value is a Map
421
+ */
422
+ function isMap(maybeMap: any): boolean;
423
+
424
+ /**
425
+ * Creates a new Map from alternating keys and values
426
+ */
427
+ function of(...keyValues: any[]): Map<any, any>;
428
+ }
429
+
430
+ /**
431
+ * Creates a new Immutable Map.
432
+ *
433
+ * Created with the same key value pairs as the provided Iterable.Keyed or
434
+ * JavaScript Object or expects an Iterable of [K, V] tuple entries.
435
+ *
436
+ * var newMap = Map({key: "value"});
437
+ * var newMap = Map([["key", "value"]]);
438
+ *
439
+ * Keep in mind, when using JS objects to construct Immutable Maps, that
440
+ * JavaScript Object properties are always strings, even if written in a
441
+ * quote-less shorthand, while Immutable Maps accept keys of any type.
442
+ *
443
+ * ```js
444
+ * var obj = { 1: "one" };
445
+ * Object.keys(obj); // [ "1" ]
446
+ * obj["1"]; // "one"
447
+ * obj[1]; // "one"
448
+ *
449
+ * var map = Map(obj);
450
+ * map.get("1"); // "one"
451
+ * map.get(1); // undefined
452
+ * ```
453
+ *
454
+ * Property access for JavaScript Objects first converts the key to a string,
455
+ * but since Immutable Map keys can be of any type the argument to `get()` is
456
+ * not altered.
457
+ */
458
+ export function Map<K, V>(): Map<K, V>;
459
+ export function Map<K, V>(iter: Iterable.Keyed<K, V>): Map<K, V>;
460
+ export function Map<K, V>(iter: Iterable<any, /*[K,V]*/Array<any>>): Map<K, V>;
461
+ export function Map<K, V>(array: Array</*[K,V]*/Array<any>>): Map<K, V>;
462
+ export function Map<V>(obj: {[key: string]: V}): Map<string, V>;
463
+ export function Map<K, V>(iterator: Iterator</*[K,V]*/Array<any>>): Map<K, V>;
464
+ export function Map<K, V>(iterable: /*Iterable<[K,V]>*/Object): Map<K, V>;
465
+
466
+ export interface Map<K, V> extends Collection.Keyed<K, V> {
467
+
468
+ // Persistent changes
469
+
470
+ /**
471
+ * Returns a new Map also containing the new key, value pair. If an equivalent
472
+ * key already exists in this Map, it will be replaced.
473
+ */
474
+ set(key: K, value: V): Map<K, V>;
475
+
476
+ /**
477
+ * Returns a new Map which excludes this `key`.
478
+ *
479
+ * Note: `delete` cannot be safely used in IE8, but is provided to mirror
480
+ * the ES6 collection API.
481
+ * @alias remove
482
+ */
483
+ delete(key: K): Map<K, V>;
484
+ remove(key: K): Map<K, V>;
485
+
486
+ /**
487
+ * Returns a new Map containing no keys or values.
488
+ */
489
+ clear(): Map<K, V>;
490
+
491
+ /**
492
+ * Returns a new Map having updated the value at this `key` with the return
493
+ * value of calling `updater` with the existing value, or `notSetValue` if
494
+ * the key was not set. If called with only a single argument, `updater` is
495
+ * called with the Map itself.
496
+ *
497
+ * Equivalent to: `map.set(key, updater(map.get(key, notSetValue)))`.
498
+ */
499
+ update(updater: (value: Map<K, V>) => Map<K, V>): Map<K, V>;
500
+ update(key: K, updater: (value: V) => V): Map<K, V>;
501
+ update(key: K, notSetValue: V, updater: (value: V) => V): Map<K, V>;
502
+
503
+ /**
504
+ * Returns a new Map resulting from merging the provided Iterables
505
+ * (or JS objects) into this Map. In other words, this takes each entry of
506
+ * each iterable and sets it on this Map.
507
+ *
508
+ * If any of the values provided to `merge` are not Iterable (would return
509
+ * false for `Immutable.Iterable.isIterable`) then they are deeply converted
510
+ * via `Immutable.fromJS` before being merged. However, if the value is an
511
+ * Iterable but includes non-iterable JS objects or arrays, those nested
512
+ * values will be preserved.
513
+ *
514
+ * var x = Immutable.Map({a: 10, b: 20, c: 30});
515
+ * var y = Immutable.Map({b: 40, a: 50, d: 60});
516
+ * x.merge(y) // { a: 50, b: 40, c: 30, d: 60 }
517
+ * y.merge(x) // { b: 20, a: 10, d: 60, c: 30 }
518
+ *
519
+ */
520
+ merge(...iterables: Iterable<K, V>[]): Map<K, V>;
521
+ merge(...iterables: {[key: string]: V}[]): Map<string, V>;
522
+
523
+ /**
524
+ * Like `merge()`, `mergeWith()` returns a new Map resulting from merging
525
+ * the provided Iterables (or JS objects) into this Map, but uses the
526
+ * `merger` function for dealing with conflicts.
527
+ *
528
+ * var x = Immutable.Map({a: 10, b: 20, c: 30});
529
+ * var y = Immutable.Map({b: 40, a: 50, d: 60});
530
+ * x.mergeWith((prev, next) => prev / next, y) // { a: 0.2, b: 0.5, c: 30, d: 60 }
531
+ * y.mergeWith((prev, next) => prev / next, x) // { b: 2, a: 5, d: 60, c: 30 }
532
+ *
533
+ */
534
+ mergeWith(
535
+ merger: (previous?: V, next?: V, key?: K) => V,
536
+ ...iterables: Iterable<K, V>[]
537
+ ): Map<K, V>;
538
+ mergeWith(
539
+ merger: (previous?: V, next?: V, key?: K) => V,
540
+ ...iterables: {[key: string]: V}[]
541
+ ): Map<string, V>;
542
+
543
+ /**
544
+ * Like `merge()`, but when two Iterables conflict, it merges them as well,
545
+ * recursing deeply through the nested data.
546
+ *
547
+ * var x = Immutable.fromJS({a: { x: 10, y: 10 }, b: { x: 20, y: 50 } });
548
+ * var y = Immutable.fromJS({a: { x: 2 }, b: { y: 5 }, c: { z: 3 } });
549
+ * x.mergeDeep(y) // {a: { x: 2, y: 10 }, b: { x: 20, y: 5 }, c: { z: 3 } }
550
+ *
551
+ */
552
+ mergeDeep(...iterables: Iterable<K, V>[]): Map<K, V>;
553
+ mergeDeep(...iterables: {[key: string]: V}[]): Map<string, V>;
554
+
555
+ /**
556
+ * Like `mergeDeep()`, but when two non-Iterables conflict, it uses the
557
+ * `merger` function to determine the resulting value.
558
+ *
559
+ * var x = Immutable.fromJS({a: { x: 10, y: 10 }, b: { x: 20, y: 50 } });
560
+ * var y = Immutable.fromJS({a: { x: 2 }, b: { y: 5 }, c: { z: 3 } });
561
+ * x.mergeDeepWith((prev, next) => prev / next, y)
562
+ * // {a: { x: 5, y: 10 }, b: { x: 20, y: 10 }, c: { z: 3 } }
563
+ *
564
+ */
565
+ mergeDeepWith(
566
+ merger: (previous?: V, next?: V, key?: K) => V,
567
+ ...iterables: Iterable<K, V>[]
568
+ ): Map<K, V>;
569
+ mergeDeepWith(
570
+ merger: (previous?: V, next?: V, key?: K) => V,
571
+ ...iterables: {[key: string]: V}[]
572
+ ): Map<string, V>;
573
+
574
+
575
+ // Deep persistent changes
576
+
577
+ /**
578
+ * Returns a new Map having set `value` at this `keyPath`. If any keys in
579
+ * `keyPath` do not exist, a new immutable Map will be created at that key.
580
+ */
581
+ setIn(keyPath: Array<any>, value: any): Map<K, V>;
582
+ setIn(KeyPath: Iterable<any, any>, value: any): Map<K, V>;
583
+
584
+ /**
585
+ * Returns a new Map having removed the value at this `keyPath`. If any keys
586
+ * in `keyPath` do not exist, no change will occur.
587
+ *
588
+ * @alias removeIn
589
+ */
590
+ deleteIn(keyPath: Array<any>): Map<K, V>;
591
+ deleteIn(keyPath: Iterable<any, any>): Map<K, V>;
592
+ removeIn(keyPath: Array<any>): Map<K, V>;
593
+ removeIn(keyPath: Iterable<any, any>): Map<K, V>;
594
+
595
+ /**
596
+ * Returns a new Map having applied the `updater` to the entry found at the
597
+ * keyPath.
598
+ *
599
+ * If any keys in `keyPath` do not exist, new Immutable `Map`s will
600
+ * be created at those keys. If the `keyPath` does not already contain a
601
+ * value, the `updater` function will be called with `notSetValue`, if
602
+ * provided, otherwise `undefined`.
603
+ *
604
+ * var data = Immutable.fromJS({ a: { b: { c: 10 } } });
605
+ * data = data.updateIn(['a', 'b', 'c'], val => val * 2);
606
+ * // { a: { b: { c: 20 } } }
607
+ *
608
+ * If the `updater` function returns the same value it was called with, then
609
+ * no change will occur. This is still true if `notSetValue` is provided.
610
+ *
611
+ * var data1 = Immutable.fromJS({ a: { b: { c: 10 } } });
612
+ * data2 = data1.updateIn(['x', 'y', 'z'], 100, val => val);
613
+ * assert(data2 === data1);
614
+ *
615
+ */
616
+ updateIn(
617
+ keyPath: Array<any>,
618
+ updater: (value: any) => any
619
+ ): Map<K, V>;
620
+ updateIn(
621
+ keyPath: Array<any>,
622
+ notSetValue: any,
623
+ updater: (value: any) => any
624
+ ): Map<K, V>;
625
+ updateIn(
626
+ keyPath: Iterable<any, any>,
627
+ updater: (value: any) => any
628
+ ): Map<K, V>;
629
+ updateIn(
630
+ keyPath: Iterable<any, any>,
631
+ notSetValue: any,
632
+ updater: (value: any) => any
633
+ ): Map<K, V>;
634
+
635
+ /**
636
+ * A combination of `updateIn` and `merge`, returning a new Map, but
637
+ * performing the merge at a point arrived at by following the keyPath.
638
+ * In other words, these two lines are equivalent:
639
+ *
640
+ * x.updateIn(['a', 'b', 'c'], abc => abc.merge(y));
641
+ * x.mergeIn(['a', 'b', 'c'], y);
642
+ *
643
+ */
644
+ mergeIn(
645
+ keyPath: Iterable<any, any>,
646
+ ...iterables: Iterable<K, V>[]
647
+ ): Map<K, V>;
648
+ mergeIn(
649
+ keyPath: Array<any>,
650
+ ...iterables: Iterable<K, V>[]
651
+ ): Map<K, V>;
652
+ mergeIn(
653
+ keyPath: Array<any>,
654
+ ...iterables: {[key: string]: V}[]
655
+ ): Map<string, V>;
656
+
657
+ /**
658
+ * A combination of `updateIn` and `mergeDeep`, returning a new Map, but
659
+ * performing the deep merge at a point arrived at by following the keyPath.
660
+ * In other words, these two lines are equivalent:
661
+ *
662
+ * x.updateIn(['a', 'b', 'c'], abc => abc.mergeDeep(y));
663
+ * x.mergeDeepIn(['a', 'b', 'c'], y);
664
+ *
665
+ */
666
+ mergeDeepIn(
667
+ keyPath: Iterable<any, any>,
668
+ ...iterables: Iterable<K, V>[]
669
+ ): Map<K, V>;
670
+ mergeDeepIn(
671
+ keyPath: Array<any>,
672
+ ...iterables: Iterable<K, V>[]
673
+ ): Map<K, V>;
674
+ mergeDeepIn(
675
+ keyPath: Array<any>,
676
+ ...iterables: {[key: string]: V}[]
677
+ ): Map<string, V>;
678
+
679
+
680
+ // Transient changes
681
+
682
+ /**
683
+ * Every time you call one of the above functions, a new immutable Map is
684
+ * created. If a pure function calls a number of these to produce a final
685
+ * return value, then a penalty on performance and memory has been paid by
686
+ * creating all of the intermediate immutable Maps.
687
+ *
688
+ * If you need to apply a series of mutations to produce a new immutable
689
+ * Map, `withMutations()` creates a temporary mutable copy of the Map which
690
+ * can apply mutations in a highly performant manner. In fact, this is
691
+ * exactly how complex mutations like `merge` are done.
692
+ *
693
+ * As an example, this results in the creation of 2, not 4, new Maps:
694
+ *
695
+ * var map1 = Immutable.Map();
696
+ * var map2 = map1.withMutations(map => {
697
+ * map.set('a', 1).set('b', 2).set('c', 3);
698
+ * });
699
+ * assert(map1.size === 0);
700
+ * assert(map2.size === 3);
701
+ *
702
+ * Note: Not all methods can be used on a mutable collection or within
703
+ * `withMutations`! Only `set` and `merge` may be used mutatively.
704
+ *
705
+ */
706
+ withMutations(mutator: (mutable: Map<K, V>) => any): Map<K, V>;
707
+
708
+ /**
709
+ * Another way to avoid creation of intermediate Immutable maps is to create
710
+ * a mutable copy of this collection. Mutable copies *always* return `this`,
711
+ * and thus shouldn't be used for equality. Your function should never return
712
+ * a mutable copy of a collection, only use it internally to create a new
713
+ * collection. If possible, use `withMutations` as it provides an easier to
714
+ * use API.
715
+ *
716
+ * Note: if the collection is already mutable, `asMutable` returns itself.
717
+ *
718
+ * Note: Not all methods can be used on a mutable collection or within
719
+ * `withMutations`! Only `set` and `merge` may be used mutatively.
720
+ */
721
+ asMutable(): Map<K, V>;
722
+
723
+ /**
724
+ * The yin to `asMutable`'s yang. Because it applies to mutable collections,
725
+ * this operation is *mutable* and returns itself. Once performed, the mutable
726
+ * copy has become immutable and can be safely returned from a function.
727
+ */
728
+ asImmutable(): Map<K, V>;
729
+ }
730
+
731
+
732
+ /**
733
+ * A type of Map that has the additional guarantee that the iteration order of
734
+ * entries will be the order in which they were set().
735
+ *
736
+ * The iteration behavior of OrderedMap is the same as native ES6 Map and
737
+ * JavaScript Object.
738
+ *
739
+ * Note that `OrderedMap` are more expensive than non-ordered `Map` and may
740
+ * consume more memory. `OrderedMap#set` is amortized O(log32 N), but not
741
+ * stable.
742
+ */
743
+
744
+ export module OrderedMap {
745
+
746
+ /**
747
+ * True if the provided value is an OrderedMap.
748
+ */
749
+ function isOrderedMap(maybeOrderedMap: any): boolean;
750
+ }
751
+
752
+ /**
753
+ * Creates a new Immutable OrderedMap.
754
+ *
755
+ * Created with the same key value pairs as the provided Iterable.Keyed or
756
+ * JavaScript Object or expects an Iterable of [K, V] tuple entries.
757
+ *
758
+ * The iteration order of key-value pairs provided to this constructor will
759
+ * be preserved in the OrderedMap.
760
+ *
761
+ * var newOrderedMap = OrderedMap({key: "value"});
762
+ * var newOrderedMap = OrderedMap([["key", "value"]]);
763
+ *
764
+ */
765
+ export function OrderedMap<K, V>(): OrderedMap<K, V>;
766
+ export function OrderedMap<K, V>(iter: Iterable.Keyed<K, V>): OrderedMap<K, V>;
767
+ export function OrderedMap<K, V>(iter: Iterable<any, /*[K,V]*/Array<any>>): OrderedMap<K, V>;
768
+ export function OrderedMap<K, V>(array: Array</*[K,V]*/Array<any>>): OrderedMap<K, V>;
769
+ export function OrderedMap<V>(obj: {[key: string]: V}): OrderedMap<string, V>;
770
+ export function OrderedMap<K, V>(iterator: Iterator</*[K,V]*/Array<any>>): OrderedMap<K, V>;
771
+ export function OrderedMap<K, V>(iterable: /*Iterable<[K,V]>*/Object): OrderedMap<K, V>;
772
+
773
+ export interface OrderedMap<K, V> extends Map<K, V> {}
774
+
775
+
776
+ /**
777
+ * A Collection of unique values with `O(log32 N)` adds and has.
778
+ *
779
+ * When iterating a Set, the entries will be (value, value) pairs. Iteration
780
+ * order of a Set is undefined, however is stable. Multiple iterations of the
781
+ * same Set will iterate in the same order.
782
+ *
783
+ * Set values, like Map keys, may be of any type. Equality is determined using
784
+ * `Immutable.is`, enabling Sets to uniquely include other Immutable
785
+ * collections, custom value types, and NaN.
786
+ */
787
+ export module Set {
788
+
789
+ /**
790
+ * True if the provided value is a Set
791
+ */
792
+ function isSet(maybeSet: any): boolean;
793
+
794
+ /**
795
+ * Creates a new Set containing `values`.
796
+ */
797
+ function of<T>(...values: T[]): Set<T>;
798
+
799
+ /**
800
+ * `Set.fromKeys()` creates a new immutable Set containing the keys from
801
+ * this Iterable or JavaScript Object.
802
+ */
803
+ function fromKeys<T>(iter: Iterable<T, any>): Set<T>;
804
+ function fromKeys(obj: {[key: string]: any}): Set<string>;
805
+ }
806
+
807
+ /**
808
+ * Create a new immutable Set containing the values of the provided
809
+ * iterable-like.
810
+ */
811
+ export function Set<T>(): Set<T>;
812
+ export function Set<T>(iter: Iterable.Set<T>): Set<T>;
813
+ export function Set<T>(iter: Iterable.Indexed<T>): Set<T>;
814
+ export function Set<K, V>(iter: Iterable.Keyed<K, V>): Set</*[K,V]*/any>;
815
+ export function Set<T>(array: Array<T>): Set<T>;
816
+ export function Set<T>(iterator: Iterator<T>): Set<T>;
817
+ export function Set<T>(iterable: /*Iterable<T>*/Object): Set<T>;
818
+
819
+ export interface Set<T> extends Collection.Set<T> {
820
+
821
+ // Persistent changes
822
+
823
+ /**
824
+ * Returns a new Set which also includes this value.
825
+ */
826
+ add(value: T): Set<T>;
827
+
828
+ /**
829
+ * Returns a new Set which excludes this value.
830
+ *
831
+ * Note: `delete` cannot be safely used in IE8
832
+ * @alias remove
833
+ */
834
+ delete(value: T): Set<T>;
835
+ remove(value: T): Set<T>;
836
+
837
+ /**
838
+ * Returns a new Set containing no values.
839
+ */
840
+ clear(): Set<T>;
841
+
842
+ /**
843
+ * Returns a Set including any value from `iterables` that does not already
844
+ * exist in this Set.
845
+ * @alias merge
846
+ */
847
+ union(...iterables: Iterable<any, T>[]): Set<T>;
848
+ union(...iterables: Array<T>[]): Set<T>;
849
+ merge(...iterables: Iterable<any, T>[]): Set<T>;
850
+ merge(...iterables: Array<T>[]): Set<T>;
851
+
852
+
853
+ /**
854
+ * Returns a Set which has removed any values not also contained
855
+ * within `iterables`.
856
+ */
857
+ intersect(...iterables: Iterable<any, T>[]): Set<T>;
858
+ intersect(...iterables: Array<T>[]): Set<T>;
859
+
860
+ /**
861
+ * Returns a Set excluding any values contained within `iterables`.
862
+ */
863
+ subtract(...iterables: Iterable<any, T>[]): Set<T>;
864
+ subtract(...iterables: Array<T>[]): Set<T>;
865
+
866
+
867
+ // Transient changes
868
+
869
+ /**
870
+ * Note: Not all methods can be used on a mutable collection or within
871
+ * `withMutations`! Only `add` may be used mutatively.
872
+ *
873
+ * @see `Map#withMutations`
874
+ */
875
+ withMutations(mutator: (mutable: Set<T>) => any): Set<T>;
876
+
877
+ /**
878
+ * @see `Map#asMutable`
879
+ */
880
+ asMutable(): Set<T>;
881
+
882
+ /**
883
+ * @see `Map#asImmutable`
884
+ */
885
+ asImmutable(): Set<T>;
886
+ }
887
+
888
+
889
+ /**
890
+ * A type of Set that has the additional guarantee that the iteration order of
891
+ * values will be the order in which they were `add`ed.
892
+ *
893
+ * The iteration behavior of OrderedSet is the same as native ES6 Set.
894
+ *
895
+ * Note that `OrderedSet` are more expensive than non-ordered `Set` and may
896
+ * consume more memory. `OrderedSet#add` is amortized O(log32 N), but not
897
+ * stable.
898
+ */
899
+ export module OrderedSet {
900
+
901
+ /**
902
+ * True if the provided value is an OrderedSet.
903
+ */
904
+ function isOrderedSet(maybeOrderedSet: any): boolean;
905
+
906
+ /**
907
+ * Creates a new OrderedSet containing `values`.
908
+ */
909
+ function of<T>(...values: T[]): OrderedSet<T>;
910
+
911
+ /**
912
+ * `OrderedSet.fromKeys()` creates a new immutable OrderedSet containing
913
+ * the keys from this Iterable or JavaScript Object.
914
+ */
915
+ function fromKeys<T>(iter: Iterable<T, any>): OrderedSet<T>;
916
+ function fromKeys(obj: {[key: string]: any}): OrderedSet<string>;
917
+ }
918
+
919
+ /**
920
+ * Create a new immutable OrderedSet containing the values of the provided
921
+ * iterable-like.
922
+ */
923
+ export function OrderedSet<T>(): OrderedSet<T>;
924
+ export function OrderedSet<T>(iter: Iterable.Set<T>): OrderedSet<T>;
925
+ export function OrderedSet<T>(iter: Iterable.Indexed<T>): OrderedSet<T>;
926
+ export function OrderedSet<K, V>(iter: Iterable.Keyed<K, V>): OrderedSet</*[K,V]*/any>;
927
+ export function OrderedSet<T>(array: Array<T>): OrderedSet<T>;
928
+ export function OrderedSet<T>(iterator: Iterator<T>): OrderedSet<T>;
929
+ export function OrderedSet<T>(iterable: /*Iterable<T>*/Object): OrderedSet<T>;
930
+
931
+ export interface OrderedSet<T> extends Set<T> {}
932
+
933
+
934
+ /**
935
+ * Stacks are indexed collections which support very efficient O(1) addition
936
+ * and removal from the front using `unshift(v)` and `shift()`.
937
+ *
938
+ * For familiarity, Stack also provides `push(v)`, `pop()`, and `peek()`, but
939
+ * be aware that they also operate on the front of the list, unlike List or
940
+ * a JavaScript Array.
941
+ *
942
+ * Note: `reverse()` or any inherent reverse traversal (`reduceRight`,
943
+ * `lastIndexOf`, etc.) is not efficient with a Stack.
944
+ *
945
+ * Stack is implemented with a Single-Linked List.
946
+ */
947
+ export module Stack {
948
+
949
+ /**
950
+ * True if the provided value is a Stack
951
+ */
952
+ function isStack(maybeStack: any): boolean;
953
+
954
+ /**
955
+ * Creates a new Stack containing `values`.
956
+ */
957
+ function of<T>(...values: T[]): Stack<T>;
958
+ }
959
+
960
+ /**
961
+ * Create a new immutable Stack containing the values of the provided
962
+ * iterable-like.
963
+ *
964
+ * The iteration order of the provided iterable is preserved in the
965
+ * resulting `Stack`.
966
+ */
967
+ export function Stack<T>(): Stack<T>;
968
+ export function Stack<T>(iter: Iterable.Indexed<T>): Stack<T>;
969
+ export function Stack<T>(iter: Iterable.Set<T>): Stack<T>;
970
+ export function Stack<K, V>(iter: Iterable.Keyed<K, V>): Stack</*[K,V]*/any>;
971
+ export function Stack<T>(array: Array<T>): Stack<T>;
972
+ export function Stack<T>(iterator: Iterator<T>): Stack<T>;
973
+ export function Stack<T>(iterable: /*Iterable<T>*/Object): Stack<T>;
974
+
975
+ export interface Stack<T> extends Collection.Indexed<T> {
976
+
977
+ // Reading values
978
+
979
+ /**
980
+ * Alias for `Stack.first()`.
981
+ */
982
+ peek(): T;
983
+
984
+
985
+ // Persistent changes
986
+
987
+ /**
988
+ * Returns a new Stack with 0 size and no values.
989
+ */
990
+ clear(): Stack<T>;
991
+
992
+ /**
993
+ * Returns a new Stack with the provided `values` prepended, shifting other
994
+ * values ahead to higher indices.
995
+ *
996
+ * This is very efficient for Stack.
997
+ */
998
+ unshift(...values: T[]): Stack<T>;
999
+
1000
+ /**
1001
+ * Like `Stack#unshift`, but accepts a iterable rather than varargs.
1002
+ */
1003
+ unshiftAll(iter: Iterable<any, T>): Stack<T>;
1004
+ unshiftAll(iter: Array<T>): Stack<T>;
1005
+
1006
+ /**
1007
+ * Returns a new Stack with a size ones less than this Stack, excluding
1008
+ * the first item in this Stack, shifting all other values to a lower index.
1009
+ *
1010
+ * Note: this differs from `Array#shift` because it returns a new
1011
+ * Stack rather than the removed value. Use `first()` or `peek()` to get the
1012
+ * first value in this Stack.
1013
+ */
1014
+ shift(): Stack<T>;
1015
+
1016
+ /**
1017
+ * Alias for `Stack#unshift` and is not equivalent to `List#push`.
1018
+ */
1019
+ push(...values: T[]): Stack<T>;
1020
+
1021
+ /**
1022
+ * Alias for `Stack#unshiftAll`.
1023
+ */
1024
+ pushAll(iter: Iterable<any, T>): Stack<T>;
1025
+ pushAll(iter: Array<T>): Stack<T>;
1026
+
1027
+ /**
1028
+ * Alias for `Stack#shift` and is not equivalent to `List#pop`.
1029
+ */
1030
+ pop(): Stack<T>;
1031
+
1032
+
1033
+ // Transient changes
1034
+
1035
+ /**
1036
+ * Note: Not all methods can be used on a mutable collection or within
1037
+ * `withMutations`! Only `set`, `push`, and `pop` may be used mutatively.
1038
+ *
1039
+ * @see `Map#withMutations`
1040
+ */
1041
+ withMutations(mutator: (mutable: Stack<T>) => any): Stack<T>;
1042
+
1043
+ /**
1044
+ * @see `Map#asMutable`
1045
+ */
1046
+ asMutable(): Stack<T>;
1047
+
1048
+ /**
1049
+ * @see `Map#asImmutable`
1050
+ */
1051
+ asImmutable(): Stack<T>;
1052
+ }
1053
+
1054
+
1055
+ /**
1056
+ * Returns a Seq.Indexed of numbers from `start` (inclusive) to `end`
1057
+ * (exclusive), by `step`, where `start` defaults to 0, `step` to 1, and `end` to
1058
+ * infinity. When `start` is equal to `end`, returns empty range.
1059
+ *
1060
+ * Range() // [0,1,2,3,...]
1061
+ * Range(10) // [10,11,12,13,...]
1062
+ * Range(10,15) // [10,11,12,13,14]
1063
+ * Range(10,30,5) // [10,15,20,25]
1064
+ * Range(30,10,5) // [30,25,20,15]
1065
+ * Range(30,30,5) // []
1066
+ *
1067
+ */
1068
+ export function Range(start?: number, end?: number, step?: number): Seq.Indexed<number>;
1069
+
1070
+
1071
+ /**
1072
+ * Returns a Seq.Indexed of `value` repeated `times` times. When `times` is
1073
+ * not defined, returns an infinite `Seq` of `value`.
1074
+ *
1075
+ * Repeat('foo') // ['foo','foo','foo',...]
1076
+ * Repeat('bar',4) // ['bar','bar','bar','bar']
1077
+ *
1078
+ */
1079
+ export function Repeat<T>(value: T, times?: number): Seq.Indexed<T>;
1080
+
1081
+
1082
+ /**
1083
+ * Creates a new Class which produces Record instances. A record is similar to
1084
+ * a JS object, but enforce a specific set of allowed string keys, and have
1085
+ * default values.
1086
+ *
1087
+ * var ABRecord = Record({a:1, b:2})
1088
+ * var myRecord = new ABRecord({b:3})
1089
+ *
1090
+ * Records always have a value for the keys they define. `remove`ing a key
1091
+ * from a record simply resets it to the default value for that key.
1092
+ *
1093
+ * myRecord.size // 2
1094
+ * myRecord.get('a') // 1
1095
+ * myRecord.get('b') // 3
1096
+ * myRecordWithoutB = myRecord.remove('b')
1097
+ * myRecordWithoutB.get('b') // 2
1098
+ * myRecordWithoutB.size // 2
1099
+ *
1100
+ * Values provided to the constructor not found in the Record type will
1101
+ * be ignored. For example, in this case, ABRecord is provided a key "x" even
1102
+ * though only "a" and "b" have been defined. The value for "x" will be
1103
+ * ignored for this record.
1104
+ *
1105
+ * var myRecord = new ABRecord({b:3, x:10})
1106
+ * myRecord.get('x') // undefined
1107
+ *
1108
+ * Because Records have a known set of string keys, property get access works
1109
+ * as expected, however property sets will throw an Error.
1110
+ *
1111
+ * Note: IE8 does not support property access. Only use `get()` when
1112
+ * supporting IE8.
1113
+ *
1114
+ * myRecord.b // 3
1115
+ * myRecord.b = 5 // throws Error
1116
+ *
1117
+ * Record Classes can be extended as well, allowing for custom methods on your
1118
+ * Record. This is not a common pattern in functional environments, but is in
1119
+ * many JS programs.
1120
+ *
1121
+ * Note: TypeScript does not support this type of subclassing.
1122
+ *
1123
+ * class ABRecord extends Record({a:1,b:2}) {
1124
+ * getAB() {
1125
+ * return this.a + this.b;
1126
+ * }
1127
+ * }
1128
+ *
1129
+ * var myRecord = new ABRecord({b: 3})
1130
+ * myRecord.getAB() // 4
1131
+ *
1132
+ */
1133
+ export module Record {
1134
+ export interface Class {
1135
+ new (): Map<string, any>;
1136
+ new (values: {[key: string]: any}): Map<string, any>;
1137
+ new (values: Iterable<string, any>): Map<string, any>; // deprecated
1138
+
1139
+ (): Map<string, any>;
1140
+ (values: {[key: string]: any}): Map<string, any>;
1141
+ (values: Iterable<string, any>): Map<string, any>; // deprecated
1142
+ }
1143
+ }
1144
+
1145
+ export function Record(
1146
+ defaultValues: {[key: string]: any}, name?: string
1147
+ ): Record.Class;
1148
+
1149
+
1150
+ /**
1151
+ * Represents a sequence of values, but may not be backed by a concrete data
1152
+ * structure.
1153
+ *
1154
+ * **Seq is immutable** — Once a Seq is created, it cannot be
1155
+ * changed, appended to, rearranged or otherwise modified. Instead, any
1156
+ * mutative method called on a `Seq` will return a new `Seq`.
1157
+ *
1158
+ * **Seq is lazy** — Seq does as little work as necessary to respond to any
1159
+ * method call. Values are often created during iteration, including implicit
1160
+ * iteration when reducing or converting to a concrete data structure such as
1161
+ * a `List` or JavaScript `Array`.
1162
+ *
1163
+ * For example, the following performs no work, because the resulting
1164
+ * Seq's values are never iterated:
1165
+ *
1166
+ * var oddSquares = Immutable.Seq.of(1,2,3,4,5,6,7,8)
1167
+ * .filter(x => x % 2).map(x => x * x);
1168
+ *
1169
+ * Once the Seq is used, it performs only the work necessary. In this
1170
+ * example, no intermediate data structures are ever created, filter is only
1171
+ * called three times, and map is only called once:
1172
+ *
1173
+ * console.log(oddSquares.get(1)); // 9
1174
+ *
1175
+ * Seq allows for the efficient chaining of operations,
1176
+ * allowing for the expression of logic that can otherwise be very tedious:
1177
+ *
1178
+ * Immutable.Seq({a:1, b:1, c:1})
1179
+ * .flip().map(key => key.toUpperCase()).flip().toObject();
1180
+ * // Map { A: 1, B: 1, C: 1 }
1181
+ *
1182
+ * As well as expressing logic that would otherwise be memory or time limited:
1183
+ *
1184
+ * Immutable.Range(1, Infinity)
1185
+ * .skip(1000)
1186
+ * .map(n => -n)
1187
+ * .filter(n => n % 2 === 0)
1188
+ * .take(2)
1189
+ * .reduce((r, n) => r * n, 1);
1190
+ * // 1006008
1191
+ *
1192
+ * Seq is often used to provide a rich collection API to JavaScript Object.
1193
+ *
1194
+ * Immutable.Seq({ x: 0, y: 1, z: 2 }).map(v => v * 2).toObject();
1195
+ * // { x: 0, y: 2, z: 4 }
1196
+ */
1197
+
1198
+ export module Seq {
1199
+ /**
1200
+ * True if `maybeSeq` is a Seq, it is not backed by a concrete
1201
+ * structure such as Map, List, or Set.
1202
+ */
1203
+ function isSeq(maybeSeq: any): boolean;
1204
+
1205
+ /**
1206
+ * Returns a Seq of the values provided. Alias for `Seq.Indexed.of()`.
1207
+ */
1208
+ function of<T>(...values: T[]): Seq.Indexed<T>;
1209
+
1210
+
1211
+ /**
1212
+ * `Seq` which represents key-value pairs.
1213
+ */
1214
+ export module Keyed {}
1215
+
1216
+ /**
1217
+ * Always returns a Seq.Keyed, if input is not keyed, expects an
1218
+ * iterable of [K, V] tuples.
1219
+ */
1220
+ export function Keyed<K, V>(): Seq.Keyed<K, V>;
1221
+ export function Keyed<K, V>(seq: Iterable.Keyed<K, V>): Seq.Keyed<K, V>;
1222
+ export function Keyed<K, V>(seq: Iterable<any, /*[K,V]*/any>): Seq.Keyed<K, V>;
1223
+ export function Keyed<K, V>(array: Array</*[K,V]*/any>): Seq.Keyed<K, V>;
1224
+ export function Keyed<V>(obj: {[key: string]: V}): Seq.Keyed<string, V>;
1225
+ export function Keyed<K, V>(iterator: Iterator</*[K,V]*/any>): Seq.Keyed<K, V>;
1226
+ export function Keyed<K, V>(iterable: /*Iterable<[K,V]>*/Object): Seq.Keyed<K, V>;
1227
+
1228
+ export interface Keyed<K, V> extends Seq<K, V>, Iterable.Keyed<K, V> {
1229
+
1230
+ /**
1231
+ * Returns itself
1232
+ */
1233
+ toSeq(): /*this*/Seq.Keyed<K, V>
1234
+ }
1235
+
1236
+
1237
+ /**
1238
+ * `Seq` which represents an ordered indexed list of values.
1239
+ */
1240
+ module Indexed {
1241
+
1242
+ /**
1243
+ * Provides an Seq.Indexed of the values provided.
1244
+ */
1245
+ function of<T>(...values: T[]): Seq.Indexed<T>;
1246
+ }
1247
+
1248
+ /**
1249
+ * Always returns Seq.Indexed, discarding associated keys and
1250
+ * supplying incrementing indices.
1251
+ */
1252
+ export function Indexed<T>(): Seq.Indexed<T>;
1253
+ export function Indexed<T>(seq: Iterable.Indexed<T>): Seq.Indexed<T>;
1254
+ export function Indexed<T>(seq: Iterable.Set<T>): Seq.Indexed<T>;
1255
+ export function Indexed<K, V>(seq: Iterable.Keyed<K, V>): Seq.Indexed</*[K,V]*/any>;
1256
+ export function Indexed<T>(array: Array<T>): Seq.Indexed<T>;
1257
+ export function Indexed<T>(iterator: Iterator<T>): Seq.Indexed<T>;
1258
+ export function Indexed<T>(iterable: /*Iterable<T>*/Object): Seq.Indexed<T>;
1259
+
1260
+ export interface Indexed<T> extends Seq<number, T>, Iterable.Indexed<T> {
1261
+
1262
+ /**
1263
+ * Returns itself
1264
+ */
1265
+ toSeq(): /*this*/Seq.Indexed<T>
1266
+ }
1267
+
1268
+
1269
+ /**
1270
+ * `Seq` which represents a set of values.
1271
+ *
1272
+ * Because `Seq` are often lazy, `Seq.Set` does not provide the same guarantee
1273
+ * of value uniqueness as the concrete `Set`.
1274
+ */
1275
+ export module Set {
1276
+
1277
+ /**
1278
+ * Returns a Seq.Set of the provided values
1279
+ */
1280
+ function of<T>(...values: T[]): Seq.Set<T>;
1281
+ }
1282
+
1283
+ /**
1284
+ * Always returns a Seq.Set, discarding associated indices or keys.
1285
+ */
1286
+ export function Set<T>(): Seq.Set<T>;
1287
+ export function Set<T>(seq: Iterable.Set<T>): Seq.Set<T>;
1288
+ export function Set<T>(seq: Iterable.Indexed<T>): Seq.Set<T>;
1289
+ export function Set<K, V>(seq: Iterable.Keyed<K, V>): Seq.Set</*[K,V]*/any>;
1290
+ export function Set<T>(array: Array<T>): Seq.Set<T>;
1291
+ export function Set<T>(iterator: Iterator<T>): Seq.Set<T>;
1292
+ export function Set<T>(iterable: /*Iterable<T>*/Object): Seq.Set<T>;
1293
+
1294
+ export interface Set<T> extends Seq<T, T>, Iterable.Set<T> {
1295
+
1296
+ /**
1297
+ * Returns itself
1298
+ */
1299
+ toSeq(): /*this*/Seq.Set<T>
1300
+ }
1301
+
1302
+ }
1303
+
1304
+ /**
1305
+ * Creates a Seq.
1306
+ *
1307
+ * Returns a particular kind of `Seq` based on the input.
1308
+ *
1309
+ * * If a `Seq`, that same `Seq`.
1310
+ * * If an `Iterable`, a `Seq` of the same kind (Keyed, Indexed, or Set).
1311
+ * * If an Array-like, an `Seq.Indexed`.
1312
+ * * If an Object with an Iterator, an `Seq.Indexed`.
1313
+ * * If an Iterator, an `Seq.Indexed`.
1314
+ * * If an Object, a `Seq.Keyed`.
1315
+ *
1316
+ */
1317
+ export function Seq<K, V>(): Seq<K, V>;
1318
+ export function Seq<K, V>(seq: Seq<K, V>): Seq<K, V>;
1319
+ export function Seq<K, V>(iterable: Iterable<K, V>): Seq<K, V>;
1320
+ export function Seq<T>(array: Array<T>): Seq.Indexed<T>;
1321
+ export function Seq<V>(obj: {[key: string]: V}): Seq.Keyed<string, V>;
1322
+ export function Seq<T>(iterator: Iterator<T>): Seq.Indexed<T>;
1323
+ export function Seq<T>(iterable: /*ES6Iterable<T>*/Object): Seq.Indexed<T>;
1324
+
1325
+ export interface Seq<K, V> extends Iterable<K, V> {
1326
+
1327
+ /**
1328
+ * Some Seqs can describe their size lazily. When this is the case,
1329
+ * size will be an integer. Otherwise it will be undefined.
1330
+ *
1331
+ * For example, Seqs returned from `map()` or `reverse()`
1332
+ * preserve the size of the original `Seq` while `filter()` does not.
1333
+ *
1334
+ * Note: `Range`, `Repeat` and `Seq`s made from `Array`s and `Object`s will
1335
+ * always have a size.
1336
+ */
1337
+ size: number/*?*/;
1338
+
1339
+
1340
+ // Force evaluation
1341
+
1342
+ /**
1343
+ * Because Sequences are lazy and designed to be chained together, they do
1344
+ * not cache their results. For example, this map function is called a total
1345
+ * of 6 times, as each `join` iterates the Seq of three values.
1346
+ *
1347
+ * var squares = Seq.of(1,2,3).map(x => x * x);
1348
+ * squares.join() + squares.join();
1349
+ *
1350
+ * If you know a `Seq` will be used multiple times, it may be more
1351
+ * efficient to first cache it in memory. Here, the map function is called
1352
+ * only 3 times.
1353
+ *
1354
+ * var squares = Seq.of(1,2,3).map(x => x * x).cacheResult();
1355
+ * squares.join() + squares.join();
1356
+ *
1357
+ * Use this method judiciously, as it must fully evaluate a Seq which can be
1358
+ * a burden on memory and possibly performance.
1359
+ *
1360
+ * Note: after calling `cacheResult`, a Seq will always have a `size`.
1361
+ */
1362
+ cacheResult(): /*this*/Seq<K, V>;
1363
+ }
1364
+
1365
+ /**
1366
+ * The `Iterable` is a set of (key, value) entries which can be iterated, and
1367
+ * is the base class for all collections in `immutable`, allowing them to
1368
+ * make use of all the Iterable methods (such as `map` and `filter`).
1369
+ *
1370
+ * Note: An iterable is always iterated in the same order, however that order
1371
+ * may not always be well defined, as is the case for the `Map` and `Set`.
1372
+ */
1373
+ export module Iterable {
1374
+ /**
1375
+ * True if `maybeIterable` is an Iterable, or any of its subclasses.
1376
+ */
1377
+ function isIterable(maybeIterable: any): boolean;
1378
+
1379
+ /**
1380
+ * True if `maybeKeyed` is an Iterable.Keyed, or any of its subclasses.
1381
+ */
1382
+ function isKeyed(maybeKeyed: any): boolean;
1383
+
1384
+ /**
1385
+ * True if `maybeIndexed` is a Iterable.Indexed, or any of its subclasses.
1386
+ */
1387
+ function isIndexed(maybeIndexed: any): boolean;
1388
+
1389
+ /**
1390
+ * True if `maybeAssociative` is either a keyed or indexed Iterable.
1391
+ */
1392
+ function isAssociative(maybeAssociative: any): boolean;
1393
+
1394
+ /**
1395
+ * True if `maybeOrdered` is an Iterable where iteration order is well
1396
+ * defined. True for Iterable.Indexed as well as OrderedMap and OrderedSet.
1397
+ */
1398
+ function isOrdered(maybeOrdered: any): boolean;
1399
+
1400
+
1401
+ /**
1402
+ * Keyed Iterables have discrete keys tied to each value.
1403
+ *
1404
+ * When iterating `Iterable.Keyed`, each iteration will yield a `[K, V]`
1405
+ * tuple, in other words, `Iterable#entries` is the default iterator for
1406
+ * Keyed Iterables.
1407
+ */
1408
+ export module Keyed {}
1409
+
1410
+ /**
1411
+ * Creates an Iterable.Keyed
1412
+ *
1413
+ * Similar to `Iterable()`, however it expects iterable-likes of [K, V]
1414
+ * tuples if not constructed from a Iterable.Keyed or JS Object.
1415
+ */
1416
+ export function Keyed<K, V>(iter: Iterable.Keyed<K, V>): Iterable.Keyed<K, V>;
1417
+ export function Keyed<K, V>(iter: Iterable<any, /*[K,V]*/any>): Iterable.Keyed<K, V>;
1418
+ export function Keyed<K, V>(array: Array</*[K,V]*/any>): Iterable.Keyed<K, V>;
1419
+ export function Keyed<V>(obj: {[key: string]: V}): Iterable.Keyed<string, V>;
1420
+ export function Keyed<K, V>(iterator: Iterator</*[K,V]*/any>): Iterable.Keyed<K, V>;
1421
+ export function Keyed<K, V>(iterable: /*Iterable<[K,V]>*/Object): Iterable.Keyed<K, V>;
1422
+
1423
+ export interface Keyed<K, V> extends Iterable<K, V> {
1424
+
1425
+ /**
1426
+ * Returns Seq.Keyed.
1427
+ * @override
1428
+ */
1429
+ toSeq(): Seq.Keyed<K, V>;
1430
+
1431
+
1432
+ // Sequence functions
1433
+
1434
+ /**
1435
+ * Returns a new Iterable.Keyed of the same type where the keys and values
1436
+ * have been flipped.
1437
+ *
1438
+ * Seq({ a: 'z', b: 'y' }).flip() // { z: 'a', y: 'b' }
1439
+ *
1440
+ */
1441
+ flip(): /*this*/Iterable.Keyed<V, K>;
1442
+
1443
+ /**
1444
+ * Returns a new Iterable.Keyed of the same type with keys passed through
1445
+ * a `mapper` function.
1446
+ *
1447
+ * Seq({ a: 1, b: 2 })
1448
+ * .mapKeys(x => x.toUpperCase())
1449
+ * // Seq { A: 1, B: 2 }
1450
+ *
1451
+ */
1452
+ mapKeys<M>(
1453
+ mapper: (key?: K, value?: V, iter?: /*this*/Iterable.Keyed<K, V>) => M,
1454
+ context?: any
1455
+ ): /*this*/Iterable.Keyed<M, V>;
1456
+
1457
+ /**
1458
+ * Returns a new Iterable.Keyed of the same type with entries
1459
+ * ([key, value] tuples) passed through a `mapper` function.
1460
+ *
1461
+ * Seq({ a: 1, b: 2 })
1462
+ * .mapEntries(([k, v]) => [k.toUpperCase(), v * 2])
1463
+ * // Seq { A: 2, B: 4 }
1464
+ *
1465
+ */
1466
+ mapEntries<KM, VM>(
1467
+ mapper: (
1468
+ entry?: /*(K, V)*/Array<any>,
1469
+ index?: number,
1470
+ iter?: /*this*/Iterable.Keyed<K, V>
1471
+ ) => /*[KM, VM]*/Array<any>,
1472
+ context?: any
1473
+ ): /*this*/Iterable.Keyed<KM, VM>;
1474
+ }
1475
+
1476
+
1477
+ /**
1478
+ * Indexed Iterables have incrementing numeric keys. They exhibit
1479
+ * slightly different behavior than `Iterable.Keyed` for some methods in order
1480
+ * to better mirror the behavior of JavaScript's `Array`, and add methods
1481
+ * which do not make sense on non-indexed Iterables such as `indexOf`.
1482
+ *
1483
+ * Unlike JavaScript arrays, `Iterable.Indexed`s are always dense. "Unset"
1484
+ * indices and `undefined` indices are indistinguishable, and all indices from
1485
+ * 0 to `size` are visited when iterated.
1486
+ *
1487
+ * All Iterable.Indexed methods return re-indexed Iterables. In other words,
1488
+ * indices always start at 0 and increment until size. If you wish to
1489
+ * preserve indices, using them as keys, convert to a Iterable.Keyed by
1490
+ * calling `toKeyedSeq`.
1491
+ */
1492
+ export module Indexed {}
1493
+
1494
+ /**
1495
+ * Creates a new Iterable.Indexed.
1496
+ */
1497
+ export function Indexed<T>(iter: Iterable.Indexed<T>): Iterable.Indexed<T>;
1498
+ export function Indexed<T>(iter: Iterable.Set<T>): Iterable.Indexed<T>;
1499
+ export function Indexed<K, V>(iter: Iterable.Keyed<K, V>): Iterable.Indexed</*[K,V]*/any>;
1500
+ export function Indexed<T>(array: Array<T>): Iterable.Indexed<T>;
1501
+ export function Indexed<T>(iterator: Iterator<T>): Iterable.Indexed<T>;
1502
+ export function Indexed<T>(iterable: /*Iterable<T>*/Object): Iterable.Indexed<T>;
1503
+
1504
+ export interface Indexed<T> extends Iterable<number, T> {
1505
+
1506
+ // Reading values
1507
+
1508
+ /**
1509
+ * Returns the value associated with the provided index, or notSetValue if
1510
+ * the index is beyond the bounds of the Iterable.
1511
+ *
1512
+ * `index` may be a negative number, which indexes back from the end of the
1513
+ * Iterable. `s.get(-1)` gets the last item in the Iterable.
1514
+ */
1515
+ get(index: number, notSetValue?: T): T;
1516
+
1517
+
1518
+ // Conversion to Seq
1519
+
1520
+ /**
1521
+ * Returns Seq.Indexed.
1522
+ * @override
1523
+ */
1524
+ toSeq(): Seq.Indexed<T>;
1525
+
1526
+ /**
1527
+ * If this is an iterable of [key, value] entry tuples, it will return a
1528
+ * Seq.Keyed of those entries.
1529
+ */
1530
+ fromEntrySeq(): Seq.Keyed<any, any>;
1531
+
1532
+
1533
+ // Combination
1534
+
1535
+ /**
1536
+ * Returns an Iterable of the same type with `separator` between each item
1537
+ * in this Iterable.
1538
+ */
1539
+ interpose(separator: T): /*this*/Iterable.Indexed<T>;
1540
+
1541
+ /**
1542
+ * Returns an Iterable of the same type with the provided `iterables`
1543
+ * interleaved into this iterable.
1544
+ *
1545
+ * The resulting Iterable includes the first item from each, then the
1546
+ * second from each, etc.
1547
+ *
1548
+ * I.Seq.of(1,2,3).interleave(I.Seq.of('A','B','C'))
1549
+ * // Seq [ 1, 'A', 2, 'B', 3, 'C' ]
1550
+ *
1551
+ * The shortest Iterable stops interleave.
1552
+ *
1553
+ * I.Seq.of(1,2,3).interleave(
1554
+ * I.Seq.of('A','B'),
1555
+ * I.Seq.of('X','Y','Z')
1556
+ * )
1557
+ * // Seq [ 1, 'A', 'X', 2, 'B', 'Y' ]
1558
+ */
1559
+ interleave(...iterables: Array<Iterable<any, T>>): /*this*/Iterable.Indexed<T>;
1560
+
1561
+ /**
1562
+ * Splice returns a new indexed Iterable by replacing a region of this
1563
+ * Iterable with new values. If values are not provided, it only skips the
1564
+ * region to be removed.
1565
+ *
1566
+ * `index` may be a negative number, which indexes back from the end of the
1567
+ * Iterable. `s.splice(-2)` splices after the second to last item.
1568
+ *
1569
+ * Seq(['a','b','c','d']).splice(1, 2, 'q', 'r', 's')
1570
+ * // Seq ['a', 'q', 'r', 's', 'd']
1571
+ *
1572
+ */
1573
+ splice(
1574
+ index: number,
1575
+ removeNum: number,
1576
+ ...values: /*Array<Iterable.Indexed<T> | T>*/any[]
1577
+ ): /*this*/Iterable.Indexed<T>;
1578
+
1579
+ /**
1580
+ * Returns an Iterable of the same type "zipped" with the provided
1581
+ * iterables.
1582
+ *
1583
+ * Like `zipWith`, but using the default `zipper`: creating an `Array`.
1584
+ *
1585
+ * var a = Seq.of(1, 2, 3);
1586
+ * var b = Seq.of(4, 5, 6);
1587
+ * var c = a.zip(b); // Seq [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]
1588
+ *
1589
+ */
1590
+ zip(...iterables: Array<Iterable<any, any>>): /*this*/Iterable.Indexed<any>;
1591
+
1592
+ /**
1593
+ * Returns an Iterable of the same type "zipped" with the provided
1594
+ * iterables by using a custom `zipper` function.
1595
+ *
1596
+ * var a = Seq.of(1, 2, 3);
1597
+ * var b = Seq.of(4, 5, 6);
1598
+ * var c = a.zipWith((a, b) => a + b, b); // Seq [ 5, 7, 9 ]
1599
+ *
1600
+ */
1601
+ zipWith<U, Z>(
1602
+ zipper: (value: T, otherValue: U) => Z,
1603
+ otherIterable: Iterable<any, U>
1604
+ ): Iterable.Indexed<Z>;
1605
+ zipWith<U, V, Z>(
1606
+ zipper: (value: T, otherValue: U, thirdValue: V) => Z,
1607
+ otherIterable: Iterable<any, U>,
1608
+ thirdIterable: Iterable<any, V>
1609
+ ): Iterable.Indexed<Z>;
1610
+ zipWith<Z>(
1611
+ zipper: (...any: Array<any>) => Z,
1612
+ ...iterables: Array<Iterable<any, any>>
1613
+ ): Iterable.Indexed<Z>;
1614
+
1615
+
1616
+ // Search for value
1617
+
1618
+ /**
1619
+ * Returns the first index at which a given value can be found in the
1620
+ * Iterable, or -1 if it is not present.
1621
+ */
1622
+ indexOf(searchValue: T): number;
1623
+
1624
+ /**
1625
+ * Returns the last index at which a given value can be found in the
1626
+ * Iterable, or -1 if it is not present.
1627
+ */
1628
+ lastIndexOf(searchValue: T): number;
1629
+
1630
+ /**
1631
+ * Returns the first index in the Iterable where a value satisfies the
1632
+ * provided predicate function. Otherwise -1 is returned.
1633
+ */
1634
+ findIndex(
1635
+ predicate: (value?: T, index?: number, iter?: /*this*/Iterable.Indexed<T>) => boolean,
1636
+ context?: any
1637
+ ): number;
1638
+
1639
+ /**
1640
+ * Returns the last index in the Iterable where a value satisfies the
1641
+ * provided predicate function. Otherwise -1 is returned.
1642
+ */
1643
+ findLastIndex(
1644
+ predicate: (value?: T, index?: number, iter?: /*this*/Iterable.Indexed<T>) => boolean,
1645
+ context?: any
1646
+ ): number;
1647
+ }
1648
+
1649
+
1650
+ /**
1651
+ * Set Iterables only represent values. They have no associated keys or
1652
+ * indices. Duplicate values are possible in Seq.Sets, however the
1653
+ * concrete `Set` does not allow duplicate values.
1654
+ *
1655
+ * Iterable methods on Iterable.Set such as `map` and `forEach` will provide
1656
+ * the value as both the first and second arguments to the provided function.
1657
+ *
1658
+ * var seq = Seq.Set.of('A', 'B', 'C');
1659
+ * assert.equal(seq.every((v, k) => v === k), true);
1660
+ *
1661
+ */
1662
+ export module Set {}
1663
+
1664
+ /**
1665
+ * Similar to `Iterable()`, but always returns a Iterable.Set.
1666
+ */
1667
+ export function Set<T>(iter: Iterable.Set<T>): Iterable.Set<T>;
1668
+ export function Set<T>(iter: Iterable.Indexed<T>): Iterable.Set<T>;
1669
+ export function Set<K, V>(iter: Iterable.Keyed<K, V>): Iterable.Set</*[K,V]*/any>;
1670
+ export function Set<T>(array: Array<T>): Iterable.Set<T>;
1671
+ export function Set<T>(iterator: Iterator<T>): Iterable.Set<T>;
1672
+ export function Set<T>(iterable: /*Iterable<T>*/Object): Iterable.Set<T>;
1673
+
1674
+ export interface Set<T> extends Iterable<T, T> {
1675
+
1676
+ /**
1677
+ * Returns Seq.Set.
1678
+ * @override
1679
+ */
1680
+ toSeq(): Seq.Set<T>;
1681
+ }
1682
+
1683
+ }
1684
+
1685
+ /**
1686
+ * Creates an Iterable.
1687
+ *
1688
+ * The type of Iterable created is based on the input.
1689
+ *
1690
+ * * If an `Iterable`, that same `Iterable`.
1691
+ * * If an Array-like, an `Iterable.Indexed`.
1692
+ * * If an Object with an Iterator, an `Iterable.Indexed`.
1693
+ * * If an Iterator, an `Iterable.Indexed`.
1694
+ * * If an Object, an `Iterable.Keyed`.
1695
+ *
1696
+ * This methods forces the conversion of Objects and Strings to Iterables.
1697
+ * If you want to ensure that a Iterable of one item is returned, use
1698
+ * `Seq.of`.
1699
+ */
1700
+ export function Iterable<K, V>(iterable: Iterable<K, V>): Iterable<K, V>;
1701
+ export function Iterable<T>(array: Array<T>): Iterable.Indexed<T>;
1702
+ export function Iterable<V>(obj: {[key: string]: V}): Iterable.Keyed<string, V>;
1703
+ export function Iterable<T>(iterator: Iterator<T>): Iterable.Indexed<T>;
1704
+ export function Iterable<T>(iterable: /*ES6Iterable<T>*/Object): Iterable.Indexed<T>;
1705
+ export function Iterable<V>(value: V): Iterable.Indexed<V>;
1706
+
1707
+ export interface Iterable<K, V> {
1708
+
1709
+ // Value equality
1710
+
1711
+ /**
1712
+ * True if this and the other Iterable have value equality, as defined
1713
+ * by `Immutable.is()`.
1714
+ *
1715
+ * Note: This is equivalent to `Immutable.is(this, other)`, but provided to
1716
+ * allow for chained expressions.
1717
+ */
1718
+ equals(other: Iterable<K, V>): boolean;
1719
+
1720
+ /**
1721
+ * Computes and returns the hashed identity for this Iterable.
1722
+ *
1723
+ * The `hashCode` of an Iterable is used to determine potential equality,
1724
+ * and is used when adding this to a `Set` or as a key in a `Map`, enabling
1725
+ * lookup via a different instance.
1726
+ *
1727
+ * var a = List.of(1, 2, 3);
1728
+ * var b = List.of(1, 2, 3);
1729
+ * assert(a !== b); // different instances
1730
+ * var set = Set.of(a);
1731
+ * assert(set.has(b) === true);
1732
+ *
1733
+ * If two values have the same `hashCode`, they are [not guaranteed
1734
+ * to be equal][Hash Collision]. If two values have different `hashCode`s,
1735
+ * they must not be equal.
1736
+ *
1737
+ * [Hash Collision]: http://en.wikipedia.org/wiki/Collision_(computer_science)
1738
+ */
1739
+ hashCode(): number;
1740
+
1741
+
1742
+ // Reading values
1743
+
1744
+ /**
1745
+ * Returns the value associated with the provided key, or notSetValue if
1746
+ * the Iterable does not contain this key.
1747
+ *
1748
+ * Note: it is possible a key may be associated with an `undefined` value,
1749
+ * so if `notSetValue` is not provided and this method returns `undefined`,
1750
+ * that does not guarantee the key was not found.
1751
+ */
1752
+ get(key: K, notSetValue?: V): V;
1753
+
1754
+ /**
1755
+ * True if a key exists within this `Iterable`, using `Immutable.is` to determine equality
1756
+ */
1757
+ has(key: K): boolean;
1758
+
1759
+ /**
1760
+ * True if a value exists within this `Iterable`, using `Immutable.is` to determine equality
1761
+ * @alias contains
1762
+ */
1763
+ includes(value: V): boolean;
1764
+ contains(value: V): boolean;
1765
+
1766
+ /**
1767
+ * The first value in the Iterable.
1768
+ */
1769
+ first(): V;
1770
+
1771
+ /**
1772
+ * The last value in the Iterable.
1773
+ */
1774
+ last(): V;
1775
+
1776
+
1777
+ // Reading deep values
1778
+
1779
+ /**
1780
+ * Returns the value found by following a path of keys or indices through
1781
+ * nested Iterables.
1782
+ */
1783
+ getIn(searchKeyPath: Array<any>, notSetValue?: any): any;
1784
+ getIn(searchKeyPath: Iterable<any, any>, notSetValue?: any): any;
1785
+
1786
+ /**
1787
+ * True if the result of following a path of keys or indices through nested
1788
+ * Iterables results in a set value.
1789
+ */
1790
+ hasIn(searchKeyPath: Array<any>): boolean;
1791
+ hasIn(searchKeyPath: Iterable<any, any>): boolean;
1792
+
1793
+
1794
+ // Conversion to JavaScript types
1795
+
1796
+ /**
1797
+ * Deeply converts this Iterable to equivalent JS.
1798
+ *
1799
+ * `Iterable.Indexeds`, and `Iterable.Sets` become Arrays, while
1800
+ * `Iterable.Keyeds` become Objects.
1801
+ *
1802
+ * @alias toJSON
1803
+ */
1804
+ toJS(): any;
1805
+
1806
+ /**
1807
+ * Shallowly converts this iterable to an Array, discarding keys.
1808
+ */
1809
+ toArray(): Array<V>;
1810
+
1811
+ /**
1812
+ * Shallowly converts this Iterable to an Object.
1813
+ *
1814
+ * Throws if keys are not strings.
1815
+ */
1816
+ toObject(): { [key: string]: V };
1817
+
1818
+
1819
+ // Conversion to Collections
1820
+
1821
+ /**
1822
+ * Converts this Iterable to a Map, Throws if keys are not hashable.
1823
+ *
1824
+ * Note: This is equivalent to `Map(this.toKeyedSeq())`, but provided
1825
+ * for convenience and to allow for chained expressions.
1826
+ */
1827
+ toMap(): Map<K, V>;
1828
+
1829
+ /**
1830
+ * Converts this Iterable to a Map, maintaining the order of iteration.
1831
+ *
1832
+ * Note: This is equivalent to `OrderedMap(this.toKeyedSeq())`, but
1833
+ * provided for convenience and to allow for chained expressions.
1834
+ */
1835
+ toOrderedMap(): OrderedMap<K, V>;
1836
+
1837
+ /**
1838
+ * Converts this Iterable to a Set, discarding keys. Throws if values
1839
+ * are not hashable.
1840
+ *
1841
+ * Note: This is equivalent to `Set(this)`, but provided to allow for
1842
+ * chained expressions.
1843
+ */
1844
+ toSet(): Set<V>;
1845
+
1846
+ /**
1847
+ * Converts this Iterable to a Set, maintaining the order of iteration and
1848
+ * discarding keys.
1849
+ *
1850
+ * Note: This is equivalent to `OrderedSet(this.valueSeq())`, but provided
1851
+ * for convenience and to allow for chained expressions.
1852
+ */
1853
+ toOrderedSet(): OrderedSet<V>;
1854
+
1855
+ /**
1856
+ * Converts this Iterable to a List, discarding keys.
1857
+ *
1858
+ * Note: This is equivalent to `List(this)`, but provided to allow
1859
+ * for chained expressions.
1860
+ */
1861
+ toList(): List<V>;
1862
+
1863
+ /**
1864
+ * Converts this Iterable to a Stack, discarding keys. Throws if values
1865
+ * are not hashable.
1866
+ *
1867
+ * Note: This is equivalent to `Stack(this)`, but provided to allow for
1868
+ * chained expressions.
1869
+ */
1870
+ toStack(): Stack<V>;
1871
+
1872
+
1873
+ // Conversion to Seq
1874
+
1875
+ /**
1876
+ * Converts this Iterable to a Seq of the same kind (indexed,
1877
+ * keyed, or set).
1878
+ */
1879
+ toSeq(): Seq<K, V>;
1880
+
1881
+ /**
1882
+ * Returns a Seq.Keyed from this Iterable where indices are treated as keys.
1883
+ *
1884
+ * This is useful if you want to operate on an
1885
+ * Iterable.Indexed and preserve the [index, value] pairs.
1886
+ *
1887
+ * The returned Seq will have identical iteration order as
1888
+ * this Iterable.
1889
+ *
1890
+ * Example:
1891
+ *
1892
+ * var indexedSeq = Immutable.Seq.of('A', 'B', 'C');
1893
+ * indexedSeq.filter(v => v === 'B').toString() // Seq [ 'B' ]
1894
+ * var keyedSeq = indexedSeq.toKeyedSeq();
1895
+ * keyedSeq.filter(v => v === 'B').toString() // Seq { 1: 'B' }
1896
+ *
1897
+ */
1898
+ toKeyedSeq(): Seq.Keyed<K, V>;
1899
+
1900
+ /**
1901
+ * Returns an Seq.Indexed of the values of this Iterable, discarding keys.
1902
+ */
1903
+ toIndexedSeq(): Seq.Indexed<V>;
1904
+
1905
+ /**
1906
+ * Returns a Seq.Set of the values of this Iterable, discarding keys.
1907
+ */
1908
+ toSetSeq(): Seq.Set<V>;
1909
+
1910
+
1911
+ // Iterators
1912
+
1913
+ /**
1914
+ * An iterator of this `Iterable`'s keys.
1915
+ *
1916
+ * Note: this will return an ES6 iterator which does not support Immutable JS sequence algorithms. Use `keySeq` instead, if this is what you want.
1917
+ */
1918
+ keys(): Iterator<K>;
1919
+
1920
+ /**
1921
+ * An iterator of this `Iterable`'s values.
1922
+ *
1923
+ * Note: this will return an ES6 iterator which does not support Immutable JS sequence algorithms. Use `valueSeq` instead, if this is what you want.
1924
+ */
1925
+ values(): Iterator<V>;
1926
+
1927
+ /**
1928
+ * An iterator of this `Iterable`'s entries as `[key, value]` tuples.
1929
+ *
1930
+ * Note: this will return an ES6 iterator which does not support Immutable JS sequence algorithms. Use `entrySeq` instead, if this is what you want.
1931
+ */
1932
+ entries(): Iterator</*[K, V]*/Array<any>>;
1933
+
1934
+
1935
+ // Iterables (Seq)
1936
+
1937
+ /**
1938
+ * Returns a new Seq.Indexed of the keys of this Iterable,
1939
+ * discarding values.
1940
+ */
1941
+ keySeq(): Seq.Indexed<K>;
1942
+
1943
+ /**
1944
+ * Returns an Seq.Indexed of the values of this Iterable, discarding keys.
1945
+ */
1946
+ valueSeq(): Seq.Indexed<V>;
1947
+
1948
+ /**
1949
+ * Returns a new Seq.Indexed of [key, value] tuples.
1950
+ */
1951
+ entrySeq(): Seq.Indexed</*(K, V)*/Array<any>>;
1952
+
1953
+
1954
+ // Sequence algorithms
1955
+
1956
+ /**
1957
+ * Returns a new Iterable of the same type with values passed through a
1958
+ * `mapper` function.
1959
+ *
1960
+ * Seq({ a: 1, b: 2 }).map(x => 10 * x)
1961
+ * // Seq { a: 10, b: 20 }
1962
+ *
1963
+ */
1964
+ map<M>(
1965
+ mapper: (value?: V, key?: K, iter?: /*this*/Iterable<K, V>) => M,
1966
+ context?: any
1967
+ ): /*this*/Iterable<K, M>;
1968
+
1969
+ /**
1970
+ * Returns a new Iterable of the same type with only the entries for which
1971
+ * the `predicate` function returns true.
1972
+ *
1973
+ * Seq({a:1,b:2,c:3,d:4}).filter(x => x % 2 === 0)
1974
+ * // Seq { b: 2, d: 4 }
1975
+ *
1976
+ */
1977
+ filter(
1978
+ predicate: (value?: V, key?: K, iter?: /*this*/Iterable<K, V>) => boolean,
1979
+ context?: any
1980
+ ): /*this*/Iterable<K, V>;
1981
+
1982
+ /**
1983
+ * Returns a new Iterable of the same type with only the entries for which
1984
+ * the `predicate` function returns false.
1985
+ *
1986
+ * Seq({a:1,b:2,c:3,d:4}).filterNot(x => x % 2 === 0)
1987
+ * // Seq { a: 1, c: 3 }
1988
+ *
1989
+ */
1990
+ filterNot(
1991
+ predicate: (value?: V, key?: K, iter?: /*this*/Iterable<K, V>) => boolean,
1992
+ context?: any
1993
+ ): /*this*/Iterable<K, V>;
1994
+
1995
+ /**
1996
+ * Returns a new Iterable of the same type in reverse order.
1997
+ */
1998
+ reverse(): /*this*/Iterable<K, V>;
1999
+
2000
+ /**
2001
+ * Returns a new Iterable of the same type which includes the same entries,
2002
+ * stably sorted by using a `comparator`.
2003
+ *
2004
+ * If a `comparator` is not provided, a default comparator uses `<` and `>`.
2005
+ *
2006
+ * `comparator(valueA, valueB)`:
2007
+ *
2008
+ * * Returns `0` if the elements should not be swapped.
2009
+ * * Returns `-1` (or any negative number) if `valueA` comes before `valueB`
2010
+ * * Returns `1` (or any positive number) if `valueA` comes after `valueB`
2011
+ * * Is pure, i.e. it must always return the same value for the same pair
2012
+ * of values.
2013
+ *
2014
+ * When sorting collections which have no defined order, their ordered
2015
+ * equivalents will be returned. e.g. `map.sort()` returns OrderedMap.
2016
+ */
2017
+ sort(comparator?: (valueA: V, valueB: V) => number): /*this*/Iterable<K, V>;
2018
+
2019
+ /**
2020
+ * Like `sort`, but also accepts a `comparatorValueMapper` which allows for
2021
+ * sorting by more sophisticated means:
2022
+ *
2023
+ * hitters.sortBy(hitter => hitter.avgHits);
2024
+ *
2025
+ */
2026
+ sortBy<C>(
2027
+ comparatorValueMapper: (value?: V, key?: K, iter?: /*this*/Iterable<K, V>) => C,
2028
+ comparator?: (valueA: C, valueB: C) => number
2029
+ ): /*this*/Iterable<K, V>;
2030
+
2031
+ /**
2032
+ * Returns a `Iterable.Keyed` of `Iterable.Keyeds`, grouped by the return
2033
+ * value of the `grouper` function.
2034
+ *
2035
+ * Note: This is always an eager operation.
2036
+ */
2037
+ groupBy<G>(
2038
+ grouper: (value?: V, key?: K, iter?: /*this*/Iterable<K, V>) => G,
2039
+ context?: any
2040
+ ): /*Map*/Seq.Keyed<G, /*this*/Iterable<K, V>>;
2041
+
2042
+
2043
+ // Side effects
2044
+
2045
+ /**
2046
+ * The `sideEffect` is executed for every entry in the Iterable.
2047
+ *
2048
+ * Unlike `Array#forEach`, if any call of `sideEffect` returns
2049
+ * `false`, the iteration will stop. Returns the number of entries iterated
2050
+ * (including the last iteration which returned false).
2051
+ */
2052
+ forEach(
2053
+ sideEffect: (value?: V, key?: K, iter?: /*this*/Iterable<K, V>) => any,
2054
+ context?: any
2055
+ ): number;
2056
+
2057
+
2058
+ // Creating subsets
2059
+
2060
+ /**
2061
+ * Returns a new Iterable of the same type representing a portion of this
2062
+ * Iterable from start up to but not including end.
2063
+ *
2064
+ * If begin is negative, it is offset from the end of the Iterable. e.g.
2065
+ * `slice(-2)` returns a Iterable of the last two entries. If it is not
2066
+ * provided the new Iterable will begin at the beginning of this Iterable.
2067
+ *
2068
+ * If end is negative, it is offset from the end of the Iterable. e.g.
2069
+ * `slice(0, -1)` returns an Iterable of everything but the last entry. If
2070
+ * it is not provided, the new Iterable will continue through the end of
2071
+ * this Iterable.
2072
+ *
2073
+ * If the requested slice is equivalent to the current Iterable, then it
2074
+ * will return itself.
2075
+ */
2076
+ slice(begin?: number, end?: number): /*this*/Iterable<K, V>;
2077
+
2078
+ /**
2079
+ * Returns a new Iterable of the same type containing all entries except
2080
+ * the first.
2081
+ */
2082
+ rest(): /*this*/Iterable<K, V>;
2083
+
2084
+ /**
2085
+ * Returns a new Iterable of the same type containing all entries except
2086
+ * the last.
2087
+ */
2088
+ butLast(): /*this*/Iterable<K, V>;
2089
+
2090
+ /**
2091
+ * Returns a new Iterable of the same type which excludes the first `amount`
2092
+ * entries from this Iterable.
2093
+ */
2094
+ skip(amount: number): /*this*/Iterable<K, V>;
2095
+
2096
+ /**
2097
+ * Returns a new Iterable of the same type which excludes the last `amount`
2098
+ * entries from this Iterable.
2099
+ */
2100
+ skipLast(amount: number): /*this*/Iterable<K, V>;
2101
+
2102
+ /**
2103
+ * Returns a new Iterable of the same type which includes entries starting
2104
+ * from when `predicate` first returns false.
2105
+ *
2106
+ * Seq.of('dog','frog','cat','hat','god')
2107
+ * .skipWhile(x => x.match(/g/))
2108
+ * // Seq [ 'cat', 'hat', 'god' ]
2109
+ *
2110
+ */
2111
+ skipWhile(
2112
+ predicate: (value?: V, key?: K, iter?: /*this*/Iterable<K, V>) => boolean,
2113
+ context?: any
2114
+ ): /*this*/Iterable<K, V>;
2115
+
2116
+ /**
2117
+ * Returns a new Iterable of the same type which includes entries starting
2118
+ * from when `predicate` first returns true.
2119
+ *
2120
+ * Seq.of('dog','frog','cat','hat','god')
2121
+ * .skipUntil(x => x.match(/hat/))
2122
+ * // Seq [ 'hat', 'god' ]
2123
+ *
2124
+ */
2125
+ skipUntil(
2126
+ predicate: (value?: V, key?: K, iter?: /*this*/Iterable<K, V>) => boolean,
2127
+ context?: any
2128
+ ): /*this*/Iterable<K, V>;
2129
+
2130
+ /**
2131
+ * Returns a new Iterable of the same type which includes the first `amount`
2132
+ * entries from this Iterable.
2133
+ */
2134
+ take(amount: number): /*this*/Iterable<K, V>;
2135
+
2136
+ /**
2137
+ * Returns a new Iterable of the same type which includes the last `amount`
2138
+ * entries from this Iterable.
2139
+ */
2140
+ takeLast(amount: number): /*this*/Iterable<K, V>;
2141
+
2142
+ /**
2143
+ * Returns a new Iterable of the same type which includes entries from this
2144
+ * Iterable as long as the `predicate` returns true.
2145
+ *
2146
+ * Seq.of('dog','frog','cat','hat','god')
2147
+ * .takeWhile(x => x.match(/o/))
2148
+ * // Seq [ 'dog', 'frog' ]
2149
+ *
2150
+ */
2151
+ takeWhile(
2152
+ predicate: (value?: V, key?: K, iter?: /*this*/Iterable<K, V>) => boolean,
2153
+ context?: any
2154
+ ): /*this*/Iterable<K, V>;
2155
+
2156
+ /**
2157
+ * Returns a new Iterable of the same type which includes entries from this
2158
+ * Iterable as long as the `predicate` returns false.
2159
+ *
2160
+ * Seq.of('dog','frog','cat','hat','god').takeUntil(x => x.match(/at/))
2161
+ * // ['dog', 'frog']
2162
+ *
2163
+ */
2164
+ takeUntil(
2165
+ predicate: (value?: V, key?: K, iter?: /*this*/Iterable<K, V>) => boolean,
2166
+ context?: any
2167
+ ): /*this*/Iterable<K, V>;
2168
+
2169
+
2170
+ // Combination
2171
+
2172
+ /**
2173
+ * Returns a new Iterable of the same type with other values and
2174
+ * iterable-like concatenated to this one.
2175
+ *
2176
+ * For Seqs, all entries will be present in
2177
+ * the resulting iterable, even if they have the same key.
2178
+ */
2179
+ concat(...valuesOrIterables: /*Array<Iterable<K, V>|V*/any[]): /*this*/Iterable<K, V>;
2180
+
2181
+ /**
2182
+ * Flattens nested Iterables.
2183
+ *
2184
+ * Will deeply flatten the Iterable by default, returning an Iterable of the
2185
+ * same type, but a `depth` can be provided in the form of a number or
2186
+ * boolean (where true means to shallowly flatten one level). A depth of 0
2187
+ * (or shallow: false) will deeply flatten.
2188
+ *
2189
+ * Flattens only others Iterable, not Arrays or Objects.
2190
+ *
2191
+ * Note: `flatten(true)` operates on Iterable<any, Iterable<K, V>> and
2192
+ * returns Iterable<K, V>
2193
+ */
2194
+ flatten(depth?: number): /*this*/Iterable<any, any>;
2195
+ flatten(shallow?: boolean): /*this*/Iterable<any, any>;
2196
+
2197
+ /**
2198
+ * Flat-maps the Iterable, returning an Iterable of the same type.
2199
+ *
2200
+ * Similar to `iter.map(...).flatten(true)`.
2201
+ */
2202
+ flatMap<MK, MV>(
2203
+ mapper: (value?: V, key?: K, iter?: /*this*/Iterable<K, V>) => Iterable<MK, MV>,
2204
+ context?: any
2205
+ ): /*this*/Iterable<MK, MV>;
2206
+ flatMap<MK, MV>(
2207
+ mapper: (value?: V, key?: K, iter?: /*this*/Iterable<K, V>) => /*iterable-like*/any,
2208
+ context?: any
2209
+ ): /*this*/Iterable<MK, MV>;
2210
+
2211
+
2212
+ // Reducing a value
2213
+
2214
+ /**
2215
+ * Reduces the Iterable to a value by calling the `reducer` for every entry
2216
+ * in the Iterable and passing along the reduced value.
2217
+ *
2218
+ * If `initialReduction` is not provided, or is null, the first item in the
2219
+ * Iterable will be used.
2220
+ *
2221
+ * @see `Array#reduce`.
2222
+ */
2223
+ reduce<R>(
2224
+ reducer: (reduction?: R, value?: V, key?: K, iter?: /*this*/Iterable<K, V>) => R,
2225
+ initialReduction?: R,
2226
+ context?: any
2227
+ ): R;
2228
+
2229
+ /**
2230
+ * Reduces the Iterable in reverse (from the right side).
2231
+ *
2232
+ * Note: Similar to this.reverse().reduce(), and provided for parity
2233
+ * with `Array#reduceRight`.
2234
+ */
2235
+ reduceRight<R>(
2236
+ reducer: (reduction?: R, value?: V, key?: K, iter?: /*this*/Iterable<K, V>) => R,
2237
+ initialReduction?: R,
2238
+ context?: any
2239
+ ): R;
2240
+
2241
+ /**
2242
+ * True if `predicate` returns true for all entries in the Iterable.
2243
+ */
2244
+ every(
2245
+ predicate: (value?: V, key?: K, iter?: /*this*/Iterable<K, V>) => boolean,
2246
+ context?: any
2247
+ ): boolean;
2248
+
2249
+ /**
2250
+ * True if `predicate` returns true for any entry in the Iterable.
2251
+ */
2252
+ some(
2253
+ predicate: (value?: V, key?: K, iter?: /*this*/Iterable<K, V>) => boolean,
2254
+ context?: any
2255
+ ): boolean;
2256
+
2257
+ /**
2258
+ * Joins values together as a string, inserting a separator between each.
2259
+ * The default separator is `","`.
2260
+ */
2261
+ join(separator?: string): string;
2262
+
2263
+ /**
2264
+ * Returns true if this Iterable includes no values.
2265
+ *
2266
+ * For some lazy `Seq`, `isEmpty` might need to iterate to determine
2267
+ * emptiness. At most one iteration will occur.
2268
+ */
2269
+ isEmpty(): boolean;
2270
+
2271
+ /**
2272
+ * Returns the size of this Iterable.
2273
+ *
2274
+ * Regardless of if this Iterable can describe its size lazily (some Seqs
2275
+ * cannot), this method will always return the correct size. E.g. it
2276
+ * evaluates a lazy `Seq` if necessary.
2277
+ *
2278
+ * If `predicate` is provided, then this returns the count of entries in the
2279
+ * Iterable for which the `predicate` returns true.
2280
+ */
2281
+ count(): number;
2282
+ count(
2283
+ predicate: (value?: V, key?: K, iter?: /*this*/Iterable<K, V>) => boolean,
2284
+ context?: any
2285
+ ): number;
2286
+
2287
+ /**
2288
+ * Returns a `Seq.Keyed` of counts, grouped by the return value of
2289
+ * the `grouper` function.
2290
+ *
2291
+ * Note: This is not a lazy operation.
2292
+ */
2293
+ countBy<G>(
2294
+ grouper: (value?: V, key?: K, iter?: /*this*/Iterable<K, V>) => G,
2295
+ context?: any
2296
+ ): Map<G, number>;
2297
+
2298
+
2299
+ // Search for value
2300
+
2301
+ /**
2302
+ * Returns the first value for which the `predicate` returns true.
2303
+ */
2304
+ find(
2305
+ predicate: (value?: V, key?: K, iter?: /*this*/Iterable<K, V>) => boolean,
2306
+ context?: any,
2307
+ notSetValue?: V
2308
+ ): V;
2309
+
2310
+ /**
2311
+ * Returns the last value for which the `predicate` returns true.
2312
+ *
2313
+ * Note: `predicate` will be called for each entry in reverse.
2314
+ */
2315
+ findLast(
2316
+ predicate: (value?: V, key?: K, iter?: /*this*/Iterable<K, V>) => boolean,
2317
+ context?: any,
2318
+ notSetValue?: V
2319
+ ): V;
2320
+
2321
+ /**
2322
+ * Returns the first [key, value] entry for which the `predicate` returns true.
2323
+ */
2324
+ findEntry(
2325
+ predicate: (value?: V, key?: K, iter?: /*this*/Iterable<K, V>) => boolean,
2326
+ context?: any,
2327
+ notSetValue?: V
2328
+ ): /*[K, V]*/Array<any>;
2329
+
2330
+ /**
2331
+ * Returns the last [key, value] entry for which the `predicate`
2332
+ * returns true.
2333
+ *
2334
+ * Note: `predicate` will be called for each entry in reverse.
2335
+ */
2336
+ findLastEntry(
2337
+ predicate: (value?: V, key?: K, iter?: /*this*/Iterable<K, V>) => boolean,
2338
+ context?: any,
2339
+ notSetValue?: V
2340
+ ): /*[K, V]*/Array<any>;
2341
+
2342
+ /**
2343
+ * Returns the key for which the `predicate` returns true.
2344
+ */
2345
+ findKey(
2346
+ predicate: (value?: V, key?: K, iter?: /*this*/Iterable.Keyed<K, V>) => boolean,
2347
+ context?: any
2348
+ ): K;
2349
+
2350
+ /**
2351
+ * Returns the last key for which the `predicate` returns true.
2352
+ *
2353
+ * Note: `predicate` will be called for each entry in reverse.
2354
+ */
2355
+ findLastKey(
2356
+ predicate: (value?: V, key?: K, iter?: /*this*/Iterable.Keyed<K, V>) => boolean,
2357
+ context?: any
2358
+ ): K;
2359
+
2360
+ /**
2361
+ * Returns the key associated with the search value, or undefined.
2362
+ */
2363
+ keyOf(searchValue: V): K;
2364
+
2365
+ /**
2366
+ * Returns the last key associated with the search value, or undefined.
2367
+ */
2368
+ lastKeyOf(searchValue: V): K;
2369
+
2370
+ /**
2371
+ * Returns the maximum value in this collection. If any values are
2372
+ * comparatively equivalent, the first one found will be returned.
2373
+ *
2374
+ * The `comparator` is used in the same way as `Iterable#sort`. If it is not
2375
+ * provided, the default comparator is `>`.
2376
+ *
2377
+ * When two values are considered equivalent, the first encountered will be
2378
+ * returned. Otherwise, `max` will operate independent of the order of input
2379
+ * as long as the comparator is commutative. The default comparator `>` is
2380
+ * commutative *only* when types do not differ.
2381
+ *
2382
+ * If `comparator` returns 0 and either value is NaN, undefined, or null,
2383
+ * that value will be returned.
2384
+ */
2385
+ max(comparator?: (valueA: V, valueB: V) => number): V;
2386
+
2387
+ /**
2388
+ * Like `max`, but also accepts a `comparatorValueMapper` which allows for
2389
+ * comparing by more sophisticated means:
2390
+ *
2391
+ * hitters.maxBy(hitter => hitter.avgHits);
2392
+ *
2393
+ */
2394
+ maxBy<C>(
2395
+ comparatorValueMapper: (value?: V, key?: K, iter?: /*this*/Iterable<K, V>) => C,
2396
+ comparator?: (valueA: C, valueB: C) => number
2397
+ ): V;
2398
+
2399
+ /**
2400
+ * Returns the minimum value in this collection. If any values are
2401
+ * comparatively equivalent, the first one found will be returned.
2402
+ *
2403
+ * The `comparator` is used in the same way as `Iterable#sort`. If it is not
2404
+ * provided, the default comparator is `<`.
2405
+ *
2406
+ * When two values are considered equivalent, the first encountered will be
2407
+ * returned. Otherwise, `min` will operate independent of the order of input
2408
+ * as long as the comparator is commutative. The default comparator `<` is
2409
+ * commutative *only* when types do not differ.
2410
+ *
2411
+ * If `comparator` returns 0 and either value is NaN, undefined, or null,
2412
+ * that value will be returned.
2413
+ */
2414
+ min(comparator?: (valueA: V, valueB: V) => number): V;
2415
+
2416
+ /**
2417
+ * Like `min`, but also accepts a `comparatorValueMapper` which allows for
2418
+ * comparing by more sophisticated means:
2419
+ *
2420
+ * hitters.minBy(hitter => hitter.avgHits);
2421
+ *
2422
+ */
2423
+ minBy<C>(
2424
+ comparatorValueMapper: (value?: V, key?: K, iter?: /*this*/Iterable<K, V>) => C,
2425
+ comparator?: (valueA: C, valueB: C) => number
2426
+ ): V;
2427
+
2428
+
2429
+ // Comparison
2430
+
2431
+ /**
2432
+ * True if `iter` includes every value in this Iterable.
2433
+ */
2434
+ isSubset(iter: Iterable<any, V>): boolean;
2435
+ isSubset(iter: Array<V>): boolean;
2436
+
2437
+ /**
2438
+ * True if this Iterable includes every value in `iter`.
2439
+ */
2440
+ isSuperset(iter: Iterable<any, V>): boolean;
2441
+ isSuperset(iter: Array<V>): boolean;
2442
+
2443
+
2444
+ /**
2445
+ * Note: this is here as a convenience to work around an issue with
2446
+ * TypeScript https://github.com/Microsoft/TypeScript/issues/285, but
2447
+ * Iterable does not define `size`, instead `Seq` defines `size` as
2448
+ * nullable number, and `Collection` defines `size` as always a number.
2449
+ *
2450
+ * @ignore
2451
+ */
2452
+ size: number;
2453
+ }
2454
+
2455
+
2456
+ /**
2457
+ * Collection is the abstract base class for concrete data structures. It
2458
+ * cannot be constructed directly.
2459
+ *
2460
+ * Implementations should extend one of the subclasses, `Collection.Keyed`,
2461
+ * `Collection.Indexed`, or `Collection.Set`.
2462
+ */
2463
+ export module Collection {
2464
+
2465
+
2466
+ /**
2467
+ * `Collection` which represents key-value pairs.
2468
+ */
2469
+ export module Keyed {}
2470
+
2471
+ export interface Keyed<K, V> extends Collection<K, V>, Iterable.Keyed<K, V> {
2472
+
2473
+ /**
2474
+ * Returns Seq.Keyed.
2475
+ * @override
2476
+ */
2477
+ toSeq(): Seq.Keyed<K, V>;
2478
+ }
2479
+
2480
+
2481
+ /**
2482
+ * `Collection` which represents ordered indexed values.
2483
+ */
2484
+ export module Indexed {}
2485
+
2486
+ export interface Indexed<T> extends Collection<number, T>, Iterable.Indexed<T> {
2487
+
2488
+ /**
2489
+ * Returns Seq.Indexed.
2490
+ * @override
2491
+ */
2492
+ toSeq(): Seq.Indexed<T>;
2493
+ }
2494
+
2495
+
2496
+ /**
2497
+ * `Collection` which represents values, unassociated with keys or indices.
2498
+ *
2499
+ * `Collection.Set` implementations should guarantee value uniqueness.
2500
+ */
2501
+ export module Set {}
2502
+
2503
+ export interface Set<T> extends Collection<T, T>, Iterable.Set<T> {
2504
+
2505
+ /**
2506
+ * Returns Seq.Set.
2507
+ * @override
2508
+ */
2509
+ toSeq(): Seq.Set<T>;
2510
+ }
2511
+
2512
+ }
2513
+
2514
+ export interface Collection<K, V> extends Iterable<K, V> {
2515
+
2516
+ /**
2517
+ * All collections maintain their current `size` as an integer.
2518
+ */
2519
+ size: number;
2520
+ }
2521
+
2522
+
2523
+ /**
2524
+ * ES6 Iterator.
2525
+ *
2526
+ * This is not part of the Immutable library, but a common interface used by
2527
+ * many types in ES6 JavaScript.
2528
+ *
2529
+ * @ignore
2530
+ */
2531
+ export interface Iterator<T> {
2532
+ next(): { value: T; done: boolean; }
2533
+ }
2534
+
2535
+