import { Observable, ObservableInput } from '../Observable'; import { withLatestFrom as higherOrder } from '../operators/withLatestFrom'; /* tslint:disable:max-line-length */ export function withLatestFrom(this: Observable, project: (v1: T) => R): Observable; export function withLatestFrom(this: Observable, v2: ObservableInput, project: (v1: T, v2: T2) => R): Observable; export function withLatestFrom(this: Observable, v2: ObservableInput, v3: ObservableInput, project: (v1: T, v2: T2, v3: T3) => R): Observable; export function withLatestFrom(this: Observable, v2: ObservableInput, v3: ObservableInput, v4: ObservableInput, project: (v1: T, v2: T2, v3: T3, v4: T4) => R): Observable; export function withLatestFrom(this: Observable, v2: ObservableInput, v3: ObservableInput, v4: ObservableInput, v5: ObservableInput, project: (v1: T, v2: T2, v3: T3, v4: T4, v5: T5) => R): Observable; export function withLatestFrom(this: Observable, v2: ObservableInput, v3: ObservableInput, v4: ObservableInput, v5: ObservableInput, v6: ObservableInput, project: (v1: T, v2: T2, v3: T3, v4: T4, v5: T5, v6: T6) => R): Observable ; export function withLatestFrom(this: Observable, v2: ObservableInput): Observable<[T, T2]>; export function withLatestFrom(this: Observable, v2: ObservableInput, v3: ObservableInput): Observable<[T, T2, T3]>; export function withLatestFrom(this: Observable, v2: ObservableInput, v3: ObservableInput, v4: ObservableInput): Observable<[T, T2, T3, T4]>; export function withLatestFrom(this: Observable, v2: ObservableInput, v3: ObservableInput, v4: ObservableInput, v5: ObservableInput): Observable<[T, T2, T3, T4, T5]>; export function withLatestFrom(this: Observable, v2: ObservableInput, v3: ObservableInput, v4: ObservableInput, v5: ObservableInput, v6: ObservableInput): Observable<[T, T2, T3, T4, T5, T6]> ; export function withLatestFrom(this: Observable, ...observables: Array | ((...values: Array) => R)>): Observable; export function withLatestFrom(this: Observable, array: ObservableInput[]): Observable; export function withLatestFrom(this: Observable, array: ObservableInput[], project: (...values: Array) => R): Observable; /* tslint:enable:max-line-length */ /** * Combines the source Observable with other Observables to create an Observable * whose values are calculated from the latest values of each, only when the * source emits. * * Whenever the source Observable emits a value, it * computes a formula using that value plus the latest values from other input * Observables, then emits the output of that formula. * * * * `withLatestFrom` combines each value from the source Observable (the * instance) with the latest values from the other input Observables only when * the source emits a value, optionally using a `project` function to determine * the value to be emitted on the output Observable. All input Observables must * emit at least one value before the output Observable will emit a value. * * @example On every click event, emit an array with the latest timer event plus the click event * var clicks = Rx.Observable.fromEvent(document, 'click'); * var timer = Rx.Observable.interval(1000); * var result = clicks.withLatestFrom(timer); * result.subscribe(x => console.log(x)); * * @see {@link combineLatest} * * @param {ObservableInput} other An input Observable to combine with the source * Observable. More than one input Observables may be given as argument. * @param {Function} [project] Projection function for combining values * together. Receives all values in order of the Observables passed, where the * first parameter is a value from the source Observable. (e.g. * `a.withLatestFrom(b, c, (a1, b1, c1) => a1 + b1 + c1)`). If this is not * passed, arrays will be emitted on the output Observable. * @return {Observable} An Observable of projected values from the most recent * values from each input Observable, or an array of the most recent values from * each input Observable. * @method withLatestFrom * @owner Observable */ export function withLatestFrom(this: Observable, ...args: Array | ((...values: Array) => R)>): Observable { return higherOrder(...args)(this); }