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.
TBD
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 );
5 6 7 8 9 Sequence complete
skipWhile
does not by default operate on any particular
Scheduler.
skipWhile(Func1)
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)
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'); });
Next: 3 Next: 4 Next: 5 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
TBD
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);
Next value: 3 Next value: 4 Next value: 5 Complete!
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);
Next value: 4 Next value: 5 Complete!
TBD