1 import { Subscriber } from '../Subscriber';
2 export function find(predicate, thisArg) {
3 if (typeof predicate !== 'function') {
4 throw new TypeError('predicate is not a function');
6 return (source) => source.lift(new FindValueOperator(predicate, source, false, thisArg));
8 export class FindValueOperator {
9 constructor(predicate, source, yieldIndex, thisArg) {
10 this.predicate = predicate;
12 this.yieldIndex = yieldIndex;
13 this.thisArg = thisArg;
15 call(observer, source) {
16 return source.subscribe(new FindValueSubscriber(observer, this.predicate, this.source, this.yieldIndex, this.thisArg));
19 export class FindValueSubscriber extends Subscriber {
20 constructor(destination, predicate, source, yieldIndex, thisArg) {
22 this.predicate = predicate;
24 this.yieldIndex = yieldIndex;
25 this.thisArg = thisArg;
28 notifyComplete(value) {
29 const destination = this.destination;
30 destination.next(value);
31 destination.complete();
35 const { predicate, thisArg } = this;
36 const index = this.index++;
38 const result = predicate.call(thisArg || this, value, index, this.source);
40 this.notifyComplete(this.yieldIndex ? index : value);
44 this.destination.error(err);
48 this.notifyComplete(this.yieldIndex ? -1 : undefined);
51 //# sourceMappingURL=find.js.map