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
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 );
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.
skip(long,TimeUnit)
skip(long,TimeUnit,Scheduler)
skip
In RxJava, this operator is implemented as skip
.
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.
skip(long,TimeUnit)
skip(long,TimeUnit,Scheduler)
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'); });
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:
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).
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'); });
skipUntilWithTime
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
© ReactiveX contributors
Licensed under the Apache License 2.0.
http://reactivex.io/documentation/operators/skip.html