discard items emitted by an Observable until a specified condition becomes false
The SkipWhile subscribes to the source Observable, but ignores its emissions until such time as some condition you specify becomes false, at which point SkipWhile begins to mirror the source Observable.
skipWhile
The skipWhile
operator returns an Observable that discards items emitted by the source Observable until such time as a function, applied to an item emitted by that Observable, returns false
, whereupon the new Observable emits that item and the remainder of the items emitted by the source Observable.
numbers = Observable.from( [1, 2, 3, 4, 5, 6, 7, 8, 9] ); numbers.skipWhile({ (5 != it) }).subscribe( { println(it); }, // onNext { println("Error: " + it.getMessage()); }, // onError { println("Sequence complete"); } // onCompleted );
skipWhile
does not by default operate on any particular Scheduler.
skipWhile(Func1)
skipWhile
The skipWhile
operator returns an Observable that discards items emitted by the source Observable until such time as a function, applied to an item emitted by that Observable, returns false
, whereupon the new Observable emits that item and the remainder of the items emitted by the source Observable.
skipWhile
does not by default operate on any particular Scheduler.
skipWhile(Func1)
skipWhile
RxJS implements the skipWhile
operator. You pass it a function that governs the skipping process. skipWhile
calls that function for each item emitted by the source Observable until such time as the function returns false
, whereupon skipWhile
begins mirroring the source Observable (starting with that item). The function takes three parameters:
You may optionally pass a second parameter to skipWhile
. If so, that item will also be available to your predicate function as “this
”.
var source = Rx.Observable.range(1, 5) .skipWhile(function (x) { return x < 3; }); var subscription = source.subscribe( function (x) { console.log('Next: ' + x); }, function (err) { console.log('Error: ' + err); }, function () { console.log('Completed'); });
skipWhile
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
skipWhile skipWhileWithIndex
RxPHP implements this operator as skipWhile
.
Bypasses elements in an observable sequence as long as a specified condition is true and then returns the remaining elements.
//from https://github.com/ReactiveX/RxPHP/blob/master/demo/skip/skipWhile.php $observable = Rx\Observable::range(1, 5) ->skipWhile(function ($x) { return $x < 3; }); $observable->subscribe($stdoutObserver);
RxPHP also has an operator skipWhileWithIndex
.
Bypasses elements in an observable sequence as long as a specified condition is true and then returns the remaining elements. The element's index is used in the logic of the predicate function.
//from https://github.com/ReactiveX/RxPHP/blob/master/demo/skip/skipWhileWithIndex.php $observable = Rx\Observable::range(1, 5) ->skipWhileWithIndex(function ($i, $value) { return $i < 3; }); $observable->subscribe($stdoutObserver);
© ReactiveX contributors
Licensed under the Apache License 2.0.
http://reactivex.io/documentation/operators/skipwhile.html