immutable.js.flow 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  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. * This file provides type definitions for use with the Flow type checker.
  9. *
  10. * An important caveat when using these definitions is that the types for
  11. * `Iterable.Keyed`, `Iterable.Indexed`, `Seq.Keyed`, and so on are stubs.
  12. * When referring to those types, you can get the proper definitions by
  13. * importing the types `KeyedIterable`, `IndexedIterable`, `KeyedSeq`, etc.
  14. * For example,
  15. *
  16. * import { Seq } from 'immutable'
  17. * import type { IndexedIterable, IndexedSeq } from 'immutable'
  18. *
  19. * const someSeq: IndexedSeq<number> = Seq.Indexed.of(1, 2, 3)
  20. *
  21. * function takesASeq<T, TS: IndexedIterable<T>>(iter: TS): TS {
  22. * return iter.butLast()
  23. * }
  24. *
  25. * takesASeq(someSeq)
  26. *
  27. * @flow
  28. */
  29. /*
  30. * Alias for ECMAScript `Iterable` type, declared in
  31. * https://github.com/facebook/flow/blob/master/lib/core.js
  32. *
  33. * Note that Immutable values implement the `ESIterable` interface.
  34. */
  35. type ESIterable<T> = $Iterable<T,void,void>;
  36. declare class Iterable<K, V> extends _Iterable<K, V, typeof KeyedIterable, typeof IndexedIterable, typeof SetIterable> {}
  37. declare class _Iterable<K, V, KI, II, SI> {
  38. static Keyed: KI;
  39. static Indexed: II;
  40. static Set: SI;
  41. static isIterable(maybeIterable: any): boolean;
  42. static isKeyed(maybeKeyed: any): boolean;
  43. static isIndexed(maybeIndexed: any): boolean;
  44. static isAssociative(maybeAssociative: any): boolean;
  45. static isOrdered(maybeOrdered: any): boolean;
  46. equals(other: Iterable<K,V>): boolean;
  47. hashCode(): number;
  48. get(key: K): V;
  49. get<V_>(key: K, notSetValue: V_): V|V_;
  50. has(key: K): boolean;
  51. includes(value: V): boolean;
  52. contains(value: V): boolean;
  53. first(): V;
  54. last(): V;
  55. getIn<T>(searchKeyPath: ESIterable<any>, notSetValue: T): T;
  56. getIn<T>(searchKeyPath: ESIterable<any>): T;
  57. hasIn(searchKeyPath: ESIterable<any>): boolean;
  58. toJS(): any;
  59. toArray(): V[];
  60. toObject(): { [key: string]: V };
  61. toMap(): Map<K,V>;
  62. toOrderedMap(): Map<K,V>;
  63. toSet(): Set<V>;
  64. toOrderedSet(): Set<V>;
  65. toList(): List<V>;
  66. toStack(): Stack<V>;
  67. toSeq(): Seq<K,V>;
  68. toKeyedSeq(): KeyedSeq<K,V>;
  69. toIndexedSeq(): IndexedSeq<V>;
  70. toSetSeq(): SetSeq<V>;
  71. keys(): Iterator<K>;
  72. values(): Iterator<V>;
  73. entries(): Iterator<[K,V]>;
  74. keySeq(): IndexedSeq<K>;
  75. valueSeq(): IndexedSeq<V>;
  76. entrySeq(): IndexedSeq<[K,V]>;
  77. reverse(): this;
  78. sort(comparator?: (valueA: V, valueB: V) => number): this;
  79. sortBy<C>(
  80. comparatorValueMapper: (value: V, key: K, iter: this) => C,
  81. comparator?: (valueA: C, valueB: C) => number
  82. ): this;
  83. groupBy<G>(
  84. grouper: (value: V, key: K, iter: this) => G,
  85. context?: any
  86. ): KeyedSeq<G, this>;
  87. forEach(
  88. sideEffect: (value: V, key: K, iter: this) => any,
  89. context?: any
  90. ): number;
  91. slice(begin?: number, end?: number): this;
  92. rest(): this;
  93. butLast(): this;
  94. skip(amount: number): this;
  95. skipLast(amount: number): this;
  96. skipWhile(predicate: (value: V, key: K, iter: this) => mixed, context?: any): this;
  97. skipUntil(predicate: (value: V, key: K, iter: this) => mixed, context?: any): this;
  98. take(amount: number): this;
  99. takeLast(amount: number): this;
  100. takeWhile(predicate: (value: V, key: K, iter: this) => mixed, context?: any): this;
  101. takeUntil(predicate: (value: V, key: K, iter: this) => mixed, context?: any): this;
  102. flatten(depth?: number): /*this*/Iterable<any,any>;
  103. flatten(shallow?: boolean): /*this*/Iterable<any,any>;
  104. filter(
  105. predicate: (value: V, key: K, iter: this) => mixed,
  106. context?: any
  107. ): this;
  108. filterNot(
  109. predicate: (value: V, key: K, iter: this) => mixed,
  110. context?: any
  111. ): this;
  112. reduce<R>(
  113. reducer: (reduction: R, value: V, key: K, iter: this) => R,
  114. initialReduction?: R,
  115. context?: any,
  116. ): R;
  117. reduceRight<R>(
  118. reducer: (reduction: R, value: V, key: K, iter: this) => R,
  119. initialReduction?: R,
  120. context?: any,
  121. ): R;
  122. every(predicate: (value: V, key: K, iter: this) => mixed, context?: any): boolean;
  123. some(predicate: (value: V, key: K, iter: this) => mixed, context?: any): boolean;
  124. join(separator?: string): string;
  125. isEmpty(): boolean;
  126. count(predicate?: (value: V, key: K, iter: this) => mixed, context?: any): number;
  127. countBy<G>(grouper: (value: V, key: K, iter: this) => G, context?: any): Map<G,number>;
  128. find(
  129. predicate: (value: V, key: K, iter: this) => mixed,
  130. context?: any,
  131. ): ?V;
  132. find<V_>(
  133. predicate: (value: V, key: K, iter: this) => mixed,
  134. context: any,
  135. notSetValue: V_
  136. ): V|V_;
  137. findLast(
  138. predicate: (value: V, key: K, iter: this) => mixed,
  139. context?: any,
  140. ): ?V;
  141. findLast<V_>(
  142. predicate: (value: V, key: K, iter: this) => mixed,
  143. context: any,
  144. notSetValue: V_
  145. ): V|V_;
  146. findEntry(predicate: (value: V, key: K, iter: this) => mixed): ?[K,V];
  147. findLastEntry(predicate: (value: V, key: K, iter: this) => mixed): ?[K,V];
  148. findKey(predicate: (value: V, key: K, iter: this) => mixed, context?: any): ?K;
  149. findLastKey(predicate: (value: V, key: K, iter: this) => mixed, context?: any): ?K;
  150. keyOf(searchValue: V): ?K;
  151. lastKeyOf(searchValue: V): ?K;
  152. max(comparator?: (valueA: V, valueB: V) => number): V;
  153. maxBy<C>(
  154. comparatorValueMapper: (value: V, key: K, iter: this) => C,
  155. comparator?: (valueA: C, valueB: C) => number
  156. ): V;
  157. min(comparator?: (valueA: V, valueB: V) => number): V;
  158. minBy<C>(
  159. comparatorValueMapper: (value: V, key: K, iter: this) => C,
  160. comparator?: (valueA: C, valueB: C) => number
  161. ): V;
  162. isSubset(iter: Iterable<any, V>): boolean;
  163. isSubset(iter: ESIterable<V>): boolean;
  164. isSuperset(iter: Iterable<any, V>): boolean;
  165. isSuperset(iter: ESIterable<V>): boolean;
  166. }
  167. declare class KeyedIterable<K,V> extends Iterable<K,V> {
  168. static <K,V>(iter?: ESIterable<[K,V]>): KeyedIterable<K,V>;
  169. static <K,V>(obj?: { [key: K]: V }): KeyedIterable<K,V>;
  170. @@iterator(): Iterator<[K,V]>;
  171. toSeq(): KeyedSeq<K,V>;
  172. flip(): /*this*/KeyedIterable<V,K>;
  173. mapKeys<K_>(
  174. mapper: (key: K, value: V, iter: this) => K_,
  175. context?: any
  176. ): /*this*/KeyedIterable<K_,V>;
  177. mapEntries<K_,V_>(
  178. mapper: (entry: [K,V], index: number, iter: this) => [K_,V_],
  179. context?: any
  180. ): /*this*/KeyedIterable<K_,V_>;
  181. concat(...iters: ESIterable<[K,V]>[]): this;
  182. map<V_>(
  183. mapper: (value: V, key: K, iter: this) => V_,
  184. context?: any
  185. ): /*this*/KeyedIterable<K,V_>;
  186. flatMap<K_, V_>(
  187. mapper: (value: V, key: K, iter: this) => ESIterable<[K_,V_]>,
  188. context?: any
  189. ): /*this*/KeyedIterable<K_,V_>;
  190. flatten(depth?: number): /*this*/KeyedIterable<any,any>;
  191. flatten(shallow?: boolean): /*this*/KeyedIterable<any,any>;
  192. }
  193. declare class IndexedIterable<T> extends Iterable<number,T> {
  194. static <T>(iter?: ESIterable<T>): IndexedIterable<T>;
  195. @@iterator(): Iterator<T>;
  196. toSeq(): IndexedSeq<T>;
  197. fromEntrySeq<K,V>(): KeyedSeq<K,V>;
  198. interpose(separator: T): this;
  199. interleave(...iterables: ESIterable<T>[]): this;
  200. splice(
  201. index: number,
  202. removeNum: number,
  203. ...values: T[]
  204. ): this;
  205. zip<A>(
  206. a: ESIterable<A>,
  207. $?: null
  208. ): IndexedIterable<[T,A]>;
  209. zip<A,B>(
  210. a: ESIterable<A>,
  211. b: ESIterable<B>,
  212. $?: null
  213. ): IndexedIterable<[T,A,B]>;
  214. zip<A,B,C>(
  215. a: ESIterable<A>,
  216. b: ESIterable<B>,
  217. c: ESIterable<C>,
  218. $?: null
  219. ): IndexedIterable<[T,A,B,C]>;
  220. zip<A,B,C,D>(
  221. a: ESIterable<A>,
  222. b: ESIterable<B>,
  223. c: ESIterable<C>,
  224. d: ESIterable<D>,
  225. $?: null
  226. ): IndexedIterable<[T,A,B,C,D]>;
  227. zip<A,B,C,D,E>(
  228. a: ESIterable<A>,
  229. b: ESIterable<B>,
  230. c: ESIterable<C>,
  231. d: ESIterable<D>,
  232. e: ESIterable<E>,
  233. $?: null
  234. ): IndexedIterable<[T,A,B,C,D,E]>;
  235. zipWith<A,R>(
  236. zipper: (value: T, a: A) => R,
  237. a: ESIterable<A>,
  238. $?: null
  239. ): IndexedIterable<R>;
  240. zipWith<A,B,R>(
  241. zipper: (value: T, a: A, b: B) => R,
  242. a: ESIterable<A>,
  243. b: ESIterable<B>,
  244. $?: null
  245. ): IndexedIterable<R>;
  246. zipWith<A,B,C,R>(
  247. zipper: (value: T, a: A, b: B, c: C) => R,
  248. a: ESIterable<A>,
  249. b: ESIterable<B>,
  250. c: ESIterable<C>,
  251. $?: null
  252. ): IndexedIterable<R>;
  253. zipWith<A,B,C,D,R>(
  254. zipper: (value: T, a: A, b: B, c: C, d: D) => R,
  255. a: ESIterable<A>,
  256. b: ESIterable<B>,
  257. c: ESIterable<C>,
  258. d: ESIterable<D>,
  259. $?: null
  260. ): IndexedIterable<R>;
  261. zipWith<A,B,C,D,E,R>(
  262. zipper: (value: T, a: A, b: B, c: C, d: D, e: E) => R,
  263. a: ESIterable<A>,
  264. b: ESIterable<B>,
  265. c: ESIterable<C>,
  266. d: ESIterable<D>,
  267. e: ESIterable<E>,
  268. $?: null
  269. ): IndexedIterable<R>;
  270. indexOf(searchValue: T): number;
  271. lastIndexOf(searchValue: T): number;
  272. findIndex(
  273. predicate: (value: T, index: number, iter: this) => mixed,
  274. context?: any
  275. ): number;
  276. findLastIndex(
  277. predicate: (value: T, index: number, iter: this) => mixed,
  278. context?: any
  279. ): number;
  280. concat(...iters: ESIterable<T>[]): this;
  281. map<U>(
  282. mapper: (value: T, index: number, iter: this) => U,
  283. context?: any
  284. ): /*this*/IndexedIterable<U>;
  285. flatMap<U>(
  286. mapper: (value: T, index: number, iter: this) => ESIterable<U>,
  287. context?: any
  288. ): /*this*/IndexedIterable<U>;
  289. flatten(depth?: number): /*this*/IndexedIterable<any>;
  290. flatten(shallow?: boolean): /*this*/IndexedIterable<any>;
  291. }
  292. declare class SetIterable<T> extends Iterable<T,T> {
  293. static <T>(iter?: ESIterable<T>): SetIterable<T>;
  294. @@iterator(): Iterator<T>;
  295. toSeq(): SetSeq<T>;
  296. concat(...iters: ESIterable<T>[]): this;
  297. // `map` and `flatMap` cannot be defined further up the hiearchy, because the
  298. // implementation for `KeyedIterable` allows the value type to change without
  299. // constraining the key type. That does not work for `SetIterable` - the value
  300. // and key types *must* match.
  301. map<U>(
  302. mapper: (value: T, value: T, iter: this) => U,
  303. context?: any
  304. ): /*this*/SetIterable<U>;
  305. flatMap<U>(
  306. mapper: (value: T, value: T, iter: this) => ESIterable<U>,
  307. context?: any
  308. ): /*this*/SetIterable<U>;
  309. flatten(depth?: number): /*this*/SetIterable<any>;
  310. flatten(shallow?: boolean): /*this*/SetIterable<any>;
  311. }
  312. declare class Collection<K,V> extends _Iterable<K,V, typeof KeyedCollection, typeof IndexedCollection, typeof SetCollection> {
  313. size: number;
  314. }
  315. declare class KeyedCollection<K,V> extends Collection<K,V> mixins KeyedIterable<K,V> {
  316. toSeq(): KeyedSeq<K,V>;
  317. }
  318. declare class IndexedCollection<T> extends Collection<number,T> mixins IndexedIterable<T> {
  319. toSeq(): IndexedSeq<T>;
  320. }
  321. declare class SetCollection<T> extends Collection<T,T> mixins SetIterable<T> {
  322. toSeq(): SetSeq<T>;
  323. }
  324. declare class Seq<K,V> extends _Iterable<K,V, typeof KeyedSeq, typeof IndexedSeq, typeof SetSeq> {
  325. static <K,V>(iter: KeyedSeq<K,V>): KeyedSeq<K,V>;
  326. static <T> (iter: SetSeq<T>): SetSeq<K,V>;
  327. static <T> (iter?: ESIterable<T>): IndexedSeq<T>;
  328. static <K,V>(iter: { [key: K]: V }): KeyedSeq<K,V>;
  329. static isSeq(maybeSeq: any): boolean;
  330. static of<T>(...values: T[]): IndexedSeq<T>;
  331. size: ?number;
  332. cacheResult(): this;
  333. toSeq(): this;
  334. }
  335. declare class KeyedSeq<K,V> extends Seq<K,V> mixins KeyedIterable<K,V> {
  336. static <K,V>(iter?: ESIterable<[K,V]>): KeyedSeq<K,V>;
  337. static <K,V>(iter?: { [key: K]: V }): KeyedSeq<K,V>;
  338. }
  339. declare class IndexedSeq<T> extends Seq<number,T> mixins IndexedIterable<T> {
  340. static <T>(iter?: ESIterable<T>): IndexedSeq<T>;
  341. static of<T>(...values: T[]): IndexedSeq<T>;
  342. }
  343. declare class SetSeq<T> extends Seq<T,T> mixins SetIterable<T> {
  344. static <T>(iter?: ESIterable<T>): IndexedSeq<T>;
  345. static of<T>(...values: T[]): SetSeq<T>;
  346. }
  347. declare class List<T> extends IndexedCollection<T> {
  348. static (iterable?: ESIterable<T>): List<T>;
  349. static isList(maybeList: any): boolean;
  350. static of<T>(...values: T[]): List<T>;
  351. set<U>(index: number, value: U): List<T|U>;
  352. delete(index: number): this;
  353. remove(index: number): this;
  354. insert<U>(index: number, value: U): List<T|U>;
  355. clear(): this;
  356. push<U>(...values: U[]): List<T|U>;
  357. pop(): this;
  358. unshift<U>(...values: U[]): List<T|U>;
  359. shift(): this;
  360. update<U>(updater: (value: this) => List<U>): List<U>;
  361. update<U>(index: number, updater: (value: T) => U): List<T|U>;
  362. update<U>(index: number, notSetValue: U, updater: (value: T) => U): List<T|U>;
  363. merge<U>(...iterables: ESIterable<U>[]): List<T|U>;
  364. mergeWith<U,V>(
  365. merger: (previous: T, next: U, key: number) => V,
  366. ...iterables: ESIterable<U>[]
  367. ): List<T|U|V>;
  368. mergeDeep<U>(...iterables: ESIterable<U>[]): List<T|U>;
  369. mergeDeepWith<U,V>(
  370. merger: (previous: T, next: U, key: number) => V,
  371. ...iterables: ESIterable<U>[]
  372. ): List<T|U|V>;
  373. setSize(size: number): List<?T>;
  374. setIn(keyPath: ESIterable<any>, value: any): List<T>;
  375. deleteIn(keyPath: ESIterable<any>, value: any): this;
  376. removeIn(keyPath: ESIterable<any>, value: any): this;
  377. updateIn(keyPath: ESIterable<any>, notSetValue: any, value: any): List<T>;
  378. updateIn(keyPath: ESIterable<any>, value: any): List<T>;
  379. mergeIn(keyPath: ESIterable<any>, ...iterables: ESIterable<any>[]): List<T>;
  380. mergeDeepIn(keyPath: ESIterable<any>, ...iterables: ESIterable<any>[]): List<T>;
  381. withMutations(mutator: (mutable: this) => any): this;
  382. asMutable(): this;
  383. asImmutable(): this;
  384. // Overrides that specialize return types
  385. map<M>(
  386. mapper: (value: T, index: number, iter: this) => M,
  387. context?: any
  388. ): List<M>;
  389. flatMap<M>(
  390. mapper: (value: T, index: number, iter: this) => ESIterable<M>,
  391. context?: any
  392. ): List<M>;
  393. flatten(depth?: number): /*this*/List<any>;
  394. flatten(shallow?: boolean): /*this*/List<any>;
  395. }
  396. declare class Map<K,V> extends KeyedCollection<K,V> {
  397. static <K, V>(): Map<K, V>;
  398. static <V>(obj?: {[key: string]: V}): Map<string, V>;
  399. static <K, V>(iterable?: ESIterable<[K,V]>): Map<K, V>;
  400. static isMap(maybeMap: any): boolean;
  401. set<K_, V_>(key: K_, value: V_): Map<K|K_, V|V_>;
  402. delete(key: K): this;
  403. remove(key: K): this;
  404. clear(): this;
  405. update<K_,V_>(updater: (value: this) => Map<K_,V_>): Map<K_,V_>;
  406. update<V_>(key: K, updater: (value: V) => V_): Map<K,V|V_>;
  407. update<V_>(key: K, notSetValue: V_, updater: (value: V) => V_): Map<K,V|V_>;
  408. merge<K_,V_>(
  409. ...iterables: (ESIterable<[K_,V_]> | { [key: K_]: V_ })[]
  410. ): Map<K|K_,V|V_>;
  411. mergeWith<K_,W,X>(
  412. merger: (previous: V, next: W, key: number) => X,
  413. ...iterables: ESIterable<W>[]
  414. ): Map<K,V|W|X>;
  415. mergeDeep<K_,V_>(
  416. ...iterables: (ESIterable<[K_,V_]> | { [key: K_]: V_ })[]
  417. ): Map<K|K_,V|V_>;
  418. mergeDeepWith<K_,W,X>(
  419. merger: (previous: V, next: W, key: number) => X,
  420. ...iterables: ESIterable<W>[]
  421. ): Map<K,V|W|X>;
  422. setIn(keyPath: ESIterable<any>, value: any): Map<K,V>;
  423. deleteIn(keyPath: ESIterable<any>, value: any): this;
  424. removeIn(keyPath: ESIterable<any>, value: any): this;
  425. updateIn(keyPath: ESIterable<any>, notSetValue: any, value: any): Map<K,V>;
  426. updateIn(keyPath: ESIterable<any>, value: any): Map<K,V>;
  427. mergeIn(keyPath: ESIterable<any>, ...iterables: ESIterable<any>[]): Map<K,V>;
  428. mergeDeepIn(keyPath: ESIterable<any>, ...iterables: ESIterable<any>[]): Map<K,V>;
  429. withMutations(mutator: (mutable: this) => any): this;
  430. asMutable(): this;
  431. asImmutable(): this;
  432. // Overrides that specialize return types
  433. map<V_>(
  434. mapper: (value: V, key: K, iter: this) => V_,
  435. context?: any
  436. ): Map<K,V_>;
  437. flatMap<K_,V_>(
  438. mapper: (value: V, key: K, iter: this) => ESIterable<[K_,V_]>,
  439. context?: any
  440. ): Map<K_,V_>;
  441. flip(): Map<V,K>;
  442. mapKeys<K_>(
  443. mapper: (key: K, value: V, iter: this) => K_,
  444. context?: any
  445. ): Map<K_,V>;
  446. flatten(depth?: number): /*this*/Map<any,any>;
  447. flatten(shallow?: boolean): /*this*/Map<any,any>;
  448. }
  449. // OrderedMaps have nothing that Maps do not have. We do not need to override constructor & other statics
  450. declare class OrderedMap<K,V> extends Map<K,V> {
  451. static isOrderedMap(maybeOrderedMap: any): bool;
  452. }
  453. declare class Set<T> extends SetCollection<T> {
  454. static <T>(iterable?: ESIterable<T>): Set<T>;
  455. static isSet(maybeSet: any): boolean;
  456. static of<T>(...values: T[]): Set<T>;
  457. static fromKeys<T>(iter: ESIterable<[T,any]>): Set<T>;
  458. static fromKeys(iter: { [key: string]: any }): Set<string>;
  459. add<U>(value: U): Set<T|U>;
  460. delete(value: T): this;
  461. remove(value: T): this;
  462. clear(): this;
  463. union<U>(...iterables: ESIterable<U>[]): Set<T|U>;
  464. merge<U>(...iterables: ESIterable<U>[]): Set<T|U>;
  465. intersect<U>(...iterables: ESIterable<U>[]): Set<T&U>;
  466. subtract<U>(...iterables: ESIterable<U>[]): Set<T>;
  467. withMutations(mutator: (mutable: this) => any): this;
  468. asMutable(): this;
  469. asImmutable(): this;
  470. // Overrides that specialize return types
  471. map<M>(
  472. mapper: (value: T, value: T, iter: this) => M,
  473. context?: any
  474. ): Set<M>;
  475. flatMap<M>(
  476. mapper: (value: T, value: T, iter: this) => ESIterable<M>,
  477. context?: any
  478. ): Set<M>;
  479. flatten(depth?: number): /*this*/Set<any>;
  480. flatten(shallow?: boolean): /*this*/Set<any>;
  481. }
  482. // OrderedSets have nothing that Sets do not have. We do not need to override constructor & other statics
  483. declare class OrderedSet<T> extends Set<T> {
  484. static isOrderedSet(maybeOrderedSet: any): bool;
  485. }
  486. declare class Stack<T> extends IndexedCollection<T> {
  487. static <T>(iterable?: ESIterable<T>): Stack<T>;
  488. static isStack(maybeStack: any): boolean;
  489. static of<T>(...values: T[]): Stack<T>;
  490. peek(): T;
  491. clear(): this;
  492. unshift<U>(...values: U[]): Stack<T|U>;
  493. unshiftAll<U>(iter: ESIterable<U>): Stack<T|U>;
  494. shift(): this;
  495. push<U>(...values: U[]): Stack<T|U>;
  496. pushAll<U>(iter: ESIterable<U>): Stack<T|U>;
  497. pop(): this;
  498. withMutations(mutator: (mutable: this) => any): this;
  499. asMutable(): this;
  500. asImmutable(): this;
  501. // Overrides that specialize return types
  502. map<U>(
  503. mapper: (value: T, index: number, iter: this) => U,
  504. context?: any
  505. ): Stack<U>;
  506. flatMap<U>(
  507. mapper: (value: T, index: number, iter: this) => ESIterable<U>,
  508. context?: any
  509. ): Stack<U>;
  510. flatten(depth?: number): /*this*/Stack<any>;
  511. flatten(shallow?: boolean): /*this*/Stack<any>;
  512. }
  513. declare function Range(start?: number, end?: number, step?: number): IndexedSeq<number>;
  514. declare function Repeat<T>(value: T, times?: number): IndexedSeq<T>;
  515. //TODO: Once flow can extend normal Objects we can change this back to actually reflect Record behavior.
  516. // For now fallback to any to not break existing Code
  517. declare class Record<T: Object> {
  518. static <T: Object>(spec: T, name?: string): /*T & Record<T>*/any;
  519. get<A>(key: $Keys<T>): A;
  520. set<A>(key: $Keys<T>, value: A): /*T & Record<T>*/this;
  521. remove(key: $Keys<T>): /*T & Record<T>*/this;
  522. }
  523. declare function fromJS(json: any, reviver?: (k: any, v: Iterable<any,any>) => any): any;
  524. declare function is(first: any, second: any): boolean;
  525. export {
  526. Iterable,
  527. Collection,
  528. Seq,
  529. // These classes do not actually exist under these names. But it is useful to
  530. // have the types available.
  531. KeyedIterable,
  532. IndexedIterable,
  533. SetIterable,
  534. KeyedCollection,
  535. IndexedCollection,
  536. SetCollection,
  537. KeyedSeq,
  538. IndexedSeq,
  539. SetSeq,
  540. List,
  541. Map,
  542. OrderedMap,
  543. OrderedSet,
  544. Range,
  545. Repeat,
  546. Record,
  547. Set,
  548. Stack,
  549. fromJS,
  550. is,
  551. }