effa7b00abcc916868d5b00f8c4f952b075085a68cda2faee2028ec06a54a63426b03a2ce75e4be6c1b4452d2368cc94bf8f26818fd723c5c39ed6ca4b25f9 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { MonoTypeOperatorFunction } from '../types';
  2. import { filter } from './filter';
  3. /**
  4. * Returns an Observable that skips the first `count` items emitted by the source Observable.
  5. *
  6. * ![](skip.png)
  7. *
  8. * Skips the values until the sent notifications are equal or less than provided skip count. It raises
  9. * an error if skip count is equal or more than the actual number of emits and source raises an error.
  10. *
  11. * ## Example
  12. *
  13. * Skip the values before the emission
  14. *
  15. * ```ts
  16. * import { interval, skip } from 'rxjs';
  17. *
  18. * // emit every half second
  19. * const source = interval(500);
  20. * // skip the first 10 emitted values
  21. * const result = source.pipe(skip(10));
  22. *
  23. * result.subscribe(value => console.log(value));
  24. * // output: 10...11...12...13...
  25. * ```
  26. *
  27. * @see {@link last}
  28. * @see {@link skipWhile}
  29. * @see {@link skipUntil}
  30. * @see {@link skipLast}
  31. *
  32. * @param count The number of times, items emitted by source Observable should be skipped.
  33. * @return A function that returns an Observable that skips the first `count`
  34. * values emitted by the source Observable.
  35. */
  36. export function skip<T>(count: number): MonoTypeOperatorFunction<T> {
  37. return filter((_, index) => count <= index);
  38. }