generate

signature: generate(initialStateOrOptions: GenerateOptions, condition?: ConditionFunc, iterate?: IterateFunc, resultSelectorOrObservable?: (ResultFunc) | SchedulerLike, scheduler?: SchedulerLike): Observable

Generates an observable sequence by running a state-driven loop producing the sequence's elements, using the specified scheduler to send out observer messages.

Examples

Example 1: Generate

( StackBlitz )

// RxJS v6+
import { generate } from 'rxjs';

generate(2, x => x <= 8, x => x + 3).subscribe(console.log);

/*
OUTPUT:
2
5
8
*/
Example 2: Generate with result selector

( StackBlitz )

// RxJS v6+
import { generate } from 'rxjs';

generate(2, x => x <= 38, x => x + 3, x => '.'.repeat(x)).subscribe(
  console.log
);

/*
OUTPUT:
..
.....
........
...........
..............
.................
....................
.......................
..........................
.............................
................................
...................................
......................................
*/

Additional Resources


:file_folder: Source Code: https://github.com/ReactiveX/rxjs/blob/master/src/internal/observable/generate.ts

results matching ""

    No results matching ""