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.
( StackBlitz )
// RxJS v6+
import { generate } from 'rxjs';
generate(
2,
x => x <= 8,
x => x + 3
).subscribe(console.log);
/*
OUTPUT:
2
5
8
*/
( StackBlitz )
// RxJS v6+
import { generate } from 'rxjs';
generate(
2,
x => x <= 38,
x => x + 3,
x => '.'.repeat(x)
).subscribe(console.log);
/*
OUTPUT:
..
.....
........
...........
..............
.................
....................
.......................
..........................
.............................
................................
...................................
......................................
*/
- generate 📰 - Official docs
📁 Source Code: https://github.com/ReactiveX/rxjs/blob/master/src/internal/observable/generate.ts