snakster / cpp.react

C++React: A reactive programming library for C++11.
http://snakster.github.io/cpp.react/
Boost Software License 1.0
1.02k stars 128 forks source link

Misleading example in BasicSignals.cpp / Example 4 #2

Closed klaufir closed 10 years ago

klaufir commented 10 years ago
        SignalT<float> Average = Iterate(
            Input,
            0.0f,
            [] (int sample, float oldAvg) {
                return (oldAvg + sample) / 2.0f;
            });

This does not calculate an average. This code calculates

Therefore, the code

Sensor mySensor;
mySensor.Input << 10 << 5 << 10 << 8;
cout << "Average: " << mySensor.Average() << endl;

Produces the output

Example 4 - Creating stateful signals (2)
Average: 7.75

The average of the values (10, 5, 10, 8) is 8.25, not 7.75.