i have stream of values limit using lower , upper bound, , decrease amount of logging emit values if change. problem second distinctuntilchanged()
in following snippet still produces duplicates:
observable // emits i.e. [2, 2, 2, 5, 5, 10, 20] .distinctuntilchanged() // becomes [2, 5, 10, 20] .map(target => { const correctedtarget = math.min(math.max(target, minimum), maximum); // let's min: 5, max: 10 if(correctedtarget != target) { logger.warn(`prediction wants scale out-of-bounds ${target}, limiting ${correctedtarget}`); } return correctedtarget; }) // becomes [5, 5, 10, 10] .distinctuntilchanged() // should [5, 10], [5, 5, 10, 10]
the rxjs docs state filter defaults simple equality comparison, i'd expect should work™.
one of colleagues (once again) identified problem (also matt). turns out initial assumption wrong - outline of code follows:
observable // emits credentials on interval .flatmap(credentials => { return observable2.dosomething() .distinctuntilchanged() ... })
as can see, distinctuntilchanged
chained observable2
, new observable stream every time credentials emitted. explains why comparator function made doesn't called @ all: there 1 value every time there nothing compare to.
Comments
Post a Comment