import { Observable } from '../../observable.js' import { IntoObservable } from '../../types' export function static$combine(...$s: Array>): Observable export function static$combine( $1: IntoObservable, $2: IntoObservable, ): Observable<[T1, T2]> export function static$combine( $1: IntoObservable, $2: IntoObservable, $3: IntoObservable, ): Observable<[T1, T2, T3]> export function static$combine( $1: IntoObservable, $2: IntoObservable, $3: IntoObservable, $4: IntoObservable, ): Observable<[T1, T2, T3, T4]> export function static$combine( $1: IntoObservable, $2: IntoObservable, $3: IntoObservable, $4: IntoObservable, $5: IntoObservable, ): Observable<[T1, T2, T3, T4, T5]> export function static$combine(...$s: Array>): Observable { const EMPTY = Symbol('empty') const state: any[] = $s.map(() => EMPTY) return new Observable(({next, error, complete}) => { const subs = $s.map(($, i) => Observable.from($).subscribe({ next: val => { state[i] = val if (state.some(val => val === EMPTY)) return return next(state) }, error, complete, }), ) return () => subs.forEach(sub => sub.unsubscribe()) }) } Observable.combine = static$combine declare module '../../observable.js' { namespace Observable { export let combine: typeof static$combine } }