Skip to content

Instantly share code, notes, and snippets.

@kosich
Created April 15, 2019 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kosich/10c409101c4c1ff21e4b60c17bd2de06 to your computer and use it in GitHub Desktop.
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
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