victory-core 36.6.2 → 36.6.5

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