-
Notifications
You must be signed in to change notification settings - Fork 231
/
most.d.ts
426 lines (368 loc) · 12.9 KB
/
most.d.ts
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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
declare type SeedValue<S, V> = { seed: S, value: V };
declare type TimeValue<V> = { time: number, value: V };
declare interface Generator<A, B, C> {}
declare interface Iterable<A> { [Symbol.iterator](): IterableIterator<A> }
declare type CreateGenerator<A> = (...args: Array<any>) => Generator<A|Promise<A>, any, any>;
export interface 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 interface Task {
run(time: number): void;
error(time: number, e: Error): void;
dispose(): void;
}
export interface ScheduledTask {
task: Task;
run(): void;
error(err: Error): void;
dispose(): void;
}
export interface 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 interface Disposable<A> {
dispose(): void | Promise<A>;
}
export interface Source<A> {
run (sink: Sink<A>, scheduler: Scheduler): Disposable<A>;
}
export interface Observable<A> {
subscribe(subscriber: Subscriber<A>): Subscription<A>;
}
export interface Subscriber<A> {
next(value: A): void;
error(err: Error): void;
// complete value parameter is deprecated
complete(value?: A): void;
}
export interface Subscription<A> {
unsubscribe(): void;
}
export interface Stream<A> extends Source<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>;
join<B>(this: Stream<Stream<B>>): Stream<B>;
switch<B>(this: Stream<Stream<B>>): Stream<B>;
switchLatest<B>(this: Stream<Stream<B>>): Stream<B>;
continueWith(f: (a: any) => Stream<A>): Stream<A>;
concatMap<B>(f: (a: A) => Stream<B>): Stream<B>;
mergeConcurrently<B>(this: Stream<Stream<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<B extends A>(p: (val: A) => val is B): Stream<B>;
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>;
await<B>(this: Stream<Promise<B>>): Stream<B>;
awaitPromises<B>(this: Stream<Promise<B>>): Stream<B>;
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 interface DisposeFn {
(): void|Promise<any>;
}
export class Stream<A> {
source: Source<A>;
constructor(source: Source<A>);
}
export function just<A>(a: A): Stream<A>;
export function of<A>(a: A): Stream<A>;
export function empty(): Stream<any>;
export function never(): Stream<any>;
export function from<A>(as: ArrayLike<A> | Iterable<A> | Observable<A>): Stream<A>;
export function periodic<A>(period: number, a?: A): Stream<A>;
export function fromEvent<T extends Event>(event: string, target: any, useCapture?: boolean): Stream<T>;
export function fromEvent<T>(event: string, target: any): Stream<T>;
export function unfold<A, B, S>(f: (seed: S) => SeedValue<S, B|Promise<B>>, seed: S): Stream<B>;
export function iterate<A>(f: (a: A) => A|Promise<A>, a: A): Stream<A>;
export function generate<A>(g: CreateGenerator<A>, ...args: Array<any>): Stream<A>;
export function reduce<A, B>(f: (b: B, a: A) => B, b: B, s: Stream<A>): Promise<B>;
export function observe<A>(f: (a: A) => any, s: Stream<A>): Promise<any>;
export function forEach<A>(f: (a: A) => any, s: Stream<A>): Promise<any>;
export function drain<A>(s: Stream<A>): Promise<any>;
export function subscribe<A>(subscriber: Subscriber<A>, s: Stream<A>): Subscription<A>;
export function constant<A, B>(b: B, s: Stream<A>): Stream<B>;
export function map<A, B>(f: (a: A) => B, s: Stream<A>): Stream<B>;
export function tap<A>(f: (a: A) => any, s: Stream<A>): Stream<A>;
export function ap<A, B>(fs: Stream<(a: A) => B>, as: Stream<A> ): Stream<B>;
export function chain<A, B>(f: (a: A) => Stream<B>, s: Stream<A>): Stream<B>;
export function flatMap<A, B>(f: (a: A) => Stream<B>, s: Stream<A>): Stream<B>;
export function join<A>(s: Stream<Stream<A>>): Stream<A>;
export function switchLatest<A>(s: Stream<Stream<A>>): Stream<A>;
export function continueWith<A>(f: (a: any) => Stream<A>, s: Stream<A>): Stream<A>;
export function concatMap<A, B>(f: (a: A) => Stream<B>, s: Stream<A>): Stream<B>;
export function mergeConcurrently<A>(concurrency: number, s: Stream<Stream<A>>): Stream<A>;
export function merge<A>(...ss: Array<Stream<A>>): Stream<A>;
export function mergeArray<A>(streams: Array<Stream<A>>): Stream<A>;
export function combine<A, B, R>(
fn: (a: A, b: B) => R,
a: Stream<A>,
b: Stream<B>
): Stream<R>;
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>;
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>;
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>;
export function combineArray<A, B, R>(
fn: (a: A, b: B) => R,
streams: [Stream<A>, Stream<B>]
): Stream<R>;
export function combineArray<A, B, C, R>(
fn: (a: A, b: B, c: C) => R,
streams: [Stream<A>, Stream<B>, Stream<C>]
): Stream<R>;
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>;
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>;
export function combineArray<V, R> (
fn: (...items: V[]) => R,
items: Stream<V>[]
): Stream<R>;
export function scan<A, B>(f: (b: B, a: A) => B, b: B, s: Stream<A>): Stream<B>;
export function loop<A, B, S>(f: (seed: S, a: A) => SeedValue<S, B>, seed: S, s: Stream<A>): Stream<B>;
export function concat<A>(s1: Stream<A>, s2: Stream<A>): Stream<A>;
export function startWith<A>(a: A, s: Stream<A>): Stream<A>;
export function filter<A, B extends A>(
p: (val: A) => val is B,
s: Stream<A>
): Stream<B>;
export function filter<A>(p: (a: A) => boolean, s: Stream<A>): Stream<A>;
export function skipRepeats<A>(s: Stream<A>): Stream<A>;
export function skipRepeatsWith<A>(eq: (a1: A, a2: A) => boolean, s: Stream<A>): Stream<A>;
export function take<A>(n: number, s: Stream<A>): Stream<A>;
export function skip<A>(n: number, s: Stream<A>): Stream<A>;
export function takeWhile<A>(p: (a: A) => boolean, s: Stream<A>): Stream<A>;
export function skipWhile<A>(p: (a: A) => boolean, s: Stream<A>): Stream<A>;
export function skipAfter<A>(p: (a: A) => boolean, s: Stream<A>): Stream<A>;
export function slice<A>(start: number, end: number, s: Stream<A>): Stream<A>;
export function until<A>(signal: Stream<any>, s: Stream<A>): Stream<A>;
export function takeUntil<A>(signal: Stream<any>, s: Stream<A>): Stream<A>;
export function since<A>(signal: Stream<any>, s: Stream<A>): Stream<A>;
export function skipUntil<A>(signal: Stream<any>, s: Stream<A>): Stream<A>;
export function during<A>(timeWindow: Stream<Stream<any>>, s: Stream<A>): Stream<A>;
export function throttle<A>(period: number, s: Stream<A>): Stream<A>;
export function debounce<A>(period: number, s: Stream<A>): Stream<A>;
export function timestamp<A>(s: Stream<A>): Stream<TimeValue<A>>;
export function delay<A>(dt: number, s: Stream<A>): Stream<A>;
export function fromPromise<A>(p: Promise<A>): Stream<A>;
export function await<A>(s: Stream<Promise<A>>): Stream<A>;
export function awaitPromises<A>(s: Stream<Promise<A>>): Stream<A>;
export function sample<A, B, R>(
fn: (a: A, b: B) => R,
sampler: Stream<any>,
a: Stream<A>,
b: Stream<B>
): Stream<R>;
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>;
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>;
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>;
export function sampleWith<A>(sampler: Stream<any>, s: Stream<A>): Stream<A>;
export function zip<A, B, R>(
fn: (a: A, b: B) => R,
a: Stream<A>,
b: Stream<B>
): Stream<R>;
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>;
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>;
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>;
export function recoverWith<A, B, C>(p: (a: B) => Stream<C>, s: Stream<A>): Stream<A | C>;
export function throwError(e: Error): Stream<any>;
export function multicast<A>(s: Stream<A>): Stream<A>;
declare const defaultScheduler: Scheduler;
export { defaultScheduler }
export class PropagateTask<T> implements Task {
protected _run: (time: number, value: T, sink: Sink<T>) => any
protected value: T;
protected sink: Sink<T>;
protected active: boolean;
constructor (run: (time: number, value: T, sink: Sink<T>) => any, value: T, sink: Sink<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>;
run(time: number): void;
error(time: number, e: Error): void;
dispose(): void;
}