Example #1
0
        public static RecordObserver <T> RecordWithGetValueAndSubscribe <T>(this IReadOnlyReactiveProperty <T> source)
        {
            var d        = new SingleAssignmentDisposable();
            var observer = new RecordObserver <T>(d);

            d.Disposable = source.GetValueAndSubscribe(observer);
            return(observer);
        }
        public static RecordObserver <T> Record <T>(this IObservable <T> source)
        {
            var d        = new SingleAssignmentDisposable();
            var observer = new RecordObserver <T>(d);

            d.Disposable = source.Subscribe(observer);

            return(observer);
        }
        public void GroupBy()
        {
            var subject = new Subject <int>();

            RecordObserver <int> a = null;
            RecordObserver <int> b = null;
            RecordObserver <int> c = null;

            subject.GroupBy(x => x % 3)
            .Subscribe(x =>
            {
                if (x.Key == 0)
                {
                    a = x.Record();
                }
                else if (x.Key == 1)
                {
                    b = x.Record();
                }
                else if (x.Key == 2)
                {
                    c = x.Record();
                }
            });

            subject.OnNext(99);
            subject.OnNext(100);
            subject.OnNext(101);

            subject.OnNext(0);
            subject.OnNext(1);
            subject.OnNext(2);

            a.Values.Is(99, 0);
            b.Values.Is(100, 1);
            c.Values.Is(101, 2);
        }