Last active
January 10, 2017 19:37
-
-
Save briancavalier/e288e28e2bc2d2c84d91 to your computer and use it in GitHub Desktop.
Beginnings of a flow type declaration file for most.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*@flow*/ | |
export type SeedValue<S, V> = { seed: S, value: V }; | |
export type TimeValue<V> = { time: number, value: V }; | |
type CreateGenerator<A> = (...args:Array<any>) => Generator<A|Promise<A>, any, any> | |
export type Stream<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>; | |
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>; | |
// Note: Without higher-kinded types, the types for these | |
// cannot be written properly | |
ap<B, C>(bs:Stream<B>): Stream<C>; | |
join<B>(): Stream<B>; | |
switch<B>(): Stream<B>; | |
switchLatest<B>(): Stream<B>; | |
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>; | |
combine<B>(f:(a:A, ...args:Array<any>) => B, ...ss:Array<Stream<any>>): Stream<B>; | |
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>; | |
cycle(): Stream<A>; | |
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>; | |
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>; | |
// Note: Without higher-kinded types, this type cannot be written properly | |
awaitPromises<B>(): Stream<B>; | |
sample<B>(f:(...as:any) => B, ...ss:Array<Stream<any>>): Stream<B>; | |
sampleWith(sampler:Stream<any>): Stream<A>; | |
zip(f:(a:A, ...as:any) => A, ...ss:Array<Stream<any>>): Stream<A>; | |
recoverWith<B>(p:(a:B) => A): Stream<A>; | |
multicast(): Stream<A>; | |
}; | |
declare module 'most' { | |
declare function just<A>(a:A): Stream<A>; | |
declare function of<A>(a:A): Stream<A>; | |
declare function from<A>(as:Iterable<A>): Stream<A>; | |
declare function periodic<A>(period:number, a:?A): Stream<?A>; | |
declare function unfold<A, B, S>(f:(seed:S) => SeedValue<S, B|Promise<B>>, seed:S): Stream<B>; | |
declare function iterate<A>(f:(a:A) => A|Promise<A>, a:A): Stream<A>; | |
declare function generate<A>(g:CreateGenerator<A>, ...args:Array<any>): Stream<A> | |
declare function reduce<A, B>(f:(b:B, a:A) => B, b:B, s:Stream<A>): Promise<B>; | |
declare function observe<A>(f:(a:A) => any, s:Stream<A>): Promise<any>; | |
declare function forEach<A>(f:(a:A) => any, s:Stream<A>): Promise<any>; | |
declare function drain<A>(s:Stream<A>): Promise<any>; | |
declare function constant<A, B>(b:B, s:Stream<A>): Stream<B>; | |
declare function map<A, B>(f:(a:A) => B, s:Stream<A>): Stream<B>; | |
declare function tap<A>(f:(a:A) => any, s:Stream<A>): Stream<A>; | |
declare function ap<A, B>(fs:Stream<(a:A)=>B>, as:Stream<A>): Stream<B>; | |
declare function chain<A, B>(f:(a:A) => Stream<B>, s:Stream<A>): Stream<B>; | |
declare function flatMap<A, B>(f:(a:A) => Stream<B>, s:Stream<A>): Stream<B>; | |
declare function join<A>(s:Stream<Stream<A>>): Stream<A>; | |
declare function switchLatest<A>(s:Stream<Stream<A>>): Stream<A>; | |
declare function continueWith<A>(f:(a:any) => Stream<A>, s:Stream<A>): Stream<A>; | |
declare function concatMap<A, B>(f:(a:A) => Stream<B>, s:Stream<A>): Stream<B>; | |
declare function mergeConcurrently<A>(concurrency:number, s:Stream<Stream<A>>): Stream<A>; | |
declare function merge<A>(...ss:Array<Stream<A>>): Stream<A>; | |
declare function combine<A>(f:(...args:Array<any>) => A, ...ss:Array<Stream<any>>): Stream<A>; | |
declare function scan<A, B>(f:(b:B, a:A) => B, b:B, s:Stream<A>): Stream<B>; | |
declare function loop<A, B, S>(f:(seed:S, a:A) => SeedValue<S, B>, seed:S, s:Stream<A>): Stream<B>; | |
declare function cycle<A>(s:Stream<A>): Stream<A>; | |
declare function concat<A>(s1:Stream<A>, s2:Stream<A>): Stream<A>; | |
declare function startWith<A>(a:A, s:Stream<A>): Stream<A>; | |
declare function filter<A>(p:(a:A) => boolean, s:Stream<A>) : Stream<A>; | |
declare function skipRepeats<A>(s:Stream<A>): Stream<A>; | |
declare function skipRepeatsWith<A>(eq:(a1:A, a2:A) => boolean, s:Stream<A>) : Stream<A>; | |
declare function take<A>(n:number, s:Stream<A>): Stream<A>; | |
declare function skip<A>(n:number, s:Stream<A>): Stream<A>; | |
declare function takeWhile<A>(p:(a:A) => boolean, s:Stream<A>): Stream<A>; | |
declare function skipWhile<A>(p:(a:A) => boolean, s:Stream<A>): Stream<A>; | |
declare function slice<A>(start:number, end:number, s:Stream<A>): Stream<A>; | |
declare function until<A>(signal:Stream<any>, s:Stream<A>): Stream<A>; | |
declare function takeUntil<A>(signal:Stream<any>, s:Stream<A>): Stream<A>; | |
declare function since<A>(signal:Stream<any>, s:Stream<A>): Stream<A>; | |
declare function skipUntil<A>(signal:Stream<any>, s:Stream<A>): Stream<A>; | |
declare function during<A>(timeWindow:Stream<Stream<any>>, s:Stream<A>): Stream<A>; | |
declare function throttle<A>(period:number, s:Stream<A>): Stream<A>; | |
declare function debounce<A>(period:number, s:Stream<A>): Stream<A>; | |
declare function timestamp<A>(s:Stream<A>): Stream<TimeValue<A>>; | |
declare function delay<A>(dt:number, s:Stream<A>): Stream<A>; | |
declare function fromPromise<A>(p:Promise<A>): Stream<A>; | |
declare function awaitPromises<A>(s:Stream<Promise<A>>): Stream<A>; | |
declare function sample<A>(f:(...as:any) => A, sampler:Stream<any>, ...ss:Array<Stream<any>>): Stream<A>; | |
declare function sampleWith<A>(sampler:Stream<any>, s:Stream<A>): Stream<A>; | |
declare function zip<A>(f:(...as:any) => A, ...ss:Array<Stream<any>>): Stream<A>; | |
declare function recoverWith<A, B>(p:(a:B) => A, s:Stream<A>): Stream<A>; | |
declare function throwError(e:Error): Stream<any>; | |
declare function multicast<A>(s:Stream<A>): Stream<A>; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment