I want to combine two subjects in similar way as zip does, but with the following important difference.
I want an observables that combines two subjects in this way. When both have emitted values, emit the latest of their values. Then, both need to emit at least once again, then emit their latest emitted values. Etc.
Both subjects:
1 ———- 2 —– 3 — 4 ——————- 5 ——
——- a ——————- b — c — d —-————
Goal observable:
——- 1a —————– 4b —————-5d —-
Simple example: subject1 emits 5 times and after that subject2 emits once. The first emitted value of zip is a pair of both first emits of the subjects. I want (subj1-emit5, subj2-emit1).
2
Answers
How about
withLatestFrom
?stackblitz
I would proceed building an
almostZip
function with something like this (comments within the code to explain the logic)Here a stackblitz that represents how this work