RxJS Pipe Extensions
Install
$ npm install --save rxjs rxjs-pipe-ext
Usage
The available operators so far are the following:
- flatMap
- zipMap
- flatZipMap
- projectToFormer
- projectToLatter
- projectTo
- mapFormer
- mapLatter
- flatMapFormer
- flatMapLatter
- listMap
- flatListMap
- listFlatMap
- flatListFlatMap
flatMap
An alias of RxJS's mergeMap
. Just to get rid of the deprecation warning.
zipMap
Useful when one wants to transform a value, but also keep the original value to access later:
;; of1, 2, 3 .pipezipMap`` .subscribeconsole.logx, s;
Instead of the following code or similar solutions to store the original value of the observable:
;; ; of1, 2, 3 .pipetapnummericalVal = x .pipemap`` .subscribeconsole.lognummericalVal, s;
flatZipMap
Similar to flatMap
, it is used when the transformation returns an observable.
;; of1, 2, 3 .pipeflatZipMapof`` .subscribeconsole.logx, s;
projectToFormer
Projects an observable of pairs, i.e. Observable<[T1, T2]>
, to the first coordinate,
so to get an Observable<T1>
.
;; of<>, .pipeprojectToFormer .subscribeconsole.logn;
projectToLatter
Projects an observable of pairs, i.e. Observable<[T1, T2]>
, to the second coordinate,
so to get an Observable<T2>
.
;; of<>, .pipeprojectToLatter .subscribeconsole.logs;
projectTo
Projects an observable of tuples, i.e. Observable<T[]>
, to a custom coordinate,
so to get an Observable<T>
.
;; of, .pipeprojectTo1 // of(2, 5) .subscribeconsole.log;
mapFormer
Transforms the first coordinate of an observable of pairs.
;; of<>, .pipemapFormerx * 2 // [2, '1'], [4, '2'] .subscribeconsole.log;
mapLatter
Transforms the second coordinate of an observable of pairs.
;; of<>, .pipemapLatter`+` // [1, '1+1'], [2, '2+2'] .subscribeconsole.log;
flatMapFormer
Similar to mapFormer
, but works on stream-returning transformations:
;; of<>, .pipeflatMapFormerofx * 2 // [2, '1'], [4, '2'] .subscribeconsole.log;
flatMapLatter
Similar to mapLatter
, but works on stream-returning transformations:
;; of<>, .pipeflatMapLatterof`+` // [1, '1+1'], [2, '2+2'] .subscribeconsole.log;
listMap
Transforming an observable of list, with a mapping on the list elements:
;; of .pipelistMapx * 2 .subscribeconsole.log; // [2, 4, 6]
flatListMap
Transforming an observable of list, with a stream-returning member transformation:
;; of .pipeflatListMapofx * 2 .subscribeconsole.log; // [2, 4, 6]
listFlatMap
Transforming an observable of list, with a list-returning member transformation:
;; of .pipelistFlatMap .subscribeconsole.log; // [1, 2, 2, 4, 3, 6]
flatListFlatMap
Transforming an observable of list, with a list-observable-returning transformation:
;; of .pipeflatListFlatMapof .subscribeconsole.log; // [1, 2, 2, 4, 3, 6]
IDE Type Inference
If the IDE could not infer the type of operators like zipMap
, import them from
rxjs-pipe-ext/lib
instead:
;