2 var __extends = (this && this.__extends) || (function () {
3 var extendStatics = function (d, b) {
4 extendStatics = Object.setPrototypeOf ||
5 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7 return extendStatics(d, b);
9 return function (d, b) {
11 function __() { this.constructor = d; }
12 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15 Object.defineProperty(exports, "__esModule", { value: true });
16 var Subscriber_1 = require("../Subscriber");
17 function find(predicate, thisArg) {
18 if (typeof predicate !== 'function') {
19 throw new TypeError('predicate is not a function');
21 return function (source) { return source.lift(new FindValueOperator(predicate, source, false, thisArg)); };
24 var FindValueOperator = (function () {
25 function FindValueOperator(predicate, source, yieldIndex, thisArg) {
26 this.predicate = predicate;
28 this.yieldIndex = yieldIndex;
29 this.thisArg = thisArg;
31 FindValueOperator.prototype.call = function (observer, source) {
32 return source.subscribe(new FindValueSubscriber(observer, this.predicate, this.source, this.yieldIndex, this.thisArg));
34 return FindValueOperator;
36 exports.FindValueOperator = FindValueOperator;
37 var FindValueSubscriber = (function (_super) {
38 __extends(FindValueSubscriber, _super);
39 function FindValueSubscriber(destination, predicate, source, yieldIndex, thisArg) {
40 var _this = _super.call(this, destination) || this;
41 _this.predicate = predicate;
42 _this.source = source;
43 _this.yieldIndex = yieldIndex;
44 _this.thisArg = thisArg;
48 FindValueSubscriber.prototype.notifyComplete = function (value) {
49 var destination = this.destination;
50 destination.next(value);
51 destination.complete();
54 FindValueSubscriber.prototype._next = function (value) {
55 var _a = this, predicate = _a.predicate, thisArg = _a.thisArg;
56 var index = this.index++;
58 var result = predicate.call(thisArg || this, value, index, this.source);
60 this.notifyComplete(this.yieldIndex ? index : value);
64 this.destination.error(err);
67 FindValueSubscriber.prototype._complete = function () {
68 this.notifyComplete(this.yieldIndex ? -1 : undefined);
70 return FindValueSubscriber;
71 }(Subscriber_1.Subscriber));
72 exports.FindValueSubscriber = FindValueSubscriber;
73 //# sourceMappingURL=find.js.map