takeLast.d.ts 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { Observable } from '../Observable';
  2. /**
  3. * Emits only the last `count` values emitted by the source Observable.
  4. *
  5. * <span class="informal">Remembers the latest `count` values, then emits those
  6. * only when the source completes.</span>
  7. *
  8. * <img src="./img/takeLast.png" width="100%">
  9. *
  10. * `takeLast` returns an Observable that emits at most the last `count` values
  11. * emitted by the source Observable. If the source emits fewer than `count`
  12. * values then all of its values are emitted. This operator must wait until the
  13. * `complete` notification emission from the source in order to emit the `next`
  14. * values on the output Observable, because otherwise it is impossible to know
  15. * whether or not more values will be emitted on the source. For this reason,
  16. * all values are emitted synchronously, followed by the complete notification.
  17. *
  18. * @example <caption>Take the last 3 values of an Observable with many values</caption>
  19. * var many = Rx.Observable.range(1, 100);
  20. * var lastThree = many.takeLast(3);
  21. * lastThree.subscribe(x => console.log(x));
  22. *
  23. * @see {@link take}
  24. * @see {@link takeUntil}
  25. * @see {@link takeWhile}
  26. * @see {@link skip}
  27. *
  28. * @throws {ArgumentOutOfRangeError} When using `takeLast(i)`, it delivers an
  29. * ArgumentOutOrRangeError to the Observer's `error` callback if `i < 0`.
  30. *
  31. * @param {number} count The maximum number of values to emit from the end of
  32. * the sequence of values emitted by the source Observable.
  33. * @return {Observable<T>} An Observable that emits at most the last count
  34. * values emitted by the source Observable.
  35. * @method takeLast
  36. * @owner Observable
  37. */
  38. export declare function takeLast<T>(this: Observable<T>, count: number): Observable<T>;