import { Emitter } from './actions'; /** * Operators can transform and control the flow of values. * [[pipe]] is used to transform one Emitter into another by stacking operators to its values. * To build your own operator that looks like the built-in ones, * create a function which returns an operator. * The following custom operator multiplies the passed value: * * ```ts * function multiplyBy(multiplier: number): Operator { * return done => value => done(value * multiplier) * } * * const foo = stream() * const multipliedFoo = pipe(foo, multiplyBy(3)) * subscribe(multipliedFoo, value => console.log(value)) * publish(foo, 42) * ``` */ export interface Operator { (done: (value: Output) => void): (value: Input) => void; } /** @internal */ declare type O = Operator; /** * Creates a new emitter from the passed one by piping its values through one or more operators. * Operators can perform various actions like filter values, pull values from other emitters, or compute new values. * * ```ts * const foo = stream() * * // create an emitter that first adds 2 to the passed value, then multiplies it by * 2 * const bar = pipe(foo, map(value => value + 2), map(value => value * 2)) * subscribe(bar, value => console.log(value)) * publish(foo, 2) // outputs 8 * ``` * #### Sharing Subscription Calculations * * `pipe` acts as a proxy for the source emitter, and re-runs the operators for each subscription to the derived emitter. * Use [[streamFromEmitter]] or [[statefulStreamFromEmitter]] to avoid that. */ export declare function pipe(s: Emitter): Emitter; export declare function pipe(s: Emitter, o1: O): Emitter; export declare function pipe(s: Emitter, ...o: [O, O]): Emitter; export declare function pipe(s: Emitter, ...o: [O, O, O]): Emitter; export declare function pipe(s: Emitter, ...o: [O, O, O, O]): Emitter; export declare function pipe(s: Emitter, ...o: [O, O, O, O, O]): Emitter; export declare function pipe(s: Emitter, ...o: [O, O, O, O, O, O]): Emitter; export declare function pipe(s: Emitter, ...o: [O, O, O, O, O, O, O]): Emitter; /** * A function which determines if two values are equal. * Implement custom comparators when [[distinctUntilChanged]] needs to work on non-primitive objects. * @returns true if values should be considered equal. */ export interface Comparator { (previous: T, next: T): boolean; } /** * The default [[Comparator]] for [[distinctUntilChanged]] and [[duc]]. */ export declare function defaultComparator(previous: T, next: T): boolean; /** * Filters out identical values. Pass an optional [[Comparator]] if you need to filter non-primitive values. * ```ts * const foo = stream() * * subscribe( * pipe(foo, distinctUntilChanged()), * console.log * ) // will be called only once * * publish(foo, 42) * publish(foo, 42) * ``` */ export declare function distinctUntilChanged(comparator?: Comparator): Operator; /** * Filters out values for which the predicator does not return `true`-ish. * ```ts * const foo = stream() * * subscribe( * pipe(foo, filter(value => value % 2 === 0)), * console.log * ) // will be called only with even values * * publish(foo, 2) * publish(foo, 3) * publish(foo, 4) * publish(foo, 5) * ``` */ export declare function filter(predicate: (value: T) => boolean): Operator; /** * Maps values using the provided project function. * ```ts * const foo = stream() * * subscribe( * pipe(foo, map(value => value * 2)), * console.log * ) // 4, 6 * * publish(foo, 2) * publish(foo, 3) * ``` */ export declare function map(project: (value: T) => K): Operator; /** * Maps values to the hard-coded value. * ```ts * const foo = stream() * * subscribe( * pipe(foo, mapTo(3)), * console.log * ) // 3, 3 * * publish(foo, 1) * publish(foo, 2) * ``` */ export declare function mapTo(value: T): Operator; /** * Works like Array#reduce. * Applies an accumulator function on the emitter, and outputs intermediate result. Starts with the initial value. * ```ts * const foo = stream() * * subscribe( * pipe(foo, scan((acc, value) => acc + value, 2), * console.log * ) // 3, 5 * * publish(foo, 1) * publish(foo, 2) * ``` */ export declare function scan(scanner: (current: T, value: K) => T, initial: T): Operator; /** * Skips the specified amount of values from the emitter. * ```ts * const foo = stream() * * subscribe( * pipe(foo, skip(2)), * console.log * ) // 3, 4 * * publish(foo, 1) // skipped * publish(foo, 2) // skipped * publish(foo, 3) * publish(foo, 4) * ``` */ export declare function skip(times: number): Operator; /** * Throttles flowing values at the provided interval in milliseconds. * [Throttle VS Debounce in SO](https://stackoverflow.com/questions/25991367/difference-between-throttling-and-debouncing-a-function). * * ```ts * const foo = stream() * publish(foo, 1) * * setTimeout(() => publish(foo, 2), 20) * setTimeout(() => publish(foo, 3), 20) * * subscribe(pipe(foo, throttleTime(50)), val => { * console.log(value); // 3 * }) * ``` */ export declare function throttleTime(interval: number): Operator; /** * Debounces flowing values at the provided interval in milliseconds. * [Throttle VS Debounce in SO](https://stackoverflow.com/questions/25991367/difference-between-throttling-and-debouncing-a-function). * * ```ts * const foo = stream() * publish(foo, 1) * * setTimeout(() => publish(foo, 2), 20) * setTimeout(() => publish(foo, 3), 20) * * subscribe(pipe(foo, debounceTime(50)), val => { * console.log(value); // 3 * }) * ``` */ export declare function debounceTime(interval: number): Operator; /** * Combines the source Emitter with the latest values from the specified Emitters into an array. Outputs only when the source Emitter emits. * See [[combineLatest]] for a transformer that outputs when any of the emitters emit. * * ```ts * const foo = stream() * const bar = stream() * subscribe( * pipe( * foo, * withLatestFrom(bar) * ), * (([foo, bar]) => console.log({ foo, bar })) * ) * * publish(foo, 1) // nothing happens, bar has not emitted yet * publish(bar, 1) // still nothing * publish(foo, 2) // logs { foo: 2, bar: 1 } * publish(bar, 2) * publish(foo, 3) // logs { foo: 3, bar: 2 } * ``` */ export declare function withLatestFrom(...s: [Emitter]): Operator; export declare function withLatestFrom(...s: [Emitter, Emitter]): Operator; export declare function withLatestFrom(...s: [Emitter, Emitter, Emitter]): Operator; export declare function withLatestFrom(...s: [Emitter, Emitter, Emitter, Emitter]): Operator; export declare function withLatestFrom(...s: [Emitter, Emitter, Emitter, Emitter, Emitter]): Operator; export declare function withLatestFrom(...s: [Emitter, Emitter, Emitter, Emitter, Emitter, Emitter]): Operator; export declare function withLatestFrom(...s: [Emitter, Emitter, Emitter, Emitter, Emitter, Emitter, Emitter]): Operator; export {};