RxJS operators to deal with arrays, tuples, and dragging the original values along while adding more values to the pipeline.
npm install --save @rxjsx/rxjsx rxjs
import { of } from 'rxjs';
import { flatListMap } from '@rxjsx/rxjsx';
of([1, 2, 3], [4], [5, 6])
.pipe(flatListMap(x => of(x, 10+x)))
.subscribe(console.log);
You can experiment with the above code by forking this ReplIt repo or through this Medium article.
// instead of this
of([1, 2, 3]).pipe(map(l => l.map(e => e * 2))
// you can do this
of([1, 2, 3]).pipe(listMap(e => e * 2)) // [2, 4, 6]
// instead of this
let device;
deviceService.getDevice(id)
.pipe(tap(_device => device = _device))
.pipe(flatMap(_device => userService.getUser(device.owner)))
.pipe(map(_user => userService.unassignDevice(_user, _device)))
// you can do this
deviceService.getDevice(id)
.pipe(flatZipMap(device => userService.getUser(device.owner)))
.pipe(map(([device, user]) => userService.unassignDevice(user, device)))
The available operators so far are the following:
Operator | Description |
---|---|
flatMap / mergeMap |
RxJS's mergeMap alias |
zipMap |
To zip the transformed value with the original value |
flatZipMap / mergeZipMap |
Similar to zipMap, but to be used when a transformation returns an observable |
projectToFormer |
To project an observable of pairs, to get the first coordinate |
projectToLatter |
To project an observable of pairs, to get the second coordinate |
projectTo |
To project an observable of tuples |
mapFormer |
To transform the first coordinate of an observable of pairs |
mapLatter |
To transform the second coordinate of an observable of pairs |
flatMapFormer / mergeMapFormer |
Similar to mapFormer, but to work on stream-returning transformations |
flatMapLatter / mergeMapLatter |
Similar to mapLatter, but to work on stream-returning transformations |
listMap |
To transform an observable of list, with a mapping on the list elements |
flatListMap / mergeListMap |
To transform an observable of list, with a stream-returning member transformation |
listFlatMap |
To transform an observable of list, with a list-returning member transformation |
flatListFlatMap / mergeListFlatMap |
To transform an observable of list, with a list-observable-returning transformation |
Thanks goes to these wonderful people (emoji key):
Mohammad-Ali A'RΓBI π π§ π¦ |
SchweizS π€ π» π |
This project follows the all-contributors specification. Contributions of any kind welcome!
This project needs your support. Don't forget to leave a β behind.