-
Notifications
You must be signed in to change notification settings - Fork 206
/
index.js.flow
400 lines (348 loc) · 12.7 KB
/
index.js.flow
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
// @flow
declare type SeedValue<S, V> = { seed: S, value: V };
declare type TimeValue<V> = { time: number, value: V };
declare type CreateGenerator<A> = (...args: Array<any>) => Generator<A|Promise<A>, any, any>;
export type Sink<A> = {
event(time: number, value: A): void;
// end value parameter is deprecated
end(time: number, value?: A): void;
error(time: number, err: Error): void;
}
export type Task = {
run(time: number): void;
error(time: number, e: Error): void;
dispose(): void;
}
export type ScheduledTask = {
task: Task;
run(): void;
error(err: Error): void;
dispose(): void;
}
export type Scheduler = {
now(): number;
asap(task: Task): ScheduledTask;
delay(delay: number, task: Task): ScheduledTask;
periodic(period: number, task: Task): ScheduledTask;
schedule(delay: number, period: number, task: Task): ScheduledTask;
cancel(task: Task): void;
cancelAll(predicate: (task: Task) => boolean): void;
}
export type Disposable<A> = {
dispose(): void | Promise<A>;
}
export type Source<A> = {
run (sink: Sink<A>, scheduler: Scheduler): Disposable<A>;
}
export type Observable<A> = {
subscribe(subscriber: Subscriber<A>): Subscription<A>;
}
export type Subscriber<A> = {
+next?: (value: A) => void;
+error?: (err: Error) => void;
// complete value parameter is deprecated
+complete?: (value?: A) => void;
}
export type Subscription<A> = {
unsubscribe(): void;
}
declare export class Stream<A> {
constructor(source: Source<A>): Stream<A>;
source: Source<A>;
run (sink: Sink<A>, scheduler: Scheduler): Disposable<A>;
reduce<B>(f: (b: B, a: A) => B, b: B): Promise<B>;
observe(f: (a: A) => any): Promise<any>;
forEach(f: (a: A) => any): Promise<any>;
drain(): Promise<any>;
subscribe(subscriber: Subscriber<A>): Subscription<A>;
constant<B>(b: B): Stream<B>;
map<B>(f: (a: A) => B): Stream<B>;
tap(f: (a: A) => any): Stream<A>;
chain<B>(f: (a: A) => Stream<B>): Stream<B>;
flatMap<B>(f: (a: A) => Stream<B>): Stream<B>;
ap<B, C>(fs: Stream<(a: A) => B>): Stream<C>;
continueWith(f: (a: any) => Stream<A>): Stream<A>;
concatMap<B>(f: (a: A) => Stream<B>): Stream<B>;
mergeConcurrently<B>(concurrency: number): Stream<B>;
merge(...ss: Array<Stream<A>>): Stream<A>;
mergeArray(streams: Array<Stream<A>>): Stream<A>;
combine<B, R>(
fn: (a: A, b: B) => R,
b: Stream<B>
): Stream<R>;
combine<B, C, R>(
fn: (a: A, b: B, c: C) => R,
b: Stream<B>,
c: Stream<C>
): Stream<R>;
combine<B, C, D, R>(
fn: (a: A, b: B, c: C, d: D) => R,
b: Stream<B>,
c: Stream<C>,
d: Stream<D>
): Stream<R>;
combine<B, C, D, E, R>(
fn: (a: A, b: B, c: C, d: D, e: E) => R,
b: Stream<B>,
c: Stream<C>,
d: Stream<D>,
e: Stream<E>
): Stream<R>;
combineArray<B, R>(
fn: (a: A, b: B) => R,
streams: [Stream<B>]
): Stream<R>;
combineArray<B, C, R>(
fn: (a: A, b: B, c: C) => R,
streams: [Stream<B>, Stream<C>]
): Stream<R>;
combineArray<B, C, D, R>(
fn: (a: A, b: B, c: C, d: D) => R,
streams: [Stream<B>, Stream<C>, Stream<D>]
): Stream<R>;
combineArray<B, C, D, E, R>(
fn: (a: A, b: B, c: C, d: D, e: E) => R,
streams: [Stream<B>, Stream<C>, Stream<D>, Stream<E>]
): Stream<R>;
combineArray<V, R>(
fn: (a: A, ...rest: V[]) => R,
streams: Stream<V>[]
): Stream<R>;
scan<B>(f: (b: B, a: A) => B, b: B): Stream<B>;
loop<S, B>(f: (seed: S, a: A) => SeedValue<S, B>, seed: S): Stream<B>;
concat(s2: Stream<A>): Stream<A>;
startWith(a: A): Stream<A>;
filter(p: (a: A) => boolean): Stream<A>;
skipRepeats(): Stream<A>;
skipRepeatsWith(eq: (a1: A, a2: A) => boolean): Stream<A>;
take(n: number): Stream<A>;
skip(n: number): Stream<A>;
takeWhile(p: (a: A) => boolean): Stream<A>;
skipWhile(p: (a: A) => boolean): Stream<A>;
skipAfter(p: (a: A) => boolean): Stream<A>;
slice(start: number, end: number): Stream<A>;
until(signal: Stream<any>): Stream<A>;
takeUntil(signal: Stream<any>): Stream<A>;
since(signal: Stream<any>): Stream<A>;
skipUntil(signal: Stream<any>): Stream<A>;
during(timeWindow: Stream<Stream<any>>): Stream<A>;
throttle(period: number): Stream<A>;
debounce(period: number): Stream<A>;
timestamp(): Stream<TimeValue<A>>;
delay(dt: number): Stream<A>;
sample<B, C, R>(
fn: (b: B, c: C) => R,
b: Stream<B>,
c: Stream<C>
): Stream<R>;
sample<B, C, D, R>(
fn: (b: B, c: C, d: D) => R,
b: Stream<B>,
c: Stream<C>,
d: Stream<D>
): Stream<R>;
sample<B, C, D, E, R>(
fn: (b: B, c: C, d: D, e: E) => R,
b: Stream<B>,
c: Stream<C>,
d: Stream<D>,
e: Stream<E>
): Stream<R>;
sampleWith(sampler: Stream<any>): Stream<A>;
zip<B, R>(
fn: (a: A, b: B) => R,
b: Stream<B>
): Stream<R>;
zip<B, C, R>(
fn: (a: A, b: B, c: C) => R,
b: Stream<B>,
c: Stream<C>
): Stream<R>;
zip<B, C, D, R>(
fn: (a: A, b: B, c: C, d: D) => R,
b: Stream<B>,
c: Stream<C>,
d: Stream<D>
): Stream<R>;
zip<B, C, D, E, R>(
fn: (a: A, b: B, c: C, d: D, e: E) => R,
b: Stream<B>,
c: Stream<C>,
d: Stream<D>,
e: Stream<E>
): Stream<R>;
recoverWith<B, C>(p: (a: B) => Stream<C>): Stream<A | C>;
multicast(): Stream<A>;
thru<B>(transform: (stream: Stream<A>) => B): B;
}
declare export function just<A>(a: A): Stream<A>;
declare export function of<A>(a: A): Stream<A>;
declare export function empty(): Stream<any>;
declare export function never(): Stream<any>;
declare export function from<A>(as: A[] | Iterable<A> | Observable<A>): Stream<A>;
declare export function periodic<A>(period: number, a?: A): Stream<A>;
declare export function fromEvent<T: Event>(event: string, target: any, useCapture?: boolean): Stream<T>;
declare export function fromEvent<T>(event: string, target: any): Stream<T>;
declare export function unfold<A, B, S>(f: (seed: S) => SeedValue<S, B|Promise<B>>, seed: S): Stream<B>;
declare export function iterate<A>(f: (a: A) => A|Promise<A>, a: A): Stream<A>;
declare export function generate<A>(g: CreateGenerator<A>, ...args: Array<any>): Stream<A>;
declare export function reduce<A, B>(f: (b: B, a: A) => B, b: B, s: Stream<A>): Promise<B>;
declare export function observe<A>(f: (a: A) => any, s: Stream<A>): Promise<any>;
declare export function forEach<A>(f: (a: A) => any, s: Stream<A>): Promise<any>;
declare export function drain<A>(s: Stream<A>): Promise<any>;
declare export function subscribe<A>(subscriber: Subscriber<A>, s: Stream<A>): Subscription<A>;
declare export function constant<A, B>(b: B, s: Stream<A>): Stream<B>;
declare export function map<A, B>(f: (a: A) => B, s: Stream<A>): Stream<B>;
declare export function tap<A>(f: (a: A) => any, s: Stream<A>): Stream<A>;
declare export function ap<A, B>(fs: Stream<(a: A) => B>, as: Stream<A> ): Stream<B>;
declare export function chain<A, B>(f: (a: A) => Stream<B>, s: Stream<A>): Stream<B>;
declare export function flatMap<A, B>(f: (a: A) => Stream<B>, s: Stream<A>): Stream<B>;
declare export function join<A>(s: Stream<Stream<A>>): Stream<A>;
declare export function switchLatest<A>(s: Stream<Stream<A>>): Stream<A>;
declare export function continueWith<A>(f: (a: any) => Stream<A>, s: Stream<A>): Stream<A>;
declare export function concatMap<A, B>(f: (a: A) => Stream<B>, s: Stream<A>): Stream<B>;
declare export function mergeConcurrently<A>(concurrency: number, s: Stream<Stream<A>>): Stream<A>;
declare export function merge<A>(...ss: Array<Stream<A>>): Stream<A>;
declare export function mergeArray<A>(streams: Array<Stream<A>>): Stream<A>;
declare export function combine<A, B, R>(
fn: (a: A, b: B) => R,
a: Stream<A>,
b: Stream<B>
): Stream<R>;
declare export function combine<A, B, C, R>(
fn: (a: A, b: B, c: C) => R,
a: Stream<A>,
b: Stream<B>,
c: Stream<C>
): Stream<R>;
declare export function combine<A, B, C, D, R>(
fn: (a: A, b: B, c: C, d: D) => R,
a: Stream<A>,
b: Stream<B>,
c: Stream<C>,
d: Stream<D>
): Stream<R>;
declare export function combine<A, B, C, D, E, R>(
fn: (a: A, b: B, c: C, d: D, e: E) => R,
a: Stream<A>,
b: Stream<B>,
c: Stream<C>,
d: Stream<D>,
e: Stream<E>
): Stream<R>;
declare export function combineArray<A, B, R>(
fn: (a: A, b: B) => R,
streams: [Stream<A>, Stream<B>]
): Stream<R>;
declare export function combineArray<A, B, C, R>(
fn: (a: A, b: B, c: C) => R,
streams: [Stream<A>, Stream<B>, Stream<C>]
): Stream<R>;
declare export function combineArray<A, B, C, D, R>(
fn: (a: A, b: B, c: C, d: D) => R,
streams: [Stream<A>, Stream<B>, Stream<C>, Stream<D>]
): Stream<R>;
declare export function combineArray<A, B, C, D, E, R>(
fn: (a: A, b: B, c: C, d: D, e: E) => R,
streams: [Stream<A>, Stream<B>, Stream<C>, Stream<D>, Stream<E>]
): Stream<R>;
declare export function combineArray<V, R> (
fn: (...items: V[]) => R,
items: Stream<V>[]
): Stream<R>;
declare export function scan<A, B>(f: (b: B, a: A) => B, b: B, s: Stream<A>): Stream<B>;
declare export function loop<A, B, S>(f: (seed: S, a: A) => SeedValue<S, B>, seed: S, s: Stream<A>): Stream<B>;
declare export function concat<A>(s1: Stream<A>, s2: Stream<A>): Stream<A>;
declare export function startWith<A>(a: A, s: Stream<A>): Stream<A>;
declare export function filter<A>(p: (a: A) => boolean, s: Stream<A>): Stream<A>;
declare export function skipRepeats<A>(s: Stream<A>): Stream<A>;
declare export function skipRepeatsWith<A>(eq: (a1: A, a2: A) => boolean, s: Stream<A>): Stream<A>;
declare export function take<A>(n: number, s: Stream<A>): Stream<A>;
declare export function skip<A>(n: number, s: Stream<A>): Stream<A>;
declare export function takeWhile<A>(p: (a: A) => boolean, s: Stream<A>): Stream<A>;
declare export function skipWhile<A>(p: (a: A) => boolean, s: Stream<A>): Stream<A>;
declare export function skipAfter<A>(p: (a: A) => boolean, s: Stream<A>): Stream<A>;
declare export function slice<A>(start: number, end: number, s: Stream<A>): Stream<A>;
declare export function until<A>(signal: Stream<any>, s: Stream<A>): Stream<A>;
declare export function takeUntil<A>(signal: Stream<any>, s: Stream<A>): Stream<A>;
declare export function since<A>(signal: Stream<any>, s: Stream<A>): Stream<A>;
declare export function skipUntil<A>(signal: Stream<any>, s: Stream<A>): Stream<A>;
declare export function during<A>(timeWindow: Stream<Stream<any>>, s: Stream<A>): Stream<A>;
declare export function throttle<A>(period: number, s: Stream<A>): Stream<A>;
declare export function debounce<A>(period: number, s: Stream<A>): Stream<A>;
declare export function timestamp<A>(s: Stream<A>): Stream<TimeValue<A>>;
declare export function delay<A>(dt: number, s: Stream<A>): Stream<A>;
declare export function fromPromise<A>(p: Promise<A>): Stream<A>;
declare export function await<A>(s: Stream<Promise<A>>): Stream<A>;
declare export function awaitPromises<A>(s: Stream<Promise<A>>): Stream<A>;
declare export function sample<A, B, R>(
fn: (a: A, b: B) => R,
sampler: Stream<any>,
a: Stream<A>,
b: Stream<B>
): Stream<R>;
declare export function sample<A, B, C, R>(
fn: (a: A, b: B, c: C) => R,
sampler: Stream<any>,
a: Stream<A>,
b: Stream<B>,
c: Stream<C>
): Stream<R>;
declare export function sample<A, B, C, D, R>(
fn: (a: A, b: B, c: C, d: D) => R,
sampler: Stream<any>,
a: Stream<A>,
b: Stream<B>,
c: Stream<C>,
d: Stream<D>
): Stream<R>;
declare export function sample<A, B, C, D, E, R>(
fn: (a: A, b: B, c: C, d: D, e: E) => R,
sampler: Stream<any>,
a: Stream<A>,
b: Stream<B>,
c: Stream<C>,
d: Stream<D>,
e: Stream<E>
): Stream<R>;
declare export function sampleWith<A>(sampler: Stream<any>, s: Stream<A>): Stream<A>;
declare export function zip<A, B, R>(
fn: (a: A, b: B) => R,
a: Stream<A>,
b: Stream<B>
): Stream<R>;
declare export function zip<A, B, C, R>(
fn: (a: A, b: B, c: C) => R,
a: Stream<A>,
b: Stream<B>,
c: Stream<C>
): Stream<R>;
declare export function zip<A, B, C, D, R>(
fn: (a: A, b: B, c: C, d: D) => R,
a: Stream<A>,
b: Stream<B>,
c: Stream<C>,
d: Stream<D>
): Stream<R>;
declare export function zip<A, B, C, D, E, R>(
fn: (a: A, b: B, c: C, d: D, e: E) => R,
a: Stream<A>,
b: Stream<B>,
c: Stream<C>,
d: Stream<D>,
e: Stream<E>
): Stream<R>;
declare export function recoverWith<A, B, C>(p: (a: B) => Stream<C>, s: Stream<A>): Stream<A | C>;
declare export function throwError(e: Error): Stream<any>;
declare export function multicast<A>(s: Stream<A>): Stream<A>;
declare export var defaultScheduler: Scheduler;
declare export class PropagateTask<T> {
static event <T> (value: T, sink: Sink<T>): PropagateTask<T>;
static error (error: Error, sink: Sink<any>): PropagateTask<any>;
// end value parameter is deprecated
static end <T> (value: T, sink: Sink<T>): PropagateTask<T>;
constructor (run: (time: number, value: T, sink: Sink<T>) => any, value: T, sink: Sink<T>): PropagateTask<T>;
run(time: number): void;
error(time: number, e: Error): void;
dispose(): void;
}