I have two hot observables of integer. I want to combine both of them to a resulting one which always notifies observer with new sum every time a new value come in through either of the observables.
Suppose observable1 goes as follows ....., 3, 5, 9, 10, 16 -->
observable 2 goes like this .............., 1, 3, 2 --->
I want resulting one to maintain a sum in a way that adds everything to the sum coming through 1 and subtracts everything coming through 2 so in above example resulting one would go like this
..........................................37, 38, 35, 38, 33, 35, 26, 16 --->
I am thinking of doing it the following way
var result = Observable.Merge(observable1.Scan((p, n) => p + n),
.observable2.Scan((p, n) => p - n)))
.Scan((p, n) => p + n);
Does anybody know a better way?