1 /** PURE_IMPORTS_START tslib,_Subscriber PURE_IMPORTS_END */
2 import * as tslib_1 from "tslib";
3 import { Subscriber } from '../Subscriber';
4 export function find(predicate, thisArg) {
5 if (typeof predicate !== 'function') {
6 throw new TypeError('predicate is not a function');
8 return function (source) { return source.lift(new FindValueOperator(predicate, source, false, thisArg)); };
10 var FindValueOperator = /*@__PURE__*/ (function () {
11 function FindValueOperator(predicate, source, yieldIndex, thisArg) {
12 this.predicate = predicate;
14 this.yieldIndex = yieldIndex;
15 this.thisArg = thisArg;
17 FindValueOperator.prototype.call = function (observer, source) {
18 return source.subscribe(new FindValueSubscriber(observer, this.predicate, this.source, this.yieldIndex, this.thisArg));
20 return FindValueOperator;
22 export { FindValueOperator };
23 var FindValueSubscriber = /*@__PURE__*/ (function (_super) {
24 tslib_1.__extends(FindValueSubscriber, _super);
25 function FindValueSubscriber(destination, predicate, source, yieldIndex, thisArg) {
26 var _this = _super.call(this, destination) || this;
27 _this.predicate = predicate;
28 _this.source = source;
29 _this.yieldIndex = yieldIndex;
30 _this.thisArg = thisArg;
34 FindValueSubscriber.prototype.notifyComplete = function (value) {
35 var destination = this.destination;
36 destination.next(value);
37 destination.complete();
40 FindValueSubscriber.prototype._next = function (value) {
41 var _a = this, predicate = _a.predicate, thisArg = _a.thisArg;
42 var index = this.index++;
44 var result = predicate.call(thisArg || this, value, index, this.source);
46 this.notifyComplete(this.yieldIndex ? index : value);
50 this.destination.error(err);
53 FindValueSubscriber.prototype._complete = function () {
54 this.notifyComplete(this.yieldIndex ? -1 : undefined);
56 return FindValueSubscriber;
58 export { FindValueSubscriber };
59 //# sourceMappingURL=find.js.map