Beispiel #1
0
        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            var svc = new PrimeCheckService();

            //var subscription = Observable.Range(2, 10)
            //                             .SelectMany((number) => svc.IsPrimeAsync(number),
            //                                         (number, isPrime) => new { number, isPrime})
            //                             .Where(x => x.isPrime)
            //                             .Select(x => x.number)
            //                             .Subscribe(x => Console.WriteLine(x));

            //var subscription = Observable.Range(2, 10)
            //                             .SelectMany((number) => svc.IsPrimeAsync(number),
            //                                         (number, isPrime) => new { number, isPrime })
            //                             .Where(x => x.isPrime)
            //                             .Select(x => x.number)
            //                             .Subscribe(x => Console.WriteLine(x));
            var subscription1 = Observable.Range(2, 10)
                                .SelectMany(async(number) => await svc.IsPrimeAsync(number))
                                .Where(x => x)
                                .Select(x => x)
                                .Subscribe(x => Console.WriteLine(x));

            //IObservable<int> primes =
            //    from number in Observable.Range(2, 10)
            //    from isPrime in svc.IsPrimeAsync(number)
            //    where isPrime
            //    select number;
            //primes.Subscribe(x => Console.WriteLine(x));
        }
Beispiel #2
0
        private void Button_Click_4(object sender, RoutedEventArgs e)
        {
            var svc = new PrimeCheckService();
            IObservable <int> primes =
                Observable.Range(2, 10)
                .Select(async number => new { number, isPrime = await svc.IsPrimeAsync(number) })
                .Concat()
                .Where(x => x.isPrime)
                .Select(x => x.number);

            primes.Subscribe(x => Console.WriteLine(x));
        }