Transformation Operators part I

Observable as a Monad!

Nested Observable schema

MergeMap Operator

Named flatMap Operator on RxJS <= 4.X


        const clicks$ = rxjs.fromEvent(document, 'click')
        clicks$.pipe(rxjs.operators.mergeMap((ev) => rxjs.interval(1000)))
    
Maps each value to an Observable, then flattens all of these inner Observables using mergeAll

concatMap Operator


                const clicks$ = rxjs.fromEvent(document, 'click')
                clicks$.pipe(rxjs.operators.concatMap(
                    (ev) => rxjs.interval(1000)
                        .pipe(rxjs.operators.take(5)))
                )
        
Maps each value to an Observable, then flattens all of these inner Observables using concatAll

switchMap


            const clicks$ = rxjs.fromEvent(document, 'click')
            clicks$.pipe(
                rxjs.operators.switchMap(
                    (ev) => rxjs.interval(1000).pipe(rxjs.operators.take(5))
                )
            )
    
Maps each value to an Observable, then flattens all of these inner Observables using switchAll || Map to observable, complete previous inner observable, emit values

ExhaustMap Operator


                const clicks$ = rxjs.fromEvent(document, 'click')
                clicks$.pipe(rxjs.operators.exhaustMap(
                        (ev) => rxjs.interval(1000).pipe(rxjs.operators.take(5))
                    )
                )
        
Maps each value to an Observable, then flattens all of these inner Observables using exhaust || Map to inner observable, ignore other values until that observable completes

Other Transformation Operators