January 2019
Beginner
210 pages
4h 47m
English
The reduce operator function can be used to transform all the values in an observable into one single value:
import { from } from "rxjs";import { reduce } from "rxjs/operators";const observable = from<number>([1, 2, 3, 3, 4, 5]);observable.pipe(reduce((x, y) => x + y));const subscription = observable.subscribe( (value) => console.log(value));subscription.unsubscribe();
The preceding code snippet uses the reduce operator to transform the values in an observable into a new single value (the total of all the values). The function that transforms multiple values into one single value is known as an accumulator. The following marble diagram showcases the initial sequence and the result sequence after applying the reduce operator:
The result ...
Read now
Unlock full access