Skip to content

Instantly share code, notes, and snippets.

@TerribleDev
Last active November 5, 2015 23:59
Show Gist options
  • Save TerribleDev/b24e5816e383bf76db52 to your computer and use it in GitHub Desktop.
Save TerribleDev/b24e5816e383bf76db52 to your computer and use it in GitHub Desktop.
Get Friday the 13ths Linq Style
void Main()
{
var next5Friday13 = DateTime.Today
.Recurse(a=>a.AddDays(1))
.Where(a=>a.Day == 13 && a.DayOfWeek == DayOfWeek.Friday).Take(5);
}
public static class Extension
{
public static IEnumerable<T> Recurse<T>(this T obj, Func<T,T> action)
{
var local = obj;
while(true)
{
local = action(local);
yield return local;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment