UNPKG

2.79 kBTypeScriptView Raw
1// tslint:disable:strict-export-declare-modifiers
2/** Creates an empty stream. */
3declare function Stream<T>(): Stream<T>; // eslint-disable-line no-unnecessary-generics
4/** Creates a stream with an initial value. */
5declare function Stream<T>(value: T): Stream<T>; // tslint:disable-line unified-signatures
6
7declare interface Stream<T> {
8 /** Returns the value of the stream. */
9 (): T;
10 /** Sets the value of the stream. */
11 (value: T): this;
12 /** Creates a dependent stream whose value is set to the result of the callback function. */
13 map<U>(f: (current: T) => U | typeof Stream.SKIP): Stream<U>;
14 /** This method is functionally identical to stream. It exists to conform to Fantasy Land's Applicative specification. */
15 of(val: T): Stream<T>;
16 /** Apply. */
17 ap<U>(f: Stream<(value: T) => U>): Stream<U>;
18 /** A co-dependent stream that unregisters dependent streams when set to true. */
19 end: Stream<boolean>;
20 /** When a stream is passed as the argument to JSON.stringify(), the value of the stream is serialized. */
21 toJSON(): string;
22 /** Returns the value of the stream. */
23 valueOf(): T;
24}
25
26declare namespace Stream {
27 /** Creates a computed stream that reactively updates if any of its upstreams are updated. */
28 export function combine<T>(combiner: (...streams: any[]) => T, streams: Array<Stream<any>>): Stream<T>;
29 /** Combines the values of one or more streams into a single stream that is updated whenever one or more of the sources are updated */
30 export function lift<S extends any[], T>(
31 fn: (...values: S) => T,
32 ...streams: { [I in keyof S]: Stream<S[I]> }
33 ): Stream<T>;
34 /** Creates a stream whose value is the array of values from an array of streams. */
35 export function merge<S extends any[]>(streams: { [I in keyof S]: Stream<S[I]> }): Stream<{ [I in keyof S]: S[I] }>;
36 /** Creates a new stream with the results of calling the function on every incoming stream with and accumulator and the incoming value. */
37 export function scan<T, U>(fn: (acc: U, value: T) => U, acc: U, stream: Stream<T>): Stream<U>;
38 /** Takes an array of pairs of streams and scan functions and merges all those streams using the given functions into a single stream. */
39 export function scanMerge<T, U>(pairs: Array<[Stream<T>, (acc: U, value: T) => U]>, acc: U): Stream<U>;
40 /** Takes an array of pairs of streams and scan functions and merges all those streams using the given functions into a single stream. */
41 export function scanMerge<U>(pairs: Array<[Stream<any>, (acc: U, value: any) => U]>, acc: U): Stream<U>;
42 /** A special value that can be returned to stream callbacks to skip execution of downstreams. */
43 export const SKIP: unique symbol;
44}
45
46export = Stream;
47
\No newline at end of file