findIndex.d.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { Observable } from '../Observable';
  2. import { OperatorFunction } from '../interfaces';
  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. export declare function findIndex<T>(predicate: (value: T, index: number, source: Observable<T>) => boolean, thisArg?: any): OperatorFunction<T, number>;