Created
July 24, 2011 18:09
-
-
Save dahlbyk/1102893 to your computer and use it in GitHub Desktop.
Rx Sliding Window
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
static IObservable<string> CheckForFraud(IObservable<string> logins) | |
{ | |
return from g in logins.GroupByUntil(l => l, CheckForFraud) | |
from c in g.Count() | |
where c >= 3 | |
select g.Key; | |
} | |
static IObservable<Unit> CheckForFraud(IGroupedObservable<string, string> g) | |
{ | |
var loginAttemptsBeyondTwo = g.Skip(2).Select(_ => Unit.Default); | |
var fiveSecondsMax = Observable.Timer(TimeSpan.FromSeconds(5)).Select(_ => Unit.Default); | |
return loginAttemptsBeyondTwo.Amb(fiveSecondsMax); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment