1 /** PURE_IMPORTS_START tslib,_Subscriber,_util_EmptyError PURE_IMPORTS_END */
2 import * as tslib_1 from "tslib";
3 import { Subscriber } from '../Subscriber';
4 import { EmptyError } from '../util/EmptyError';
5 export function single(predicate) {
6 return function (source) { return source.lift(new SingleOperator(predicate, source)); };
8 var SingleOperator = /*@__PURE__*/ (function () {
9 function SingleOperator(predicate, source) {
10 this.predicate = predicate;
13 SingleOperator.prototype.call = function (subscriber, source) {
14 return source.subscribe(new SingleSubscriber(subscriber, this.predicate, this.source));
16 return SingleOperator;
18 var SingleSubscriber = /*@__PURE__*/ (function (_super) {
19 tslib_1.__extends(SingleSubscriber, _super);
20 function SingleSubscriber(destination, predicate, source) {
21 var _this = _super.call(this, destination) || this;
22 _this.predicate = predicate;
23 _this.source = source;
24 _this.seenValue = false;
28 SingleSubscriber.prototype.applySingleValue = function (value) {
30 this.destination.error('Sequence contains more than one element');
33 this.seenValue = true;
34 this.singleValue = value;
37 SingleSubscriber.prototype._next = function (value) {
38 var index = this.index++;
40 this.tryNext(value, index);
43 this.applySingleValue(value);
46 SingleSubscriber.prototype.tryNext = function (value, index) {
48 if (this.predicate(value, index, this.source)) {
49 this.applySingleValue(value);
53 this.destination.error(err);
56 SingleSubscriber.prototype._complete = function () {
57 var destination = this.destination;
59 destination.next(this.seenValue ? this.singleValue : undefined);
60 destination.complete();
63 destination.error(new EmptyError);
66 return SingleSubscriber;
68 //# sourceMappingURL=single.js.map