Range

create an Observable that emits a particular range of sequential integers

Range

The Range operator emits a range of sequential integers, in order, where you select the start of the range and its length.

See Also

Language-Specific Information:

range

RxGroovy implements this operator as range. It accepts as its parameters the start value of the range and the number of items in the range. If you set that number of items to zero, the resulting Observable will emit no values (if you set it to a negative number, range will cause an exception).

range does not by default operate on any particular Scheduler, but there is a variant that allows you to set the Scheduler by passing one in as a parameter.

Sample Code

// myObservable emits the integers 5, 6, and 7 before completing:
def myObservable = Observable.range(5, 3);
range

RxJava implements this operator as range. It accepts as its parameters the start value of the range and the number of items in the range. If you set that number of items to zero, the resulting Observable will emit no values (if you set it to a negative number, range will cause an exception).

range does not by default operate on any particular Scheduler, but there is a variant that allows you to set the Scheduler by passing one in as a parameter.

range

RxJS implements this operator as range. It accepts as its parameters the start value of the range and the number of items in the range.

range operates by default on the currentThread Scheduler, but there is a variant that allows you to set the Scheduler by passing one in as the optional third parameter.

Sample Code

var source = Rx.Observable.range(0, 3);

var subscription = source.subscribe(
    function (x) { console.log('Next: ' + x); },
    function (err) { console.log('Error: ' + err); },
    function () { console.log('Completed'); });
Next: 0
Next: 1
Next: 2
Completed

range is found in each of the following distributions:

  • rx.js
  • rx.compat.js
  • rx.lite.js
  • rx.lite.compat.js

RxPHP implements this operator as range.

Generates an observable sequence of integral numbers within a specified range, using the specified scheduler to send out observer messages.

Sample Code

//from https://github.com/ReactiveX/RxPHP/blob/master/demo/range/range.php

$observable = \Rx\Observable::range(0, 3);

$observable->subscribe($stdoutObserver);

//Next value: 0
//Next value: 1
//Next value: 2
//Complete!

   
Next value: 0
Next value: 1
Next value: 2
Complete!