immutable 4.0.0-rc.6 → 4.0.0

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,4677 +0,0 @@
1
- /**
2
- * Copyright (c) 2014-present, Facebook, Inc.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- /**
9
- * Immutable data encourages pure functions (data-in, data-out) and lends itself
10
- * to much simpler application development and enabling techniques from
11
- * functional programming such as lazy evaluation.
12
- *
13
- * While designed to bring these powerful functional concepts to JavaScript, it
14
- * presents an Object-Oriented API familiar to Javascript engineers and closely
15
- * mirroring that of Array, Map, and Set. It is easy and efficient to convert to
16
- * and from plain Javascript types.
17
- *
18
- * ## How to read these docs
19
- *
20
- * In order to better explain what kinds of values the Immutable.js API expects
21
- * and produces, this documentation is presented in a statically typed dialect of
22
- * JavaScript (like [Flow][] or [TypeScript][]). You *don't need* to use these
23
- * type checking tools in order to use Immutable.js, however becoming familiar
24
- * with their syntax will help you get a deeper understanding of this API.
25
- *
26
- * **A few examples and how to read them.**
27
- *
28
- * All methods describe the kinds of data they accept and the kinds of data
29
- * they return. For example a function which accepts two numbers and returns
30
- * a number would look like this:
31
- *
32
- * ```js
33
- * sum(first: number, second: number): number
34
- * ```
35
- *
36
- * Sometimes, methods can accept different kinds of data or return different
37
- * kinds of data, and this is described with a *type variable*, which is
38
- * typically in all-caps. For example, a function which always returns the same
39
- * kind of data it was provided would look like this:
40
- *
41
- * ```js
42
- * identity<T>(value: T): T
43
- * ```
44
- *
45
- * Type variables are defined with classes and referred to in methods. For
46
- * example, a class that holds onto a value for you might look like this:
47
- *
48
- * ```js
49
- * class Box<T> {
50
- * constructor(value: T)
51
- * getValue(): T
52
- * }
53
- * ```
54
- *
55
- * In order to manipulate Immutable data, methods that we're used to affecting
56
- * a Collection instead return a new Collection of the same type. The type
57
- * `this` refers to the same kind of class. For example, a List which returns
58
- * new Lists when you `push` a value onto it might look like:
59
- *
60
- * ```js
61
- * class List<T> {
62
- * push(value: T): this
63
- * }
64
- * ```
65
- *
66
- * Many methods in Immutable.js accept values which implement the JavaScript
67
- * [Iterable][] protocol, and might appear like `Iterable<string>` for something
68
- * which represents sequence of strings. Typically in JavaScript we use plain
69
- * Arrays (`[]`) when an Iterable is expected, but also all of the Immutable.js
70
- * collections are iterable themselves!
71
- *
72
- * For example, to get a value deep within a structure of data, we might use
73
- * `getIn` which expects an `Iterable` path:
74
- *
75
- * ```
76
- * getIn(path: Iterable<string | number>): any
77
- * ```
78
- *
79
- * To use this method, we could pass an array: `data.getIn([ "key", 2 ])`.
80
- *
81
- *
82
- * Note: All examples are presented in the modern [ES2015][] version of
83
- * JavaScript. To run in older browsers, they need to be translated to ES3.
84
- *
85
- * For example:
86
- *
87
- * ```js
88
- * // ES2015
89
- * const mappedFoo = foo.map(x => x * x);
90
- * // ES5
91
- * var mappedFoo = foo.map(function (x) { return x * x; });
92
- * ```
93
- *
94
- * [ES2015]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/New_in_JavaScript/ECMAScript_6_support_in_Mozilla
95
- * [TypeScript]: http://www.typescriptlang.org/
96
- * [Flow]: https://flowtype.org/
97
- * [Iterable]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols
98
- */
99
-
100
-
101
-
102
- /**
103
- * Deeply converts plain JS objects and arrays to Immutable Maps and Lists.
104
- *
105
- * If a `reviver` is optionally provided, it will be called with every
106
- * collection as a Seq (beginning with the most nested collections
107
- * and proceeding to the top-level collection itself), along with the key
108
- * refering to each collection and the parent JS object provided as `this`.
109
- * For the top level, object, the key will be `""`. This `reviver` is expected
110
- * to return a new Immutable Collection, allowing for custom conversions from
111
- * deep JS objects. Finally, a `path` is provided which is the sequence of
112
- * keys to this value from the starting value.
113
- *
114
- * `reviver` acts similarly to the [same parameter in `JSON.parse`][1].
115
- *
116
- * If `reviver` is not provided, the default behavior will convert Objects
117
- * into Maps and Arrays into Lists like so:
118
- *
119
- * <!-- runkit:activate -->
120
- * ```js
121
- * const { fromJS, isKeyed } = require('immutable@4.0.0-rc.6')
122
- * function (key, value) {
123
- * return isKeyed(value) ? value.Map() : value.toList()
124
- * }
125
- * ```
126
- *
127
- * `fromJS` is conservative in its conversion. It will only convert
128
- * arrays which pass `Array.isArray` to Lists, and only raw objects (no custom
129
- * prototype) to Map.
130
- *
131
- * Accordingly, this example converts native JS data to OrderedMap and List:
132
- *
133
- * <!-- runkit:activate -->
134
- * ```js
135
- * const { fromJS, isKeyed } = require('immutable@4.0.0-rc.6')
136
- * fromJS({ a: {b: [10, 20, 30]}, c: 40}, function (key, value, path) {
137
- * console.log(key, value, path)
138
- * return isKeyed(value) ? value.toOrderedMap() : value.toList()
139
- * })
140
- *
141
- * > "b", [ 10, 20, 30 ], [ "a", "b" ]
142
- * > "a", {b: [10, 20, 30]}, [ "a" ]
143
- * > "", {a: {b: [10, 20, 30]}, c: 40}, []
144
- * ```
145
- *
146
- * Keep in mind, when using JS objects to construct Immutable Maps, that
147
- * JavaScript Object properties are always strings, even if written in a
148
- * quote-less shorthand, while Immutable Maps accept keys of any type.
149
- *
150
- * <!-- runkit:activate -->
151
- * ```js
152
- * const { Map } = require('immutable@4.0.0-rc.6')
153
- * let obj = { 1: "one" };
154
- * Object.keys(obj); // [ "1" ]
155
- * assert.equal(obj["1"], obj[1]); // "one" === "one"
156
- *
157
- * let map = Map(obj);
158
- * assert.notEqual(map.get("1"), map.get(1)); // "one" !== undefined
159
- * ```
160
- *
161
- * Property access for JavaScript Objects first converts the key to a string,
162
- * but since Immutable Map keys can be of any type the argument to `get()` is
163
- * not altered.
164
- *
165
- * [1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Example.3A_Using_the_reviver_parameter
166
- * "Using the reviver parameter"
167
- */
168
- export function fromJS(
169
- jsValue: any,
170
- reviver?: (
171
- key: string | number,
172
- sequence: Collection.Keyed<string, any> | Collection.Indexed<any>,
173
- path?: Array<string | number>
174
- ) => any
175
- ): any;
176
-
177
-
178
- /**
179
- * Value equality check with semantics similar to `Object.is`, but treats
180
- * Immutable `Collection`s as values, equal if the second `Collection` includes
181
- * equivalent values.
182
- *
183
- * It's used throughout Immutable when checking for equality, including `Map`
184
- * key equality and `Set` membership.
185
- *
186
- * <!-- runkit:activate -->
187
- * ```js
188
- * const { Map, is } = require('immutable@4.0.0-rc.6')
189
- * const map1 = Map({ a: 1, b: 1, c: 1 })
190
- * const map2 = Map({ a: 1, b: 1, c: 1 })
191
- * assert.equal(map1 !== map2, true)
192
- * assert.equal(Object.is(map1, map2), false)
193
- * assert.equal(is(map1, map2), true)
194
- * ```
195
- *
196
- * `is()` compares primitive types like strings and numbers, Immutable.js
197
- * collections like `Map` and `List`, but also any custom object which
198
- * implements `ValueObject` by providing `equals()` and `hashCode()` methods.
199
- *
200
- * Note: Unlike `Object.is`, `Immutable.is` assumes `0` and `-0` are the same
201
- * value, matching the behavior of ES6 Map key equality.
202
- */
203
- export function is(first: any, second: any): boolean;
204
-
205
-
206
- /**
207
- * The `hash()` function is an important part of how Immutable determines if
208
- * two values are equivalent and is used to determine how to store those
209
- * values. Provided with any value, `hash()` will return a 31-bit integer.
210
- *
211
- * When designing Objects which may be equal, it's important than when a
212
- * `.equals()` method returns true, that both values `.hashCode()` method
213
- * return the same value. `hash()` may be used to produce those values.
214
- *
215
- * For non-Immutable Objects that do not provide a `.hashCode()` functions
216
- * (including plain Objects, plain Arrays, Date objects, etc), a unique hash
217
- * value will be created for each *instance*. That is, the create hash
218
- * represents referential equality, and not value equality for Objects. This
219
- * ensures that if that Object is mutated over time that its hash code will
220
- * remain consistent, allowing Objects to be used as keys and values in
221
- * Immutable.js collections.
222
- *
223
- * Note that `hash()` attempts to balance between speed and avoiding
224
- * collisions, however it makes no attempt to produce secure hashes.
225
- *
226
- * *New in Version 4.0*
227
- */
228
- export function hash(value: any): number;
229
-
230
- /**
231
- * True if `maybeImmutable` is an Immutable Collection or Record.
232
- *
233
- * <!-- runkit:activate -->
234
- * ```js
235
- * const { isImmutable, Map, List, Stack } = require('immutable@4.0.0-rc.6');
236
- * isImmutable([]); // false
237
- * isImmutable({}); // false
238
- * isImmutable(Map()); // true
239
- * isImmutable(List()); // true
240
- * isImmutable(Stack()); // true
241
- * isImmutable(Map().asMutable()); // false
242
- * ```
243
- */
244
- export function isImmutable(maybeImmutable: any): maybeImmutable is Collection<any, any>;
245
-
246
- /**
247
- * True if `maybeCollection` is a Collection, or any of its subclasses.
248
- *
249
- * <!-- runkit:activate -->
250
- * ```js
251
- * const { isCollection, Map, List, Stack } = require('immutable@4.0.0-rc.6');
252
- * isCollection([]); // false
253
- * isCollection({}); // false
254
- * isCollection(Map()); // true
255
- * isCollection(List()); // true
256
- * isCollection(Stack()); // true
257
- * ```
258
- */
259
- export function isCollection(maybeCollection: any): maybeCollection is Collection<any, any>;
260
-
261
- /**
262
- * True if `maybeKeyed` is a Collection.Keyed, or any of its subclasses.
263
- *
264
- * <!-- runkit:activate -->
265
- * ```js
266
- * const { isKeyed, Map, List, Stack } = require('immutable@4.0.0-rc.6');
267
- * isKeyed([]); // false
268
- * isKeyed({}); // false
269
- * isKeyed(Map()); // true
270
- * isKeyed(List()); // false
271
- * isKeyed(Stack()); // false
272
- * ```
273
- */
274
- export function isKeyed(maybeKeyed: any): maybeKeyed is Collection.Keyed<any, any>;
275
-
276
- /**
277
- * True if `maybeIndexed` is a Collection.Indexed, or any of its subclasses.
278
- *
279
- * <!-- runkit:activate -->
280
- * ```js
281
- * const { isIndexed, Map, List, Stack, Set } = require('immutable@4.0.0-rc.6');
282
- * isIndexed([]); // false
283
- * isIndexed({}); // false
284
- * isIndexed(Map()); // false
285
- * isIndexed(List()); // true
286
- * isIndexed(Stack()); // true
287
- * isIndexed(Set()); // false
288
- * ```
289
- */
290
- export function isIndexed(maybeIndexed: any): maybeIndexed is Collection.Indexed<any>;
291
-
292
- /**
293
- * True if `maybeAssociative` is either a Keyed or Indexed Collection.
294
- *
295
- * <!-- runkit:activate -->
296
- * ```js
297
- * const { isAssociative, Map, List, Stack, Set } = require('immutable@4.0.0-rc.6');
298
- * isAssociative([]); // false
299
- * isAssociative({}); // false
300
- * isAssociative(Map()); // true
301
- * isAssociative(List()); // true
302
- * isAssociative(Stack()); // true
303
- * isAssociative(Set()); // false
304
- * ```
305
- */
306
- export function isAssociative(maybeAssociative: any): maybeAssociative is Collection.Keyed<any, any> | Collection.Indexed<any>;
307
-
308
- /**
309
- * True if `maybeOrdered` is a Collection where iteration order is well
310
- * defined. True for Collection.Indexed as well as OrderedMap and OrderedSet.
311
- *
312
- * <!-- runkit:activate -->
313
- * ```js
314
- * const { isOrdered, Map, OrderedMap, List, Set } = require('immutable@4.0.0-rc.6');
315
- * isOrdered([]); // false
316
- * isOrdered({}); // false
317
- * isOrdered(Map()); // false
318
- * isOrdered(OrderedMap()); // true
319
- * isOrdered(List()); // true
320
- * isOrdered(Set()); // false
321
- * ```
322
- */
323
- export function isOrdered(maybeOrdered: any): boolean;
324
-
325
- /**
326
- * True if `maybeValue` is a JavaScript Object which has *both* `equals()`
327
- * and `hashCode()` methods.
328
- *
329
- * Any two instances of *value objects* can be compared for value equality with
330
- * `Immutable.is()` and can be used as keys in a `Map` or members in a `Set`.
331
- */
332
- export function isValueObject(maybeValue: any): maybeValue is ValueObject;
333
-
334
- /**
335
- * The interface to fulfill to qualify as a Value Object.
336
- */
337
- export interface ValueObject {
338
- /**
339
- * True if this and the other Collection have value equality, as defined
340
- * by `Immutable.is()`.
341
- *
342
- * Note: This is equivalent to `Immutable.is(this, other)`, but provided to
343
- * allow for chained expressions.
344
- */
345
- equals(other: any): boolean;
346
-
347
- /**
348
- * Computes and returns the hashed identity for this Collection.
349
- *
350
- * The `hashCode` of a Collection is used to determine potential equality,
351
- * and is used when adding this to a `Set` or as a key in a `Map`, enabling
352
- * lookup via a different instance.
353
- *
354
- * <!-- runkit:activate -->
355
- * ```js
356
- * const { List, Set } = require('immutable@4.0.0-rc.6');
357
- * const a = List([ 1, 2, 3 ]);
358
- * const b = List([ 1, 2, 3 ]);
359
- * assert.notStrictEqual(a, b); // different instances
360
- * const set = Set([ a ]);
361
- * assert.equal(set.has(b), true);
362
- * ```
363
- *
364
- * Note: hashCode() MUST return a Uint32 number. The easiest way to
365
- * guarantee this is to return `myHash | 0` from a custom implementation.
366
- *
367
- * If two values have the same `hashCode`, they are [not guaranteed
368
- * to be equal][Hash Collision]. If two values have different `hashCode`s,
369
- * they must not be equal.
370
- *
371
- * Note: `hashCode()` is not guaranteed to always be called before
372
- * `equals()`. Most but not all Immutable.js collections use hash codes to
373
- * organize their internal data structures, while all Immutable.js
374
- * collections use equality during lookups.
375
- *
376
- * [Hash Collision]: http://en.wikipedia.org/wiki/Collision_(computer_science)
377
- */
378
- hashCode(): number;
379
- }
380
-
381
- /**
382
- * Lists are ordered indexed dense collections, much like a JavaScript
383
- * Array.
384
- *
385
- * Lists are immutable and fully persistent with O(log32 N) gets and sets,
386
- * and O(1) push and pop.
387
- *
388
- * Lists implement Deque, with efficient addition and removal from both the
389
- * end (`push`, `pop`) and beginning (`unshift`, `shift`).
390
- *
391
- * Unlike a JavaScript Array, there is no distinction between an
392
- * "unset" index and an index set to `undefined`. `List#forEach` visits all
393
- * indices from 0 to size, regardless of whether they were explicitly defined.
394
- */
395
- export module List {
396
-
397
- /**
398
- * True if the provided value is a List
399
- *
400
- * <!-- runkit:activate -->
401
- * ```js
402
- * const { List } = require('immutable@4.0.0-rc.6');
403
- * List.isList([]); // false
404
- * List.isList(List()); // true
405
- * ```
406
- */
407
- function isList(maybeList: any): maybeList is List<any>;
408
-
409
- /**
410
- * Creates a new List containing `values`.
411
- *
412
- * <!-- runkit:activate -->
413
- * ```js
414
- * const { List } = require('immutable@4.0.0-rc.6');
415
- * List.of(1, 2, 3, 4)
416
- * // List [ 1, 2, 3, 4 ]
417
- * ```
418
- *
419
- * Note: Values are not altered or converted in any way.
420
- *
421
- * <!-- runkit:activate -->
422
- * ```js
423
- * const { List } = require('immutable@4.0.0-rc.6');
424
- * List.of({x:1}, 2, [3], 4)
425
- * // List [ { x: 1 }, 2, [ 3 ], 4 ]
426
- * ```
427
- */
428
- function of<T>(...values: Array<T>): List<T>;
429
- }
430
-
431
- /**
432
- * Create a new immutable List containing the values of the provided
433
- * collection-like.
434
- *
435
- * <!-- runkit:activate -->
436
- * ```js
437
- * const { List, Set } = require('immutable@4.0.0-rc.6')
438
- *
439
- * const emptyList = List()
440
- * // List []
441
- *
442
- * const plainArray = [ 1, 2, 3, 4 ]
443
- * const listFromPlainArray = List(plainArray)
444
- * // List [ 1, 2, 3, 4 ]
445
- *
446
- * const plainSet = Set([ 1, 2, 3, 4 ])
447
- * const listFromPlainSet = List(plainSet)
448
- * // List [ 1, 2, 3, 4 ]
449
- *
450
- * const arrayIterator = plainArray[Symbol.iterator]()
451
- * const listFromCollectionArray = List(arrayIterator)
452
- * // List [ 1, 2, 3, 4 ]
453
- *
454
- * listFromPlainArray.equals(listFromCollectionArray) // true
455
- * listFromPlainSet.equals(listFromCollectionArray) // true
456
- * listFromPlainSet.equals(listFromPlainArray) // true
457
- * ```
458
- */
459
- export function List(): List<any>;
460
- export function List<T>(): List<T>;
461
- export function List<T>(collection: Iterable<T>): List<T>;
462
-
463
- export interface List<T> extends Collection.Indexed<T> {
464
-
465
- /**
466
- * The number of items in this List.
467
- */
468
- readonly size: number;
469
-
470
- // Persistent changes
471
-
472
- /**
473
- * Returns a new List which includes `value` at `index`. If `index` already
474
- * exists in this List, it will be replaced.
475
- *
476
- * `index` may be a negative number, which indexes back from the end of the
477
- * List. `v.set(-1, "value")` sets the last item in the List.
478
- *
479
- * If `index` larger than `size`, the returned List's `size` will be large
480
- * enough to include the `index`.
481
- *
482
- * <!-- runkit:activate
483
- * { "preamble": "const { List } = require(\"immutable\");" }
484
- * -->
485
- * ```js
486
- * const originalList = List([ 0 ]);
487
- * // List [ 0 ]
488
- * originalList.set(1, 1);
489
- * // List [ 0, 1 ]
490
- * originalList.set(0, 'overwritten');
491
- * // List [ "overwritten" ]
492
- * originalList.set(2, 2);
493
- * // List [ 0, undefined, 2 ]
494
- *
495
- * List().set(50000, 'value').size;
496
- * // 50001
497
- * ```
498
- *
499
- * Note: `set` can be used in `withMutations`.
500
- */
501
- set(index: number, value: T): List<T>;
502
-
503
- /**
504
- * Returns a new List which excludes this `index` and with a size 1 less
505
- * than this List. Values at indices above `index` are shifted down by 1 to
506
- * fill the position.
507
- *
508
- * This is synonymous with `list.splice(index, 1)`.
509
- *
510
- * `index` may be a negative number, which indexes back from the end of the
511
- * List. `v.delete(-1)` deletes the last item in the List.
512
- *
513
- * Note: `delete` cannot be safely used in IE8
514
- *
515
- * <!-- runkit:activate
516
- * { "preamble": "const { List } = require(\"immutable\");" }
517
- * -->
518
- * ```js
519
- * List([ 0, 1, 2, 3, 4 ]).delete(0);
520
- * // List [ 1, 2, 3, 4 ]
521
- * ```
522
- *
523
- * Note: `delete` *cannot* be used in `withMutations`.
524
- *
525
- * @alias remove
526
- */
527
- delete(index: number): List<T>;
528
- remove(index: number): List<T>;
529
-
530
- /**
531
- * Returns a new List with `value` at `index` with a size 1 more than this
532
- * List. Values at indices above `index` are shifted over by 1.
533
- *
534
- * This is synonymous with `list.splice(index, 0, value)`.
535
- *
536
- * <!-- runkit:activate
537
- * { "preamble": "const { List } = require(\"immutable\");" }
538
- * -->
539
- * ```js
540
- * List([ 0, 1, 2, 3, 4 ]).insert(6, 5)
541
- * // List [ 0, 1, 2, 3, 4, 5 ]
542
- * ```
543
- *
544
- * Note: `insert` *cannot* be used in `withMutations`.
545
- */
546
- insert(index: number, value: T): List<T>;
547
-
548
- /**
549
- * Returns a new List with 0 size and no values.
550
- *
551
- * <!-- runkit:activate
552
- * { "preamble": "const { List } = require(\"immutable\");" }
553
- * -->
554
- * ```js
555
- * List([ 1, 2, 3, 4 ]).clear()
556
- * // List []
557
- * ```
558
- *
559
- * Note: `clear` can be used in `withMutations`.
560
- */
561
- clear(): List<T>;
562
-
563
- /**
564
- * Returns a new List with the provided `values` appended, starting at this
565
- * List's `size`.
566
- *
567
- * <!-- runkit:activate
568
- * { "preamble": "const { List } = require(\"immutable\");" }
569
- * -->
570
- * ```js
571
- * List([ 1, 2, 3, 4 ]).push(5)
572
- * // List [ 1, 2, 3, 4, 5 ]
573
- * ```
574
- *
575
- * Note: `push` can be used in `withMutations`.
576
- */
577
- push(...values: Array<T>): List<T>;
578
-
579
- /**
580
- * Returns a new List with a size ones less than this List, excluding
581
- * the last index in this List.
582
- *
583
- * Note: this differs from `Array#pop` because it returns a new
584
- * List rather than the removed value. Use `last()` to get the last value
585
- * in this List.
586
- *
587
- * ```js
588
- * List([ 1, 2, 3, 4 ]).pop()
589
- * // List[ 1, 2, 3 ]
590
- * ```
591
- *
592
- * Note: `pop` can be used in `withMutations`.
593
- */
594
- pop(): List<T>;
595
-
596
- /**
597
- * Returns a new List with the provided `values` prepended, shifting other
598
- * values ahead to higher indices.
599
- *
600
- * <!-- runkit:activate
601
- * { "preamble": "const { List } = require(\"immutable\");" }
602
- * -->
603
- * ```js
604
- * List([ 2, 3, 4]).unshift(1);
605
- * // List [ 1, 2, 3, 4 ]
606
- * ```
607
- *
608
- * Note: `unshift` can be used in `withMutations`.
609
- */
610
- unshift(...values: Array<T>): List<T>;
611
-
612
- /**
613
- * Returns a new List with a size ones less than this List, excluding
614
- * the first index in this List, shifting all other values to a lower index.
615
- *
616
- * Note: this differs from `Array#shift` because it returns a new
617
- * List rather than the removed value. Use `first()` to get the first
618
- * value in this List.
619
- *
620
- * <!-- runkit:activate
621
- * { "preamble": "const { List } = require(\"immutable\");" }
622
- * -->
623
- * ```js
624
- * List([ 0, 1, 2, 3, 4 ]).shift();
625
- * // List [ 1, 2, 3, 4 ]
626
- * ```
627
- *
628
- * Note: `shift` can be used in `withMutations`.
629
- */
630
- shift(): List<T>;
631
-
632
- /**
633
- * Returns a new List with an updated value at `index` with the return
634
- * value of calling `updater` with the existing value, or `notSetValue` if
635
- * `index` was not set. If called with a single argument, `updater` is
636
- * called with the List itself.
637
- *
638
- * `index` may be a negative number, which indexes back from the end of the
639
- * List. `v.update(-1)` updates the last item in the List.
640
- *
641
- * <!-- runkit:activate
642
- * { "preamble": "const { List } = require(\"immutable\");" }
643
- * -->
644
- * ```js
645
- * const list = List([ 'a', 'b', 'c' ])
646
- * const result = list.update(2, val => val.toUpperCase())
647
- * // List [ "a", "b", "C" ]
648
- * ```
649
- *
650
- * This can be very useful as a way to "chain" a normal function into a
651
- * sequence of methods. RxJS calls this "let" and lodash calls it "thru".
652
- *
653
- * For example, to sum a List after mapping and filtering:
654
- *
655
- * <!-- runkit:activate
656
- * { "preamble": "const { List } = require(\"immutable\");" }
657
- * -->
658
- * ```js
659
- * function sum(collection) {
660
- * return collection.reduce((sum, x) => sum + x, 0)
661
- * }
662
- *
663
- * List([ 1, 2, 3 ])
664
- * .map(x => x + 1)
665
- * .filter(x => x % 2 === 0)
666
- * .update(sum)
667
- * // 6
668
- * ```
669
- *
670
- * Note: `update(index)` can be used in `withMutations`.
671
- *
672
- * @see `Map#update`
673
- */
674
- update(index: number, notSetValue: T, updater: (value: T) => T): this;
675
- update(index: number, updater: (value: T) => T): this;
676
- update<R>(updater: (value: this) => R): R;
677
-
678
- /**
679
- * Returns a new List with size `size`. If `size` is less than this
680
- * List's size, the new List will exclude values at the higher indices.
681
- * If `size` is greater than this List's size, the new List will have
682
- * undefined values for the newly available indices.
683
- *
684
- * When building a new List and the final size is known up front, `setSize`
685
- * used in conjunction with `withMutations` may result in the more
686
- * performant construction.
687
- */
688
- setSize(size: number): List<T>;
689
-
690
-
691
- // Deep persistent changes
692
-
693
- /**
694
- * Returns a new List having set `value` at this `keyPath`. If any keys in
695
- * `keyPath` do not exist, a new immutable Map will be created at that key.
696
- *
697
- * Index numbers are used as keys to determine the path to follow in
698
- * the List.
699
- *
700
- * <!-- runkit:activate -->
701
- * ```js
702
- * const { List } = require("immutable")
703
- * const list = List([ 0, 1, 2, List([ 3, 4 ])])
704
- * list.setIn([3, 0], 999);
705
- * // List [ 0, 1, 2, List [ 999, 4 ] ]
706
- * ```
707
- *
708
- * Note: `setIn` can be used in `withMutations`.
709
- */
710
- setIn(keyPath: Iterable<any>, value: any): this;
711
-
712
- /**
713
- * Returns a new List having removed the value at this `keyPath`. If any
714
- * keys in `keyPath` do not exist, no change will occur.
715
- *
716
- * <!-- runkit:activate -->
717
- * ```js
718
- * const { List } = require("immutable")
719
- * const list = List([ 0, 1, 2, List([ 3, 4 ])])
720
- * list.deleteIn([3, 0]);
721
- * // List [ 0, 1, 2, List [ 4 ] ]
722
- * ```
723
- *
724
- * Note: `deleteIn` *cannot* be safely used in `withMutations`.
725
- *
726
- * @alias removeIn
727
- */
728
- deleteIn(keyPath: Iterable<any>): this;
729
- removeIn(keyPath: Iterable<any>): this;
730
-
731
- /**
732
- * Note: `updateIn` can be used in `withMutations`.
733
- *
734
- * @see `Map#updateIn`
735
- */
736
- updateIn(keyPath: Iterable<any>, notSetValue: any, updater: (value: any) => any): this;
737
- updateIn(keyPath: Iterable<any>, updater: (value: any) => any): this;
738
-
739
- /**
740
- * Note: `mergeIn` can be used in `withMutations`.
741
- *
742
- * @see `Map#mergeIn`
743
- */
744
- mergeIn(keyPath: Iterable<any>, ...collections: Array<any>): this;
745
-
746
- /**
747
- * Note: `mergeDeepIn` can be used in `withMutations`.
748
- *
749
- * @see `Map#mergeDeepIn`
750
- */
751
- mergeDeepIn(keyPath: Iterable<any>, ...collections: Array<any>): this;
752
-
753
- // Transient changes
754
-
755
- /**
756
- * Note: Not all methods can be safely used on a mutable collection or within
757
- * `withMutations`! Check the documentation for each method to see if it
758
- * allows being used in `withMutations`.
759
- *
760
- * @see `Map#withMutations`
761
- */
762
- withMutations(mutator: (mutable: this) => any): this;
763
-
764
- /**
765
- * An alternative API for withMutations()
766
- *
767
- * Note: Not all methods can be safely used on a mutable collection or within
768
- * `withMutations`! Check the documentation for each method to see if it
769
- * allows being used in `withMutations`.
770
- *
771
- * @see `Map#asMutable`
772
- */
773
- asMutable(): this;
774
-
775
- /**
776
- * @see `Map#wasAltered`
777
- */
778
- wasAltered(): boolean;
779
-
780
- /**
781
- * @see `Map#asImmutable`
782
- */
783
- asImmutable(): this;
784
-
785
- // Sequence algorithms
786
-
787
- /**
788
- * Returns a new List with other values or collections concatenated to this one.
789
- *
790
- * Note: `concat` *cannot* be safely used in `withMutations`.
791
- *
792
- * @alias merge
793
- */
794
- concat<C>(...valuesOrCollections: Array<Iterable<C> | C>): List<T | C>;
795
- merge<C>(...collections: Array<Iterable<C>): List<T | C>;
796
-
797
- /**
798
- * Returns a new List with values passed through a
799
- * `mapper` function.
800
- *
801
- * <!-- runkit:activate
802
- * { "preamble": "const { List } = require(\"immutable\");" }
803
- * -->
804
- * ```js
805
- * List([ 1, 2 ]).map(x => 10 * x)
806
- * // List [ 10, 20 ]
807
- * ```
808
- *
809
- * Note: `map()` always returns a new instance, even if it produced the same
810
- * value at every step.
811
- */
812
- map<M>(
813
- mapper: (value: T, key: number, iter: this) => M,
814
- context?: any
815
- ): List<M>;
816
-
817
- /**
818
- * Flat-maps the List, returning a new List.
819
- *
820
- * Similar to `list.map(...).flatten(true)`.
821
- */
822
- flatMap<M>(
823
- mapper: (value: T, key: number, iter: this) => Iterable<M>,
824
- context?: any
825
- ): List<M>;
826
-
827
- /**
828
- * Returns a new List with only the values for which the `predicate`
829
- * function returns true.
830
- *
831
- * Note: `filter()` always returns a new instance, even if it results in
832
- * not filtering out any values.
833
- */
834
- filter<F extends T>(
835
- predicate: (value: T, index: number, iter: this) => value is F,
836
- context?: any
837
- ): List<F>;
838
- filter(
839
- predicate: (value: T, index: number, iter: this) => any,
840
- context?: any
841
- ): this;
842
-
843
- /**
844
- * Returns a List "zipped" with the provided collection.
845
- *
846
- * Like `zipWith`, but using the default `zipper`: creating an `Array`.
847
- *
848
- * <!-- runkit:activate
849
- * { "preamble": "const { List } = require(\"immutable\");" }
850
- * -->
851
- * ```js
852
- * const a = List([ 1, 2, 3 ]);
853
- * const b = List([ 4, 5, 6 ]);
854
- * const c = a.zip(b); // List [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]
855
- * ```
856
- */
857
- zip<U>(other: Collection<any, U>): List<[T,U]>;
858
- zip<U,V>(other: Collection<any, U>, other2: Collection<any,V>): List<[T,U,V]>;
859
- zip(...collections: Array<Collection<any, any>>): List<any>;
860
-
861
- /**
862
- * Returns a List "zipped" with the provided collections.
863
- *
864
- * Unlike `zip`, `zipAll` continues zipping until the longest collection is
865
- * exhausted. Missing values from shorter collections are filled with `undefined`.
866
- *
867
- * <!-- runkit:activate
868
- * { "preamble": "const { List } = require(\"immutable\");" }
869
- * -->
870
- * ```js
871
- * const a = List([ 1, 2 ]);
872
- * const b = List([ 3, 4, 5 ]);
873
- * const c = a.zipAll(b); // List [ [ 1, 3 ], [ 2, 4 ], [ undefined, 5 ] ]
874
- * ```
875
- *
876
- * Note: Since zipAll will return a collection as large as the largest
877
- * input, some results may contain undefined values. TypeScript cannot
878
- * account for these without cases (as of v2.5).
879
- */
880
- zipAll<U>(other: Collection<any, U>): List<[T,U]>;
881
- zipAll<U,V>(other: Collection<any, U>, other2: Collection<any,V>): List<[T,U,V]>;
882
- zipAll(...collections: Array<Collection<any, any>>): List<any>;
883
-
884
- /**
885
- * Returns a List "zipped" with the provided collections by using a
886
- * custom `zipper` function.
887
- *
888
- * <!-- runkit:activate
889
- * { "preamble": "const { List } = require(\"immutable\");" }
890
- * -->
891
- * ```js
892
- * const a = List([ 1, 2, 3 ]);
893
- * const b = List([ 4, 5, 6 ]);
894
- * const c = a.zipWith((a, b) => a + b, b);
895
- * // List [ 5, 7, 9 ]
896
- * ```
897
- */
898
- zipWith<U, Z>(
899
- zipper: (value: T, otherValue: U) => Z,
900
- otherCollection: Collection<any, U>
901
- ): List<Z>;
902
- zipWith<U, V, Z>(
903
- zipper: (value: T, otherValue: U, thirdValue: V) => Z,
904
- otherCollection: Collection<any, U>,
905
- thirdCollection: Collection<any, V>
906
- ): List<Z>;
907
- zipWith<Z>(
908
- zipper: (...any: Array<any>) => Z,
909
- ...collections: Array<Collection<any, any>>
910
- ): List<Z>;
911
- }
912
-
913
-
914
- /**
915
- * Immutable Map is an unordered Collection.Keyed of (key, value) pairs with
916
- * `O(log32 N)` gets and `O(log32 N)` persistent sets.
917
- *
918
- * Iteration order of a Map is undefined, however is stable. Multiple
919
- * iterations of the same Map will iterate in the same order.
920
- *
921
- * Map's keys can be of any type, and use `Immutable.is` to determine key
922
- * equality. This allows the use of any value (including NaN) as a key.
923
- *
924
- * Because `Immutable.is` returns equality based on value semantics, and
925
- * Immutable collections are treated as values, any Immutable collection may
926
- * be used as a key.
927
- *
928
- * <!-- runkit:activate -->
929
- * ```js
930
- * const { Map, List } = require('immutable@4.0.0-rc.6');
931
- * Map().set(List([ 1 ]), 'listofone').get(List([ 1 ]));
932
- * // 'listofone'
933
- * ```
934
- *
935
- * Any JavaScript object may be used as a key, however strict identity is used
936
- * to evaluate key equality. Two similar looking objects will represent two
937
- * different keys.
938
- *
939
- * Implemented by a hash-array mapped trie.
940
- */
941
- export module Map {
942
-
943
- /**
944
- * True if the provided value is a Map
945
- *
946
- * <!-- runkit:activate -->
947
- * ```js
948
- * const { Map } = require('immutable@4.0.0-rc.6')
949
- * Map.isMap({}) // false
950
- * Map.isMap(Map()) // true
951
- * ```
952
- */
953
- function isMap(maybeMap: any): maybeMap is Map<any, any>;
954
-
955
- /**
956
- * Creates a new Map from alternating keys and values
957
- *
958
- * <!-- runkit:activate -->
959
- * ```js
960
- * const { Map } = require('immutable@4.0.0-rc.6')
961
- * Map.of(
962
- * 'key', 'value',
963
- * 'numerical value', 3,
964
- * 0, 'numerical key'
965
- * )
966
- * // Map { 0: "numerical key", "key": "value", "numerical value": 3 }
967
- * ```
968
- *
969
- * @deprecated Use Map([ [ 'k', 'v' ] ]) or Map({ k: 'v' })
970
- */
971
- function of(...keyValues: Array<any>): Map<any, any>;
972
- }
973
-
974
- /**
975
- * Creates a new Immutable Map.
976
- *
977
- * Created with the same key value pairs as the provided Collection.Keyed or
978
- * JavaScript Object or expects a Collection of [K, V] tuple entries.
979
- *
980
- * <!-- runkit:activate -->
981
- * ```js
982
- * const { Map } = require('immutable@4.0.0-rc.6')
983
- * Map({ key: "value" })
984
- * Map([ [ "key", "value" ] ])
985
- * ```
986
- *
987
- * Keep in mind, when using JS objects to construct Immutable Maps, that
988
- * JavaScript Object properties are always strings, even if written in a
989
- * quote-less shorthand, while Immutable Maps accept keys of any type.
990
- *
991
- * <!-- runkit:activate
992
- * { "preamble": "const { Map } = require(\"immutable\");" }
993
- * -->
994
- * ```js
995
- * let obj = { 1: "one" }
996
- * Object.keys(obj) // [ "1" ]
997
- * assert.equal(obj["1"], obj[1]) // "one" === "one"
998
- *
999
- * let map = Map(obj)
1000
- * assert.notEqual(map.get("1"), map.get(1)) // "one" !== undefined
1001
- * ```
1002
- *
1003
- * Property access for JavaScript Objects first converts the key to a string,
1004
- * but since Immutable Map keys can be of any type the argument to `get()` is
1005
- * not altered.
1006
- */
1007
- export function Map<K, V>(collection: Iterable<[K, V]>): Map<K, V>;
1008
- export function Map<T>(collection: Iterable<Iterable<T>>): Map<T, T>;
1009
- export function Map<V>(obj: {[key: string]: V}): Map<string, V>;
1010
- export function Map<K, V>(): Map<K, V>;
1011
- export function Map(): Map<any, any>;
1012
-
1013
- export interface Map<K, V> extends Collection.Keyed<K, V> {
1014
-
1015
- /**
1016
- * The number of entries in this Map.
1017
- */
1018
- readonly size: number;
1019
-
1020
- // Persistent changes
1021
-
1022
- /**
1023
- * Returns a new Map also containing the new key, value pair. If an equivalent
1024
- * key already exists in this Map, it will be replaced.
1025
- *
1026
- * <!-- runkit:activate -->
1027
- * ```js
1028
- * const { Map } = require('immutable@4.0.0-rc.6')
1029
- * const originalMap = Map()
1030
- * const newerMap = originalMap.set('key', 'value')
1031
- * const newestMap = newerMap.set('key', 'newer value')
1032
- *
1033
- * originalMap
1034
- * // Map {}
1035
- * newerMap
1036
- * // Map { "key": "value" }
1037
- * newestMap
1038
- * // Map { "key": "newer value" }
1039
- * ```
1040
- *
1041
- * Note: `set` can be used in `withMutations`.
1042
- */
1043
- set(key: K, value: V): this;
1044
-
1045
- /**
1046
- * Returns a new Map which excludes this `key`.
1047
- *
1048
- * Note: `delete` cannot be safely used in IE8, but is provided to mirror
1049
- * the ES6 collection API.
1050
- *
1051
- * <!-- runkit:activate -->
1052
- * ```js
1053
- * const { Map } = require('immutable@4.0.0-rc.6')
1054
- * const originalMap = Map({
1055
- * key: 'value',
1056
- * otherKey: 'other value'
1057
- * })
1058
- * // Map { "key": "value", "otherKey": "other value" }
1059
- * originalMap.delete('otherKey')
1060
- * // Map { "key": "value" }
1061
- * ```
1062
- *
1063
- * Note: `delete` can be used in `withMutations`.
1064
- *
1065
- * @alias remove
1066
- */
1067
- delete(key: K): this;
1068
- remove(key: K): this;
1069
-
1070
- /**
1071
- * Returns a new Map which excludes the provided `keys`.
1072
- *
1073
- * <!-- runkit:activate -->
1074
- * ```js
1075
- * const { Map } = require('immutable@4.0.0-rc.6')
1076
- * const names = Map({ a: "Aaron", b: "Barry", c: "Connor" })
1077
- * names.deleteAll([ 'a', 'c' ])
1078
- * // Map { "b": "Barry" }
1079
- * ```
1080
- *
1081
- * Note: `deleteAll` can be used in `withMutations`.
1082
- *
1083
- * @alias removeAll
1084
- */
1085
- deleteAll(keys: Iterable<K>): this;
1086
- removeAll(keys: Iterable<K>): this;
1087
-
1088
- /**
1089
- * Returns a new Map containing no keys or values.
1090
- *
1091
- * <!-- runkit:activate -->
1092
- * ```js
1093
- * const { Map } = require('immutable@4.0.0-rc.6')
1094
- * Map({ key: 'value' }).clear()
1095
- * // Map {}
1096
- * ```
1097
- *
1098
- * Note: `clear` can be used in `withMutations`.
1099
- */
1100
- clear(): this;
1101
-
1102
- /**
1103
- * Returns a new Map having updated the value at this `key` with the return
1104
- * value of calling `updater` with the existing value.
1105
- *
1106
- * Similar to: `map.set(key, updater(map.get(key)))`.
1107
- *
1108
- * <!-- runkit:activate -->
1109
- * ```js
1110
- * const { Map } = require('immutable@4.0.0-rc.6')
1111
- * const aMap = Map({ key: 'value' })
1112
- * const newMap = aMap.update('key', value => value + value)
1113
- * // Map { "key": "valuevalue" }
1114
- * ```
1115
- *
1116
- * This is most commonly used to call methods on collections within a
1117
- * structure of data. For example, in order to `.push()` onto a nested `List`,
1118
- * `update` and `push` can be used together:
1119
- *
1120
- * <!-- runkit:activate
1121
- * { "preamble": "const { Map, List } = require(\"immutable\");" }
1122
- * -->
1123
- * ```js
1124
- * const aMap = Map({ nestedList: List([ 1, 2, 3 ]) })
1125
- * const newMap = aMap.update('nestedList', list => list.push(4))
1126
- * // Map { "nestedList": List [ 1, 2, 3, 4 ] }
1127
- * ```
1128
- *
1129
- * When a `notSetValue` is provided, it is provided to the `updater`
1130
- * function when the value at the key does not exist in the Map.
1131
- *
1132
- * <!-- runkit:activate
1133
- * { "preamble": "const { Map } = require(\"immutable\");" }
1134
- * -->
1135
- * ```js
1136
- * const aMap = Map({ key: 'value' })
1137
- * const newMap = aMap.update('noKey', 'no value', value => value + value)
1138
- * // Map { "key": "value", "noKey": "no valueno value" }
1139
- * ```
1140
- *
1141
- * However, if the `updater` function returns the same value it was called
1142
- * with, then no change will occur. This is still true if `notSetValue`
1143
- * is provided.
1144
- *
1145
- * <!-- runkit:activate
1146
- * { "preamble": "const { Map } = require(\"immutable\");" }
1147
- * -->
1148
- * ```js
1149
- * const aMap = Map({ apples: 10 })
1150
- * const newMap = aMap.update('oranges', 0, val => val)
1151
- * // Map { "apples": 10 }
1152
- * assert.strictEqual(newMap, map);
1153
- * ```
1154
- *
1155
- * For code using ES2015 or later, using `notSetValue` is discourged in
1156
- * favor of function parameter default values. This helps to avoid any
1157
- * potential confusion with identify functions as described above.
1158
- *
1159
- * The previous example behaves differently when written with default values:
1160
- *
1161
- * <!-- runkit:activate
1162
- * { "preamble": "const { Map } = require(\"immutable\");" }
1163
- * -->
1164
- * ```js
1165
- * const aMap = Map({ apples: 10 })
1166
- * const newMap = aMap.update('oranges', (val = 0) => val)
1167
- * // Map { "apples": 10, "oranges": 0 }
1168
- * ```
1169
- *
1170
- * If no key is provided, then the `updater` function return value is
1171
- * returned as well.
1172
- *
1173
- * <!-- runkit:activate
1174
- * { "preamble": "const { Map } = require(\"immutable\");" }
1175
- * -->
1176
- * ```js
1177
- * const aMap = Map({ key: 'value' })
1178
- * const result = aMap.update(aMap => aMap.get('key'))
1179
- * // "value"
1180
- * ```
1181
- *
1182
- * This can be very useful as a way to "chain" a normal function into a
1183
- * sequence of methods. RxJS calls this "let" and lodash calls it "thru".
1184
- *
1185
- * For example, to sum the values in a Map
1186
- *
1187
- * <!-- runkit:activate
1188
- * { "preamble": "const { Map } = require(\"immutable\");" }
1189
- * -->
1190
- * ```js
1191
- * function sum(collection) {
1192
- * return collection.reduce((sum, x) => sum + x, 0)
1193
- * }
1194
- *
1195
- * Map({ x: 1, y: 2, z: 3 })
1196
- * .map(x => x + 1)
1197
- * .filter(x => x % 2 === 0)
1198
- * .update(sum)
1199
- * // 6
1200
- * ```
1201
- *
1202
- * Note: `update(key)` can be used in `withMutations`.
1203
- */
1204
- update(key: K, notSetValue: V, updater: (value: V) => V): this;
1205
- update(key: K, updater: (value: V) => V): this;
1206
- update<R>(updater: (value: this) => R): R;
1207
-
1208
- /**
1209
- * Returns a new Map resulting from merging the provided Collections
1210
- * (or JS objects) into this Map. In other words, this takes each entry of
1211
- * each collection and sets it on this Map.
1212
- *
1213
- * Note: Values provided to `merge` are shallowly converted before being
1214
- * merged. No nested values are altered.
1215
- *
1216
- * <!-- runkit:activate -->
1217
- * ```js
1218
- * const { Map } = require('immutable@4.0.0-rc.6')
1219
- * const one = Map({ a: 10, b: 20, c: 30 })
1220
- * const two = Map({ b: 40, a: 50, d: 60 })
1221
- * one.merge(two) // Map { "a": 50, "b": 40, "c": 30, "d": 60 }
1222
- * two.merge(one) // Map { "b": 20, "a": 10, "d": 60, "c": 30 }
1223
- * ```
1224
- *
1225
- * Note: `merge` can be used in `withMutations`.
1226
- */
1227
- merge(...collections: Array<Iterable<[K, V]> | {[key: string]: V}>): this;
1228
-
1229
- /**
1230
- * Like `merge()`, `mergeWith()` returns a new Map resulting from merging
1231
- * the provided Collections (or JS objects) into this Map, but uses the
1232
- * `merger` function for dealing with conflicts.
1233
- *
1234
- * <!-- runkit:activate -->
1235
- * ```js
1236
- * const { Map } = require('immutable@4.0.0-rc.6')
1237
- * const one = Map({ a: 10, b: 20, c: 30 })
1238
- * const two = Map({ b: 40, a: 50, d: 60 })
1239
- * one.mergeWith((oldVal, newVal) => oldVal / newVal, two)
1240
- * // { "a": 0.2, "b": 0.5, "c": 30, "d": 60 }
1241
- * two.mergeWith((oldVal, newVal) => oldVal / newVal, one)
1242
- * // { "b": 2, "a": 5, "d": 60, "c": 30 }
1243
- * ```
1244
- *
1245
- * Note: `mergeWith` can be used in `withMutations`.
1246
- */
1247
- mergeWith(
1248
- merger: (oldVal: V, newVal: V, key: K) => V,
1249
- ...collections: Array<Iterable<[K, V]> | {[key: string]: V}>
1250
- ): this;
1251
-
1252
- /**
1253
- * Like `merge()`, but when two Collections conflict, it merges them as well,
1254
- * recursing deeply through the nested data.
1255
- *
1256
- * Note: Values provided to `merge` are shallowly converted before being
1257
- * merged. No nested values are altered unless they will also be merged at
1258
- * a deeper level.
1259
- *
1260
- * <!-- runkit:activate -->
1261
- * ```js
1262
- * const { Map } = require('immutable@4.0.0-rc.6')
1263
- * const one = Map({ a: Map({ x: 10, y: 10 }), b: Map({ x: 20, y: 50 }) })
1264
- * const two = Map({ a: Map({ x: 2 }), b: Map({ y: 5 }), c: Map({ z: 3 }) })
1265
- * one.mergeDeep(two)
1266
- * // Map {
1267
- * // "a": Map { "x": 2, "y": 10 },
1268
- * // "b": Map { "x": 20, "y": 5 },
1269
- * // "c": Map { "z": 3 }
1270
- * // }
1271
- * ```
1272
- *
1273
- * Note: `mergeDeep` can be used in `withMutations`.
1274
- */
1275
- mergeDeep(...collections: Array<Iterable<[K, V]> | {[key: string]: V}>): this;
1276
-
1277
- /**
1278
- * Like `mergeDeep()`, but when two non-Collections conflict, it uses the
1279
- * `merger` function to determine the resulting value.
1280
- *
1281
- * <!-- runkit:activate -->
1282
- * ```js
1283
- * const { Map } = require('immutable@4.0.0-rc.6')
1284
- * const one = Map({ a: Map({ x: 10, y: 10 }), b: Map({ x: 20, y: 50 }) })
1285
- * const two = Map({ a: Map({ x: 2 }), b: Map({ y: 5 }), c: Map({ z: 3 }) })
1286
- * one.mergeDeepWith((oldVal, newVal) => oldVal / newVal, two)
1287
- * // Map {
1288
- * // "a": Map { "x": 5, "y": 10 },
1289
- * // "b": Map { "x": 20, "y": 10 },
1290
- * // "c": Map { "z": 3 }
1291
- * // }
1292
- * ```
1293
-
1294
- * Note: `mergeDeepWith` can be used in `withMutations`.
1295
- */
1296
- mergeDeepWith(
1297
- merger: (oldVal: V, newVal: V, key: K) => V,
1298
- ...collections: Array<Iterable<[K, V]> | {[key: string]: V}>
1299
- ): this;
1300
-
1301
-
1302
- // Deep persistent changes
1303
-
1304
- /**
1305
- * Returns a new Map having set `value` at this `keyPath`. If any keys in
1306
- * `keyPath` do not exist, a new immutable Map will be created at that key.
1307
- *
1308
- * <!-- runkit:activate -->
1309
- * ```js
1310
- * const { Map } = require('immutable@4.0.0-rc.6')
1311
- * const originalMap = Map({
1312
- * subObject: Map({
1313
- * subKey: 'subvalue',
1314
- * subSubObject: Map({
1315
- * subSubKey: 'subSubValue'
1316
- * })
1317
- * })
1318
- * })
1319
- *
1320
- * const newMap = originalMap.setIn(['subObject', 'subKey'], 'ha ha!')
1321
- * // Map {
1322
- * // "subObject": Map {
1323
- * // "subKey": "ha ha!",
1324
- * // "subSubObject": Map { "subSubKey": "subSubValue" }
1325
- * // }
1326
- * // }
1327
- *
1328
- * const newerMap = originalMap.setIn(
1329
- * ['subObject', 'subSubObject', 'subSubKey'],
1330
- * 'ha ha ha!'
1331
- * )
1332
- * // Map {
1333
- * // "subObject": Map {
1334
- * // "subKey": "subvalue",
1335
- * // "subSubObject": Map { "subSubKey": "ha ha ha!" }
1336
- * // }
1337
- * // }
1338
- * ```
1339
- *
1340
- * If any key in the path exists but does not have a `.set()` method
1341
- * (such as Map and List), an error will be throw.
1342
- *
1343
- * Note: `setIn` can be used in `withMutations`.
1344
- */
1345
- setIn(keyPath: Iterable<any>, value: any): this;
1346
-
1347
- /**
1348
- * Returns a new Map having removed the value at this `keyPath`. If any keys
1349
- * in `keyPath` do not exist, no change will occur.
1350
- *
1351
- * Note: `deleteIn` can be used in `withMutations`.
1352
- *
1353
- * @alias removeIn
1354
- */
1355
- deleteIn(keyPath: Iterable<any>): this;
1356
- removeIn(keyPath: Iterable<any>): this;
1357
-
1358
- /**
1359
- * Returns a new Map having applied the `updater` to the entry found at the
1360
- * keyPath.
1361
- *
1362
- * This is most commonly used to call methods on collections nested within a
1363
- * structure of data. For example, in order to `.push()` onto a nested `List`,
1364
- * `updateIn` and `push` can be used together:
1365
- *
1366
- * <!-- runkit:activate -->
1367
- * ```js
1368
- * const { Map, List } = require('immutable@4.0.0-rc.6')
1369
- * const map = Map({ inMap: Map({ inList: List([ 1, 2, 3 ]) }) })
1370
- * const newMap = map.updateIn(['inMap', 'inList'], list => list.push(4))
1371
- * // Map { "inMap": Map { "inList": List [ 1, 2, 3, 4 ] } }
1372
- * ```
1373
- *
1374
- * If any keys in `keyPath` do not exist, new Immutable `Map`s will
1375
- * be created at those keys. If the `keyPath` does not already contain a
1376
- * value, the `updater` function will be called with `notSetValue`, if
1377
- * provided, otherwise `undefined`.
1378
- *
1379
- * <!-- runkit:activate
1380
- * { "preamble": "const { Map } = require('immutable@4.0.0-rc.6')" }
1381
- * -->
1382
- * ```js
1383
- * const map = Map({ a: Map({ b: Map({ c: 10 }) }) })
1384
- * const newMap = map.updateIn(['a', 'b', 'c'], val => val * 2)
1385
- * // Map { "a": Map { "b": Map { "c": 20 } } }
1386
- * ```
1387
- *
1388
- * If the `updater` function returns the same value it was called with, then
1389
- * no change will occur. This is still true if `notSetValue` is provided.
1390
- *
1391
- * <!-- runkit:activate
1392
- * { "preamble": "const { Map } = require('immutable@4.0.0-rc.6')" }
1393
- * -->
1394
- * ```js
1395
- * const map = Map({ a: Map({ b: Map({ c: 10 }) }) })
1396
- * const newMap = map.updateIn(['a', 'b', 'x'], 100, val => val)
1397
- * // Map { "a": Map { "b": Map { "c": 10 } } }
1398
- * assert.strictEqual(newMap, aMap)
1399
- * ```
1400
- *
1401
- * For code using ES2015 or later, using `notSetValue` is discourged in
1402
- * favor of function parameter default values. This helps to avoid any
1403
- * potential confusion with identify functions as described above.
1404
- *
1405
- * The previous example behaves differently when written with default values:
1406
- *
1407
- * <!-- runkit:activate
1408
- * { "preamble": "const { Map } = require('immutable@4.0.0-rc.6')" }
1409
- * -->
1410
- * ```js
1411
- * const map = Map({ a: Map({ b: Map({ c: 10 }) }) })
1412
- * const newMap = map.updateIn(['a', 'b', 'x'], (val = 100) => val)
1413
- * // Map { "a": Map { "b": Map { "c": 10, "x": 100 } } }
1414
- * ```
1415
- *
1416
- * If any key in the path exists but does not have a .set() method (such as
1417
- * Map and List), an error will be thrown.
1418
- */
1419
- updateIn(keyPath: Iterable<any>, notSetValue: any, updater: (value: any) => any): this;
1420
- updateIn(keyPath: Iterable<any>, updater: (value: any) => any): this;
1421
-
1422
- /**
1423
- * A combination of `updateIn` and `merge`, returning a new Map, but
1424
- * performing the merge at a point arrived at by following the keyPath.
1425
- * In other words, these two lines are equivalent:
1426
- *
1427
- * ```js
1428
- * map.updateIn(['a', 'b', 'c'], abc => abc.merge(y))
1429
- * map.mergeIn(['a', 'b', 'c'], y)
1430
- * ```
1431
- *
1432
- * Note: `mergeIn` can be used in `withMutations`.
1433
- */
1434
- mergeIn(keyPath: Iterable<any>, ...collections: Array<any>): this;
1435
-
1436
- /**
1437
- * A combination of `updateIn` and `mergeDeep`, returning a new Map, but
1438
- * performing the deep merge at a point arrived at by following the keyPath.
1439
- * In other words, these two lines are equivalent:
1440
- *
1441
- * ```js
1442
- * map.updateIn(['a', 'b', 'c'], abc => abc.mergeDeep(y))
1443
- * map.mergeDeepIn(['a', 'b', 'c'], y)
1444
- * ```
1445
- *
1446
- * Note: `mergeDeepIn` can be used in `withMutations`.
1447
- */
1448
- mergeDeepIn(keyPath: Iterable<any>, ...collections: Array<any>): this;
1449
-
1450
- // Transient changes
1451
-
1452
- /**
1453
- * Every time you call one of the above functions, a new immutable Map is
1454
- * created. If a pure function calls a number of these to produce a final
1455
- * return value, then a penalty on performance and memory has been paid by
1456
- * creating all of the intermediate immutable Maps.
1457
- *
1458
- * If you need to apply a series of mutations to produce a new immutable
1459
- * Map, `withMutations()` creates a temporary mutable copy of the Map which
1460
- * can apply mutations in a highly performant manner. In fact, this is
1461
- * exactly how complex mutations like `merge` are done.
1462
- *
1463
- * As an example, this results in the creation of 2, not 4, new Maps:
1464
- *
1465
- * <!-- runkit:activate -->
1466
- * ```js
1467
- * const { Map } = require('immutable@4.0.0-rc.6')
1468
- * const map1 = Map()
1469
- * const map2 = map1.withMutations(map => {
1470
- * map.set('a', 1).set('b', 2).set('c', 3)
1471
- * })
1472
- * assert.equal(map1.size, 0)
1473
- * assert.equal(map2.size, 3)
1474
- * ```
1475
- *
1476
- * Note: Not all methods can be used on a mutable collection or within
1477
- * `withMutations`! Read the documentation for each method to see if it
1478
- * is safe to use in `withMutations`.
1479
- */
1480
- withMutations(mutator: (mutable: this) => any): this;
1481
-
1482
- /**
1483
- * Another way to avoid creation of intermediate Immutable maps is to create
1484
- * a mutable copy of this collection. Mutable copies *always* return `this`,
1485
- * and thus shouldn't be used for equality. Your function should never return
1486
- * a mutable copy of a collection, only use it internally to create a new
1487
- * collection. If possible, use `withMutations` as it provides an easier to
1488
- * use API.
1489
- *
1490
- * Note: if the collection is already mutable, `asMutable` returns itself.
1491
- *
1492
- * Note: Not all methods can be used on a mutable collection or within
1493
- * `withMutations`! Read the documentation for each method to see if it
1494
- * is safe to use in `withMutations`.
1495
- */
1496
- asMutable(): this;
1497
-
1498
- /**
1499
- * Returns true if this is a mutable copy (see `asMutable()`) and mutative
1500
- * alterations have been applied.
1501
- *
1502
- * @see `Map#asMutable`
1503
- */
1504
- wasAltered(): boolean;
1505
-
1506
- /**
1507
- * The yin to `asMutable`'s yang. Because it applies to mutable collections,
1508
- * this operation is *mutable* and returns itself. Once performed, the mutable
1509
- * copy has become immutable and can be safely returned from a function.
1510
- */
1511
- asImmutable(): this;
1512
-
1513
- // Sequence algorithms
1514
-
1515
- /**
1516
- * Returns a new Map with other collections concatenated to this one.
1517
- */
1518
- concat<KC, VC>(...collections: Array<Iterable<[KC, VC]>>): Map<K | KC, V | VC>;
1519
- concat<C>(...collections: Array<{[key: string]: C}>): Map<K | string, V | C>;
1520
-
1521
- /**
1522
- * Returns a new Map with values passed through a
1523
- * `mapper` function.
1524
- *
1525
- * Map({ a: 1, b: 2 }).map(x => 10 * x)
1526
- * // Map { a: 10, b: 20 }
1527
- *
1528
- * Note: `map()` always returns a new instance, even if it produced the same
1529
- * value at every step.
1530
- */
1531
- map<M>(
1532
- mapper: (value: V, key: K, iter: this) => M,
1533
- context?: any
1534
- ): Map<K, M>;
1535
-
1536
- /**
1537
- * @see Collection.Keyed.mapKeys
1538
- */
1539
- mapKeys<M>(
1540
- mapper: (key: K, value: V, iter: this) => M,
1541
- context?: any
1542
- ): Map<M, V>;
1543
-
1544
- /**
1545
- * @see Collection.Keyed.mapEntries
1546
- */
1547
- mapEntries<KM, VM>(
1548
- mapper: (entry: [K, V], index: number, iter: this) => [KM, VM],
1549
- context?: any
1550
- ): Map<KM, VM>;
1551
-
1552
- /**
1553
- * Flat-maps the Map, returning a new Map.
1554
- *
1555
- * Similar to `data.map(...).flatten(true)`.
1556
- */
1557
- flatMap<KM, VM>(
1558
- mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>,
1559
- context?: any
1560
- ): Map<KM, VM>;
1561
-
1562
- /**
1563
- * Returns a new Map with only the entries for which the `predicate`
1564
- * function returns true.
1565
- *
1566
- * Note: `filter()` always returns a new instance, even if it results in
1567
- * not filtering out any values.
1568
- */
1569
- filter<F extends V>(
1570
- predicate: (value: V, key: K, iter: this) => value is F,
1571
- context?: any
1572
- ): Map<K, F>;
1573
- filter(
1574
- predicate: (value: V, key: K, iter: this) => any,
1575
- context?: any
1576
- ): this;
1577
-
1578
- /**
1579
- * @see Collection.Keyed.flip
1580
- */
1581
- flip(): Map<V, K>;
1582
- }
1583
-
1584
-
1585
- /**
1586
- * A type of Map that has the additional guarantee that the iteration order of
1587
- * entries will be the order in which they were set().
1588
- *
1589
- * The iteration behavior of OrderedMap is the same as native ES6 Map and
1590
- * JavaScript Object.
1591
- *
1592
- * Note that `OrderedMap` are more expensive than non-ordered `Map` and may
1593
- * consume more memory. `OrderedMap#set` is amortized O(log32 N), but not
1594
- * stable.
1595
- */
1596
-
1597
- export module OrderedMap {
1598
-
1599
- /**
1600
- * True if the provided value is an OrderedMap.
1601
- */
1602
- function isOrderedMap(maybeOrderedMap: any): maybeOrderedMap is OrderedMap<any, any>;
1603
- }
1604
-
1605
- /**
1606
- * Creates a new Immutable OrderedMap.
1607
- *
1608
- * Created with the same key value pairs as the provided Collection.Keyed or
1609
- * JavaScript Object or expects a Collection of [K, V] tuple entries.
1610
- *
1611
- * The iteration order of key-value pairs provided to this constructor will
1612
- * be preserved in the OrderedMap.
1613
- *
1614
- * let newOrderedMap = OrderedMap({key: "value"})
1615
- * let newOrderedMap = OrderedMap([["key", "value"]])
1616
- *
1617
- */
1618
- export function OrderedMap<K, V>(collection: Iterable<[K, V]>): OrderedMap<K, V>;
1619
- export function OrderedMap<T>(collection: Iterable<Iterable<T>>): OrderedMap<T, T>;
1620
- export function OrderedMap<V>(obj: {[key: string]: V}): OrderedMap<string, V>;
1621
- export function OrderedMap<K, V>(): OrderedMap<K, V>;
1622
- export function OrderedMap(): OrderedMap<any, any>;
1623
-
1624
- export interface OrderedMap<K, V> extends Map<K, V> {
1625
-
1626
- /**
1627
- * The number of entries in this OrderedMap.
1628
- */
1629
- readonly size: number;
1630
-
1631
- // Sequence algorithms
1632
-
1633
- /**
1634
- * Returns a new OrderedMap with other collections concatenated to this one.
1635
- */
1636
- concat<KC, VC>(...collections: Array<Iterable<[KC, VC]>>): OrderedMap<K | KC, V | VC>;
1637
- concat<C>(...collections: Array<{[key: string]: C}>): OrderedMap<K | string, V | C>;
1638
-
1639
- /**
1640
- * Returns a new OrderedMap with values passed through a
1641
- * `mapper` function.
1642
- *
1643
- * OrderedMap({ a: 1, b: 2 }).map(x => 10 * x)
1644
- * // OrderedMap { "a": 10, "b": 20 }
1645
- *
1646
- * Note: `map()` always returns a new instance, even if it produced the same
1647
- * value at every step.
1648
- */
1649
- map<M>(
1650
- mapper: (value: V, key: K, iter: this) => M,
1651
- context?: any
1652
- ): OrderedMap<K, M>;
1653
-
1654
- /**
1655
- * @see Collection.Keyed.mapKeys
1656
- */
1657
- mapKeys<M>(
1658
- mapper: (key: K, value: V, iter: this) => M,
1659
- context?: any
1660
- ): OrderedMap<M, V>;
1661
-
1662
- /**
1663
- * @see Collection.Keyed.mapEntries
1664
- */
1665
- mapEntries<KM, VM>(
1666
- mapper: (entry: [K, V], index: number, iter: this) => [KM, VM],
1667
- context?: any
1668
- ): OrderedMap<KM, VM>;
1669
-
1670
- /**
1671
- * Flat-maps the OrderedMap, returning a new OrderedMap.
1672
- *
1673
- * Similar to `data.map(...).flatten(true)`.
1674
- */
1675
- flatMap<KM, VM>(
1676
- mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>,
1677
- context?: any
1678
- ): OrderedMap<KM, VM>;
1679
-
1680
- /**
1681
- * Returns a new OrderedMap with only the entries for which the `predicate`
1682
- * function returns true.
1683
- *
1684
- * Note: `filter()` always returns a new instance, even if it results in
1685
- * not filtering out any values.
1686
- */
1687
- filter<F extends V>(
1688
- predicate: (value: V, key: K, iter: this) => value is F,
1689
- context?: any
1690
- ): OrderedMap<K, F>;
1691
- filter(
1692
- predicate: (value: V, key: K, iter: this) => any,
1693
- context?: any
1694
- ): this;
1695
-
1696
- /**
1697
- * @see Collection.Keyed.flip
1698
- */
1699
- flip(): OrderedMap<V, K>;
1700
- }
1701
-
1702
-
1703
- /**
1704
- * A Collection of unique values with `O(log32 N)` adds and has.
1705
- *
1706
- * When iterating a Set, the entries will be (value, value) pairs. Iteration
1707
- * order of a Set is undefined, however is stable. Multiple iterations of the
1708
- * same Set will iterate in the same order.
1709
- *
1710
- * Set values, like Map keys, may be of any type. Equality is determined using
1711
- * `Immutable.is`, enabling Sets to uniquely include other Immutable
1712
- * collections, custom value types, and NaN.
1713
- */
1714
- export module Set {
1715
-
1716
- /**
1717
- * True if the provided value is a Set
1718
- */
1719
- function isSet(maybeSet: any): maybeSet is Set<any>;
1720
-
1721
- /**
1722
- * Creates a new Set containing `values`.
1723
- */
1724
- function of<T>(...values: Array<T>): Set<T>;
1725
-
1726
- /**
1727
- * `Set.fromKeys()` creates a new immutable Set containing the keys from
1728
- * this Collection or JavaScript Object.
1729
- */
1730
- function fromKeys<T>(iter: Collection<T, any>): Set<T>;
1731
- function fromKeys(obj: {[key: string]: any}): Set<string>;
1732
-
1733
- /**
1734
- * `Set.intersect()` creates a new immutable Set that is the intersection of
1735
- * a collection of other sets.
1736
- *
1737
- * ```js
1738
- * const { Set } = require('immutable@4.0.0-rc.6')
1739
- * const intersected = Set.intersect([
1740
- * Set([ 'a', 'b', 'c' ])
1741
- * Set([ 'c', 'a', 't' ])
1742
- * ])
1743
- * // Set [ "a", "c"" ]
1744
- * ```
1745
- */
1746
- function intersect<T>(sets: Iterable<Iterable<T>>): Set<T>;
1747
-
1748
- /**
1749
- * `Set.union()` creates a new immutable Set that is the union of a
1750
- * collection of other sets.
1751
- *
1752
- * ```js
1753
- * const { Set } = require('immutable@4.0.0-rc.6')
1754
- * const unioned = Set.union([
1755
- * Set([ 'a', 'b', 'c' ])
1756
- * Set([ 'c', 'a', 't' ])
1757
- * ])
1758
- * // Set [ "a", "b", "c", "t"" ]
1759
- * ```
1760
- */
1761
- function union<T>(sets: Iterable<Iterable<T>>): Set<T>;
1762
- }
1763
-
1764
- /**
1765
- * Create a new immutable Set containing the values of the provided
1766
- * collection-like.
1767
- */
1768
- export function Set(): Set<any>;
1769
- export function Set<T>(): Set<T>;
1770
- export function Set<T>(collection: Iterable<T>): Set<T>;
1771
-
1772
- export interface Set<T> extends Collection.Set<T> {
1773
-
1774
- /**
1775
- * The number of items in this Set.
1776
- */
1777
- readonly size: number;
1778
-
1779
- // Persistent changes
1780
-
1781
- /**
1782
- * Returns a new Set which also includes this value.
1783
- *
1784
- * Note: `add` can be used in `withMutations`.
1785
- */
1786
- add(value: T): this;
1787
-
1788
- /**
1789
- * Returns a new Set which excludes this value.
1790
- *
1791
- * Note: `delete` can be used in `withMutations`.
1792
- *
1793
- * Note: `delete` **cannot** be safely used in IE8, use `remove` if
1794
- * supporting old browsers.
1795
- *
1796
- * @alias remove
1797
- */
1798
- delete(value: T): this;
1799
- remove(value: T): this;
1800
-
1801
- /**
1802
- * Returns a new Set containing no values.
1803
- *
1804
- * Note: `clear` can be used in `withMutations`.
1805
- */
1806
- clear(): this;
1807
-
1808
- /**
1809
- * Returns a Set including any value from `collections` that does not already
1810
- * exist in this Set.
1811
- *
1812
- * Note: `union` can be used in `withMutations`.
1813
- * @alias merge
1814
- */
1815
- union(...collections: Array<Iterable<T>>): this;
1816
- merge(...collections: Array<Iterable<T>>): this;
1817
-
1818
- /**
1819
- * Returns a Set which has removed any values not also contained
1820
- * within `collections`.
1821
- *
1822
- * Note: `intersect` can be used in `withMutations`.
1823
- */
1824
- intersect(...collections: Array<Collection<any, T> | Array<T>>): this;
1825
-
1826
- /**
1827
- * Returns a Set excluding any values contained within `collections`.
1828
- *
1829
- * Note: `subtract` can be used in `withMutations`.
1830
- */
1831
- subtract(...collections: Array<Collection<any, T> | Array<T>>): this;
1832
-
1833
-
1834
- // Transient changes
1835
-
1836
- /**
1837
- * Note: Not all methods can be used on a mutable collection or within
1838
- * `withMutations`! Check the documentation for each method to see if it
1839
- * mentions being safe to use in `withMutations`.
1840
- *
1841
- * @see `Map#withMutations`
1842
- */
1843
- withMutations(mutator: (mutable: this) => any): this;
1844
-
1845
- /**
1846
- * Note: Not all methods can be used on a mutable collection or within
1847
- * `withMutations`! Check the documentation for each method to see if it
1848
- * mentions being safe to use in `withMutations`.
1849
- *
1850
- * @see `Map#asMutable`
1851
- */
1852
- asMutable(): this;
1853
-
1854
- /**
1855
- * @see `Map#wasAltered`
1856
- */
1857
- wasAltered(): boolean;
1858
-
1859
- /**
1860
- * @see `Map#asImmutable`
1861
- */
1862
- asImmutable(): this;
1863
-
1864
- // Sequence algorithms
1865
-
1866
- /**
1867
- * Returns a new Set with other collections concatenated to this one.
1868
- */
1869
- concat<C>(...valuesOrCollections: Array<Iterable<C> | C>): Set<T | C>;
1870
-
1871
- /**
1872
- * Returns a new Set with values passed through a
1873
- * `mapper` function.
1874
- *
1875
- * Set([1,2]).map(x => 10 * x)
1876
- * // Set [10,20]
1877
- *
1878
- * Note: `map()` always returns a new instance, even if it produced the same
1879
- * value at every step.
1880
- */
1881
- map<M>(
1882
- mapper: (value: T, key: T, iter: this) => M,
1883
- context?: any
1884
- ): Set<M>;
1885
-
1886
- /**
1887
- * Flat-maps the Set, returning a new Set.
1888
- *
1889
- * Similar to `set.map(...).flatten(true)`.
1890
- */
1891
- flatMap<M>(
1892
- mapper: (value: T, key: T, iter: this) => Iterable<M>,
1893
- context?: any
1894
- ): Set<M>;
1895
-
1896
- /**
1897
- * Returns a new Set with only the values for which the `predicate`
1898
- * function returns true.
1899
- *
1900
- * Note: `filter()` always returns a new instance, even if it results in
1901
- * not filtering out any values.
1902
- */
1903
- filter<F extends T>(
1904
- predicate: (value: T, key: T, iter: this) => value is F,
1905
- context?: any
1906
- ): Set<F>;
1907
- filter(
1908
- predicate: (value: T, key: T, iter: this) => any,
1909
- context?: any
1910
- ): this;
1911
- }
1912
-
1913
-
1914
- /**
1915
- * A type of Set that has the additional guarantee that the iteration order of
1916
- * values will be the order in which they were `add`ed.
1917
- *
1918
- * The iteration behavior of OrderedSet is the same as native ES6 Set.
1919
- *
1920
- * Note that `OrderedSet` are more expensive than non-ordered `Set` and may
1921
- * consume more memory. `OrderedSet#add` is amortized O(log32 N), but not
1922
- * stable.
1923
- */
1924
- export module OrderedSet {
1925
-
1926
- /**
1927
- * True if the provided value is an OrderedSet.
1928
- */
1929
- function isOrderedSet(maybeOrderedSet: any): boolean;
1930
-
1931
- /**
1932
- * Creates a new OrderedSet containing `values`.
1933
- */
1934
- function of<T>(...values: Array<T>): OrderedSet<T>;
1935
-
1936
- /**
1937
- * `OrderedSet.fromKeys()` creates a new immutable OrderedSet containing
1938
- * the keys from this Collection or JavaScript Object.
1939
- */
1940
- function fromKeys<T>(iter: Collection<T, any>): OrderedSet<T>;
1941
- function fromKeys(obj: {[key: string]: any}): OrderedSet<string>;
1942
- }
1943
-
1944
- /**
1945
- * Create a new immutable OrderedSet containing the values of the provided
1946
- * collection-like.
1947
- */
1948
- export function OrderedSet(): OrderedSet<any>;
1949
- export function OrderedSet<T>(): OrderedSet<T>;
1950
- export function OrderedSet<T>(collection: Iterable<T>): OrderedSet<T>;
1951
-
1952
- export interface OrderedSet<T> extends Set<T> {
1953
-
1954
- /**
1955
- * The number of items in this OrderedSet.
1956
- */
1957
- readonly size: number;
1958
-
1959
- // Sequence algorithms
1960
-
1961
- /**
1962
- * Returns a new OrderedSet with other collections concatenated to this one.
1963
- */
1964
- concat<C>(...valuesOrCollections: Array<Iterable<C> | C>): OrderedSet<T | C>;
1965
-
1966
- /**
1967
- * Returns a new Set with values passed through a
1968
- * `mapper` function.
1969
- *
1970
- * OrderedSet([ 1, 2 ]).map(x => 10 * x)
1971
- * // OrderedSet [10, 20]
1972
- *
1973
- * Note: `map()` always returns a new instance, even if it produced the same
1974
- * value at every step.
1975
- */
1976
- map<M>(
1977
- mapper: (value: T, key: T, iter: this) => M,
1978
- context?: any
1979
- ): OrderedSet<M>;
1980
-
1981
- /**
1982
- * Flat-maps the OrderedSet, returning a new OrderedSet.
1983
- *
1984
- * Similar to `set.map(...).flatten(true)`.
1985
- */
1986
- flatMap<M>(
1987
- mapper: (value: T, key: T, iter: this) => Iterable<M>,
1988
- context?: any
1989
- ): OrderedSet<M>;
1990
-
1991
- /**
1992
- * Returns a new OrderedSet with only the values for which the `predicate`
1993
- * function returns true.
1994
- *
1995
- * Note: `filter()` always returns a new instance, even if it results in
1996
- * not filtering out any values.
1997
- */
1998
- filter<F extends T>(
1999
- predicate: (value: T, key: T, iter: this) => value is F,
2000
- context?: any
2001
- ): OrderedSet<F>;
2002
- filter(
2003
- predicate: (value: T, key: T, iter: this) => any,
2004
- context?: any
2005
- ): this;
2006
-
2007
- /**
2008
- * Returns an OrderedSet of the same type "zipped" with the provided
2009
- * collections.
2010
- *
2011
- * Like `zipWith`, but using the default `zipper`: creating an `Array`.
2012
- *
2013
- * ```js
2014
- * const a = OrderedSet([ 1, 2, 3 ])
2015
- * const b = OrderedSet([ 4, 5, 6 ])
2016
- * const c = a.zip(b)
2017
- * // OrderedSet [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]
2018
- * ```
2019
- */
2020
- zip<U>(other: Collection<any, U>): OrderedSet<[T,U]>;
2021
- zip<U,V>(other1: Collection<any, U>, other2: Collection<any, V>): OrderedSet<[T,U,V]>;
2022
- zip(...collections: Array<Collection<any, any>>): OrderedSet<any>;
2023
-
2024
- /**
2025
- * Returns a OrderedSet of the same type "zipped" with the provided
2026
- * collections.
2027
- *
2028
- * Unlike `zip`, `zipAll` continues zipping until the longest collection is
2029
- * exhausted. Missing values from shorter collections are filled with `undefined`.
2030
- *
2031
- * ```js
2032
- * const a = OrderedSet([ 1, 2 ]);
2033
- * const b = OrderedSet([ 3, 4, 5 ]);
2034
- * const c = a.zipAll(b); // OrderedSet [ [ 1, 3 ], [ 2, 4 ], [ undefined, 5 ] ]
2035
- * ```
2036
- *
2037
- * Note: Since zipAll will return a collection as large as the largest
2038
- * input, some results may contain undefined values. TypeScript cannot
2039
- * account for these without cases (as of v2.5).
2040
- */
2041
- zipAll<U>(other: Collection<any, U>): OrderedSet<[T,U]>;
2042
- zipAll<U,V>(other1: Collection<any, U>, other2: Collection<any, V>): OrderedSet<[T,U,V]>;
2043
- zipAll(...collections: Array<Collection<any, any>>): OrderedSet<any>;
2044
-
2045
- /**
2046
- * Returns an OrderedSet of the same type "zipped" with the provided
2047
- * collections by using a custom `zipper` function.
2048
- *
2049
- * @see Seq.Indexed.zipWith
2050
- */
2051
- zipWith<U, Z>(
2052
- zipper: (value: T, otherValue: U) => Z,
2053
- otherCollection: Collection<any, U>
2054
- ): OrderedSet<Z>;
2055
- zipWith<U, V, Z>(
2056
- zipper: (value: T, otherValue: U, thirdValue: V) => Z,
2057
- otherCollection: Collection<any, U>,
2058
- thirdCollection: Collection<any, V>
2059
- ): OrderedSet<Z>;
2060
- zipWith<Z>(
2061
- zipper: (...any: Array<any>) => Z,
2062
- ...collections: Array<Collection<any, any>>
2063
- ): OrderedSet<Z>;
2064
-
2065
- }
2066
-
2067
-
2068
- /**
2069
- * Stacks are indexed collections which support very efficient O(1) addition
2070
- * and removal from the front using `unshift(v)` and `shift()`.
2071
- *
2072
- * For familiarity, Stack also provides `push(v)`, `pop()`, and `peek()`, but
2073
- * be aware that they also operate on the front of the list, unlike List or
2074
- * a JavaScript Array.
2075
- *
2076
- * Note: `reverse()` or any inherent reverse traversal (`reduceRight`,
2077
- * `lastIndexOf`, etc.) is not efficient with a Stack.
2078
- *
2079
- * Stack is implemented with a Single-Linked List.
2080
- */
2081
- export module Stack {
2082
-
2083
- /**
2084
- * True if the provided value is a Stack
2085
- */
2086
- function isStack(maybeStack: any): maybeStack is Stack<any>;
2087
-
2088
- /**
2089
- * Creates a new Stack containing `values`.
2090
- */
2091
- function of<T>(...values: Array<T>): Stack<T>;
2092
- }
2093
-
2094
- /**
2095
- * Create a new immutable Stack containing the values of the provided
2096
- * collection-like.
2097
- *
2098
- * The iteration order of the provided collection is preserved in the
2099
- * resulting `Stack`.
2100
- */
2101
- export function Stack(): Stack<any>;
2102
- export function Stack<T>(): Stack<T>;
2103
- export function Stack<T>(collection: Iterable<T>): Stack<T>;
2104
-
2105
- export interface Stack<T> extends Collection.Indexed<T> {
2106
-
2107
- /**
2108
- * The number of items in this Stack.
2109
- */
2110
- readonly size: number;
2111
-
2112
- // Reading values
2113
-
2114
- /**
2115
- * Alias for `Stack.first()`.
2116
- */
2117
- peek(): T | undefined;
2118
-
2119
-
2120
- // Persistent changes
2121
-
2122
- /**
2123
- * Returns a new Stack with 0 size and no values.
2124
- *
2125
- * Note: `clear` can be used in `withMutations`.
2126
- */
2127
- clear(): Stack<T>;
2128
-
2129
- /**
2130
- * Returns a new Stack with the provided `values` prepended, shifting other
2131
- * values ahead to higher indices.
2132
- *
2133
- * This is very efficient for Stack.
2134
- *
2135
- * Note: `unshift` can be used in `withMutations`.
2136
- */
2137
- unshift(...values: Array<T>): Stack<T>;
2138
-
2139
- /**
2140
- * Like `Stack#unshift`, but accepts a collection rather than varargs.
2141
- *
2142
- * Note: `unshiftAll` can be used in `withMutations`.
2143
- */
2144
- unshiftAll(iter: Iterable<T>): Stack<T>;
2145
-
2146
- /**
2147
- * Returns a new Stack with a size ones less than this Stack, excluding
2148
- * the first item in this Stack, shifting all other values to a lower index.
2149
- *
2150
- * Note: this differs from `Array#shift` because it returns a new
2151
- * Stack rather than the removed value. Use `first()` or `peek()` to get the
2152
- * first value in this Stack.
2153
- *
2154
- * Note: `shift` can be used in `withMutations`.
2155
- */
2156
- shift(): Stack<T>;
2157
-
2158
- /**
2159
- * Alias for `Stack#unshift` and is not equivalent to `List#push`.
2160
- */
2161
- push(...values: Array<T>): Stack<T>;
2162
-
2163
- /**
2164
- * Alias for `Stack#unshiftAll`.
2165
- */
2166
- pushAll(iter: Iterable<T>): Stack<T>;
2167
-
2168
- /**
2169
- * Alias for `Stack#shift` and is not equivalent to `List#pop`.
2170
- */
2171
- pop(): Stack<T>;
2172
-
2173
-
2174
- // Transient changes
2175
-
2176
- /**
2177
- * Note: Not all methods can be used on a mutable collection or within
2178
- * `withMutations`! Check the documentation for each method to see if it
2179
- * mentions being safe to use in `withMutations`.
2180
- *
2181
- * @see `Map#withMutations`
2182
- */
2183
- withMutations(mutator: (mutable: this) => any): this;
2184
-
2185
- /**
2186
- * Note: Not all methods can be used on a mutable collection or within
2187
- * `withMutations`! Check the documentation for each method to see if it
2188
- * mentions being safe to use in `withMutations`.
2189
- *
2190
- * @see `Map#asMutable`
2191
- */
2192
- asMutable(): this;
2193
-
2194
- /**
2195
- * @see `Map#wasAltered`
2196
- */
2197
- wasAltered(): boolean;
2198
-
2199
- /**
2200
- * @see `Map#asImmutable`
2201
- */
2202
- asImmutable(): this;
2203
-
2204
- // Sequence algorithms
2205
-
2206
- /**
2207
- * Returns a new Stack with other collections concatenated to this one.
2208
- */
2209
- concat<C>(...valuesOrCollections: Array<Iterable<C> | C>): Stack<T | C>;
2210
-
2211
- /**
2212
- * Returns a new Stack with values passed through a
2213
- * `mapper` function.
2214
- *
2215
- * Stack([ 1, 2 ]).map(x => 10 * x)
2216
- * // Stack [ 10, 20 ]
2217
- *
2218
- * Note: `map()` always returns a new instance, even if it produced the same
2219
- * value at every step.
2220
- */
2221
- map<M>(
2222
- mapper: (value: T, key: number, iter: this) => M,
2223
- context?: any
2224
- ): Stack<M>;
2225
-
2226
- /**
2227
- * Flat-maps the Stack, returning a new Stack.
2228
- *
2229
- * Similar to `stack.map(...).flatten(true)`.
2230
- */
2231
- flatMap<M>(
2232
- mapper: (value: T, key: number, iter: this) => Iterable<M>,
2233
- context?: any
2234
- ): Stack<M>;
2235
-
2236
- /**
2237
- * Returns a new Set with only the values for which the `predicate`
2238
- * function returns true.
2239
- *
2240
- * Note: `filter()` always returns a new instance, even if it results in
2241
- * not filtering out any values.
2242
- */
2243
- filter<F extends T>(
2244
- predicate: (value: T, index: number, iter: this) => value is F,
2245
- context?: any
2246
- ): Set<F>;
2247
- filter(
2248
- predicate: (value: T, index: number, iter: this) => any,
2249
- context?: any
2250
- ): this;
2251
-
2252
- /**
2253
- * Returns a Stack "zipped" with the provided collections.
2254
- *
2255
- * Like `zipWith`, but using the default `zipper`: creating an `Array`.
2256
- *
2257
- * ```js
2258
- * const a = Stack([ 1, 2, 3 ]);
2259
- * const b = Stack([ 4, 5, 6 ]);
2260
- * const c = a.zip(b); // Stack [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]
2261
- * ```
2262
- */
2263
- zip<U>(other: Collection<any, U>): Stack<[T,U]>;
2264
- zip<U,V>(other: Collection<any, U>, other2: Collection<any,V>): Stack<[T,U,V]>;
2265
- zip(...collections: Array<Collection<any, any>>): Stack<any>;
2266
-
2267
- /**
2268
- * Returns a Stack "zipped" with the provided collections.
2269
- *
2270
- * Unlike `zip`, `zipAll` continues zipping until the longest collection is
2271
- * exhausted. Missing values from shorter collections are filled with `undefined`.
2272
- *
2273
- * ```js
2274
- * const a = Stack([ 1, 2 ]);
2275
- * const b = Stack([ 3, 4, 5 ]);
2276
- * const c = a.zipAll(b); // Stack [ [ 1, 3 ], [ 2, 4 ], [ undefined, 5 ] ]
2277
- * ```
2278
- *
2279
- * Note: Since zipAll will return a collection as large as the largest
2280
- * input, some results may contain undefined values. TypeScript cannot
2281
- * account for these without cases (as of v2.5).
2282
- */
2283
- zipAll<U>(other: Collection<any, U>): Stack<[T,U]>;
2284
- zipAll<U,V>(other: Collection<any, U>, other2: Collection<any,V>): Stack<[T,U,V]>;
2285
- zipAll(...collections: Array<Collection<any, any>>): Stack<any>;
2286
-
2287
- /**
2288
- * Returns a Stack "zipped" with the provided collections by using a
2289
- * custom `zipper` function.
2290
- *
2291
- * ```js
2292
- * const a = Stack([ 1, 2, 3 ]);
2293
- * const b = Stack([ 4, 5, 6 ]);
2294
- * const c = a.zipWith((a, b) => a + b, b);
2295
- * // Stack [ 5, 7, 9 ]
2296
- * ```
2297
- */
2298
- zipWith<U, Z>(
2299
- zipper: (value: T, otherValue: U) => Z,
2300
- otherCollection: Collection<any, U>
2301
- ): Stack<Z>;
2302
- zipWith<U, V, Z>(
2303
- zipper: (value: T, otherValue: U, thirdValue: V) => Z,
2304
- otherCollection: Collection<any, U>,
2305
- thirdCollection: Collection<any, V>
2306
- ): Stack<Z>;
2307
- zipWith<Z>(
2308
- zipper: (...any: Array<any>) => Z,
2309
- ...collections: Array<Collection<any, any>>
2310
- ): Stack<Z>;
2311
- }
2312
-
2313
-
2314
- /**
2315
- * Returns a Seq.Indexed of numbers from `start` (inclusive) to `end`
2316
- * (exclusive), by `step`, where `start` defaults to 0, `step` to 1, and `end` to
2317
- * infinity. When `start` is equal to `end`, returns empty range.
2318
- *
2319
- * ```js
2320
- * const { Range } = require('immutable@4.0.0-rc.6')
2321
- * Range() // [ 0, 1, 2, 3, ... ]
2322
- * Range(10) // [ 10, 11, 12, 13, ... ]
2323
- * Range(10, 15) // [ 10, 11, 12, 13, 14 ]
2324
- * Range(10, 30, 5) // [ 10, 15, 20, 25 ]
2325
- * Range(30, 10, 5) // [ 30, 25, 20, 15 ]
2326
- * Range(30, 30, 5) // []
2327
- * ```
2328
- */
2329
- export function Range(start?: number, end?: number, step?: number): Seq.Indexed<number>;
2330
-
2331
-
2332
- /**
2333
- * Returns a Seq.Indexed of `value` repeated `times` times. When `times` is
2334
- * not defined, returns an infinite `Seq` of `value`.
2335
- *
2336
- * ```js
2337
- * const { Repeat } = require('immutable@4.0.0-rc.6')
2338
- * Repeat('foo') // [ 'foo', 'foo', 'foo', ... ]
2339
- * Repeat('bar', 4) // [ 'bar', 'bar', 'bar', 'bar' ]
2340
- * ```
2341
- */
2342
- export function Repeat<T>(value: T, times?: number): Seq.Indexed<T>;
2343
-
2344
-
2345
- /**
2346
- * A record is similar to a JS object, but enforces a specific set of allowed
2347
- * string keys, and has default values.
2348
- *
2349
- * The `Record()` function produces new Record Factories, which when called
2350
- * create Record instances.
2351
- *
2352
- * ```js
2353
- * const { Record } = require('immutable@4.0.0-rc.6')
2354
- * const ABRecord = Record({ a: 1, b: 2 })
2355
- * const myRecord = new ABRecord({ b: 3 })
2356
- * ```
2357
- *
2358
- * Records always have a value for the keys they define. `remove`ing a key
2359
- * from a record simply resets it to the default value for that key.
2360
- *
2361
- * ```js
2362
- * myRecord.size // 2
2363
- * myRecord.get('a') // 1
2364
- * myRecord.get('b') // 3
2365
- * const myRecordWithoutB = myRecord.remove('b')
2366
- * myRecordWithoutB.get('b') // 2
2367
- * myRecordWithoutB.size // 2
2368
- * ```
2369
- *
2370
- * Values provided to the constructor not found in the Record type will
2371
- * be ignored. For example, in this case, ABRecord is provided a key "x" even
2372
- * though only "a" and "b" have been defined. The value for "x" will be
2373
- * ignored for this record.
2374
- *
2375
- * ```js
2376
- * const myRecord = new ABRecord({ b: 3, x: 10 })
2377
- * myRecord.get('x') // undefined
2378
- * ```
2379
- *
2380
- * Because Records have a known set of string keys, property get access works
2381
- * as expected, however property sets will throw an Error.
2382
- *
2383
- * Note: IE8 does not support property access. Only use `get()` when
2384
- * supporting IE8.
2385
- *
2386
- * ```js
2387
- * myRecord.b // 3
2388
- * myRecord.b = 5 // throws Error
2389
- * ```
2390
- *
2391
- * Record Classes can be extended as well, allowing for custom methods on your
2392
- * Record. This is not a common pattern in functional environments, but is in
2393
- * many JS programs.
2394
- *
2395
- * ```
2396
- * class ABRecord extends Record({ a: 1, b: 2 }) {
2397
- * getAB() {
2398
- * return this.a + this.b;
2399
- * }
2400
- * }
2401
- *
2402
- * var myRecord = new ABRecord({b: 3})
2403
- * myRecord.getAB() // 4
2404
- * ```
2405
- *
2406
- *
2407
- * **Flow Typing Records:**
2408
- *
2409
- * Immutable.js exports two Flow types designed to make it easier to use
2410
- * Records with flow typed code, `RecordOf<T>` and `RecordFactory<TProps>`.
2411
- *
2412
- * When defining a new kind of Record factory function, use a flow type that
2413
- * describes the values the record contains along with `RecordFactory<TProps>`.
2414
- * To type instances of the Record (which the factory function returns),
2415
- * use `RecordOf<T>`.
2416
- *
2417
- * Typically, new Record definitions will export both the Record factory
2418
- * function as well as the Record instance type for use in other code.
2419
- *
2420
- * ```js
2421
- * import type { RecordFactory, RecordOf } from 'immutable';
2422
- *
2423
- * // Use RecordFactory<TProps> for defining new Record factory functions.
2424
- * type Point3DProps = { x: number, y: number, z: number };
2425
- * const makePoint3D: RecordFactory<Point3DProps> = Record({ x: 0, y: 0, z: 0 });
2426
- * export makePoint3D;
2427
- *
2428
- * // Use RecordOf<T> for defining new instances of that Record.
2429
- * export type Point3D = RecordOf<Point3DProps>;
2430
- * const some3DPoint: Point3D = makePoint3D({ x: 10, y: 20, z: 30 });
2431
- * ```
2432
- */
2433
- export module Record {
2434
-
2435
- /**
2436
- * True if `maybeRecord` is an instance of a Record.
2437
- */
2438
- export function isRecord(maybeRecord: any): maybeRecord is Record<any>;
2439
-
2440
- /**
2441
- * Records allow passing a second parameter to supply a descriptive name
2442
- * that appears when converting a Record to a string or in any error
2443
- * messages. A descriptive name for any record can be accessed by using this
2444
- * method. If one was not provided, the string "Record" is returned.
2445
- *
2446
- * ```js
2447
- * const { Record } = require('immutable@4.0.0-rc.6')
2448
- * const Person = Record({
2449
- * name: null
2450
- * }, 'Person')
2451
- *
2452
- * var me = Person({ name: 'My Name' })
2453
- * me.toString() // "Person { "name": "My Name" }"
2454
- * Record.getDescriptiveName(me) // "Person"
2455
- * ```
2456
- */
2457
- export function getDescriptiveName(record: Record<any>): string;
2458
-
2459
- /**
2460
- * A Record.Factory is created by the `Record()` function. Record instances
2461
- * are created by passing it some of the accepted values for that Record
2462
- * type:
2463
- *
2464
- * <!-- runkit:activate
2465
- * { "preamble": "const { Record } = require('immutable@4.0.0-rc.6')" }
2466
- * -->
2467
- * ```js
2468
- * // makePerson is a Record Factory function
2469
- * const makePerson = Record({ name: null, favoriteColor: 'unknown' });
2470
- *
2471
- * // alan is a Record instance
2472
- * const alan = makePerson({ name: 'Alan' });
2473
- * ```
2474
- *
2475
- * Note that Record Factories return `Record<TProps> & Readonly<TProps>`,
2476
- * this allows use of both the Record instance API, and direct property
2477
- * access on the resulting instances:
2478
- *
2479
- * <!-- runkit:activate
2480
- * { "preamble": "const { Record } = require('immutable@4.0.0-rc.6');const makePerson = Record({ name: null, favoriteColor: 'unknown' });const alan = makePerson({ name: 'Alan' });" }
2481
- * -->
2482
- * ```js
2483
- * // Use the Record API
2484
- * console.log('Record API: ' + alan.get('name'))
2485
- *
2486
- * // Or direct property access (Readonly)
2487
- * console.log('property access: ' + alan.name)
2488
- * ```
2489
- *
2490
- * **Flow Typing Records:**
2491
- *
2492
- * Use the `RecordFactory<TProps>` Flow type to get high quality type checking of
2493
- * Records:
2494
- *
2495
- * ```js
2496
- * import type { RecordFactory, RecordOf } from 'immutable';
2497
- *
2498
- * // Use RecordFactory<TProps> for defining new Record factory functions.
2499
- * type PersonProps = { name: ?string, favoriteColor: string };
2500
- * const makePerson: RecordFactory<PersonProps> = Record({ name: null, favoriteColor: 'unknown' });
2501
- *
2502
- * // Use RecordOf<T> for defining new instances of that Record.
2503
- * type Person = RecordOf<PersonProps>;
2504
- * const alan: Person = makePerson({ name: 'Alan' });
2505
- * ```
2506
- */
2507
- export module Factory {}
2508
-
2509
- export interface Factory<TProps extends Object> {
2510
- (values?: Partial<TProps> | Iterable<[string, any]>): Record<TProps> & Readonly<TProps>;
2511
- new (values?: Partial<TProps> | Iterable<[string, any]>): Record<TProps> & Readonly<TProps>;
2512
- }
2513
-
2514
- export function Factory(values?: Partial<TProps> | Iterable<[string, any]>): Record<TProps> & Readonly<TProps>;
2515
- }
2516
-
2517
- /**
2518
- * Unlike other types in Immutable.js, the `Record()` function creates a new
2519
- * Record Factory, which is a function that creates Record instances.
2520
- *
2521
- * See above for examples of using `Record()`.
2522
- */
2523
- export function Record<TProps>(defaultValues: TProps, name?: string): Record.Factory<TProps>;
2524
-
2525
- export interface Record<TProps extends Object> {
2526
-
2527
- // Reading values
2528
-
2529
- has(key: string): key is keyof TProps;
2530
- get<K extends keyof TProps>(key: K): TProps[K];
2531
-
2532
- // Reading deep values
2533
-
2534
- hasIn(keyPath: Iterable<any>): boolean;
2535
- getIn(keyPath: Iterable<any>): any;
2536
-
2537
- // Value equality
2538
-
2539
- equals(other: any): boolean;
2540
- hashCode(): number;
2541
-
2542
- // Persistent changes
2543
-
2544
- set<K extends keyof TProps>(key: K, value: TProps[K]): this;
2545
- update<K extends keyof TProps>(key: K, updater: (value: TProps[K]) => TProps[K]): this;
2546
- merge(...collections: Array<Partial<TProps> | Iterable<[string, any]>>): this;
2547
- mergeDeep(...collections: Array<Partial<TProps> | Iterable<[string, any]>>): this;
2548
-
2549
- mergeWith(
2550
- merger: (oldVal: any, newVal: any, key: keyof TProps) => any,
2551
- ...collections: Array<Partial<TProps> | Iterable<[string, any]>>
2552
- ): this;
2553
- mergeDeepWith(
2554
- merger: (oldVal: any, newVal: any, key: any) => any,
2555
- ...collections: Array<Partial<TProps> | Iterable<[string, any]>>
2556
- ): this;
2557
-
2558
- /**
2559
- * Returns a new instance of this Record type with the value for the
2560
- * specific key set to its default value.
2561
- *
2562
- * @alias remove
2563
- */
2564
- delete<K extends keyof TProps>(key: K): this;
2565
- remove<K extends keyof TProps>(key: K): this;
2566
-
2567
- /**
2568
- * Returns a new instance of this Record type with all values set
2569
- * to their default values.
2570
- */
2571
- clear(): this;
2572
-
2573
- // Deep persistent changes
2574
-
2575
- setIn(keyPath: Iterable<any>, value: any): this;
2576
- updateIn(keyPath: Iterable<any>, updater: (value: any) => any): this;
2577
- mergeIn(keyPath: Iterable<any>, ...collections: Array<any>): this;
2578
- mergeDeepIn(keyPath: Iterable<any>, ...collections: Array<any>): this;
2579
-
2580
- /**
2581
- * @alias removeIn
2582
- */
2583
- deleteIn(keyPath: Iterable<any>): this;
2584
- removeIn(keyPath: Iterable<any>): this;
2585
-
2586
- // Conversion to JavaScript types
2587
-
2588
- /**
2589
- * Deeply converts this Record to equivalent native JavaScript Object.
2590
- */
2591
- toJS(): { [K in keyof TProps]: any };
2592
-
2593
- /**
2594
- * Shallowly converts this Record to equivalent native JavaScript Object.
2595
- */
2596
- toJSON(): TProps;
2597
-
2598
- /**
2599
- * Shallowly converts this Record to equivalent JavaScript Object.
2600
- */
2601
- toObject(): TProps;
2602
-
2603
- // Transient changes
2604
-
2605
- /**
2606
- * Note: Not all methods can be used on a mutable collection or within
2607
- * `withMutations`! Only `set` may be used mutatively.
2608
- *
2609
- * @see `Map#withMutations`
2610
- */
2611
- withMutations(mutator: (mutable: this) => any): this;
2612
-
2613
- /**
2614
- * @see `Map#asMutable`
2615
- */
2616
- asMutable(): this;
2617
-
2618
- /**
2619
- * @see `Map#wasAltered`
2620
- */
2621
- wasAltered(): boolean;
2622
-
2623
- /**
2624
- * @see `Map#asImmutable`
2625
- */
2626
- asImmutable(): this;
2627
-
2628
- // Sequence algorithms
2629
-
2630
- toSeq(): Seq.Keyed<keyof TProps, TProps[keyof TProps]>;
2631
-
2632
- [Symbol.iterator](): IterableIterator<[keyof TProps, TProps[keyof TProps]]>;
2633
- }
2634
-
2635
- /**
2636
- * Represents a sequence of values, but may not be backed by a concrete data
2637
- * structure.
2638
- *
2639
- * **Seq is immutable** — Once a Seq is created, it cannot be
2640
- * changed, appended to, rearranged or otherwise modified. Instead, any
2641
- * mutative method called on a `Seq` will return a new `Seq`.
2642
- *
2643
- * **Seq is lazy** — Seq does as little work as necessary to respond to any
2644
- * method call. Values are often created during iteration, including implicit
2645
- * iteration when reducing or converting to a concrete data structure such as
2646
- * a `List` or JavaScript `Array`.
2647
- *
2648
- * For example, the following performs no work, because the resulting
2649
- * Seq's values are never iterated:
2650
- *
2651
- * ```js
2652
- * const { Seq } = require('immutable@4.0.0-rc.6')
2653
- * const oddSquares = Seq([ 1, 2, 3, 4, 5, 6, 7, 8 ])
2654
- * .filter(x => x % 2 !== 0)
2655
- * .map(x => x * x)
2656
- * ```
2657
- *
2658
- * Once the Seq is used, it performs only the work necessary. In this
2659
- * example, no intermediate data structures are ever created, filter is only
2660
- * called three times, and map is only called once:
2661
- *
2662
- * ```
2663
- * oddSquares.get(1)); // 9
2664
- * ```
2665
- *
2666
- * Seq allows for the efficient chaining of operations,
2667
- * allowing for the expression of logic that can otherwise be very tedious:
2668
- *
2669
- * ```
2670
- * Seq({ a: 1, b: 1, c: 1})
2671
- * .flip()
2672
- * .map(key => key.toUpperCase())
2673
- * .flip()
2674
- * // Seq { A: 1, B: 1, C: 1 }
2675
- * ```
2676
- *
2677
- * As well as expressing logic that would otherwise be memory or time limited:
2678
- *
2679
- * ```js
2680
- * const { Range } = require('immutable@4.0.0-rc.6')
2681
- * Range(1, Infinity)
2682
- * .skip(1000)
2683
- * .map(n => -n)
2684
- * .filter(n => n % 2 === 0)
2685
- * .take(2)
2686
- * .reduce((r, n) => r * n, 1)
2687
- * // 1006008
2688
- * ```
2689
- *
2690
- * Seq is often used to provide a rich collection API to JavaScript Object.
2691
- *
2692
- * ```js
2693
- * Seq({ x: 0, y: 1, z: 2 }).map(v => v * 2).toObject();
2694
- * // { x: 0, y: 2, z: 4 }
2695
- * ```
2696
- */
2697
-
2698
- export module Seq {
2699
- /**
2700
- * True if `maybeSeq` is a Seq, it is not backed by a concrete
2701
- * structure such as Map, List, or Set.
2702
- */
2703
- function isSeq(maybeSeq: any): maybeSeq is Seq.Indexed<any> | Seq.Keyed<any, any>;
2704
-
2705
-
2706
- /**
2707
- * `Seq` which represents key-value pairs.
2708
- */
2709
- export module Keyed {}
2710
-
2711
- /**
2712
- * Always returns a Seq.Keyed, if input is not keyed, expects an
2713
- * collection of [K, V] tuples.
2714
- */
2715
- export function Keyed<K, V>(collection: Iterable<[K, V]>): Seq.Keyed<K, V>;
2716
- export function Keyed<V>(obj: {[key: string]: V}): Seq.Keyed<string, V>;
2717
- export function Keyed<K, V>(): Seq.Keyed<K, V>;
2718
- export function Keyed(): Seq.Keyed<any, any>;
2719
-
2720
- export interface Keyed<K, V> extends Seq<K, V>, Collection.Keyed<K, V> {
2721
- /**
2722
- * Deeply converts this Keyed Seq to equivalent native JavaScript Object.
2723
- *
2724
- * Converts keys to Strings.
2725
- */
2726
- toJS(): Object;
2727
-
2728
- /**
2729
- * Shallowly converts this Keyed Seq to equivalent native JavaScript Object.
2730
- *
2731
- * Converts keys to Strings.
2732
- */
2733
- toJSON(): { [key: string]: V };
2734
-
2735
- /**
2736
- * Shallowly converts this collection to an Array.
2737
- */
2738
- toArray(): Array<[K, V]>;
2739
-
2740
- /**
2741
- * Returns itself
2742
- */
2743
- toSeq(): this;
2744
-
2745
- /**
2746
- * Returns a new Seq with other collections concatenated to this one.
2747
- *
2748
- * All entries will be present in the resulting Seq, even if they
2749
- * have the same key.
2750
- */
2751
- concat<KC, VC>(...collections: Array<Iterable<[KC, VC]>>): Seq.Keyed<K | KC, V | VC>;
2752
- concat<C>(...collections: Array<{[key: string]: C}>): Seq.Keyed<K | string, V | C>;
2753
-
2754
- /**
2755
- * Returns a new Seq.Keyed with values passed through a
2756
- * `mapper` function.
2757
- *
2758
- * ```js
2759
- * const { Seq } = require('immutable@4.0.0-rc.6')
2760
- * Seq.Keyed({ a: 1, b: 2 }).map(x => 10 * x)
2761
- * // Seq { "a": 10, "b": 20 }
2762
- * ```
2763
- *
2764
- * Note: `map()` always returns a new instance, even if it produced the
2765
- * same value at every step.
2766
- */
2767
- map<M>(
2768
- mapper: (value: V, key: K, iter: this) => M,
2769
- context?: any
2770
- ): Seq.Keyed<K, M>;
2771
-
2772
- /**
2773
- * @see Collection.Keyed.mapKeys
2774
- */
2775
- mapKeys<M>(
2776
- mapper: (key: K, value: V, iter: this) => M,
2777
- context?: any
2778
- ): Seq.Keyed<M, V>;
2779
-
2780
- /**
2781
- * @see Collection.Keyed.mapEntries
2782
- */
2783
- mapEntries<KM, VM>(
2784
- mapper: (entry: [K, V], index: number, iter: this) => [KM, VM],
2785
- context?: any
2786
- ): Seq.Keyed<KM, VM>;
2787
-
2788
- /**
2789
- * Flat-maps the Seq, returning a Seq of the same type.
2790
- *
2791
- * Similar to `seq.map(...).flatten(true)`.
2792
- */
2793
- flatMap<KM, VM>(
2794
- mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>,
2795
- context?: any
2796
- ): Seq.Keyed<KM, VM>;
2797
-
2798
- /**
2799
- * Returns a new Seq with only the entries for which the `predicate`
2800
- * function returns true.
2801
- *
2802
- * Note: `filter()` always returns a new instance, even if it results in
2803
- * not filtering out any values.
2804
- */
2805
- filter<F extends V>(
2806
- predicate: (value: V, key: K, iter: this) => value is F,
2807
- context?: any
2808
- ): Seq.Keyed<K, F>;
2809
- filter(
2810
- predicate: (value: V, key: K, iter: this) => any,
2811
- context?: any
2812
- ): this;
2813
-
2814
- /**
2815
- * @see Collection.Keyed.flip
2816
- */
2817
- flip(): Seq.Keyed<V, K>;
2818
- }
2819
-
2820
-
2821
- /**
2822
- * `Seq` which represents an ordered indexed list of values.
2823
- */
2824
- module Indexed {
2825
-
2826
- /**
2827
- * Provides an Seq.Indexed of the values provided.
2828
- */
2829
- function of<T>(...values: Array<T>): Seq.Indexed<T>;
2830
- }
2831
-
2832
- /**
2833
- * Always returns Seq.Indexed, discarding associated keys and
2834
- * supplying incrementing indices.
2835
- */
2836
- export function Indexed(): Seq.Indexed<any>;
2837
- export function Indexed<T>(): Seq.Indexed<T>;
2838
- export function Indexed<T>(collection: Iterable<T>): Seq.Indexed<T>;
2839
-
2840
- export interface Indexed<T> extends Seq<number, T>, Collection.Indexed<T> {
2841
- /**
2842
- * Deeply converts this Indexed Seq to equivalent native JavaScript Array.
2843
- */
2844
- toJS(): Array<any>;
2845
-
2846
- /**
2847
- * Shallowly converts this Indexed Seq to equivalent native JavaScript Array.
2848
- */
2849
- toJSON(): Array<T>;
2850
-
2851
- /**
2852
- * Shallowly converts this collection to an Array.
2853
- */
2854
- toArray(): Array<T>;
2855
-
2856
- /**
2857
- * Returns itself
2858
- */
2859
- toSeq(): this
2860
-
2861
- /**
2862
- * Returns a new Seq with other collections concatenated to this one.
2863
- */
2864
- concat<C>(...valuesOrCollections: Array<Iterable<C> | C>): Seq.Indexed<T | C>;
2865
-
2866
- /**
2867
- * Returns a new Seq.Indexed with values passed through a
2868
- * `mapper` function.
2869
- *
2870
- * ```js
2871
- * const { Seq } = require('immutable@4.0.0-rc.6')
2872
- * Seq.Indexed([ 1, 2 ]).map(x => 10 * x)
2873
- * // Seq [ 10, 20 ]
2874
- * ```
2875
- *
2876
- * Note: `map()` always returns a new instance, even if it produced the
2877
- * same value at every step.
2878
- */
2879
- map<M>(
2880
- mapper: (value: T, key: number, iter: this) => M,
2881
- context?: any
2882
- ): Seq.Indexed<M>;
2883
-
2884
- /**
2885
- * Flat-maps the Seq, returning a a Seq of the same type.
2886
- *
2887
- * Similar to `seq.map(...).flatten(true)`.
2888
- */
2889
- flatMap<M>(
2890
- mapper: (value: T, key: number, iter: this) => Iterable<M>,
2891
- context?: any
2892
- ): Seq.Indexed<M>;
2893
-
2894
- /**
2895
- * Returns a new Seq with only the values for which the `predicate`
2896
- * function returns true.
2897
- *
2898
- * Note: `filter()` always returns a new instance, even if it results in
2899
- * not filtering out any values.
2900
- */
2901
- filter<F extends T>(
2902
- predicate: (value: T, index: number, iter: this) => value is F,
2903
- context?: any
2904
- ): Seq.Indexed<F>;
2905
- filter(
2906
- predicate: (value: T, index: number, iter: this) => any,
2907
- context?: any
2908
- ): this;
2909
-
2910
- /**
2911
- * Returns a Seq "zipped" with the provided collections.
2912
- *
2913
- * Like `zipWith`, but using the default `zipper`: creating an `Array`.
2914
- *
2915
- * ```js
2916
- * const a = Seq([ 1, 2, 3 ]);
2917
- * const b = Seq([ 4, 5, 6 ]);
2918
- * const c = a.zip(b); // Seq [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]
2919
- * ```
2920
- */
2921
- zip<U>(other: Collection<any, U>): Seq.Indexed<[T,U]>;
2922
- zip<U,V>(other: Collection<any, U>, other2: Collection<any, V>): Seq.Indexed<[T,U,V]>;
2923
- zip(...collections: Array<Collection<any, any>>): Seq.Indexed<any>;
2924
-
2925
- /**
2926
- * Returns a Seq "zipped" with the provided collections.
2927
- *
2928
- * Unlike `zip`, `zipAll` continues zipping until the longest collection is
2929
- * exhausted. Missing values from shorter collections are filled with `undefined`.
2930
- *
2931
- * ```js
2932
- * const a = Seq([ 1, 2 ]);
2933
- * const b = Seq([ 3, 4, 5 ]);
2934
- * const c = a.zipAll(b); // Seq [ [ 1, 3 ], [ 2, 4 ], [ undefined, 5 ] ]
2935
- * ```
2936
- */
2937
- zipAll<U>(other: Collection<any, U>): Seq.Indexed<[T,U]>;
2938
- zipAll<U,V>(other: Collection<any, U>, other2: Collection<any, V>): Seq.Indexed<[T,U,V]>;
2939
- zipAll(...collections: Array<Collection<any, any>>): Seq.Indexed<any>;
2940
-
2941
- /**
2942
- * Returns a Seq "zipped" with the provided collections by using a
2943
- * custom `zipper` function.
2944
- *
2945
- * ```js
2946
- * const a = Seq([ 1, 2, 3 ]);
2947
- * const b = Seq([ 4, 5, 6 ]);
2948
- * const c = a.zipWith((a, b) => a + b, b);
2949
- * // Seq [ 5, 7, 9 ]
2950
- * ```
2951
- */
2952
- zipWith<U, Z>(
2953
- zipper: (value: T, otherValue: U) => Z,
2954
- otherCollection: Collection<any, U>
2955
- ): Seq.Indexed<Z>;
2956
- zipWith<U, V, Z>(
2957
- zipper: (value: T, otherValue: U, thirdValue: V) => Z,
2958
- otherCollection: Collection<any, U>,
2959
- thirdCollection: Collection<any, V>
2960
- ): Seq.Indexed<Z>;
2961
- zipWith<Z>(
2962
- zipper: (...any: Array<any>) => Z,
2963
- ...collections: Array<Collection<any, any>>
2964
- ): Seq.Indexed<Z>;
2965
- }
2966
-
2967
-
2968
- /**
2969
- * `Seq` which represents a set of values.
2970
- *
2971
- * Because `Seq` are often lazy, `Seq.Set` does not provide the same guarantee
2972
- * of value uniqueness as the concrete `Set`.
2973
- */
2974
- export module Set {
2975
-
2976
- /**
2977
- * Returns a Seq.Set of the provided values
2978
- */
2979
- function of<T>(...values: Array<T>): Seq.Set<T>;
2980
- }
2981
-
2982
- /**
2983
- * Always returns a Seq.Set, discarding associated indices or keys.
2984
- */
2985
- export function Set(): Seq.Set<any>;
2986
- export function Set<T>(): Seq.Set<T>;
2987
- export function Set<T>(collection: Iterable<T>): Seq.Set<T>;
2988
-
2989
- export interface Set<T> extends Seq<T, T>, Collection.Set<T> {
2990
- /**
2991
- * Deeply converts this Set Seq to equivalent native JavaScript Array.
2992
- */
2993
- toJS(): Array<any>;
2994
-
2995
- /**
2996
- * Shallowly converts this Set Seq to equivalent native JavaScript Array.
2997
- */
2998
- toJSON(): Array<T>;
2999
-
3000
- /**
3001
- * Shallowly converts this collection to an Array.
3002
- */
3003
- toArray(): Array<T>;
3004
-
3005
- /**
3006
- * Returns itself
3007
- */
3008
- toSeq(): this
3009
-
3010
- /**
3011
- * Returns a new Seq with other collections concatenated to this one.
3012
- *
3013
- * All entries will be present in the resulting Seq, even if they
3014
- * are duplicates.
3015
- */
3016
- concat<C>(...valuesOrCollections: Array<Iterable<C> | C>): Seq.Set<T | C>;
3017
-
3018
- /**
3019
- * Returns a new Seq.Set with values passed through a
3020
- * `mapper` function.
3021
- *
3022
- * ```js
3023
- * Seq.Set([ 1, 2 ]).map(x => 10 * x)
3024
- * // Seq { 10, 20 }
3025
- * ```
3026
- *
3027
- * Note: `map()` always returns a new instance, even if it produced the
3028
- * same value at every step.
3029
- */
3030
- map<M>(
3031
- mapper: (value: T, key: T, iter: this) => M,
3032
- context?: any
3033
- ): Seq.Set<M>;
3034
-
3035
- /**
3036
- * Flat-maps the Seq, returning a Seq of the same type.
3037
- *
3038
- * Similar to `seq.map(...).flatten(true)`.
3039
- */
3040
- flatMap<M>(
3041
- mapper: (value: T, key: T, iter: this) => Iterable<M>,
3042
- context?: any
3043
- ): Seq.Set<M>;
3044
-
3045
- /**
3046
- * Returns a new Seq with only the values for which the `predicate`
3047
- * function returns true.
3048
- *
3049
- * Note: `filter()` always returns a new instance, even if it results in
3050
- * not filtering out any values.
3051
- */
3052
- filter<F extends T>(
3053
- predicate: (value: T, key: T, iter: this) => value is F,
3054
- context?: any
3055
- ): Seq.Set<F>;
3056
- filter(
3057
- predicate: (value: T, key: T, iter: this) => any,
3058
- context?: any
3059
- ): this;
3060
- }
3061
-
3062
- }
3063
-
3064
- /**
3065
- * Creates a Seq.
3066
- *
3067
- * Returns a particular kind of `Seq` based on the input.
3068
- *
3069
- * * If a `Seq`, that same `Seq`.
3070
- * * If an `Collection`, a `Seq` of the same kind (Keyed, Indexed, or Set).
3071
- * * If an Array-like, an `Seq.Indexed`.
3072
- * * If an Object with an Iterator, an `Seq.Indexed`.
3073
- * * If an Iterator, an `Seq.Indexed`.
3074
- * * If an Object, a `Seq.Keyed`.
3075
- *
3076
- */
3077
- export function Seq<S extends Seq<any, any>>(seq: S): S;
3078
- export function Seq<K, V>(collection: Collection.Keyed<K, V>): Seq.Keyed<K, V>;
3079
- export function Seq<T>(collection: Collection.Indexed<T>): Seq.Indexed<T>;
3080
- export function Seq<T>(collection: Collection.Set<T>): Seq.Set<T>;
3081
- export function Seq<T>(collection: Iterable<T>): Seq.Indexed<T>;
3082
- export function Seq<V>(obj: {[key: string]: V}): Seq.Keyed<string, V>;
3083
- export function Seq(): Seq<any, any>;
3084
-
3085
- export interface Seq<K, V> extends Collection<K, V> {
3086
-
3087
- /**
3088
- * Some Seqs can describe their size lazily. When this is the case,
3089
- * size will be an integer. Otherwise it will be undefined.
3090
- *
3091
- * For example, Seqs returned from `map()` or `reverse()`
3092
- * preserve the size of the original `Seq` while `filter()` does not.
3093
- *
3094
- * Note: `Range`, `Repeat` and `Seq`s made from `Array`s and `Object`s will
3095
- * always have a size.
3096
- */
3097
- readonly size: number | undefined;
3098
-
3099
-
3100
- // Force evaluation
3101
-
3102
- /**
3103
- * Because Sequences are lazy and designed to be chained together, they do
3104
- * not cache their results. For example, this map function is called a total
3105
- * of 6 times, as each `join` iterates the Seq of three values.
3106
- *
3107
- * var squares = Seq([ 1, 2, 3 ]).map(x => x * x)
3108
- * squares.join() + squares.join()
3109
- *
3110
- * If you know a `Seq` will be used multiple times, it may be more
3111
- * efficient to first cache it in memory. Here, the map function is called
3112
- * only 3 times.
3113
- *
3114
- * var squares = Seq([ 1, 2, 3 ]).map(x => x * x).cacheResult()
3115
- * squares.join() + squares.join()
3116
- *
3117
- * Use this method judiciously, as it must fully evaluate a Seq which can be
3118
- * a burden on memory and possibly performance.
3119
- *
3120
- * Note: after calling `cacheResult`, a Seq will always have a `size`.
3121
- */
3122
- cacheResult(): this;
3123
-
3124
- // Sequence algorithms
3125
-
3126
- /**
3127
- * Returns a new Seq with values passed through a
3128
- * `mapper` function.
3129
- *
3130
- * ```js
3131
- * const { Seq } = require('immutable@4.0.0-rc.6')
3132
- * Seq([ 1, 2 ]).map(x => 10 * x)
3133
- * // Seq [ 10, 20 ]
3134
- * ```
3135
- *
3136
- * Note: `map()` always returns a new instance, even if it produced the same
3137
- * value at every step.
3138
- */
3139
- map<M>(
3140
- mapper: (value: V, key: K, iter: this) => M,
3141
- context?: any
3142
- ): Seq<K, M>;
3143
-
3144
- /**
3145
- * Returns a new Seq with values passed through a
3146
- * `mapper` function.
3147
- *
3148
- * ```js
3149
- * const { Seq } = require('immutable@4.0.0-rc.6')
3150
- * Seq([ 1, 2 ]).map(x => 10 * x)
3151
- * // Seq [ 10, 20 ]
3152
- * ```
3153
- *
3154
- * Note: `map()` always returns a new instance, even if it produced the same
3155
- * value at every step.
3156
- * Note: used only for sets.
3157
- */
3158
- map<M>(
3159
- mapper: (value: V, key: K, iter: this) => M,
3160
- context?: any
3161
- ): Seq<M, M>;
3162
-
3163
- /**
3164
- * Flat-maps the Seq, returning a Seq of the same type.
3165
- *
3166
- * Similar to `seq.map(...).flatten(true)`.
3167
- */
3168
- flatMap<M>(
3169
- mapper: (value: V, key: K, iter: this) => Iterable<M>,
3170
- context?: any
3171
- ): Seq<K, M>;
3172
-
3173
- /**
3174
- * Flat-maps the Seq, returning a Seq of the same type.
3175
- *
3176
- * Similar to `seq.map(...).flatten(true)`.
3177
- * Note: Used only for sets.
3178
- */
3179
- flatMap<M>(
3180
- mapper: (value: V, key: K, iter: this) => Iterable<M>,
3181
- context?: any
3182
- ): Seq<M, M>;
3183
-
3184
- /**
3185
- * Returns a new Seq with only the values for which the `predicate`
3186
- * function returns true.
3187
- *
3188
- * Note: `filter()` always returns a new instance, even if it results in
3189
- * not filtering out any values.
3190
- */
3191
- filter<F extends V>(
3192
- predicate: (value: V, key: K, iter: this) => value is F,
3193
- context?: any
3194
- ): Seq<K, F>;
3195
- filter(
3196
- predicate: (value: V, key: K, iter: this) => any,
3197
- context?: any
3198
- ): this;
3199
- }
3200
-
3201
- /**
3202
- * The `Collection` is a set of (key, value) entries which can be iterated, and
3203
- * is the base class for all collections in `immutable`, allowing them to
3204
- * make use of all the Collection methods (such as `map` and `filter`).
3205
- *
3206
- * Note: A collection is always iterated in the same order, however that order
3207
- * may not always be well defined, as is the case for the `Map` and `Set`.
3208
- *
3209
- * Collection is the abstract base class for concrete data structures. It
3210
- * cannot be constructed directly.
3211
- *
3212
- * Implementations should extend one of the subclasses, `Collection.Keyed`,
3213
- * `Collection.Indexed`, or `Collection.Set`.
3214
- */
3215
- export module Collection {
3216
-
3217
- /**
3218
- * @deprecated use `const { isKeyed } = require('immutable@4.0.0-rc.6')`
3219
- */
3220
- function isKeyed(maybeKeyed: any): maybeKeyed is Collection.Keyed<any, any>;
3221
-
3222
- /**
3223
- * @deprecated use `const { isIndexed } = require('immutable@4.0.0-rc.6')`
3224
- */
3225
- function isIndexed(maybeIndexed: any): maybeIndexed is Collection.Indexed<any>;
3226
-
3227
- /**
3228
- * @deprecated use `const { isAssociative } = require('immutable@4.0.0-rc.6')`
3229
- */
3230
- function isAssociative(maybeAssociative: any): maybeAssociative is Collection.Keyed<any, any> | Collection.Indexed<any>;
3231
-
3232
- /**
3233
- * @deprecated use `const { isOrdered } = require('immutable@4.0.0-rc.6')`
3234
- */
3235
- function isOrdered(maybeOrdered: any): boolean;
3236
-
3237
-
3238
- /**
3239
- * Keyed Collections have discrete keys tied to each value.
3240
- *
3241
- * When iterating `Collection.Keyed`, each iteration will yield a `[K, V]`
3242
- * tuple, in other words, `Collection#entries` is the default iterator for
3243
- * Keyed Collections.
3244
- */
3245
- export module Keyed {}
3246
-
3247
- /**
3248
- * Creates a Collection.Keyed
3249
- *
3250
- * Similar to `Collection()`, however it expects collection-likes of [K, V]
3251
- * tuples if not constructed from a Collection.Keyed or JS Object.
3252
- */
3253
- export function Keyed<K, V>(collection: Iterable<[K, V]>): Collection.Keyed<K, V>;
3254
- export function Keyed<V>(obj: {[key: string]: V}): Collection.Keyed<string, V>;
3255
-
3256
- export interface Keyed<K, V> extends Collection<K, V> {
3257
- /**
3258
- * Deeply converts this Keyed collection to equivalent native JavaScript Object.
3259
- *
3260
- * Converts keys to Strings.
3261
- */
3262
- toJS(): Object;
3263
-
3264
- /**
3265
- * Shallowly converts this Keyed collection to equivalent native JavaScript Object.
3266
- *
3267
- * Converts keys to Strings.
3268
- */
3269
- toJSON(): { [key: string]: V };
3270
-
3271
- /**
3272
- * Shallowly converts this collection to an Array.
3273
- */
3274
- toArray(): Array<[K, V]>;
3275
-
3276
- /**
3277
- * Returns Seq.Keyed.
3278
- * @override
3279
- */
3280
- toSeq(): Seq.Keyed<K, V>;
3281
-
3282
-
3283
- // Sequence functions
3284
-
3285
- /**
3286
- * Returns a new Collection.Keyed of the same type where the keys and values
3287
- * have been flipped.
3288
- *
3289
- * <!-- runkit:activate -->
3290
- * ```js
3291
- * const { Map } = require('immutable@4.0.0-rc.6')
3292
- * Map({ a: 'z', b: 'y' }).flip()
3293
- * // Map { "z": "a", "y": "b" }
3294
- * ```
3295
- */
3296
- flip(): Collection.Keyed<V, K>;
3297
-
3298
- /**
3299
- * Returns a new Collection with other collections concatenated to this one.
3300
- */
3301
- concat<KC, VC>(...collections: Array<Iterable<[KC, VC]>>): Collection.Keyed<K | KC, V | VC>;
3302
- concat<C>(...collections: Array<{[key: string]: C}>): Collection.Keyed<K | string, V | C>;
3303
-
3304
- /**
3305
- * Returns a new Collection.Keyed with values passed through a
3306
- * `mapper` function.
3307
- *
3308
- * ```js
3309
- * const { Collection } = require('immutable@4.0.0-rc.6')
3310
- * Collection.Keyed({ a: 1, b: 2 }).map(x => 10 * x)
3311
- * // Seq { "a": 10, "b": 20 }
3312
- * ```
3313
- *
3314
- * Note: `map()` always returns a new instance, even if it produced the
3315
- * same value at every step.
3316
- */
3317
- map<M>(
3318
- mapper: (value: V, key: K, iter: this) => M,
3319
- context?: any
3320
- ): Collection.Keyed<K, M>;
3321
-
3322
- /**
3323
- * Returns a new Collection.Keyed of the same type with keys passed through
3324
- * a `mapper` function.
3325
- *
3326
- * <!-- runkit:activate -->
3327
- * ```js
3328
- * const { Map } = require('immutable@4.0.0-rc.6')
3329
- * Map({ a: 1, b: 2 }).mapKeys(x => x.toUpperCase())
3330
- * // Map { "A": 1, "B": 2 }
3331
- * ```
3332
- *
3333
- * Note: `mapKeys()` always returns a new instance, even if it produced
3334
- * the same key at every step.
3335
- */
3336
- mapKeys<M>(
3337
- mapper: (key: K, value: V, iter: this) => M,
3338
- context?: any
3339
- ): Collection.Keyed<M, V>;
3340
-
3341
- /**
3342
- * Returns a new Collection.Keyed of the same type with entries
3343
- * ([key, value] tuples) passed through a `mapper` function.
3344
- *
3345
- * <!-- runkit:activate -->
3346
- * ```js
3347
- * const { Map } = require('immutable@4.0.0-rc.6')
3348
- * Map({ a: 1, b: 2 })
3349
- * .mapEntries(([ k, v ]) => [ k.toUpperCase(), v * 2 ])
3350
- * // Map { "A": 2, "B": 4 }
3351
- * ```
3352
- *
3353
- * Note: `mapEntries()` always returns a new instance, even if it produced
3354
- * the same entry at every step.
3355
- */
3356
- mapEntries<KM, VM>(
3357
- mapper: (entry: [K, V], index: number, iter: this) => [KM, VM],
3358
- context?: any
3359
- ): Collection.Keyed<KM, VM>;
3360
-
3361
- /**
3362
- * Flat-maps the Collection, returning a Collection of the same type.
3363
- *
3364
- * Similar to `collection.map(...).flatten(true)`.
3365
- */
3366
- flatMap<KM, VM>(
3367
- mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>,
3368
- context?: any
3369
- ): Collection.Keyed<KM, VM>;
3370
-
3371
- /**
3372
- * Returns a new Collection with only the values for which the `predicate`
3373
- * function returns true.
3374
- *
3375
- * Note: `filter()` always returns a new instance, even if it results in
3376
- * not filtering out any values.
3377
- */
3378
- filter<F extends V>(
3379
- predicate: (value: V, key: K, iter: this) => value is F,
3380
- context?: any
3381
- ): Collection.Keyed<K, F>;
3382
- filter(
3383
- predicate: (value: V, key: K, iter: this) => any,
3384
- context?: any
3385
- ): this;
3386
-
3387
- [Symbol.iterator](): IterableIterator<[K, V]>;
3388
- }
3389
-
3390
-
3391
- /**
3392
- * Indexed Collections have incrementing numeric keys. They exhibit
3393
- * slightly different behavior than `Collection.Keyed` for some methods in order
3394
- * to better mirror the behavior of JavaScript's `Array`, and add methods
3395
- * which do not make sense on non-indexed Collections such as `indexOf`.
3396
- *
3397
- * Unlike JavaScript arrays, `Collection.Indexed`s are always dense. "Unset"
3398
- * indices and `undefined` indices are indistinguishable, and all indices from
3399
- * 0 to `size` are visited when iterated.
3400
- *
3401
- * All Collection.Indexed methods return re-indexed Collections. In other words,
3402
- * indices always start at 0 and increment until size. If you wish to
3403
- * preserve indices, using them as keys, convert to a Collection.Keyed by
3404
- * calling `toKeyedSeq`.
3405
- */
3406
- export module Indexed {}
3407
-
3408
- /**
3409
- * Creates a new Collection.Indexed.
3410
- */
3411
- export function Indexed<T>(collection: Iterable<T>): Collection.Indexed<T>;
3412
-
3413
- export interface Indexed<T> extends Collection<number, T> {
3414
- /**
3415
- * Deeply converts this Indexed collection to equivalent native JavaScript Array.
3416
- */
3417
- toJS(): Array<any>;
3418
-
3419
- /**
3420
- * Shallowly converts this Indexed collection to equivalent native JavaScript Array.
3421
- */
3422
- toJSON(): Array<T>;
3423
-
3424
- /**
3425
- * Shallowly converts this collection to an Array.
3426
- */
3427
- toArray(): Array<T>;
3428
-
3429
- // Reading values
3430
-
3431
- /**
3432
- * Returns the value associated with the provided index, or notSetValue if
3433
- * the index is beyond the bounds of the Collection.
3434
- *
3435
- * `index` may be a negative number, which indexes back from the end of the
3436
- * Collection. `s.get(-1)` gets the last item in the Collection.
3437
- */
3438
- get<NSV>(index: number, notSetValue: NSV): T | NSV;
3439
- get(index: number): T | undefined;
3440
-
3441
-
3442
- // Conversion to Seq
3443
-
3444
- /**
3445
- * Returns Seq.Indexed.
3446
- * @override
3447
- */
3448
- toSeq(): Seq.Indexed<T>;
3449
-
3450
- /**
3451
- * If this is a collection of [key, value] entry tuples, it will return a
3452
- * Seq.Keyed of those entries.
3453
- */
3454
- fromEntrySeq(): Seq.Keyed<any, any>;
3455
-
3456
-
3457
- // Combination
3458
-
3459
- /**
3460
- * Returns a Collection of the same type with `separator` between each item
3461
- * in this Collection.
3462
- */
3463
- interpose(separator: T): this;
3464
-
3465
- /**
3466
- * Returns a Collection of the same type with the provided `collections`
3467
- * interleaved into this collection.
3468
- *
3469
- * The resulting Collection includes the first item from each, then the
3470
- * second from each, etc.
3471
- *
3472
- * <!-- runkit:activate
3473
- * { "preamble": "require('immutable@4.0.0-rc.6')"}
3474
- * -->
3475
- * ```js
3476
- * const { List } = require('immutable@4.0.0-rc.6')
3477
- * List([ 1, 2, 3 ]).interleave(List([ 'A', 'B', 'C' ]))
3478
- * // List [ 1, "A", 2, "B", 3, "C"" ]
3479
- * ```
3480
- *
3481
- * The shortest Collection stops interleave.
3482
- *
3483
- * <!-- runkit:activate
3484
- * { "preamble": "const { List } = require('immutable@4.0.0-rc.6')" }
3485
- * -->
3486
- * ```js
3487
- * List([ 1, 2, 3 ]).interleave(
3488
- * List([ 'A', 'B' ]),
3489
- * List([ 'X', 'Y', 'Z' ])
3490
- * )
3491
- * // List [ 1, "A", "X", 2, "B", "Y"" ]
3492
- * ```
3493
- */
3494
- interleave(...collections: Array<Collection<any, T>>): this;
3495
-
3496
- /**
3497
- * Splice returns a new indexed Collection by replacing a region of this
3498
- * Collection with new values. If values are not provided, it only skips the
3499
- * region to be removed.
3500
- *
3501
- * `index` may be a negative number, which indexes back from the end of the
3502
- * Collection. `s.splice(-2)` splices after the second to last item.
3503
- *
3504
- * <!-- runkit:activate -->
3505
- * ```js
3506
- * const { List } = require('immutable@4.0.0-rc.6')
3507
- * List([ 'a', 'b', 'c', 'd' ]).splice(1, 2, 'q', 'r', 's')
3508
- * // List [ "a", "q", "r", "s", "d" ]
3509
- * ```
3510
- */
3511
- splice(
3512
- index: number,
3513
- removeNum: number,
3514
- ...values: Array<T>
3515
- ): this;
3516
-
3517
- /**
3518
- * Returns a Collection of the same type "zipped" with the provided
3519
- * collections.
3520
- *
3521
- * Like `zipWith`, but using the default `zipper`: creating an `Array`.
3522
- *
3523
- *
3524
- * <!-- runkit:activate
3525
- * { "preamble": "const { List } = require('immutable@4.0.0-rc.6')" }
3526
- * -->
3527
- * ```js
3528
- * const a = List([ 1, 2, 3 ]);
3529
- * const b = List([ 4, 5, 6 ]);
3530
- * const c = a.zip(b); // List [ [ 1, 4 ], [ 2, 5 ], [ 3, 6 ] ]
3531
- * ```
3532
- */
3533
- zip<U>(other: Collection<any, U>): Collection.Indexed<[T,U]>;
3534
- zip<U,V>(other: Collection<any, U>, other2: Collection<any, V>): Collection.Indexed<[T,U,V]>;
3535
- zip(...collections: Array<Collection<any, any>>): Collection.Indexed<any>;
3536
-
3537
- /**
3538
- * Returns a Collection "zipped" with the provided collections.
3539
- *
3540
- * Unlike `zip`, `zipAll` continues zipping until the longest collection is
3541
- * exhausted. Missing values from shorter collections are filled with `undefined`.
3542
- *
3543
- * ```js
3544
- * const a = List([ 1, 2 ]);
3545
- * const b = List([ 3, 4, 5 ]);
3546
- * const c = a.zipAll(b); // List [ [ 1, 3 ], [ 2, 4 ], [ undefined, 5 ] ]
3547
- * ```
3548
- */
3549
- zipAll<U>(other: Collection<any, U>): Collection.Indexed<[T,U]>;
3550
- zipAll<U,V>(other: Collection<any, U>, other2: Collection<any, V>): Collection.Indexed<[T,U,V]>;
3551
- zipAll(...collections: Array<Collection<any, any>>): Collection.Indexed<any>;
3552
-
3553
- /**
3554
- * Returns a Collection of the same type "zipped" with the provided
3555
- * collections by using a custom `zipper` function.
3556
- *
3557
- * <!-- runkit:activate
3558
- * { "preamble": "const { List } = require('immutable@4.0.0-rc.6')" }
3559
- * -->
3560
- * ```js
3561
- * const a = List([ 1, 2, 3 ]);
3562
- * const b = List([ 4, 5, 6 ]);
3563
- * const c = a.zipWith((a, b) => a + b, b);
3564
- * // List [ 5, 7, 9 ]
3565
- * ```
3566
- */
3567
- zipWith<U, Z>(
3568
- zipper: (value: T, otherValue: U) => Z,
3569
- otherCollection: Collection<any, U>
3570
- ): Collection.Indexed<Z>;
3571
- zipWith<U, V, Z>(
3572
- zipper: (value: T, otherValue: U, thirdValue: V) => Z,
3573
- otherCollection: Collection<any, U>,
3574
- thirdCollection: Collection<any, V>
3575
- ): Collection.Indexed<Z>;
3576
- zipWith<Z>(
3577
- zipper: (...any: Array<any>) => Z,
3578
- ...collections: Array<Collection<any, any>>
3579
- ): Collection.Indexed<Z>;
3580
-
3581
-
3582
- // Search for value
3583
-
3584
- /**
3585
- * Returns the first index at which a given value can be found in the
3586
- * Collection, or -1 if it is not present.
3587
- */
3588
- indexOf(searchValue: T): number;
3589
-
3590
- /**
3591
- * Returns the last index at which a given value can be found in the
3592
- * Collection, or -1 if it is not present.
3593
- */
3594
- lastIndexOf(searchValue: T): number;
3595
-
3596
- /**
3597
- * Returns the first index in the Collection where a value satisfies the
3598
- * provided predicate function. Otherwise -1 is returned.
3599
- */
3600
- findIndex(
3601
- predicate: (value: T, index: number, iter: this) => boolean,
3602
- context?: any
3603
- ): number;
3604
-
3605
- /**
3606
- * Returns the last index in the Collection where a value satisfies the
3607
- * provided predicate function. Otherwise -1 is returned.
3608
- */
3609
- findLastIndex(
3610
- predicate: (value: T, index: number, iter: this) => boolean,
3611
- context?: any
3612
- ): number;
3613
-
3614
- // Sequence algorithms
3615
-
3616
- /**
3617
- * Returns a new Collection with other collections concatenated to this one.
3618
- */
3619
- concat<C>(...valuesOrCollections: Array<Iterable<C> | C>): Collection.Indexed<T | C>;
3620
-
3621
- /**
3622
- * Returns a new Collection.Indexed with values passed through a
3623
- * `mapper` function.
3624
- *
3625
- * ```js
3626
- * const { Collection } = require('immutable@4.0.0-rc.6')
3627
- * Collection.Indexed([1,2]).map(x => 10 * x)
3628
- * // Seq [ 1, 2 ]
3629
- * ```
3630
- *
3631
- * Note: `map()` always returns a new instance, even if it produced the
3632
- * same value at every step.
3633
- */
3634
- map<M>(
3635
- mapper: (value: T, key: number, iter: this) => M,
3636
- context?: any
3637
- ): Collection.Indexed<M>;
3638
-
3639
- /**
3640
- * Flat-maps the Collection, returning a Collection of the same type.
3641
- *
3642
- * Similar to `collection.map(...).flatten(true)`.
3643
- */
3644
- flatMap<M>(
3645
- mapper: (value: T, key: number, iter: this) => Iterable<M>,
3646
- context?: any
3647
- ): Collection.Indexed<M>;
3648
-
3649
- /**
3650
- * Returns a new Collection with only the values for which the `predicate`
3651
- * function returns true.
3652
- *
3653
- * Note: `filter()` always returns a new instance, even if it results in
3654
- * not filtering out any values.
3655
- */
3656
- filter<F extends T>(
3657
- predicate: (value: T, index: number, iter: this) => value is F,
3658
- context?: any
3659
- ): Collection.Indexed<F>;
3660
- filter(
3661
- predicate: (value: T, index: number, iter: this) => any,
3662
- context?: any
3663
- ): this;
3664
-
3665
- [Symbol.iterator](): IterableIterator<T>;
3666
- }
3667
-
3668
-
3669
- /**
3670
- * Set Collections only represent values. They have no associated keys or
3671
- * indices. Duplicate values are possible in the lazy `Seq.Set`s, however
3672
- * the concrete `Set` Collection does not allow duplicate values.
3673
- *
3674
- * Collection methods on Collection.Set such as `map` and `forEach` will provide
3675
- * the value as both the first and second arguments to the provided function.
3676
- *
3677
- * ```js
3678
- * const { Collection } = require('immutable@4.0.0-rc.6')
3679
- * const seq = Collection.Set([ 'A', 'B', 'C' ])
3680
- * // Seq { "A", "B", "C" }
3681
- * seq.forEach((v, k) =>
3682
- * assert.equal(v, k)
3683
- * )
3684
- * ```
3685
- */
3686
- export module Set {}
3687
-
3688
- /**
3689
- * Similar to `Collection()`, but always returns a Collection.Set.
3690
- */
3691
- export function Set<T>(collection: Iterable<T>): Collection.Set<T>;
3692
-
3693
- export interface Set<T> extends Collection<T, T> {
3694
- /**
3695
- * Deeply converts this Set collection to equivalent native JavaScript Array.
3696
- */
3697
- toJS(): Array<any>;
3698
-
3699
- /**
3700
- * Shallowly converts this Set collection to equivalent native JavaScript Array.
3701
- */
3702
- toJSON(): Array<T>;
3703
-
3704
- /**
3705
- * Shallowly converts this collection to an Array.
3706
- */
3707
- toArray(): Array<T>;
3708
-
3709
- /**
3710
- * Returns Seq.Set.
3711
- * @override
3712
- */
3713
- toSeq(): Seq.Set<T>;
3714
-
3715
- // Sequence algorithms
3716
-
3717
- /**
3718
- * Returns a new Collection with other collections concatenated to this one.
3719
- */
3720
- concat<C>(...valuesOrCollections: Array<Iterable<C> | C>): Collection.Set<T | C>;
3721
-
3722
- /**
3723
- * Returns a new Collection.Set with values passed through a
3724
- * `mapper` function.
3725
- *
3726
- * ```
3727
- * Collection.Set([ 1, 2 ]).map(x => 10 * x)
3728
- * // Seq { 1, 2 }
3729
- * ```
3730
- *
3731
- * Note: `map()` always returns a new instance, even if it produced the
3732
- * same value at every step.
3733
- */
3734
- map<M>(
3735
- mapper: (value: T, key: T, iter: this) => M,
3736
- context?: any
3737
- ): Collection.Set<M>;
3738
-
3739
- /**
3740
- * Flat-maps the Collection, returning a Collection of the same type.
3741
- *
3742
- * Similar to `collection.map(...).flatten(true)`.
3743
- */
3744
- flatMap<M>(
3745
- mapper: (value: T, key: T, iter: this) => Iterable<M>,
3746
- context?: any
3747
- ): Collection.Set<M>;
3748
-
3749
- /**
3750
- * Returns a new Collection with only the values for which the `predicate`
3751
- * function returns true.
3752
- *
3753
- * Note: `filter()` always returns a new instance, even if it results in
3754
- * not filtering out any values.
3755
- */
3756
- filter<F extends T>(
3757
- predicate: (value: T, key: T, iter: this) => value is F,
3758
- context?: any
3759
- ): Collection.Set<F>;
3760
- filter(
3761
- predicate: (value: T, key: T, iter: this) => any,
3762
- context?: any
3763
- ): this;
3764
-
3765
- [Symbol.iterator](): IterableIterator<T>;
3766
- }
3767
-
3768
- }
3769
-
3770
- /**
3771
- * Creates a Collection.
3772
- *
3773
- * The type of Collection created is based on the input.
3774
- *
3775
- * * If an `Collection`, that same `Collection`.
3776
- * * If an Array-like, an `Collection.Indexed`.
3777
- * * If an Object with an Iterator, an `Collection.Indexed`.
3778
- * * If an Iterator, an `Collection.Indexed`.
3779
- * * If an Object, an `Collection.Keyed`.
3780
- *
3781
- * This methods forces the conversion of Objects and Strings to Collections.
3782
- * If you want to ensure that a Collection of one item is returned, use
3783
- * `Seq.of`.
3784
- */
3785
- export function Collection<I extends Collection<any, any>>(collection: I): I;
3786
- export function Collection<T>(collection: Iterable<T>): Collection.Indexed<T>;
3787
- export function Collection<V>(obj: {[key: string]: V}): Collection.Keyed<string, V>;
3788
-
3789
- export interface Collection<K, V> extends ValueObject {
3790
-
3791
- // Value equality
3792
-
3793
- /**
3794
- * True if this and the other Collection have value equality, as defined
3795
- * by `Immutable.is()`.
3796
- *
3797
- * Note: This is equivalent to `Immutable.is(this, other)`, but provided to
3798
- * allow for chained expressions.
3799
- */
3800
- equals(other: any): boolean;
3801
-
3802
- /**
3803
- * Computes and returns the hashed identity for this Collection.
3804
- *
3805
- * The `hashCode` of a Collection is used to determine potential equality,
3806
- * and is used when adding this to a `Set` or as a key in a `Map`, enabling
3807
- * lookup via a different instance.
3808
- *
3809
- * <!-- runkit:activate
3810
- * { "preamble": "const { Set, List } = require('immutable@4.0.0-rc.6')" }
3811
- * -->
3812
- * ```js
3813
- * const a = List([ 1, 2, 3 ]);
3814
- * const b = List([ 1, 2, 3 ]);
3815
- * assert.notStrictEqual(a, b); // different instances
3816
- * const set = Set([ a ]);
3817
- * assert.equal(set.has(b), true);
3818
- * ```
3819
- *
3820
- * If two values have the same `hashCode`, they are [not guaranteed
3821
- * to be equal][Hash Collision]. If two values have different `hashCode`s,
3822
- * they must not be equal.
3823
- *
3824
- * [Hash Collision]: http://en.wikipedia.org/wiki/Collision_(computer_science)
3825
- */
3826
- hashCode(): number;
3827
-
3828
-
3829
- // Reading values
3830
-
3831
- /**
3832
- * Returns the value associated with the provided key, or notSetValue if
3833
- * the Collection does not contain this key.
3834
- *
3835
- * Note: it is possible a key may be associated with an `undefined` value,
3836
- * so if `notSetValue` is not provided and this method returns `undefined`,
3837
- * that does not guarantee the key was not found.
3838
- */
3839
- get<NSV>(key: K, notSetValue: NSV): V | NSV;
3840
- get(key: K): V | undefined;
3841
-
3842
- /**
3843
- * True if a key exists within this `Collection`, using `Immutable.is`
3844
- * to determine equality
3845
- */
3846
- has(key: K): boolean;
3847
-
3848
- /**
3849
- * True if a value exists within this `Collection`, using `Immutable.is`
3850
- * to determine equality
3851
- * @alias contains
3852
- */
3853
- includes(value: V): boolean;
3854
- contains(value: V): boolean;
3855
-
3856
- /**
3857
- * The first value in the Collection.
3858
- */
3859
- first(): V | undefined;
3860
-
3861
- /**
3862
- * The last value in the Collection.
3863
- */
3864
- last(): V | undefined;
3865
-
3866
-
3867
- // Reading deep values
3868
-
3869
- /**
3870
- * Returns the value found by following a path of keys or indices through
3871
- * nested Collections.
3872
- */
3873
- getIn(searchKeyPath: Iterable<any>, notSetValue?: any): any;
3874
-
3875
- /**
3876
- * True if the result of following a path of keys or indices through nested
3877
- * Collections results in a set value.
3878
- */
3879
- hasIn(searchKeyPath: Iterable<any>): boolean;
3880
-
3881
- // Persistent changes
3882
-
3883
- /**
3884
- * This can be very useful as a way to "chain" a normal function into a
3885
- * sequence of methods. RxJS calls this "let" and lodash calls it "thru".
3886
- *
3887
- * For example, to sum a Seq after mapping and filtering:
3888
- *
3889
- * <!-- runkit:activate -->
3890
- * ```js
3891
- * const { Seq } = require('immutable@4.0.0-rc.6')
3892
- *
3893
- * function sum(collection) {
3894
- * return collection.reduce((sum, x) => sum + x, 0)
3895
- * }
3896
- *
3897
- * Seq([ 1, 2, 3 ])
3898
- * .map(x => x + 1)
3899
- * .filter(x => x % 2 === 0)
3900
- * .update(sum)
3901
- * // 6
3902
- * ```
3903
- */
3904
- update<R>(updater: (value: this) => R): R;
3905
-
3906
-
3907
- // Conversion to JavaScript types
3908
-
3909
- /**
3910
- * Deeply converts this Collection to equivalent native JavaScript Array or Object.
3911
- *
3912
- * `Collection.Indexed`, and `Collection.Set` become `Array`, while
3913
- * `Collection.Keyed` become `Object`, converting keys to Strings.
3914
- */
3915
- toJS(): Array<any> | { [key: string]: any };
3916
-
3917
- /**
3918
- * Shallowly converts this Collection to equivalent native JavaScript Array or Object.
3919
- *
3920
- * `Collection.Indexed`, and `Collection.Set` become `Array`, while
3921
- * `Collection.Keyed` become `Object`, converting keys to Strings.
3922
- */
3923
- toJSON(): Array<V> | { [key: string]: V };
3924
-
3925
- /**
3926
- * Shallowly converts this collection to an Array.
3927
- *
3928
- * `Collection.Indexed`, and `Collection.Set` produce an Array of values.
3929
- * `Collection.Keyed` produce an Array of [key, value] tuples.
3930
- */
3931
- toArray(): Array<V> | Array<[K, V]>;
3932
-
3933
- /**
3934
- * Shallowly converts this Collection to an Object.
3935
- *
3936
- * Converts keys to Strings.
3937
- */
3938
- toObject(): { [key: string]: V };
3939
-
3940
-
3941
- // Conversion to Collections
3942
-
3943
- /**
3944
- * Converts this Collection to a Map, Throws if keys are not hashable.
3945
- *
3946
- * Note: This is equivalent to `Map(this.toKeyedSeq())`, but provided
3947
- * for convenience and to allow for chained expressions.
3948
- */
3949
- toMap(): Map<K, V>;
3950
-
3951
- /**
3952
- * Converts this Collection to a Map, maintaining the order of iteration.
3953
- *
3954
- * Note: This is equivalent to `OrderedMap(this.toKeyedSeq())`, but
3955
- * provided for convenience and to allow for chained expressions.
3956
- */
3957
- toOrderedMap(): OrderedMap<K, V>;
3958
-
3959
- /**
3960
- * Converts this Collection to a Set, discarding keys. Throws if values
3961
- * are not hashable.
3962
- *
3963
- * Note: This is equivalent to `Set(this)`, but provided to allow for
3964
- * chained expressions.
3965
- */
3966
- toSet(): Set<V>;
3967
-
3968
- /**
3969
- * Converts this Collection to a Set, maintaining the order of iteration and
3970
- * discarding keys.
3971
- *
3972
- * Note: This is equivalent to `OrderedSet(this.valueSeq())`, but provided
3973
- * for convenience and to allow for chained expressions.
3974
- */
3975
- toOrderedSet(): OrderedSet<V>;
3976
-
3977
- /**
3978
- * Converts this Collection to a List, discarding keys.
3979
- *
3980
- * This is similar to `List(collection)`, but provided to allow for chained
3981
- * expressions. However, when called on `Map` or other keyed collections,
3982
- * `collection.toList()` discards the keys and creates a list of only the
3983
- * values, whereas `List(collection)` creates a list of entry tuples.
3984
- *
3985
- * <!-- runkit:activate -->
3986
- * ```js
3987
- * const { Map, List } = require('immutable@4.0.0-rc.6')
3988
- * var myMap = Map({ a: 'Apple', b: 'Banana' })
3989
- * List(myMap) // List [ [ "a", "Apple" ], [ "b", "Banana" ] ]
3990
- * myMap.toList() // List [ "Apple", "Banana" ]
3991
- * ```
3992
- */
3993
- toList(): List<V>;
3994
-
3995
- /**
3996
- * Converts this Collection to a Stack, discarding keys. Throws if values
3997
- * are not hashable.
3998
- *
3999
- * Note: This is equivalent to `Stack(this)`, but provided to allow for
4000
- * chained expressions.
4001
- */
4002
- toStack(): Stack<V>;
4003
-
4004
-
4005
- // Conversion to Seq
4006
-
4007
- /**
4008
- * Converts this Collection to a Seq of the same kind (indexed,
4009
- * keyed, or set).
4010
- */
4011
- toSeq(): Seq<K, V>;
4012
-
4013
- /**
4014
- * Returns a Seq.Keyed from this Collection where indices are treated as keys.
4015
- *
4016
- * This is useful if you want to operate on an
4017
- * Collection.Indexed and preserve the [index, value] pairs.
4018
- *
4019
- * The returned Seq will have identical iteration order as
4020
- * this Collection.
4021
- *
4022
- * <!-- runkit:activate -->
4023
- * ```js
4024
- * const { Seq } = require('immutable@4.0.0-rc.6')
4025
- * const indexedSeq = Seq([ 'A', 'B', 'C' ])
4026
- * // Seq [ "A", "B", "C" ]
4027
- * indexedSeq.filter(v => v === 'B')
4028
- * // Seq [ "B" ]
4029
- * const keyedSeq = indexedSeq.toKeyedSeq()
4030
- * // Seq { 0: "A", 1: "B", 2: "C" }
4031
- * keyedSeq.filter(v => v === 'B')
4032
- * // Seq { 1: "B" }
4033
- * ```
4034
- */
4035
- toKeyedSeq(): Seq.Keyed<K, V>;
4036
-
4037
- /**
4038
- * Returns an Seq.Indexed of the values of this Collection, discarding keys.
4039
- */
4040
- toIndexedSeq(): Seq.Indexed<V>;
4041
-
4042
- /**
4043
- * Returns a Seq.Set of the values of this Collection, discarding keys.
4044
- */
4045
- toSetSeq(): Seq.Set<V>;
4046
-
4047
-
4048
- // Iterators
4049
-
4050
- /**
4051
- * An iterator of this `Collection`'s keys.
4052
- *
4053
- * Note: this will return an ES6 iterator which does not support
4054
- * Immutable.js sequence algorithms. Use `keySeq` instead, if this is
4055
- * what you want.
4056
- */
4057
- keys(): IterableIterator<K>;
4058
-
4059
- /**
4060
- * An iterator of this `Collection`'s values.
4061
- *
4062
- * Note: this will return an ES6 iterator which does not support
4063
- * Immutable.js sequence algorithms. Use `valueSeq` instead, if this is
4064
- * what you want.
4065
- */
4066
- values(): IterableIterator<V>;
4067
-
4068
- /**
4069
- * An iterator of this `Collection`'s entries as `[ key, value ]` tuples.
4070
- *
4071
- * Note: this will return an ES6 iterator which does not support
4072
- * Immutable.js sequence algorithms. Use `entrySeq` instead, if this is
4073
- * what you want.
4074
- */
4075
- entries(): IterableIterator<[K, V]>;
4076
-
4077
-
4078
- // Collections (Seq)
4079
-
4080
- /**
4081
- * Returns a new Seq.Indexed of the keys of this Collection,
4082
- * discarding values.
4083
- */
4084
- keySeq(): Seq.Indexed<K>;
4085
-
4086
- /**
4087
- * Returns an Seq.Indexed of the values of this Collection, discarding keys.
4088
- */
4089
- valueSeq(): Seq.Indexed<V>;
4090
-
4091
- /**
4092
- * Returns a new Seq.Indexed of [key, value] tuples.
4093
- */
4094
- entrySeq(): Seq.Indexed<[K, V]>;
4095
-
4096
-
4097
- // Sequence algorithms
4098
-
4099
- /**
4100
- * Returns a new Collection of the same type with values passed through a
4101
- * `mapper` function.
4102
- *
4103
- * <!-- runkit:activate -->
4104
- * ```js
4105
- * const { Collection } = require('immutable@4.0.0-rc.6')
4106
- * Collection({ a: 1, b: 2 }).map(x => 10 * x)
4107
- * // Seq { "a": 10, "b": 20 }
4108
- * ```
4109
- *
4110
- * Note: `map()` always returns a new instance, even if it produced the same
4111
- * value at every step.
4112
- */
4113
- map<M>(
4114
- mapper: (value: V, key: K, iter: this) => M,
4115
- context?: any
4116
- ): Collection<K, M>;
4117
-
4118
- /**
4119
- * Note: used only for sets, which return Collection<M, M> but are otherwise
4120
- * identical to normal `map()`.
4121
- *
4122
- * @ignore
4123
- */
4124
- map<M>(...args: never[]): any;
4125
-
4126
- /**
4127
- * Returns a new Collection of the same type with only the entries for which
4128
- * the `predicate` function returns true.
4129
- *
4130
- * <!-- runkit:activate -->
4131
- * ```js
4132
- * const { Map } = require('immutable@4.0.0-rc.6')
4133
- * Map({ a: 1, b: 2, c: 3, d: 4}).filter(x => x % 2 === 0)
4134
- * // Map { "b": 2, "d": 4 }
4135
- * ```
4136
- *
4137
- * Note: `filter()` always returns a new instance, even if it results in
4138
- * not filtering out any values.
4139
- */
4140
- filter<F extends V>(
4141
- predicate: (value: V, key: K, iter: this) => value is F,
4142
- context?: any
4143
- ): Collection<K, F>;
4144
- filter(
4145
- predicate: (value: V, key: K, iter: this) => any,
4146
- context?: any
4147
- ): this;
4148
-
4149
- /**
4150
- * Returns a new Collection of the same type with only the entries for which
4151
- * the `predicate` function returns false.
4152
- *
4153
- * <!-- runkit:activate -->
4154
- * ```js
4155
- * const { Map } = require('immutable@4.0.0-rc.6')
4156
- * Map({ a: 1, b: 2, c: 3, d: 4}).filterNot(x => x % 2 === 0)
4157
- * // Map { "a": 1, "c": 3 }
4158
- * ```
4159
- *
4160
- * Note: `filterNot()` always returns a new instance, even if it results in
4161
- * not filtering out any values.
4162
- */
4163
- filterNot(
4164
- predicate: (value: V, key: K, iter: this) => boolean,
4165
- context?: any
4166
- ): this;
4167
-
4168
- /**
4169
- * Returns a new Collection of the same type in reverse order.
4170
- */
4171
- reverse(): this;
4172
-
4173
- /**
4174
- * Returns a new Collection of the same type which includes the same entries,
4175
- * stably sorted by using a `comparator`.
4176
- *
4177
- * If a `comparator` is not provided, a default comparator uses `<` and `>`.
4178
- *
4179
- * `comparator(valueA, valueB)`:
4180
- *
4181
- * * Returns `0` if the elements should not be swapped.
4182
- * * Returns `-1` (or any negative number) if `valueA` comes before `valueB`
4183
- * * Returns `1` (or any positive number) if `valueA` comes after `valueB`
4184
- * * Is pure, i.e. it must always return the same value for the same pair
4185
- * of values.
4186
- *
4187
- * When sorting collections which have no defined order, their ordered
4188
- * equivalents will be returned. e.g. `map.sort()` returns OrderedMap.
4189
- *
4190
- * <!-- runkit:activate -->
4191
- * ```js
4192
- * const { Map } = require('immutable@4.0.0-rc.6')
4193
- * Map({ "c": 3, "a": 1, "b": 2 }).sort((a, b) => {
4194
- * if (a < b) { return -1; }
4195
- * if (a > b) { return 1; }
4196
- * if (a === b) { return 0; }
4197
- * });
4198
- * // OrderedMap { "a": 1, "b": 2, "c": 3 }
4199
- * ```
4200
- *
4201
- * Note: `sort()` Always returns a new instance, even if the original was
4202
- * already sorted.
4203
- *
4204
- * Note: This is always an eager operation.
4205
- */
4206
- sort(comparator?: (valueA: V, valueB: V) => number): this;
4207
-
4208
- /**
4209
- * Like `sort`, but also accepts a `comparatorValueMapper` which allows for
4210
- * sorting by more sophisticated means:
4211
- *
4212
- * hitters.sortBy(hitter => hitter.avgHits)
4213
- *
4214
- * Note: `sortBy()` Always returns a new instance, even if the original was
4215
- * already sorted.
4216
- *
4217
- * Note: This is always an eager operation.
4218
- */
4219
- sortBy<C>(
4220
- comparatorValueMapper: (value: V, key: K, iter: this) => C,
4221
- comparator?: (valueA: C, valueB: C) => number
4222
- ): this;
4223
-
4224
- /**
4225
- * Returns a `Collection.Keyed` of `Collection.Keyeds`, grouped by the return
4226
- * value of the `grouper` function.
4227
- *
4228
- * Note: This is always an eager operation.
4229
- *
4230
- * <!-- runkit:activate -->
4231
- * ```js
4232
- * const { List, Map } = require('immutable@4.0.0-rc.6')
4233
- * const listOfMaps = List([
4234
- * Map({ v: 0 }),
4235
- * Map({ v: 1 }),
4236
- * Map({ v: 1 }),
4237
- * Map({ v: 0 }),
4238
- * Map({ v: 2 })
4239
- * ])
4240
- * const groupsOfMaps = listOfMaps.groupBy(x => x.get('v'))
4241
- * // Map {
4242
- * // 0: List [ Map{ "v": 0 }, Map { "v": 0 } ],
4243
- * // 1: List [ Map{ "v": 1 }, Map { "v": 1 } ],
4244
- * // 2: List [ Map{ "v": 2 } ],
4245
- * // }
4246
- * ```
4247
- */
4248
- groupBy<G>(
4249
- grouper: (value: V, key: K, iter: this) => G,
4250
- context?: any
4251
- ): /*Map*/Seq.Keyed<G, /*this*/Collection<K, V>>;
4252
-
4253
-
4254
- // Side effects
4255
-
4256
- /**
4257
- * The `sideEffect` is executed for every entry in the Collection.
4258
- *
4259
- * Unlike `Array#forEach`, if any call of `sideEffect` returns
4260
- * `false`, the iteration will stop. Returns the number of entries iterated
4261
- * (including the last iteration which returned false).
4262
- */
4263
- forEach(
4264
- sideEffect: (value: V, key: K, iter: this) => any,
4265
- context?: any
4266
- ): number;
4267
-
4268
-
4269
- // Creating subsets
4270
-
4271
- /**
4272
- * Returns a new Collection of the same type representing a portion of this
4273
- * Collection from start up to but not including end.
4274
- *
4275
- * If begin is negative, it is offset from the end of the Collection. e.g.
4276
- * `slice(-2)` returns a Collection of the last two entries. If it is not
4277
- * provided the new Collection will begin at the beginning of this Collection.
4278
- *
4279
- * If end is negative, it is offset from the end of the Collection. e.g.
4280
- * `slice(0, -1)` returns a Collection of everything but the last entry. If
4281
- * it is not provided, the new Collection will continue through the end of
4282
- * this Collection.
4283
- *
4284
- * If the requested slice is equivalent to the current Collection, then it
4285
- * will return itself.
4286
- */
4287
- slice(begin?: number, end?: number): this;
4288
-
4289
- /**
4290
- * Returns a new Collection of the same type containing all entries except
4291
- * the first.
4292
- */
4293
- rest(): this;
4294
-
4295
- /**
4296
- * Returns a new Collection of the same type containing all entries except
4297
- * the last.
4298
- */
4299
- butLast(): this;
4300
-
4301
- /**
4302
- * Returns a new Collection of the same type which excludes the first `amount`
4303
- * entries from this Collection.
4304
- */
4305
- skip(amount: number): this;
4306
-
4307
- /**
4308
- * Returns a new Collection of the same type which excludes the last `amount`
4309
- * entries from this Collection.
4310
- */
4311
- skipLast(amount: number): this;
4312
-
4313
- /**
4314
- * Returns a new Collection of the same type which includes entries starting
4315
- * from when `predicate` first returns false.
4316
- *
4317
- * <!-- runkit:activate -->
4318
- * ```js
4319
- * const { List } = require('immutable@4.0.0-rc.6')
4320
- * List([ 'dog', 'frog', 'cat', 'hat', 'god' ])
4321
- * .skipWhile(x => x.match(/g/))
4322
- * // List [ "cat", "hat", "god"" ]
4323
- * ```
4324
- */
4325
- skipWhile(
4326
- predicate: (value: V, key: K, iter: this) => boolean,
4327
- context?: any
4328
- ): this;
4329
-
4330
- /**
4331
- * Returns a new Collection of the same type which includes entries starting
4332
- * from when `predicate` first returns true.
4333
- *
4334
- * <!-- runkit:activate -->
4335
- * ```js
4336
- * const { List } = require('immutable@4.0.0-rc.6')
4337
- * List([ 'dog', 'frog', 'cat', 'hat', 'god' ])
4338
- * .skipUntil(x => x.match(/hat/))
4339
- * // List [ "hat", "god"" ]
4340
- * ```
4341
- */
4342
- skipUntil(
4343
- predicate: (value: V, key: K, iter: this) => boolean,
4344
- context?: any
4345
- ): this;
4346
-
4347
- /**
4348
- * Returns a new Collection of the same type which includes the first `amount`
4349
- * entries from this Collection.
4350
- */
4351
- take(amount: number): this;
4352
-
4353
- /**
4354
- * Returns a new Collection of the same type which includes the last `amount`
4355
- * entries from this Collection.
4356
- */
4357
- takeLast(amount: number): this;
4358
-
4359
- /**
4360
- * Returns a new Collection of the same type which includes entries from this
4361
- * Collection as long as the `predicate` returns true.
4362
- *
4363
- * <!-- runkit:activate -->
4364
- * ```js
4365
- * const { List } = require('immutable@4.0.0-rc.6')
4366
- * List([ 'dog', 'frog', 'cat', 'hat', 'god' ])
4367
- * .takeWhile(x => x.match(/o/))
4368
- * // List [ "dog", "frog" ]
4369
- * ```
4370
- */
4371
- takeWhile(
4372
- predicate: (value: V, key: K, iter: this) => boolean,
4373
- context?: any
4374
- ): this;
4375
-
4376
- /**
4377
- * Returns a new Collection of the same type which includes entries from this
4378
- * Collection as long as the `predicate` returns false.
4379
- *
4380
- * <!-- runkit:activate -->
4381
- * ```js
4382
- * const { List } = require('immutable@4.0.0-rc.6')
4383
- * List([ 'dog', 'frog', 'cat', 'hat', 'god' ])
4384
- * .takeUntil(x => x.match(/at/))
4385
- * // List [ "dog", "frog" ]
4386
- * ```
4387
- */
4388
- takeUntil(
4389
- predicate: (value: V, key: K, iter: this) => boolean,
4390
- context?: any
4391
- ): this;
4392
-
4393
-
4394
- // Combination
4395
-
4396
- /**
4397
- * Returns a new Collection of the same type with other values and
4398
- * collection-like concatenated to this one.
4399
- *
4400
- * For Seqs, all entries will be present in the resulting Seq, even if they
4401
- * have the same key.
4402
- */
4403
- concat(...valuesOrCollections: Array<any>): Collection<any, any>;
4404
-
4405
- /**
4406
- * Flattens nested Collections.
4407
- *
4408
- * Will deeply flatten the Collection by default, returning a Collection of the
4409
- * same type, but a `depth` can be provided in the form of a number or
4410
- * boolean (where true means to shallowly flatten one level). A depth of 0
4411
- * (or shallow: false) will deeply flatten.
4412
- *
4413
- * Flattens only others Collection, not Arrays or Objects.
4414
- *
4415
- * Note: `flatten(true)` operates on Collection<any, Collection<K, V>> and
4416
- * returns Collection<K, V>
4417
- */
4418
- flatten(depth?: number): Collection<any, any>;
4419
- flatten(shallow?: boolean): Collection<any, any>;
4420
-
4421
- /**
4422
- * Flat-maps the Collection, returning a Collection of the same type.
4423
- *
4424
- * Similar to `collection.map(...).flatten(true)`.
4425
- */
4426
- flatMap<M>(
4427
- mapper: (value: V, key: K, iter: this) => Iterable<M>,
4428
- context?: any
4429
- ): Collection<K, M>;
4430
-
4431
- /**
4432
- * Flat-maps the Collection, returning a Collection of the same type.
4433
- *
4434
- * Similar to `collection.map(...).flatten(true)`.
4435
- * Used for Dictionaries only.
4436
- */
4437
- flatMap<KM, VM>(
4438
- mapper: (value: V, key: K, iter: this) => Iterable<[KM, VM]>,
4439
- context?: any
4440
- ): Collection<KM, VM>;
4441
-
4442
- // Reducing a value
4443
-
4444
- /**
4445
- * Reduces the Collection to a value by calling the `reducer` for every entry
4446
- * in the Collection and passing along the reduced value.
4447
- *
4448
- * If `initialReduction` is not provided, the first item in the
4449
- * Collection will be used.
4450
- *
4451
- * @see `Array#reduce`.
4452
- */
4453
- reduce<R>(
4454
- reducer: (reduction: R, value: V, key: K, iter: this) => R,
4455
- initialReduction: R,
4456
- context?: any
4457
- ): R;
4458
- reduce<R>(
4459
- reducer: (reduction: V | R, value: V, key: K, iter: this) => R
4460
- ): R;
4461
-
4462
- /**
4463
- * Reduces the Collection in reverse (from the right side).
4464
- *
4465
- * Note: Similar to this.reverse().reduce(), and provided for parity
4466
- * with `Array#reduceRight`.
4467
- */
4468
- reduceRight<R>(
4469
- reducer: (reduction: R, value: V, key: K, iter: this) => R,
4470
- initialReduction: R,
4471
- context?: any
4472
- ): R;
4473
- reduceRight<R>(
4474
- reducer: (reduction: V | R, value: V, key: K, iter: this) => R
4475
- ): R;
4476
-
4477
- /**
4478
- * True if `predicate` returns true for all entries in the Collection.
4479
- */
4480
- every(
4481
- predicate: (value: V, key: K, iter: this) => boolean,
4482
- context?: any
4483
- ): boolean;
4484
-
4485
- /**
4486
- * True if `predicate` returns true for any entry in the Collection.
4487
- */
4488
- some(
4489
- predicate: (value: V, key: K, iter: this) => boolean,
4490
- context?: any
4491
- ): boolean;
4492
-
4493
- /**
4494
- * Joins values together as a string, inserting a separator between each.
4495
- * The default separator is `","`.
4496
- */
4497
- join(separator?: string): string;
4498
-
4499
- /**
4500
- * Returns true if this Collection includes no values.
4501
- *
4502
- * For some lazy `Seq`, `isEmpty` might need to iterate to determine
4503
- * emptiness. At most one iteration will occur.
4504
- */
4505
- isEmpty(): boolean;
4506
-
4507
- /**
4508
- * Returns the size of this Collection.
4509
- *
4510
- * Regardless of if this Collection can describe its size lazily (some Seqs
4511
- * cannot), this method will always return the correct size. E.g. it
4512
- * evaluates a lazy `Seq` if necessary.
4513
- *
4514
- * If `predicate` is provided, then this returns the count of entries in the
4515
- * Collection for which the `predicate` returns true.
4516
- */
4517
- count(): number;
4518
- count(
4519
- predicate: (value: V, key: K, iter: this) => boolean,
4520
- context?: any
4521
- ): number;
4522
-
4523
- /**
4524
- * Returns a `Seq.Keyed` of counts, grouped by the return value of
4525
- * the `grouper` function.
4526
- *
4527
- * Note: This is not a lazy operation.
4528
- */
4529
- countBy<G>(
4530
- grouper: (value: V, key: K, iter: this) => G,
4531
- context?: any
4532
- ): Map<G, number>;
4533
-
4534
-
4535
- // Search for value
4536
-
4537
- /**
4538
- * Returns the first value for which the `predicate` returns true.
4539
- */
4540
- find(
4541
- predicate: (value: V, key: K, iter: this) => boolean,
4542
- context?: any,
4543
- notSetValue?: V
4544
- ): V | undefined;
4545
-
4546
- /**
4547
- * Returns the last value for which the `predicate` returns true.
4548
- *
4549
- * Note: `predicate` will be called for each entry in reverse.
4550
- */
4551
- findLast(
4552
- predicate: (value: V, key: K, iter: this) => boolean,
4553
- context?: any,
4554
- notSetValue?: V
4555
- ): V | undefined;
4556
-
4557
- /**
4558
- * Returns the first [key, value] entry for which the `predicate` returns true.
4559
- */
4560
- findEntry(
4561
- predicate: (value: V, key: K, iter: this) => boolean,
4562
- context?: any,
4563
- notSetValue?: V
4564
- ): [K, V] | undefined;
4565
-
4566
- /**
4567
- * Returns the last [key, value] entry for which the `predicate`
4568
- * returns true.
4569
- *
4570
- * Note: `predicate` will be called for each entry in reverse.
4571
- */
4572
- findLastEntry(
4573
- predicate: (value: V, key: K, iter: this) => boolean,
4574
- context?: any,
4575
- notSetValue?: V
4576
- ): [K, V] | undefined;
4577
-
4578
- /**
4579
- * Returns the key for which the `predicate` returns true.
4580
- */
4581
- findKey(
4582
- predicate: (value: V, key: K, iter: this) => boolean,
4583
- context?: any
4584
- ): K | undefined;
4585
-
4586
- /**
4587
- * Returns the last key for which the `predicate` returns true.
4588
- *
4589
- * Note: `predicate` will be called for each entry in reverse.
4590
- */
4591
- findLastKey(
4592
- predicate: (value: V, key: K, iter: this) => boolean,
4593
- context?: any
4594
- ): K | undefined;
4595
-
4596
- /**
4597
- * Returns the key associated with the search value, or undefined.
4598
- */
4599
- keyOf(searchValue: V): K | undefined;
4600
-
4601
- /**
4602
- * Returns the last key associated with the search value, or undefined.
4603
- */
4604
- lastKeyOf(searchValue: V): K | undefined;
4605
-
4606
- /**
4607
- * Returns the maximum value in this collection. If any values are
4608
- * comparatively equivalent, the first one found will be returned.
4609
- *
4610
- * The `comparator` is used in the same way as `Collection#sort`. If it is not
4611
- * provided, the default comparator is `>`.
4612
- *
4613
- * When two values are considered equivalent, the first encountered will be
4614
- * returned. Otherwise, `max` will operate independent of the order of input
4615
- * as long as the comparator is commutative. The default comparator `>` is
4616
- * commutative *only* when types do not differ.
4617
- *
4618
- * If `comparator` returns 0 and either value is NaN, undefined, or null,
4619
- * that value will be returned.
4620
- */
4621
- max(comparator?: (valueA: V, valueB: V) => number): V | undefined;
4622
-
4623
- /**
4624
- * Like `max`, but also accepts a `comparatorValueMapper` which allows for
4625
- * comparing by more sophisticated means:
4626
- *
4627
- * hitters.maxBy(hitter => hitter.avgHits);
4628
- *
4629
- */
4630
- maxBy<C>(
4631
- comparatorValueMapper: (value: V, key: K, iter: this) => C,
4632
- comparator?: (valueA: C, valueB: C) => number
4633
- ): V | undefined;
4634
-
4635
- /**
4636
- * Returns the minimum value in this collection. If any values are
4637
- * comparatively equivalent, the first one found will be returned.
4638
- *
4639
- * The `comparator` is used in the same way as `Collection#sort`. If it is not
4640
- * provided, the default comparator is `<`.
4641
- *
4642
- * When two values are considered equivalent, the first encountered will be
4643
- * returned. Otherwise, `min` will operate independent of the order of input
4644
- * as long as the comparator is commutative. The default comparator `<` is
4645
- * commutative *only* when types do not differ.
4646
- *
4647
- * If `comparator` returns 0 and either value is NaN, undefined, or null,
4648
- * that value will be returned.
4649
- */
4650
- min(comparator?: (valueA: V, valueB: V) => number): V | undefined;
4651
-
4652
- /**
4653
- * Like `min`, but also accepts a `comparatorValueMapper` which allows for
4654
- * comparing by more sophisticated means:
4655
- *
4656
- * hitters.minBy(hitter => hitter.avgHits);
4657
- *
4658
- */
4659
- minBy<C>(
4660
- comparatorValueMapper: (value: V, key: K, iter: this) => C,
4661
- comparator?: (valueA: C, valueB: C) => number
4662
- ): V | undefined;
4663
-
4664
-
4665
- // Comparison
4666
-
4667
- /**
4668
- * True if `iter` includes every value in this Collection.
4669
- */
4670
- isSubset(iter: Iterable<V>): boolean;
4671
-
4672
- /**
4673
- * True if this Collection includes every value in `iter`.
4674
- */
4675
- isSuperset(iter: Iterable<V>): boolean;
4676
- }
4677
-