Last active
August 29, 2015 14:17
-
-
Save higumachan/1a7dda35417f27681998 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IObservable<double> MovingAvg(IObservable<double> targetStream, int windowSize) | |
{ | |
return targetStream.Zip( | |
targetStream.Skip(windowSize) | |
.StartWith(Enumerable.Repeat(0.0, windowSize)), | |
(l, r) => Tuple.Create(r, l)) | |
.Scan(0.0, (ago, next) => { return ago - next.Item1 + next.Item2; }) | |
.Skip(windowSize) | |
.Select(x => x / windowSize) | |
; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment