frontend/.pnpm-store/v3/files/8f/47d8d75205a3eaf11f510808f5f9ee8475a2ae2dc8c4faa484afae08f3d222a47969bdcc75ee913fc68f57105ea7b6b682259fdcd335c91332a34682625bce

55 lines
1.7 KiB
Plaintext

/** PURE_IMPORTS_START tslib,_Subscriber PURE_IMPORTS_END */
import * as tslib_1 from "tslib";
import { Subscriber } from '../Subscriber';
export function count(predicate) {
return function (source) { return source.lift(new CountOperator(predicate, source)); };
}
var CountOperator = /*@__PURE__*/ (function () {
function CountOperator(predicate, source) {
this.predicate = predicate;
this.source = source;
}
CountOperator.prototype.call = function (subscriber, source) {
return source.subscribe(new CountSubscriber(subscriber, this.predicate, this.source));
};
return CountOperator;
}());
var CountSubscriber = /*@__PURE__*/ (function (_super) {
tslib_1.__extends(CountSubscriber, _super);
function CountSubscriber(destination, predicate, source) {
var _this = _super.call(this, destination) || this;
_this.predicate = predicate;
_this.source = source;
_this.count = 0;
_this.index = 0;
return _this;
}
CountSubscriber.prototype._next = function (value) {
if (this.predicate) {
this._tryPredicate(value);
}
else {
this.count++;
}
};
CountSubscriber.prototype._tryPredicate = function (value) {
var result;
try {
result = this.predicate(value, this.index++, this.source);
}
catch (err) {
this.destination.error(err);
return;
}
if (result) {
this.count++;
}
};
CountSubscriber.prototype._complete = function () {
this.destination.next(this.count);
this.destination.complete();
};
return CountSubscriber;
}(Subscriber));
//# sourceMappingURL=count.js.map