Skip to content

Latest commit

 

History

History
82 lines (62 loc) · 1.79 KB

generate.md

File metadata and controls

82 lines (62 loc) · 1.79 KB

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

( 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:
..
.....
........
...........
..............
.................
....................
.......................
..........................
.............................
................................
...................................
......................................
*/

Related Recipes

Additional Resources


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