suppress the first n items emitted by an Observable
You can ignore the first n items emitted by an Observable and attend only to those items that come after, by modifying the Observable with the Skip operator.
skip
In RxGroovy, this operator is implemented as skip.
numbers = Observable.from([1, 2, 3, 4, 5, 6, 7, 8]); numbers.skip(3).subscribe( { println(it); }, // onNext { println("Error: " + it.getMessage()); }, // onError { println("Sequence complete"); } // onCompleted );
4 5 6 7 8 Sequence complete
This variant of skip does not by default operate on any particular Scheduler.
skip(int)
There is also a variant of skip that takes a temporal duration rather than a quantity of items. It drops those items that are emitted during that initial 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 skip.
This variant of skip by default operates on the computation Scheduler, but you may also pass in a Scheduler of your choosing as an optional third parameter.
computation
skip(long,TimeUnit)
skip(long,TimeUnit,Scheduler)
In RxJava, this operator is implemented as skip.
skip skipUntilWithTime
RxJS implements the skip operator.
var source = Rx.Observable.range(0, 5) .skip(3); var subscription = source.subscribe( function (x) { console.log('Next: ' + x); }, function (err) { console.log('Error: ' + err); }, function () { console.log('Completed'); });
Next: 3 Next: 4 Completed
skip 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
RxJS also implements a skipUntilWithTime operator that does not skip a particular quantity of items from the source Observable, but skips items based on chronology. You set this skip period by passing in a parameter to skipUntilWithTime, in either of these formats:
skipUntilWithTime
Date
You may also, optionally, pass in a Scheduler as a second parameter, and the timer will operate on that Scheduler (skipUntilWithTime uses the timeout Scheduler by default).
timeout
var source = Rx.Observable.timer(0, 1000) .skipUntilWithTime(5000); var subscription = source.subscribe( function (x) { console.log('Next: ' + x); }, function (err) { console.log('Error: ' + err); }, function () { console.log('Completed'); });
Next: 6 Next: 7 Next: 8 Completed
skipUntilWithTime is found in each of the following distributions:
rx.time.js
RxPHP implements this operator as skip.
//from https://github.com/ReactiveX/RxPHP/blob/master/demo/skip/skip.php use Rx\Observable\ArrayObservable; $observable = Rx\Observable::fromArray([1, 1, 2, 3, 5, 8, 13]); $observable ->skip(3) ->subscribe($stdoutObserver);
Next value: 3 Next value: 5 Next value: 8 Next value: 13 Complete!
© ReactiveX contributorsLicensed under the Apache License 2.0. http://reactivex.io/documentation/operators/skip.html