takeLast.js 1.8 KB

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