Created
April 15, 2019 19:35
-
-
Save kosich/10c409101c4c1ff21e4b60c17bd2de06 to your computer and use it in GitHub Desktop.
Using array of observable functions with each items output being the next items input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { rxObserver, palette } = require('api/v0.3'); | |
const { of } = require('rxjs'); | |
const { switchMap, delay} = require('rxjs/operators'); | |
const fns = | |
[ (value) => of(value + 1).pipe(delay(100)) | |
, (value) => of(value + 3).pipe(delay(100)) | |
, (value) => of(value + 5).pipe(delay(100)) | |
] | |
fns.reduce( | |
(acc, fn) => acc.pipe( switchMap(fn) ) // switchMap to next fn result | |
, of(0) // initial value to pass to the first fn | |
) | |
.subscribe(rxObserver()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment