Learn RxJS
Search…
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
1
// RxJS v6+
2
import { generate } from 'rxjs';
3
4
generate(
5
2,
6
x => x <= 8,
7
x => x + 3
8
).subscribe(console.log);
9
10
/*
11
OUTPUT:
12
2
13
5
14
8
15
*/
Copied!
Example 2: Generate with result selector
1
// RxJS v6+
2
import { generate } from 'rxjs';
3
4
generate(
5
2,
6
x => x <= 38,
7
x => x + 3,
8
x => '.'.repeat(x)
9
).subscribe(console.log);
10
11
/*
12
OUTPUT:
13
..
14
.....
15
........
16
...........
17
..............
18
.................
19
....................
20
.......................
21
..........................
22
.............................
23
................................
24
...................................
25
......................................
26
*/
Copied!

Additional Resources

Last modified 1yr ago