How can I use Rx to watch a decline?

I have an input sequence like 8, 7, 6, 5, 4, 3, 2, 1, 0, 5, 4, 3, 2, 1, 0, 4 . The result should show 0, 0 .

Yes, that would be easy. But I do not want the result to be 0, 0 when the input is only 0, 0 .

The fact is that it should publish only 0 when the previous value was greater than zero.

+4
source share
1 answer
 IObservable<int> source = new[] { 8, 7, 6, 5, 4, 3, 2, 1, 0, 5, 4, 3, 2, 1, 0, 4 }.ToObservable(); IObservable<int> edges = source.Zip(source.Skip(1), (f, s) => Tuple.Create(f, s)) .Where(t => t.Item1 > 0 && t.Item2 == 0) .Select(t => t.Item2); 
+4
source

Source: https://habr.com/ru/post/1497106/


All Articles