Skip to content

Instantly share code, notes, and snippets.

@dahlbyk
Created July 24, 2011 18:09
Show Gist options
  • Save dahlbyk/1102893 to your computer and use it in GitHub Desktop.
Save dahlbyk/1102893 to your computer and use it in GitHub Desktop.
Rx Sliding Window
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