Created
December 29, 2011 03:07
-
-
Save plioi/1531485 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
private static IEnumerable<int> ZipWith(Func<int, int, int> combinePair, | |
IEnumerable<int> listA, | |
IEnumerable<int> listB) | |
{ | |
return listA.Zip(listB, combinePair); | |
} | |
private static IEnumerable<int> Tail(IEnumerable<int> list) | |
{ | |
return list.Skip(1); | |
} | |
private static int Plus(int x, int y) | |
{ | |
return x + y; | |
} | |
//fibs = 0 : 1 : zipWith (+) fibs (tail fibs) | |
private static IEnumerable<int> Fibs() | |
{ | |
yield return 0; | |
yield return 1; | |
foreach (int sum in ZipWith(Plus, Fibs(), Tail(Fibs()))) | |
yield return sum; | |
} | |
public static void Main() | |
{ | |
foreach (int f in Fibs().TakeWhile(x => x < 100)) | |
Console.WriteLine(f); | |
Console.ReadLine(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment