UNPKG

1.34 kBPlain TextView Raw
1import { Observable } from 'rxjs';
2import { skipLast as higherOrder } from 'rxjs/operators';
3
4/**
5 * Skip the last `count` values emitted by the source Observable.
6 *
7 * <img src="./img/skipLast.png" width="100%">
8 *
9 * `skipLast` returns an Observable that accumulates a queue with a length
10 * enough to store the first `count` values. As more values are received,
11 * values are taken from the front of the queue and produced on the result
12 * sequence. This causes values to be delayed.
13 *
14 * @example <caption>Skip the last 2 values of an Observable with many values</caption>
15 * var many = Rx.Observable.range(1, 5);
16 * var skipLastTwo = many.skipLast(2);
17 * skipLastTwo.subscribe(x => console.log(x));
18 *
19 * // Results in:
20 * // 1 2 3
21 *
22 * @see {@link skip}
23 * @see {@link skipUntil}
24 * @see {@link skipWhile}
25 * @see {@link take}
26 *
27 * @throws {ArgumentOutOfRangeError} When using `skipLast(i)`, it throws
28 * ArgumentOutOrRangeError if `i < 0`.
29 *
30 * @param {number} count Number of elements to skip from the end of the source Observable.
31 * @returns {Observable<T>} An Observable that skips the last count values
32 * emitted by the source Observable.
33 * @method skipLast
34 * @owner Observable
35 */
36export function skipLast<T>(this: Observable<T>, count: number): Observable<T> {
37 return higherOrder(count)(this) as Observable<T>;
38}