Created
April 20, 2019 20:37
-
-
Save kosich/a69f909dbb8dfe43e459beaa1a004d18 to your computer and use it in GitHub Desktop.
https://stackoverflow.com/questions/55758934/rxjs-only-emit-bigger-values-than-the-last-value/55772042 **alternative**
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 } = require('api/v0.3'); | |
const { timer, from, of, EMPTY } = require('rxjs'); | |
const { zip, debounceTime, map, scan, distinctUntilChanged } = require('rxjs/operators'); | |
// create a source using values | |
const values$ = from([ 5, 10, 20, 10, 5, 20, 0, 5, 30 ]); | |
const source$ = timer(0, 10).pipe( | |
zip(values$, (_,x)=>x) | |
); | |
const result$ = source$.pipe( | |
map(e => e), | |
scan((prev, curr) => Math.max(prev, curr), 0), | |
distinctUntilChanged() | |
); | |
source$.subscribe(rxObserver('source$')); | |
result$.subscribe(rxObserver('result$')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment