Last active
November 5, 2015 23:59
-
-
Save TerribleDev/b24e5816e383bf76db52 to your computer and use it in GitHub Desktop.
Get Friday the 13ths Linq Style
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
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