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IACrC,CAAC;IAEO,4CAAc,GAAtB,UAAuB,KAAQ,EAAE,eAAwB;QACvD,IAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;QACrC,EAAE,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;YAC7B,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC1B,CAAC;QAAC,IAAI,CAAC,CAAC;YACN,WAAW,CAAC,QAAQ,EAAE,CAAC;QACzB,CAAC;IACH,CAAC;IACH,0BAAC;AAAD,CAAC,AA5BD,CAAqC,uBAAU,GA4B9C","sourcesContent":["import { Operator } from '../Operator';\nimport { Observable } from '../Observable';\nimport { Subscriber } from '../Subscriber';\nimport { TeardownLogic } from '../Subscription';\nimport { MonoTypeOperatorFunction } from '../interfaces';\n\n/**\n * Emits values emitted by the source Observable so long as each value satisfies\n * the given `predicate`, and then completes as soon as this `predicate` is not\n * satisfied.\n *\n * <span class=\"informal\">Takes values from the source only while they pass the\n * condition given. When the first value does not satisfy, it completes.</span>\n *\n * <img src=\"./img/takeWhile.png\" width=\"100%\">\n *\n * `takeWhile` subscribes and begins mirroring the source Observable. Each value\n * emitted on the source is given to the `predicate` function which returns a\n * boolean, representing a condition to be satisfied by the source values. The\n * output Observable emits the source values until such time as the `predicate`\n * returns false, at which point `takeWhile` stops mirroring the source\n * Observable and completes the output Observable.\n *\n * @example <caption>Emit click events only while the clientX property is greater than 200</caption>\n * var clicks = Rx.Observable.fromEvent(document, 'click');\n * var result = clicks.takeWhile(ev => ev.clientX > 200);\n * result.subscribe(x => console.log(x));\n *\n * @see {@link take}\n * @see {@link takeLast}\n * @see {@link takeUntil}\n * @see {@link skip}\n *\n * @param {function(value: T, index: number): boolean} predicate A function that\n * evaluates a value emitted by the source Observable and returns a boolean.\n * Also takes the (zero-based) index as the second argument.\n * @return {Observable<T>} An Observable that emits the values from the source\n * Observable so long as each value satisfies the condition defined by the\n * `predicate`, then completes.\n * @method takeWhile\n * @owner Observable\n */\nexport function takeWhile<T>(predicate: (value: T, index: number) => boolean): MonoTypeOperatorFunction<T> {\n return (source: Observable<T>) => source.lift(new TakeWhileOperator(predicate));\n}\n\nclass TakeWhileOperator<T> implements Operator<T, T> {\n constructor(private predicate: (value: T, index: number) => boolean) {\n }\n\n call(subscriber: Subscriber<T>, source: any): TeardownLogic {\n return source.subscribe(new TakeWhileSubscriber(subscriber, this.predicate));\n }\n}\n\n/**\n * We need this JSDoc comment for affecting ESDoc.\n * @ignore\n * @extends {Ignored}\n */\nclass TakeWhileSubscriber<T> extends Subscriber<T> {\n private index: number = 0;\n\n constructor(destination: Subscriber<T>,\n private predicate: (value: T, index: number) => boolean) {\n super(destination);\n }\n\n protected _next(value: T): void {\n const destination = this.destination;\n let result: boolean;\n try {\n result = this.predicate(value, this.index++);\n } catch (err) {\n destination.error(err);\n return;\n }\n this.nextOrComplete(value, result);\n }\n\n private nextOrComplete(value: T, predicateResult: boolean): void {\n const destination = this.destination;\n if (Boolean(predicateResult)) {\n destination.next(value);\n } else {\n destination.complete();\n }\n }\n}\n"]}