当前位置: 首页>>代码示例>>C#>>正文


C# Subject.GroupBy方法代码示例

本文整理汇总了C#中Subject.GroupBy方法的典型用法代码示例。如果您正苦于以下问题:C# Subject.GroupBy方法的具体用法?C# Subject.GroupBy怎么用?C# Subject.GroupBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Subject的用法示例。


在下文中一共展示了Subject.GroupBy方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BuildnewBrokersSubject

 /// <summary>
 /// Compose a Subject that tracks each broker in the cluster. Always replay all known brokers.
 /// </summary>
 /// <returns></returns>
 private ISubject<BrokerMeta, BrokerMeta> BuildnewBrokersSubject()
 {
     var subj = new Subject<BrokerMeta>();
     var pipeline =
         // group by BrokerMeta
         subj.GroupBy(e => e).
         // select 
         Select(g =>
         {
             // we only want one per Broker
             var gg = g.DistinctUntilChanged().Replay(1, Scheduler);
             gg.Connect();
             return gg;
         }).
         Replay(Scheduler);
     pipeline.Connect();
     var pipeline2 = pipeline.Merge();
     return Subject.Create(subj, pipeline2);
 }
开发者ID:KateHuiLiu,项目名称:kafka4net,代码行数:23,代码来源:Cluster.cs

示例2: GroupBy

 public void GroupBy()
 {
     SetScehdulerForImport();
     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.IsCollection(99, 0);
     b.Values.IsCollection(100, 1);
     c.Values.IsCollection(101, 2);
     UniRx.Scheduler.SetDefaultForUnity();
 }
开发者ID:neuecc,项目名称:UniRx,代码行数:34,代码来源:TestImporter.cs

示例3: GroupBy

        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.IsCollection(99, 0);
            b.Values.IsCollection(100, 1);
            c.Values.IsCollection(101, 2);
        }
开发者ID:byfar,项目名称:UniRx,代码行数:36,代码来源:UnitTests.cs

示例4: Should_notify_with_null_when_right_do_not_have_data

        public void Should_notify_with_null_when_right_do_not_have_data()
        {
            var bets = new Subject<Currency>();
            var ex = new Subject<ExRate>();

            var betsWithExRate = from g in ex.GroupBy(x => x.Currency)
                                 from b in bets.Where(b => b.Code == g.Key).WithLatest(g, (b, x) =>
                                 {
                                     b.ExRate = x.Rate;
                                     return b;
                                 })
                                 select b;

            var received = new List<Currency>();
            using (betsWithExRate.Subscribe(i => received.Add(i)))
            {
                ex.OnNext(new ExRate { Currency = "CNY", Rate = null });
                bets.OnNext(new Currency { Id = 1, Code = "CNY" });
                ex.OnNext(new ExRate { Currency = "CNY", Rate = 2.5m });
                ex.OnNext(new ExRate { Currency = "MYR", Rate = 2.5m });
                bets.OnNext(new Currency { Id = 2, Code = "CNY" });
                ex.OnNext(new ExRate { Currency = "CNY", Rate = 2.6m });
                bets.OnNext(new Currency { Id = 3, Code = "CNY" });

                Assert.AreEqual(3, received.Count);
                Assert.AreEqual(null, received[0].ExRate);
                Assert.AreEqual(2.5m, received[1].ExRate);
                Assert.AreEqual(2.6m, received[2].ExRate);
            }
        }
开发者ID:Misterhex,项目名称:Jittuu.Rx.AddOn,代码行数:30,代码来源:Observable.WithLatest.Tests.cs


注:本文中的Subject.GroupBy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。