W3cubDocs

/ReactiveX

SkipLast

suppress the final n items emitted by an Observable
Open interactive diagram on rxmarbles.com

You can ignore the final n items emitted by an Observable and attend only to those items that come before them, by modifying the Observable with the SkipLast operator.

See Also

Language-Specific Information

skipLast

You can ignore the final n items emitted by an Observable and attend only to those items that precede them, by modifying the Observable with the skipLast(n) operator. Note that the mechanism by which this is implemented will delay the emission of any item from the source Observable until n additional items have been emitted by that Observable.

This variant of skipLast does not by default operate on any particular Scheduler.

skipLast

There is also a variant of skipLast that takes a temporal duration rather than a quantity of items. It drops those items that are emitted during that final duration of the source Observable’s lifespan. You set this duration by passing in a length of time and the time units this length is denominated in as parameters to skipLast.

Note that the mechanism by which this is implemented will delay the emission of any item from the source Observable until the given duration passes since its emission.

This variant of skipLast by default operates on the computation Scheduler, but you may also pass in a Scheduler of your choosing as an optional third parameter.

skipLast

You can ignore the final n items emitted by an Observable and attend only to those items that precede them, by modifying the Observable with the skipLast(n) operator. Note that the mechanism by which this is implemented will delay the emission of any item from the source Observable until n additional items have been emitted by that Observable.

This variant of skipLast does not by default operate on any particular Scheduler.

skipLast

There is also a variant of skipLast that takes a temporal duration rather than a quantity of items. It drops those items that are emitted during that final duration of the source Observable’s lifespan. You set this duration by passing in a length of time and the time units this length is denominated in as parameters to skipLast.

Note that the mechanism by which this is implemented will delay the emission of any item from the source Observable until the given duration passes since its emission.

This variant of skipLast by default operates on the computation Scheduler, but you may also pass in a Scheduler of your choosing as an optional third parameter.

skipLast

You can ignore the final n items emitted by an Observable and attend only to those items that precede them, by modifying the Observable with the skipLast(n) operator. Note that the mechanism by which this is implemented will delay the emission of any item from the source Observable until n additional items have been emitted by that Observable.

Sample Code

var source = Rx.Observable.range(0, 5)
    .skipLast(3);

var subscription = source.subscribe(
    function (x) { console.log('Next: ' + x); },
    function (err) { console.log('Error: ' + err); },
    function () { console.log('Completed'); });
Next: 0
Next: 1
Completed

skipLast is found in each of the following distributions:

  • rx.js
  • rx.all.js
  • rx.all.compat.js
  • rx.compat.js
  • rx.lite.js
  • rx.lite.compat.js
skipLastWithTime

The skipLastWithTime operator takes a temporal duration rather than a quantity of items. It drops those items that are emitted during that final duration of the source Observable’s lifespan. You set this duration by passing in a number of milliseconds as a parameter to skipLastWithTime.

Note that the mechanism by which this is implemented will delay the emission of any item from the source Observable until the given duration passes since its emission.

skipLastWithTime by default operates on the timeout Scheduler, but you may also pass in a Scheduler of your choosing as an optional second parameter.

Sample Code

var source = Rx.Observable.timer(0, 1000)
    .take(10)
    .skipLastWithTime(5000);

var subscription = source.subscribe(
    function (x) { console.log('Next: ' + x); },
    function (err) { console.log('Error: ' + err); },
    function () { console.log('Completed'); });
Next: 0
Next: 1
Next: 2
Next: 3
Next: 4
Completed

skipLastWithTime is found in each of the following distributions:

  • rx.all.js
  • rx.all.compat.js
  • rx.time.js (requires rx.js or rx.compat.js)
  • rx.lite.js
  • rx.lite.compat.js

RxPHP implements this operator as skipLast.

Bypasses a specified number of elements at the end of an observable sequence. This operator accumulates a queue with a length enough to store the first `count` elements. As more elements are received, elements are taken from the front of the queue and produced on the result sequence. This causes elements to be delayed.

Sample Code

//from https://github.com/ReactiveX/RxPHP/blob/master/demo/skip/skipLast.php

$observable = Rx\Observable::range(0, 5)
    ->skipLast(3);

$observable->subscribe($stdoutObserver);
Next value: 0
Next value: 1
Complete!

© ReactiveX contributors
Licensed under the Apache License 2.0.
http://reactivex.io/documentation/operators/skiplast.html