I'm using Reactive Extensions (Rx) in C# and want to filter events in the following way. Imagine I have the following originator sequence:
A B C D E F X G H I X J X X K L M N O X P
And I want to produce the following output:
E F X H I X J X X N O X
Basically, I would buffer (throttle?) events with a max bound (in the example this bound is 2), and when I get certain event (in this case event X), I want to flush that buffer to the output and start buffering again until I see the special event again.
I'm trying a few approaches but without any luck, and I imagine there should be an easy way to accomplish it that I am missing.
EDIT: one constraint, is that I expect to get TONS of events that are discarded, and only a few instances of X, so keeping a buffer in memory with thousands of events to read only the last 2 (or 20) is not really an option.