3732a5079c9bc166e6640a29b4171e7695b680780a5ab7b862aba8cbc9ec2fc45cf237ee3457f451b003538562b1309d41209df52c8b1749a2d5534504bdcc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { OperatorFunction } from '../types';
  2. /**
  3. * Emits the single value at the specified `index` in a sequence of emissions
  4. * from the source Observable.
  5. *
  6. * <span class="informal">Emits only the i-th value, then completes.</span>
  7. *
  8. * ![](elementAt.png)
  9. *
  10. * `elementAt` returns an Observable that emits the item at the specified
  11. * `index` in the source Observable, or a default value if that `index` is out
  12. * of range and the `default` argument is provided. If the `default` argument is
  13. * not given and the `index` is out of range, the output Observable will emit an
  14. * `ArgumentOutOfRangeError` error.
  15. *
  16. * ## Example
  17. *
  18. * Emit only the third click event
  19. *
  20. * ```ts
  21. * import { fromEvent, elementAt } from 'rxjs';
  22. *
  23. * const clicks = fromEvent(document, 'click');
  24. * const result = clicks.pipe(elementAt(2));
  25. * result.subscribe(x => console.log(x));
  26. *
  27. * // Results in:
  28. * // click 1 = nothing
  29. * // click 2 = nothing
  30. * // click 3 = MouseEvent object logged to console
  31. * ```
  32. *
  33. * @see {@link first}
  34. * @see {@link last}
  35. * @see {@link skip}
  36. * @see {@link single}
  37. * @see {@link take}
  38. *
  39. * @throws {ArgumentOutOfRangeError} When using `elementAt(i)`, it delivers an
  40. * `ArgumentOutOfRangeError` to the Observer's `error` callback if `i < 0` or the
  41. * Observable has completed before emitting the i-th `next` notification.
  42. *
  43. * @param index Is the number `i` for the i-th source emission that has happened
  44. * since the subscription, starting from the number `0`.
  45. * @param defaultValue The default value returned for missing indices.
  46. * @return A function that returns an Observable that emits a single item, if
  47. * it is found. Otherwise, it will emit the default value if given. If not, it
  48. * emits an error.
  49. */
  50. export declare function elementAt<T, D = T>(index: number, defaultValue?: D): OperatorFunction<T, T | D>;
  51. //# sourceMappingURL=elementAt.d.ts.map