map
turns each emitted value into another value, using mapping function
Also check out
pluck
operator and try comparing map to pluck
1234567891011121314151617181920const { rxObserver } = require('api/v0.3'); const { timer } = require('rxjs'); const { map, take } = require('rxjs/operators'); // 5 values from a timer timer(0, 10) .pipe( take(5) ) .subscribe(rxObserver('timer(0, 5)')); // 5 mapped values from a timer timer(0, 10) .pipe( map(i => i + ' 🦆'), take(5) ) .subscribe(rxObserver('map(i => i + 🦆)'));
NOTE: if your mapping function returns an Observable or a Promise — you'll need one of *Map
operators:
mergeMap, exhaustMap, switchMap, concatMap
NOTE 2: I've created a package rxjs/proxy {👓} to simplify subproperty access:
It turns Observables of Objects into Objects of Observables
And rxjs/autorun package will let you easily map a single stream or combine multiple.