How can you do in RX a simple, stateful transform of a sequence?
Say we want to make an exponential moving average transform of a IObservable noisySequence.
For many of these types of calculations, Buffer
is the easiest way
var movingAverage = noisySequence.Buffer(/*last*/ 3,
/*move forward*/ 1 /*at a time*/)
.Select(x => (x[0] + x[1] + x[2]) / 3.0);
If you need to carry state around, use the Scan
operator, which is like Aggregate
except that it yields values every iteration.
Edit: fixed comment syntax