Esempio n. 1
0
        static void Main(string[] args)
        {
            var numbers = new[] { 3, 4, 5, 6, 7, 8, 89, 13 };

            foreach (var prime in numbers.Find(IsOdd))
            {
                Console.WriteLine(prime);
            }

            var client = new WebClient();
            //Func<string> download = () => client.DownloadString("http://microsoft.com");
            Func <string, string> download = (url) => client.DownloadString(url);
            var data = download.Partial("http://microsoft.com").WithRetry();            //now partial adapting the function that does not need a parameter....

            Func <string, Func <string> > downloadCurry = download.Curry();
            var data2      = downloadCurry("http://microsoft.com").WithRetry();
            var timekeeper = new TimeKeeper();
            var elapse     = timekeeper.Measure(() =>
            {
                foreach (var val in getRandomNUmbers().Find(IsOdd).Take(2))
                {
                    Console.WriteLine(val);
                }
            });

            Console.WriteLine(elapse);

            var timekeeper2 = new TimeKeeper();
            var elapsed2    = timekeeper.Measure(() => FindOddNumberAsParellel(0, 100000000));

            Console.WriteLine("for parellel  " + elapsed2);

            Console.WriteLine("Task specific things ");
            var task = new Task <IEnumerable <int> >(

                () => FindOddNumber(3, 100000)
                );

            var task2 = task.ContinueWith((antecedent) => {
                foreach (var number in antecedent.Result)
                {
                    Console.WriteLine(number);
                }
            });

            task.Start();

            Console.WriteLine("doing some other task");
            task2.Wait();
        }