find.js 821 B

12345678910111213141516171819202122
  1. import { operate } from '../util/lift';
  2. import { createOperatorSubscriber } from './OperatorSubscriber';
  3. export function find(predicate, thisArg) {
  4. return operate(createFind(predicate, thisArg, 'value'));
  5. }
  6. export function createFind(predicate, thisArg, emit) {
  7. var findIndex = emit === 'index';
  8. return function (source, subscriber) {
  9. var index = 0;
  10. source.subscribe(createOperatorSubscriber(subscriber, function (value) {
  11. var i = index++;
  12. if (predicate.call(thisArg, value, i, source)) {
  13. subscriber.next(findIndex ? i : value);
  14. subscriber.complete();
  15. }
  16. }, function () {
  17. subscriber.next(findIndex ? -1 : undefined);
  18. subscriber.complete();
  19. }));
  20. };
  21. }
  22. //# sourceMappingURL=find.js.map