Skip to content

Latest commit

 

History

History
66 lines (53 loc) · 2.29 KB

generate.md

File metadata and controls

66 lines (53 loc) · 2.29 KB

Rx.Observable.generate(initialState, condition, iterate, resultSelector, [scheduler])

Generates an observable sequence in a manner similar to a for loop, using an optional scheduler to enumerate the values.

Arguments

  1. initialState (Any): Initial state.
  2. condition (Function): Condition to terminate generation (upon returning false).
  3. iterate (Function): Iteration step function.
  4. resultSelector (Function): Selector function for results produced in the sequence.
  5. [scheduler=Rx.Scheduler.currentThread] (Scheduler): Scheduler on which to run the generator loop. If not provided, defaults to Scheduler.currentThread.

Returns

(Observable): The generated sequence.

Example

var source = Rx.Observable.generate(
    0,
    function (x) { return x < 3; },
    function (x) { return x + 1; },
    function (x) { return x; }
);

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

Location

File:

Dist:

Prerequisites:

  • None

NPM Packages:

NuGet Packages:

Unit Tests: