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IAED,oCAAQ,GAAR;QACE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;IAChC,CAAC;IAED,wCAAY,GAAZ;QACE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC;IACrD,CAAC;IAED,0CAAc,GAAd;QACE,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;YAC3B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;YACvB,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;QAC/B,CAAC;QAAC,IAAI,CAAC,CAAC;YACN,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC;QAC9B,CAAC;IACH,CAAC;IAED,sCAAU,GAAV,UAAW,UAAa,EAAE,UAAe,EAC9B,UAAkB,EAAE,UAAkB,EACtC,QAA+B;QACxC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC7B,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;IAC/B,CAAC;IAED,qCAAS,GAAT,UAAU,KAAU,EAAE,KAAa;QACjC,MAAM,CAAC,qCAAiB,CAAW,IAAI,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;IACzE,CAAC;IACH,wBAAC;AAAD,CAAC,AArDD,CAAsC,iCAAe,GAqDpD","sourcesContent":["import { Observable, ObservableInput } from '../Observable';\nimport { ArrayObservable } from '../observable/ArrayObservable';\nimport { isArray } from '../util/isArray';\nimport { Operator } from '../Operator';\nimport { PartialObserver } from '../Observer';\nimport { Subscriber } from '../Subscriber';\nimport { OuterSubscriber } from '../OuterSubscriber';\nimport { InnerSubscriber } from '../InnerSubscriber';\nimport { subscribeToResult } from '../util/subscribeToResult';\nimport { iterator as Symbol_iterator } from '../symbol/iterator';\nimport { OperatorFunction } from '../interfaces';\n\n/* tslint:disable:max-line-length */\nexport function zip<T, R>(project: (v1: T) => R): OperatorFunction<T, R>;\nexport function zip<T, T2, R>(v2: ObservableInput<T2>, project: (v1: T, v2: T2) => R): OperatorFunction<T, R>;\nexport function zip<T, T2, T3, R>(v2: ObservableInput<T2>, v3: ObservableInput<T3>, project: (v1: T, v2: T2, v3: T3) => R): OperatorFunction<T, R>;\nexport function zip<T, T2, T3, T4, R>(v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, project: (v1: T, v2: T2, v3: T3, v4: T4) => R): OperatorFunction<T, R>;\nexport function zip<T, T2, T3, T4, T5, R>(v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, v5: ObservableInput<T5>, project: (v1: T, v2: T2, v3: T3, v4: T4, v5: T5) => R): OperatorFunction<T, R>;\nexport function zip<T, T2, T3, T4, T5, T6, R>(v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, v5: ObservableInput<T5>, v6: ObservableInput<T6>, project: (v1: T, v2: T2, v3: T3, v4: T4, v5: T5, v6: T6) => R): OperatorFunction<T, R> ;\nexport function zip<T, T2>(v2: ObservableInput<T2>): OperatorFunction<T, [T, T2]>;\nexport function zip<T, T2, T3>(v2: ObservableInput<T2>, v3: ObservableInput<T3>): OperatorFunction<T, [T, T2, T3]>;\nexport function zip<T, T2, T3, T4>(v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>): OperatorFunction<T, [T, T2, T3, T4]>;\nexport function zip<T, T2, T3, T4, T5>(v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, v5: ObservableInput<T5>): OperatorFunction<T, [T, T2, T3, T4, T5]>;\nexport function zip<T, T2, T3, T4, T5, T6>(v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, v5: ObservableInput<T5>, v6: ObservableInput<T6>): OperatorFunction<T, [T, T2, T3, T4, T5, T6]> ;\nexport function zip<T, R>(...observables: Array<ObservableInput<T> | ((...values: Array<T>) => R)>): OperatorFunction<T, R>;\nexport function zip<T, R>(array: Array<ObservableInput<T>>): OperatorFunction<T, R>;\nexport function zip<T, TOther, R>(array: Array<ObservableInput<TOther>>, project: (v1: T, ...values: Array<TOther>) => R): OperatorFunction<T, R>;\n/* tslint:enable:max-line-length */\n\n/**\n * @param observables\n * @return {Observable<R>}\n * @method zip\n * @owner Observable\n */\nexport function zip<T, R>(...observables: Array<ObservableInput<any> | ((...values: Array<any>) => R)>): OperatorFunction<T, R> {\n return function zipOperatorFunction(source: Observable<T>) {\n return source.lift.call(zipStatic<R>(source, ...observables));\n };\n}\n\n/* tslint:disable:max-line-length */\nexport function zipStatic<T, R>(v1: ObservableInput<T>, project: (v1: T) => R): Observable<R>;\nexport function zipStatic<T, T2, R>(v1: ObservableInput<T>, v2: ObservableInput<T2>, project: (v1: T, v2: T2) => R): Observable<R>;\nexport function zipStatic<T, T2, T3, R>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, project: (v1: T, v2: T2, v3: T3) => R): Observable<R>;\nexport function zipStatic<T, T2, T3, T4, R>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, project: (v1: T, v2: T2, v3: T3, v4: T4) => R): Observable<R>;\nexport function zipStatic<T, T2, T3, T4, T5, R>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, v5: ObservableInput<T5>, project: (v1: T, v2: T2, v3: T3, v4: T4, v5: T5) => R): Observable<R>;\nexport function zipStatic<T, T2, T3, T4, T5, T6, R>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, v5: ObservableInput<T5>, v6: ObservableInput<T6>, project: (v1: T, v2: T2, v3: T3, v4: T4, v5: T5, v6: T6) => R): Observable<R>;\n\nexport function zipStatic<T, T2>(v1: ObservableInput<T>, v2: ObservableInput<T2>): Observable<[T, T2]>;\nexport function zipStatic<T, T2, T3>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>): Observable<[T, T2, T3]>;\nexport function zipStatic<T, T2, T3, T4>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>): Observable<[T, T2, T3, T4]>;\nexport function zipStatic<T, T2, T3, T4, T5>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, v5: ObservableInput<T5>): Observable<[T, T2, T3, T4, T5]>;\nexport function zipStatic<T, T2, T3, T4, T5, T6>(v1: ObservableInput<T>, v2: ObservableInput<T2>, v3: ObservableInput<T3>, v4: ObservableInput<T4>, v5: ObservableInput<T5>, v6: ObservableInput<T6>): Observable<[T, T2, T3, T4, T5, T6]>;\n\nexport function zipStatic<T>(array: ObservableInput<T>[]): Observable<T[]>;\nexport function zipStatic<R>(array: ObservableInput<any>[]): Observable<R>;\nexport function zipStatic<T, R>(array: ObservableInput<T>[], project: (...values: Array<T>) => R): Observable<R>;\nexport function zipStatic<R>(array: ObservableInput<any>[], project: (...values: Array<any>) => R): Observable<R>;\n\nexport function zipStatic<T>(...observables: Array<ObservableInput<T>>): Observable<T[]>;\nexport function zipStatic<T, R>(...observables: Array<ObservableInput<T> | ((...values: Array<T>) => R)>): Observable<R>;\nexport function zipStatic<R>(...observables: Array<ObservableInput<any> | ((...values: Array<any>) => R)>): Observable<R>;\n/* tslint:enable:max-line-length */\n\n/**\n * Combines multiple Observables to create an Observable whose values are calculated from the values, in order, of each\n * of its input Observables.\n *\n * If the latest parameter is a function, this function is used to compute the created value from the input values.\n * Otherwise, an array of the input values is returned.\n *\n * @example <caption>Combine age and name from different sources</caption>\n *\n * let age$ = Observable.of<number>(27, 25, 29);\n * let name$ = Observable.of<string>('Foo', 'Bar', 'Beer');\n * let isDev$ = Observable.of<boolean>(true, true, false);\n *\n * Observable\n * .zip(age$,\n * name$,\n * isDev$,\n * (age: number, name: string, isDev: boolean) => ({ age, name, isDev }))\n * .subscribe(x => console.log(x));\n *\n * // outputs\n * // { age: 27, name: 'Foo', isDev: true }\n * // { age: 25, name: 'Bar', isDev: true }\n * // { age: 29, name: 'Beer', isDev: false }\n *\n * @param observables\n * @return {Observable<R>}\n * @static true\n * @name zip\n * @owner Observable\n */\nexport function zipStatic<T, R>(...observables: Array<ObservableInput<any> | ((...values: Array<any>) => R)>): Observable<R> {\n const project = <((...ys: Array<any>) => R)> observables[observables.length - 1];\n if (typeof project === 'function') {\n observables.pop();\n }\n return new ArrayObservable(observables).lift(new ZipOperator(project));\n}\n\nexport class ZipOperator<T, R> implements Operator<T, R> {\n\n project: (...values: Array<any>) => R;\n\n constructor(project?: (...values: Array<any>) => R) {\n this.project = project;\n }\n\n call(subscriber: Subscriber<R>, source: any): any {\n return source.subscribe(new ZipSubscriber(subscriber, this.project));\n }\n}\n\n/**\n * We need this JSDoc comment for affecting ESDoc.\n * @ignore\n * @extends {Ignored}\n */\nexport class ZipSubscriber<T, R> extends Subscriber<T> {\n private values: any;\n private project: (...values: Array<any>) => R;\n private iterators: LookAheadIterator<any>[] = [];\n private active = 0;\n\n constructor(destination: Subscriber<R>,\n project?: (...values: Array<any>) => R,\n values: any = Object.create(null)) {\n super(destination);\n this.project = (typeof project === 'function') ? project : null;\n this.values = values;\n }\n\n protected _next(value: any) {\n const iterators = this.iterators;\n if (isArray(value)) {\n iterators.push(new StaticArrayIterator(value));\n } else if (typeof value[Symbol_iterator] === 'function') {\n iterators.push(new StaticIterator(value[Symbol_iterator]()));\n } else {\n iterators.push(new ZipBufferIterator(this.destination, this, value));\n }\n }\n\n protected _complete() {\n const iterators = this.iterators;\n const len = iterators.length;\n\n if (len === 0) {\n this.destination.complete();\n return;\n }\n\n this.active = len;\n for (let i = 0; i < len; i++) {\n let iterator: ZipBufferIterator<any, any> = <any>iterators[i];\n if (iterator.stillUnsubscribed) {\n this.add(iterator.subscribe(iterator, i));\n } else {\n this.active--; // not an observable\n }\n }\n }\n\n notifyInactive() {\n this.active--;\n if (this.active === 0) {\n this.destination.complete();\n }\n }\n\n checkIterators() {\n const iterators = this.iterators;\n const len = iterators.length;\n const destination = this.destination;\n\n // abort if not all of them have values\n for (let i = 0; i < len; i++) {\n let iterator = iterators[i];\n if (typeof iterator.hasValue === 'function' && !iterator.hasValue()) {\n return;\n }\n }\n\n let shouldComplete = false;\n const args: any[] = [];\n for (let i = 0; i < len; i++) {\n let iterator = iterators[i];\n let result = iterator.next();\n\n // check to see if it's completed now that you've gotten\n // the next value.\n if (iterator.hasCompleted()) {\n shouldComplete = true;\n }\n\n if (result.done) {\n destination.complete();\n return;\n }\n\n args.push(result.value);\n }\n\n if (this.project) {\n this._tryProject(args);\n } else {\n destination.next(args);\n }\n\n if (shouldComplete) {\n destination.complete();\n }\n }\n\n protected _tryProject(args: any[]) {\n let result: any;\n try {\n result = this.project.apply(this, args);\n } catch (err) {\n this.destination.error(err);\n return;\n }\n this.destination.next(result);\n }\n}\n\ninterface LookAheadIterator<T> extends Iterator<T> {\n hasValue(): boolean;\n hasCompleted(): boolean;\n}\n\nclass StaticIterator<T> implements LookAheadIterator<T> {\n private nextResult: IteratorResult<T>;\n\n constructor(private iterator: Iterator<T>) {\n this.nextResult = iterator.next();\n }\n\n hasValue() {\n return true;\n }\n\n next(): IteratorResult<T> {\n const result = this.nextResult;\n this.nextResult = this.iterator.next();\n return result;\n }\n\n hasCompleted() {\n const nextResult = this.nextResult;\n return nextResult && nextResult.done;\n }\n}\n\nclass StaticArrayIterator<T> implements LookAheadIterator<T> {\n private index = 0;\n private length = 0;\n\n constructor(private array: T[]) {\n this.length = array.length;\n }\n\n [Symbol_iterator]() {\n return this;\n }\n\n next(value?: any): IteratorResult<T> {\n const i = this.index++;\n const array = this.array;\n return i < this.length ? { value: array[i], done: false } : { value: null, done: true };\n }\n\n hasValue() {\n return this.array.length > this.index;\n }\n\n hasCompleted() {\n return this.array.length === this.index;\n }\n}\n\n/**\n * We need this JSDoc comment for affecting ESDoc.\n * @ignore\n * @extends {Ignored}\n */\nclass ZipBufferIterator<T, R> extends OuterSubscriber<T, R> implements LookAheadIterator<T> {\n stillUnsubscribed = true;\n buffer: T[] = [];\n isComplete = false;\n\n constructor(destination: PartialObserver<T>,\n private parent: ZipSubscriber<T, R>,\n private observable: Observable<T>) {\n super(destination);\n }\n\n [Symbol_iterator]() {\n return this;\n }\n\n // NOTE: there is actually a name collision here with Subscriber.next and Iterator.next\n // this is legit because `next()` will never be called by a subscription in this case.\n next(): IteratorResult<T> {\n const buffer = this.buffer;\n if (buffer.length === 0 && this.isComplete) {\n return { value: null, done: true };\n } else {\n return { value: buffer.shift(), done: false };\n }\n }\n\n hasValue() {\n return this.buffer.length > 0;\n }\n\n hasCompleted() {\n return this.buffer.length === 0 && this.isComplete;\n }\n\n notifyComplete() {\n if (this.buffer.length > 0) {\n this.isComplete = true;\n this.parent.notifyInactive();\n } else {\n this.destination.complete();\n }\n }\n\n notifyNext(outerValue: T, innerValue: any,\n outerIndex: number, innerIndex: number,\n innerSub: InnerSubscriber<T, R>): void {\n this.buffer.push(innerValue);\n this.parent.checkIterators();\n }\n\n subscribe(value: any, index: number) {\n return subscribeToResult<any, any>(this, this.observable, this, index);\n }\n}\n"]}
|