index.js.flow 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. // @flow
  2. import type { Stream, Sink, Scheduler, Task, Disposable, Time, Period, Delay } from '@most/types'
  3. export type SeedValue <S, A> = {
  4. seed: S,
  5. value: A
  6. }
  7. declare export function runEffects <A> (s: Stream<A>, scheduler: Scheduler): Promise<void>
  8. declare export function runEffects <A> (s: Stream<A>): (scheduler: Scheduler) => Promise<void>
  9. declare export function run <A> (sink: Sink<A>, scheduler: Scheduler, s: Stream<A>): Disposable
  10. declare export function run <A> (sink: Sink<A>): (scheduler: Scheduler, s: Stream<A>) => Disposable
  11. declare export function run <A> (sink: Sink<A>, scheduler: Scheduler): (s: Stream<A>) => Disposable
  12. declare export function run <A> (sink: Sink<A>): (scheduler: Scheduler) => (s: Stream<A>) => Disposable
  13. declare export function empty (): Stream<any>
  14. declare export function never (): Stream<any>
  15. declare export function now <A> (a: A): Stream<A>
  16. declare export function at <A> (t: Time, a: A): Stream<A>
  17. declare export function at <A> (t: Time): (a: A) => Stream<A>
  18. export type RunStream<A> = (sink: Sink<A>, scheduler: Scheduler) => Disposable
  19. declare export function newStream <A> (run: RunStream<A>): Stream<A>
  20. declare export function startWith <A> (a: A, s: Stream<A>): Stream<A>
  21. declare export function startWith <A> (a: A): (s: Stream<A>) => Stream<A>
  22. declare export function periodic (period: Period): Stream<void>
  23. declare export function map <A, B> (f: (A) => B, s: Stream<A>): Stream<B>
  24. declare export function map <A, B> (f: (A) => B): (s: Stream<A>) => Stream<B>
  25. declare export function constant <A, B> (a: A, s: Stream<B>): Stream<A>
  26. declare export function constant <A, B> (a: A): (s: Stream<B>) => Stream<A>
  27. declare export function tap <A> (f: (A) => any, s: Stream<A>): Stream<A>
  28. declare export function tap <A> (f: (A) => any): (s: Stream<A>) => Stream<A>
  29. declare export function scan <A, B> (f: (B, A) => B, b: B, s: Stream<A>): Stream<B>
  30. declare export function scan <A, B> (f: (B, A) => B): (b: B, s: Stream<A>) => Stream<B>
  31. declare export function scan <A, B> (f: (B, A) => B, b: B): (s: Stream<A>) => Stream<B>
  32. declare export function scan <A, B> (f: (B, A) => B): (b: B) => (s: Stream<A>) => Stream<B>
  33. declare export function loop <A, B, S> (f: (S, A) => SeedValue<S, B>, seed: S, s: Stream<A>): Stream<B>
  34. declare export function loop <A, B, S> (f: (S, A) => SeedValue<S, B>): (seed: S, s: Stream<A>) => Stream<B>
  35. declare export function loop <A, B, S> (f: (S, A) => SeedValue<S, B>, seed: S): (s: Stream<A>) => Stream<B>
  36. declare export function loop <A, B, S> (f: (S, A) => SeedValue<S, B>): (seed: S) => (s: Stream<A>) => Stream<B>
  37. declare export function ap <A, B> (fs: Stream<(A) => B>, s: Stream<A>): Stream<B>
  38. declare export function ap <A, B> (fs: Stream<(A) => B>): (s: Stream<A>) => Stream<B>
  39. declare export function chain <A, B> (f: (A) => Stream<B>, s: Stream<A>): Stream<B>
  40. declare export function chain <A, B> (f: (A) => Stream<B>): (s: Stream<A>) => Stream<B>
  41. declare export function join <A> (s: Stream<Stream<A>>): Stream<A>
  42. declare export function concatMap <A, B> (f: (A) => Stream<B>, s: Stream<A>): Stream<B>
  43. declare export function concatMap <A, B> (f: (A) => Stream<B>): (s: Stream<A>) => Stream<B>
  44. declare export function mergeConcurrently <A> (concurrency: number, s: Stream<Stream<A>>): Stream<A>
  45. declare export function mergeConcurrently <A> (concurrency: number): (s: Stream<Stream<A>>) => Stream<A>
  46. declare export function mergeMapConcurrently <A, B> (f: (A) => Stream<B>, concurrency: number, s: Stream<A>): Stream<B>
  47. declare export function mergeMapConcurrently <A, B> (f: (A) => Stream<B>, concurrency: number): (s: Stream<A>) => Stream<B>
  48. declare export function mergeMapConcurrently <A, B> (f: (A) => Stream<B>): {
  49. (concurrency: number, s: Stream<A>): Stream<B>,
  50. (concurrency: number): (s: Stream<A>) => Stream<B>
  51. }
  52. declare export function continueWith <A> (f: (any) => Stream<A>, s: Stream<A>): Stream<A>
  53. declare export function continueWith <A> (f: (any) => Stream<A>): (s: Stream<A>) => Stream<A>
  54. declare export function switchLatest <A> (s: Stream<Stream<A>>): Stream<A>
  55. declare export function merge <A, B> (s1: Stream<A>, s2: Stream<B>): Stream<A | B>
  56. declare export function merge <A, B> (s1: Stream<A>): (s2: Stream<B>) => Stream<A | B>
  57. type MergeArray = <A>($ReadOnlyArray<Stream<A>>) => Stream<A>
  58. declare export function mergeArray <S> (ss: S): $Call<MergeArray, S>
  59. declare export function sample <A> (values: Stream<A>, sampler: Stream<any>): Stream<A>
  60. declare export function sample <A> (values: Stream<A>): (sampler: Stream<any>) => Stream<A>
  61. declare export function snapshot <A, B, C> (f: (A, B) => C, values: Stream<A>, sampler: Stream<B>): Stream<C>
  62. declare export function snapshot <A, B, C> (f: (A, B) => C): (values: Stream<A>, sampler: Stream<B>) => Stream<C>
  63. declare export function snapshot <A, B, C> (f: (A, B) => C, values: Stream<A>): (sampler: Stream<B>) => Stream<C>
  64. declare export function snapshot <A, B, C> (f: (A, B) => C): (values: Stream<A>) => (sampler: Stream<B>) => Stream<C>
  65. declare export function combine <A, B, Z> (f: (A, B) => Z, sa: Stream<A>, sb: Stream<B>): Stream<Z>
  66. declare export function combine <A, B, Z> (f: (A, B) => Z): (sa: Stream<A>, sb: Stream<B>) => Stream<Z>
  67. declare export function combine <A, B, Z> (f: (A, B) => Z, sa: Stream<A>): (sb: Stream<B>) => Stream<Z>
  68. declare export function combine <A, B, Z> (f: (A, B) => Z): (sa: Stream<A>) => (sb: Stream<B>) => Stream<Z>
  69. declare export function combineArray <A, B, Z> (f: (A, B) => Z, ss: [Stream<A>, Stream<B>]): Stream<Z>
  70. declare export function combineArray <A, B, Z> (f: (A, B) => Z): (ss: [Stream<A>, Stream<B>]) => Stream<Z>
  71. declare export function combineArray <A, B, C, Z> (f: (A, B, C) => Z, ss: [Stream<A>, Stream<B>, Stream<C>]): Stream<Z>
  72. declare export function combineArray <A, B, C, Z> (f: (A, B, C) => Z): (ss: [Stream<A>, Stream<B>, Stream<C>]) => Stream<Z>
  73. declare export function combineArray <A, B, C, D, Z> (f: (A, B, C, D) => Z, ss: [Stream<A>, Stream<B>, Stream<C>, Stream<D>]): Stream<Z>
  74. declare export function combineArray <A, B, C, D, Z> (f: (A, B, C, D) => Z): (ss: [Stream<A>, Stream<B>, Stream<C>, Stream<D>]) => Stream<Z>
  75. declare export function combineArray <A, B, C, D, E, Z> (f: (A, B, C, D, E) => Z, ss: [Stream<A>, Stream<B>, Stream<C>, Stream<D>, Stream<E>]): Stream<Z>
  76. declare export function combineArray <A, B, C, D, E, Z> (f: (A, B, C, D, E) => Z): (ss: [Stream<A>, Stream<B>, Stream<C>, Stream<D>, Stream<E>]) => Stream<Z>
  77. declare export function combineArray <A, B, C, D, E, F, Z> (f: (A, B, C, D, E, F) => Z, ss: [Stream<A>, Stream<B>, Stream<C>, Stream<D>, Stream<E>, Stream<F>]): Stream<Z>
  78. declare export function combineArray <A, B, C, D, E, F, Z> (f: (A, B, C, D, E, F) => Z): (ss: [Stream<A>, Stream<B>, Stream<C>, Stream<D>, Stream<E>, Stream<F>]) => Stream<Z>
  79. // Catch-all combineArray
  80. declare export function combineArray <Z> (f: (...rest: Array<any>) => Z, ss: Array<Stream<any>>): Stream<Z>
  81. declare export function combineArray <Z> (f: (...rest: Array<any>) => Z): (ss: Array<Stream<any>>) => Stream<Z>
  82. declare export function zip <A, B, Z> (f: (A, B) => Z, sa: Stream<A>, sb: Stream<B>): Stream<Z>
  83. declare export function zip <A, B, Z> (f: (A, B) => Z): (sa: Stream<A>, sb: Stream<B>) => Stream<Z>
  84. declare export function zip <A, B, Z> (f: (A, B) => Z, sa: Stream<A>): (sb: Stream<B>) => Stream<Z>
  85. declare export function zip <A, B, Z> (f: (A, B) => Z): (sa: Stream<A>) => (sb: Stream<B>) => Stream<Z>
  86. declare export function zipArray <A, B, Z> (f: (A, B) => Z, ss: [Stream<A>, Stream<B>]): Stream<Z>
  87. declare export function zipArray <A, B, Z> (f: (A, B) => Z): (ss: [Stream<A>, Stream<B>]) => Stream<Z>
  88. declare export function zipArray <A, B, C, Z> (f: (A, B, C) => Z, ss: [Stream<A>, Stream<B>, Stream<C>]): Stream<Z>
  89. declare export function zipArray <A, B, C, Z> (f: (A, B, C) => Z): (ss: [Stream<A>, Stream<B>, Stream<C>]) => Stream<Z>
  90. declare export function zipArray <A, B, C, D, Z> (f: (A, B, C, D) => Z, ss: [Stream<A>, Stream<B>, Stream<C>, Stream<D>]): Stream<Z>
  91. declare export function zipArray <A, B, C, D, Z> (f: (A, B, C, D) => Z): (ss: [Stream<A>, Stream<B>, Stream<C>, Stream<D>]) => Stream<Z>
  92. declare export function zipArray <A, B, C, D, E, Z> (f: (A, B, C, D, E) => Z, ss: [Stream<A>, Stream<B>, Stream<C>, Stream<D>, Stream<E>]): Stream<Z>
  93. declare export function zipArray <A, B, C, D, E, Z> (f: (A, B, C, D, E) => Z): (ss: [Stream<A>, Stream<B>, Stream<C>, Stream<D>, Stream<E>]) => Stream<Z>
  94. declare export function zipArray <A, B, C, D, E, F, Z> (f: (A, B, C, D, E, F) => Z, ss: [Stream<A>, Stream<B>, Stream<C>, Stream<D>, Stream<E>, Stream<F>]): Stream<Z>
  95. declare export function zipArray <A, B, C, D, E, F, Z> (f: (A, B, C, D, E, F) => Z): (ss: [Stream<A>, Stream<B>, Stream<C>, Stream<D>, Stream<E>, Stream<F>]) => Stream<Z>
  96. // Catch-all zipArray
  97. declare export function zipArray <Z> (f: (...rest: Array<any>) => Z, ss: Array<Stream<any>>): Stream<Z>
  98. declare export function zipArray <Z> (f: (...rest: Array<any>) => Z): (ss: Array<Stream<any>>) => Stream<Z>
  99. declare export function withItems <A> (a: Array<A>, s: Stream<any>): Stream<A>
  100. declare export function withItems <A> (a: Array<A>): (s: Stream<any>) => Stream<A>
  101. declare export function zipItems <A, B, C> (f: (A, B) => C, a: Array<A>, s: Stream<B>): Stream<C>
  102. declare export function zipItems <A, B, C> (f: (A, B) => C): (a: Array<A>, s: Stream<B>) => Stream<C>
  103. declare export function zipItems <A, B, C> (f: (A, B) => C, a: Array<A>): (s: Stream<B>) => Stream<C>
  104. declare export function zipItems <A, B, C> (f: (A, B) => C): (a: Array<A>) => (s: Stream<B>) => Stream<C>
  105. declare export function filter <A> (p: (A) => boolean, s: Stream<A>): Stream<A>
  106. declare export function filter <A> (p: (A) => boolean): (s: Stream<A>) => Stream<A>
  107. declare export function skipRepeats <A> (s: Stream<A>): Stream<A>
  108. declare export function skipRepeatsWith <A> (equals: (a1: A, a2: A) => boolean, s: Stream<A>): Stream<A>
  109. declare export function skipRepeatsWith <A> (equals: (a1: A, a2: A) => boolean): (s: Stream<A>) => Stream<A>
  110. declare export function take <A> (n: number, s: Stream<A>): Stream<A>
  111. declare export function take <A> (n: number): (s: Stream<A>) => Stream<A>
  112. declare export function skip <A> (n: number, s: Stream<A>): Stream<A>
  113. declare export function skip <A> (n: number): (s: Stream<A>) => Stream<A>
  114. declare export function slice <A> (start: number, end: number, s: Stream<A>): Stream<A>
  115. declare export function slice <A> (start: number): (end: number, s: Stream<A>) => Stream<A>
  116. declare export function slice <A> (start: number, end: number): (s: Stream<A>) => Stream<A>
  117. declare export function slice <A> (start: number): (end: number) => (s: Stream<A>) => Stream<A>
  118. declare export function takeWhile <A> (p: (A) => boolean, s: Stream<A>): Stream<A>
  119. declare export function takeWhile <A> (p: (A) => boolean): (s: Stream<A>) => Stream<A>
  120. declare export function skipWhile <A> (p: (A) => boolean, s: Stream<A>): Stream<A>
  121. declare export function skipWhile <A> (p: (A) => boolean): (s: Stream<A>) => Stream<A>
  122. declare export function skipAfter <A> (p: (A) => boolean, s: Stream<A>): Stream<A>
  123. declare export function skipAfter <A> (p: (A) => boolean): (s: Stream<A>) => Stream<A>
  124. declare export function until <A> (until: Stream<any>, s: Stream<A>): Stream<A>
  125. declare export function until <A> (until: Stream<any>): (s: Stream<A>) => Stream<A>
  126. declare export function since <A> (since: Stream<any>, s: Stream<A>): Stream<A>
  127. declare export function since <A> (since: Stream<any>): (s: Stream<A>) => Stream<A>
  128. declare export function during <A> (since: Stream<Stream<any>>, s: Stream<A>): Stream<A>
  129. declare export function withLocalTime <A> (origin: Time, s: Stream<A>): Stream<A>
  130. declare export function withLocalTime <A> (origin: Time): (s: Stream<A>) => Stream<A>
  131. declare export function delay <A> (delay: Delay, s: Stream<A>): Stream<A>
  132. declare export function delay <A> (delay: Delay): (s: Stream<A>) => Stream<A>
  133. declare export function throttle <A> (period: Period, s: Stream<A>): Stream<A>
  134. declare export function throttle <A> (period: Period): (s: Stream<A>) => Stream<A>
  135. declare export function debounce <A> (period: Period, s: Stream<A>): Stream<A>
  136. declare export function debounce <A> (period: Period): (s: Stream<A>) => Stream<A>
  137. declare export function fromPromise <A> (pa: Promise<A>): Stream<A>
  138. declare export function awaitPromises <A> (spa: Stream<Promise<A>>): Stream<A>
  139. declare export function recoverWith <A, E:Error> (f: (E) => Stream<A>, s: Stream<A>): Stream<A>
  140. declare export function recoverWith <A, E:Error> (f: (E) => Stream<A>): (s: Stream<A>) => Stream<A>
  141. declare export function throwError <E:Error> (e: Error): Stream<any>
  142. declare export function multicast <A> (s: Stream<A>): Stream<A>
  143. declare export class MulticastSource <A> {
  144. source: Stream<A>;
  145. sinks: Array<Sink<A>>;
  146. disposable: Disposable;
  147. constructor(Stream<A>): MulticastSource<A>;
  148. run(Sink<A>, Scheduler): Disposable;
  149. event(Time, A): void;
  150. error(Time, Error): void;
  151. end(Time): void;
  152. add(Sink<A>): number;
  153. remove(Sink<A>): number;
  154. dispose(): void;
  155. }
  156. export type PropagateTask<A, B> = Task & {
  157. value: A,
  158. sink: Sink<B>,
  159. active: boolean
  160. }
  161. export type PropagateTaskRun<A, B> = (time: Time, value: A, sink: Sink<B>) => any
  162. declare export function propagateTask<A, B> (run: PropagateTaskRun<A, B>, value: A, sink: Sink<B>): PropagateTask<A, B>
  163. declare export function propagateEventTask<A> (value: A, sink: Sink<A>): PropagateTask<A, A>
  164. declare export function propagateErrorTask<E: Error> (e: E, sink: Sink<any>): PropagateTask<any, any>
  165. declare export function propagateEndTask (sink: Sink<any>): PropagateTask<void, void>