Middle+
What types of operators exist in RxJS?
sobes.tech AI
Answer from AI
In RxJS, operators are functions that allow you to create, transform, filter, and combine data streams (Observables). The main types of operators:
- Creation operators — create an Observable from various sources, such as
of(),from(),interval(). - Transformation operators — modify data in the stream, such as
map(),scan(),buffer(). - Filtering operators — filter stream elements, such as
filter(),take(),debounceTime(). - Combination operators — combine multiple Observables, such as
merge(),concat(),combineLatest(). - Error handling operators — handle errors, such as
catchError(),retry(). - Utility operators — perform auxiliary actions, such as
tap(),finalize().
Example of using the map operator to transform data:
import { of } from 'rxjs';
import { map } from 'rxjs/operators';
of(1, 2, 3)
.pipe(
map(x => x * 10)
)
.subscribe(console.log); // Will output 10, 20, 30