27 lines
1,003 B
JavaScript
27 lines
1,003 B
JavaScript
|
"use strict";
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
exports.createFind = exports.find = void 0;
|
||
|
var lift_1 = require("../util/lift");
|
||
|
var OperatorSubscriber_1 = require("./OperatorSubscriber");
|
||
|
function find(predicate, thisArg) {
|
||
|
return lift_1.operate(createFind(predicate, thisArg, 'value'));
|
||
|
}
|
||
|
exports.find = find;
|
||
|
function createFind(predicate, thisArg, emit) {
|
||
|
var findIndex = emit === 'index';
|
||
|
return function (source, subscriber) {
|
||
|
var index = 0;
|
||
|
source.subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function (value) {
|
||
|
var i = index++;
|
||
|
if (predicate.call(thisArg, value, i, source)) {
|
||
|
subscriber.next(findIndex ? i : value);
|
||
|
subscriber.complete();
|
||
|
}
|
||
|
}, function () {
|
||
|
subscriber.next(findIndex ? -1 : undefined);
|
||
|
subscriber.complete();
|
||
|
}));
|
||
|
};
|
||
|
}
|
||
|
exports.createFind = createFind;
|
||
|
//# sourceMappingURL=find.js.map
|