The Repeat operator emits an item repeatedly. Some implementations of this operator allow you to repeat a sequence of items, and some permit you to limit the number of repetitions.
TBD
TBD
RxGroovy implements this operator as repeat. It does not initiate an Observable,
but operates on an Observable in such a way that it repeats the sequence emitted by the
source Observable as its own sequence, either infinitely, or in the case of
repeat(n), n times.
repeat operates by default on the trampoline
Scheduler. There is also a variant that allows you to set the Scheduler by
passing one in as a parameter.
repeat()repeat(long)repeat(Scheduler)repeat(long,Scheduler)
There is also an operator called repeatWhen. Rather than buffering and replaying
the sequence from the source Observable, it resubscribes to and mirrors the source
Observable, but only conditionally.
It decides whether to resubscribe and remirror the source Observable by passing that
Observable’s termination notifications (error or completed) to a notification handler as
void emissions. This notification handler acts as an Observable operator, taking
an Observable that emits these void notifications as input, and returning an
Observable that emits void items (meaning, resubscribe and mirror the source
Observable) or terminates (meaning, terminate the sequence emitted by
repeatWhen).
repeatWhen operates by default on the trampoline
Scheduler. There is also a variant that allows you to set the Scheduler by
passing one in as a parameter.
repeatWhen(Func1)repeatWhen(Func1,Scheduler)
In RxGroovy, doWhile is not part of the standard set of operators, but is part of the
optional rxjava-computation-expressions package. doWhile checks a condition
after each repetition of the source sequence, and only repeats it if that condition is true.
In RxGroovy, whileDo is not part of the standard set of operators, but is part of the
optional rxjava-computation-expressions package. whileDo checks a condition
before each repetition of the source sequence, and only repeats it if that condition is true.
RxJava implements this operator as repeat. It does not initiate an Observable,
but operates on an Observable in such a way that it repeats the sequence emitted by the
source Observable as its own sequence, either infinitely, or in the case of
repeat(n), n times.
repeat operates by default on the trampoline
Scheduler. There is also a variant that allows you to set the Scheduler by
passing one in as a parameter.
repeat()repeat(long)repeat(Scheduler)repeat(long,Scheduler)
There is also an operator called repeatWhen. Rather than buffering and replaying
the sequence from the source Observable, it resubscribes to and mirrors the source
Observable, but only conditionally.
It decides whether to resubscribe and remirror the source Observable by passing that
Observable’s termination notifications (error or completed) to a notification handler as
void emissions. This notification handler acts as an Observable operator, taking
an Observable that emits these void notifications as input, and returning an
Observable that emits void items (meaning, resubscribe and mirror the source
Observable) or terminates (meaning, terminate the sequence emitted by
repeatWhen).
repeatWhen operates by default on the trampoline
Scheduler. There is also a variant that allows you to set the Scheduler by
passing one in as a parameter.
repeatWhen(Func1)repeatWhen(Func1,Scheduler)
In RxJava, doWhile is not part of the standard set of operators, but is part of the
optional rxjava-computation-expressions package. doWhile checks a condition
after each repetition of the source sequence, and only repeats it if that condition is true.
In RxJava, whileDo is not part of the standard set of operators, but is part of the
optional rxjava-computation-expressions package. whileDo checks a condition
before each repetition of the source sequence, and only repeats it if that condition is true.
RxJS implements this operator as repeat. It accepts as its parameter the item to
repeat, and optionally two other parameters: the number of times you want the item to repeat,
and the Scheduler on which you want to perform this operation (it uses the
immediate Scheduler by default).
var source = Rx.Observable.repeat(42, 3);
var subscription = source.subscribe(
function (x) { console.log('Next: ' + x); },
function (err) { console.log('Error: ' + err); },
function () { console.log('Completed'); });Next: 42 Next: 42 Next: 42 Completed
repeat is found in the following distributions:
rx.jsrx.compat.jsrx.lite.jsrx.lite.compat.js
RxJS also implements the doWhile operator. It repeats the source Observable’s sequence
of emissions only so long as a condition you specify remains true.
var i = 0;
var source = Rx.Observable.return(42).doWhile(
function (x) { return ++i < 2; });
var subscription = source.subscribe(
function (x) { console.log('Next: ' + x); },
function (err) { console.log('Error: ' + err); },
function () { console.log('Completed'); });Next: 42 Next: 42 Completed
doWhile is found in each of the following distributions.
rx.all.jsrx.all.compat.jsrx.experimental.jsIt requires one of the following distributions:
rx.jsrx.compat.jsrx.lite.jsrx.lite.compat.js
RxJS also implements the while operator. It repeats the source Observable’s sequence
of emissions only if a condition you specify is true.
var i = 0;
// Repeat until condition no longer holds
var source = Rx.Observable.while(
function () { return i++ < 3 },
Rx.Observable.return(42)
);
var subscription = source.subscribe(
function (x) { console.log('Next: ' + x); },
function (err) { console.log('Error: ' + err); },
function () { console.log('Completed'); });Next: 42 Next: 42 Next: 42 Completed
while is found in the rx.experimental.js distribution. It requires one of the
following distributions:
rx.jsrx.compat.jsrx.lite.jsrx.lite.compat.jsTBD
RxPHP implements this operator as repeat.
Generates an observable sequence that repeats the given element the specified number of times.
//from https://github.com/ReactiveX/RxPHP/blob/master/demo/repeat/repeat.php
$source = \Rx\Observable::range(1, 3)
->repeat(3);
$subscription = $source->subscribe($createStdoutObserver());
Next value: 1
Next value: 2
Next value: 3
Next value: 1
Next value: 2
Next value: 3
Next value: 1
Next value: 2
Next value: 3
Complete!