Last active
August 29, 2015 14:03
-
-
Save richorama/80125dd2809bbf620fe8 to your computer and use it in GitHub Desktop.
FuncGenerator
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace ConsoleApplication1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
foreach (var x in FuncGenerator(0, 10).Take(10)) | |
{ | |
Console.WriteLine(x(3)); | |
} | |
Console.ReadKey(); | |
} | |
static IEnumerable<Func<int, int>> FuncGenerator(int startingPoint, int increment) | |
{ | |
var count = startingPoint; | |
while (true) | |
{ | |
// we could do something interesting here, as we can calculate something for the func | |
yield return new Func<int, int>((a) => | |
{ | |
// I'm sure I could do something interesting here, as execution is deferred | |
return count * a; | |
}); | |
count += increment; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment