Learn RxJS
Search
K

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.

Ultimate RxJS

Examples

Example 1: Generate
// 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
// RxJS v6+
import { generate } from 'rxjs';
generate(
2,
x => x <= 38,
x => x + 3,
x => '.'.repeat(x)
).subscribe(console.log);
/*
OUTPUT:
..
.....
........
...........
..............
.................
....................
.......................
..........................
.............................
................................
...................................
......................................
*/

Additional Resources

Last modified 3yr ago