How can I use Rx to observe a falling edge?

c#, system.reactive

Solution

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);

Problem

I have an input sequence like `8, 7, 6, 5, 4, 3, 2, 1, 0, 5, 4, 3, 2, 1, 0, 4`. What the result should show is `0, 0`. Yeah this would be easy. But I don't want the result being `0, 0`, when the input is only `0, 0`. The thing here is that it should only publish the `0` when the previous value was something greater than zero.

Original source