1234567891011121314151617181920212223242526272829303132333435363738394041
  1. "use strict";
  2. var findIndex_1 = require('../operators/findIndex');
  3. /**
  4. * Emits only the index of the first value emitted by the source Observable that
  5. * meets some condition.
  6. *
  7. * <span class="informal">It's like {@link find}, but emits the index of the
  8. * found value, not the value itself.</span>
  9. *
  10. * <img src="./img/findIndex.png" width="100%">
  11. *
  12. * `findIndex` searches for the first item in the source Observable that matches
  13. * the specified condition embodied by the `predicate`, and returns the
  14. * (zero-based) index of the first occurrence in the source. Unlike
  15. * {@link first}, the `predicate` is required in `findIndex`, and does not emit
  16. * an error if a valid value is not found.
  17. *
  18. * @example <caption>Emit the index of first click that happens on a DIV element</caption>
  19. * var clicks = Rx.Observable.fromEvent(document, 'click');
  20. * var result = clicks.findIndex(ev => ev.target.tagName === 'DIV');
  21. * result.subscribe(x => console.log(x));
  22. *
  23. * @see {@link filter}
  24. * @see {@link find}
  25. * @see {@link first}
  26. * @see {@link take}
  27. *
  28. * @param {function(value: T, index: number, source: Observable<T>): boolean} predicate
  29. * A function called with each item to test for condition matching.
  30. * @param {any} [thisArg] An optional argument to determine the value of `this`
  31. * in the `predicate` function.
  32. * @return {Observable} An Observable of the index of the first item that
  33. * matches the condition.
  34. * @method find
  35. * @owner Observable
  36. */
  37. function findIndex(predicate, thisArg) {
  38. return findIndex_1.findIndex(predicate, thisArg)(this);
  39. }
  40. exports.findIndex = findIndex;
  41. //# sourceMappingURL=findIndex.js.map