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