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


C# Subject.SelectMany方法代码示例

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


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

示例1: values_are_taken_from_each_selected_value

        public void values_are_taken_from_each_selected_value()
        {
            var stats = new StatsObserver<int>();

            var source = new Subject<int>();
            var first = new Subject<int>();
            var second = new Subject<int>();

            var remaining = new Queue<IObservable<int>>();
            remaining.Enqueue(first);
            remaining.Enqueue(second);

            var manObs = source
                .SelectMany(x => remaining.Dequeue())
                .Subscribe(stats);

            source.OnNext(0);
            first.OnNext(1);

            source.OnNext(2);
            second.OnNext(3);
            first.OnNext(4);
            second.OnNext(5);

            Assert.AreEqual(4, stats.NextCount);
            Assert.AreEqual(1, stats.NextValues[0]);
            Assert.AreEqual(3, stats.NextValues[1]);
            Assert.AreEqual(4, stats.NextValues[2]);
            Assert.AreEqual(5, stats.NextValues[3]);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:30,代码来源:SelectManyFixture.cs

示例2: onerror_called_when_selector_throws_exception

        public void onerror_called_when_selector_throws_exception()
        {
            var stats = new StatsObserver<int>();

            var source = new Subject<int>();

            var manObs = source
                .SelectMany<int, int>(x => { throw new InvalidOperationException(); return (IObservable<int>)null; })
                .Subscribe(stats);

            source.OnNext(0);
            source.OnNext(2);

            Assert.AreEqual(1, stats.ErrorCount);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:15,代码来源:SelectManyFixture.cs

示例3: SelectMany

        public void SelectMany()
        {
            var a = new Subject<int>();
            var b = new Subject<int>();

            var list = new List<int>();
            a.SelectMany(_ => b).Subscribe(x => list.Add(x));

            a.OnNext(10);
            a.OnCompleted();
            b.OnNext(100);

            list.Count.Is(1);
            list[0].Is(100);
        }
开发者ID:uzzu,项目名称:UniRx,代码行数:15,代码来源:ObservableTest.cs

示例4: exception_thrown_when_selector_returns_null

        public void exception_thrown_when_selector_returns_null()
        {
            var stats = new StatsObserver<int>();

            var source = new Subject<int>();

            var manObs = source
                .SelectMany<int, int>(x => (IObservable<int>)null)
                .Subscribe(stats);

            source.OnNext(0);
            source.OnNext(2);

            Assert.AreEqual(0, stats.NextCount);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:15,代码来源:SelectManyFixture.cs

示例5: SelectorWithIndex

        public void SelectorWithIndex()
        {
            {
                // OnCompleted Case
                var a = new Subject<int>();
                var b = new Subject<int>();
                var c = new Subject<int>();
                var list = new List<string>();
                a.SelectMany((x, i) => (x == 10) ? b.Select(y => Tuple.Create(y, i)) : c.Select(y => Tuple.Create(y, i)))
                    .Materialize().Select(x => x.ToString()).Subscribe(x => list.Add(x));
                a.OnNext(10);
                a.OnNext(100);

                // do

                b.OnNext(200);
                c.OnNext(300);
                a.OnCompleted();
                b.OnCompleted();
                c.OnNext(400);
                c.OnCompleted();

                // check
                list.IsCollection("OnNext((200, 0))", "OnNext((300, 1))", "OnNext((400, 1))", "OnCompleted()");
            }
            {
                // OnError A
                var a = new Subject<int>();
                var b = new Subject<int>();
                var c = new Subject<int>();
                var list = new List<string>();
                a.SelectMany((x, i) => (x == 10) ? b.Select(y => Tuple.Create(y, i)) : c.Select(y => Tuple.Create(y, i)))
                    .Materialize().Select(x => x.ToString()).Subscribe(x => list.Add(x));
                a.OnNext(10);
                a.OnNext(100);

                // do

                b.OnNext(200);
                c.OnNext(300);
                a.OnError(new Exception());
                b.OnCompleted();
                c.OnNext(400);
                c.OnCompleted();

                // check
                list.IsCollection("OnNext((200, 0))", "OnNext((300, 1))", "OnError(System.Exception)");
            }
            {
                // OnError B
                var a = new Subject<int>();
                var b = new Subject<int>();
                var c = new Subject<int>();
                var list = new List<string>();
                a.SelectMany((x, i) => (x == 10) ? b.Select(y => Tuple.Create(y, i)) : c.Select(y => Tuple.Create(y, i)))
                    .Materialize().Select(x => x.ToString()).Subscribe(x => list.Add(x));
                a.OnNext(10);
                a.OnNext(100);

                // do

                b.OnNext(200);
                c.OnNext(300);
                a.OnCompleted();
                b.OnError(new Exception());
                c.OnNext(400);
                c.OnCompleted();

                // check
                list.IsCollection("OnNext((200, 0))", "OnNext((300, 1))", "OnError(System.Exception)");
            }
        }
开发者ID:ragcat,项目名称:UniRx,代码行数:72,代码来源:UnitTests.cs

示例6: SelectorEnumerableWithIndex

        public void SelectorEnumerableWithIndex()
        {
            {
                // OnCompleted Case
                var a = new Subject<int>();
                var list = new List<string>();
                a.SelectMany((x, i) => (x == 10) ? Enumerable.Range(i, 3) : Enumerable.Repeat(i, 3))
                    .Materialize().Select(x => x.ToString()).Subscribe(x => list.Add(x));
                a.OnNext(10);
                a.OnNext(100);

                // do
                a.OnCompleted();

                // check
                list.IsCollection("OnNext(0)", "OnNext(1)", "OnNext(2)", "OnNext(1)", "OnNext(1)", "OnNext(1)", "OnCompleted()");
            }
            {
                // OnError Case
                var a = new Subject<int>();
                var list = new List<string>();
                a.SelectMany((x, i) => (x == 10) ? Enumerable.Range(i, 3) : Enumerable.Repeat(i, 3))
                    .Materialize().Select(x => x.ToString()).Subscribe(x => list.Add(x));
                a.OnNext(10);
                a.OnNext(100);

                // do
                a.OnError(new Exception());

                // check
                list.IsCollection("OnNext(0)", "OnNext(1)", "OnNext(2)", "OnNext(1)", "OnNext(1)", "OnNext(1)", "OnError(System.Exception)");
            }
        }
开发者ID:ragcat,项目名称:UniRx,代码行数:33,代码来源:UnitTests.cs

示例7: Selector

        public void Selector()
        {
            {
                // OnCompleted Case
                var a = new Subject<int>();
                var b = new Subject<int>();
                var c = new Subject<int>();
                var list = new List<string>();
                a.SelectMany(x => (x == 10) ? b : c)
                    .Materialize().Select(x => x.ToString()).Subscribe(x => list.Add(x));
                a.OnNext(10);
                a.OnNext(100);

                // do

                b.OnNext(200);
                c.OnNext(300);
                a.OnCompleted();
                b.OnCompleted();
                c.OnNext(400);
                c.OnCompleted();

                // check
                list.IsCollection("OnNext(200)", "OnNext(300)", "OnNext(400)", "OnCompleted()");
            }
            {
                // OnError A
                var a = new Subject<int>();
                var b = new Subject<int>();
                var c = new Subject<int>();
                var list = new List<string>();
                a.SelectMany(x => (x == 10) ? b : c)
                    .Materialize().Select(x => x.ToString()).Subscribe(x => list.Add(x));
                a.OnNext(10);
                a.OnNext(100);

                // do

                b.OnNext(200);
                c.OnNext(300);
                a.OnError(new Exception());
                b.OnCompleted();
                c.OnNext(400);
                c.OnCompleted();

                // check
                list.IsCollection("OnNext(200)", "OnNext(300)", "OnError(System.Exception)");
            }
            {
                // OnError B
                var a = new Subject<int>();
                var b = new Subject<int>();
                var c = new Subject<int>();
                var list = new List<string>();
                a.SelectMany(x => (x == 10) ? b : c)
                    .Materialize().Select(x => x.ToString()).Subscribe(x => list.Add(x));
                a.OnNext(10);
                a.OnNext(100);

                // do

                b.OnNext(200);
                c.OnNext(300);
                a.OnCompleted();
                b.OnError(new Exception());
                c.OnNext(400);
                c.OnCompleted();

                // check
                list.IsCollection("OnNext(200)", "OnNext(300)", "OnError(System.Exception)");
            }
            {
                // OnCompleted Case2
                var a = new Subject<int>();
                var b = new Subject<int>();
                var c = new Subject<int>();
                var list = new List<string>();
                a.SelectMany(x => (x == 10) ? b : c)
                    .Materialize().Select(x => x.ToString()).Subscribe(x => list.Add(x));
                a.OnNext(10);
                a.OnNext(100);

                // do

                b.OnNext(200);
                c.OnNext(300);
                b.OnCompleted();
                c.OnCompleted();

                // check
                list.IsCollection("OnNext(200)", "OnNext(300)");

                a.OnCompleted();

                list.IsCollection("OnNext(200)", "OnNext(300)", "OnCompleted()");
            }
        }
开发者ID:ragcat,项目名称:UniRx,代码行数:97,代码来源:UnitTests.cs

示例8: ResultSelectorEnumerable

        public void ResultSelectorEnumerable()
        {
            {
                // OnCompleted Case
                var a = new Subject<int>();
                var list = new List<string>();
                a.SelectMany(x => (x == 10) ? Enumerable.Range(1, 3) : Enumerable.Repeat(10, 3), (x, y) => Tuple.Create(x, y))
                    .Materialize().Select(x => x.ToString()).Subscribe(x => list.Add(x));
                a.OnNext(10);
                a.OnNext(100);

                // do
                a.OnCompleted();

                // check
                list.IsCollection("OnNext((10, 1))", "OnNext((10, 2))", "OnNext((10, 3))", "OnNext((100, 10))", "OnNext((100, 10))", "OnNext((100, 10))", "OnCompleted()");
            }
            {
                // OnError Case
                var a = new Subject<int>();
                var list = new List<string>();
                a.SelectMany(x => (x == 10) ? Enumerable.Range(1, 3) : Enumerable.Repeat(10, 3), (x, y) => Tuple.Create(x, y))
                 .Materialize().Select(x => x.ToString()).Subscribe(x => list.Add(x));
                a.OnNext(10);
                a.OnNext(100);

                // do
                a.OnError(new Exception());

                // check
                list.IsCollection("OnNext((10, 1))", "OnNext((10, 2))", "OnNext((10, 3))", "OnNext((100, 10))", "OnNext((100, 10))", "OnNext((100, 10))", "OnError(System.Exception)");
            }
        }
开发者ID:ragcat,项目名称:UniRx,代码行数:33,代码来源:UnitTests.cs

示例9: SelectorEnumerable

 public void SelectorEnumerable()
 {
     SetScehdulerForImport();
     {
         // OnCompleted Case
         var a = new Subject<int>();
         var list = new List<string>();
         a.SelectMany(x => (x == 10) ? Enumerable.Range(1, 3) : Enumerable.Repeat(10, 3))
             .Materialize().Select(x => x.ToString()).Subscribe(x => list.Add(x));
         a.OnNext(10);
         a.OnNext(100);
         // do
         a.OnCompleted();
         // check
         list.IsCollection("OnNext(1)", "OnNext(2)", "OnNext(3)", "OnNext(10)", "OnNext(10)", "OnNext(10)", "OnCompleted()");
     }
     {
         // OnError Case
         var a = new Subject<int>();
         var list = new List<string>();
         a.SelectMany(x => (x == 10) ? Enumerable.Range(1, 3) : Enumerable.Repeat(10, 3))
             .Materialize().Select(x => x.ToString()).Subscribe(x => list.Add(x));
         a.OnNext(10);
         a.OnNext(100);
         // do
         a.OnError(new Exception());
         // check
         list.IsCollection("OnNext(1)", "OnNext(2)", "OnNext(3)", "OnNext(10)", "OnNext(10)", "OnNext(10)", "OnError(System.Exception)");
     }
     UniRx.Scheduler.SetDefaultForUnity();
 }
开发者ID:neuecc,项目名称:UniRx,代码行数:31,代码来源:TestImporter.cs

示例10: ResultSelectorWithIndex

 public void ResultSelectorWithIndex()
 {
     SetScehdulerForImport();
     {
         // OnCompleted Case
         var a = new Subject<int>();
         var b = new Subject<int>();
         var c = new Subject<int>();
         var list = new List<string>();
         a.SelectMany((x, i) => (x == 10) ? b.Select(y => Tuple.Create(y, i)) : c.Select(y => Tuple.Create(y, i)), (x, i1, y, i2) => Tuple.Create(x, i1, y.Item1, y.Item2, i2))
             .Materialize().Select(x => x.ToString()).Subscribe(x => list.Add(x));
         a.OnNext(10);
         a.OnNext(100);
         // do
         b.OnNext(200);
         c.OnNext(300);
         a.OnCompleted();
         b.OnCompleted();
         c.OnNext(400);
         c.OnCompleted();
         // check
         list.IsCollection("OnNext((10, 0, 200, 0, 0))", "OnNext((100, 1, 300, 1, 0))", "OnNext((100, 1, 400, 1, 1))", "OnCompleted()");
     }
     {
         // OnError A
         var a = new Subject<int>();
         var b = new Subject<int>();
         var c = new Subject<int>();
         var list = new List<string>();
         a.SelectMany((x, i) => (x == 10) ? b.Select(y => Tuple.Create(y, i)) : c.Select(y => Tuple.Create(y, i)), (x, i1, y, i2) => Tuple.Create(x, i1, y.Item1, y.Item2, i2))
             .Materialize().Select(x => x.ToString()).Subscribe(x => list.Add(x));
         a.OnNext(10);
         a.OnNext(100);
         // do
         b.OnNext(200);
         c.OnNext(300);
         a.OnError(new Exception());
         b.OnCompleted();
         c.OnNext(400);
         c.OnCompleted();
         // check
         list.IsCollection("OnNext((10, 0, 200, 0, 0))", "OnNext((100, 1, 300, 1, 0))", "OnError(System.Exception)");
     }
     {
         // OnError B
         var a = new Subject<int>();
         var b = new Subject<int>();
         var c = new Subject<int>();
         var list = new List<string>();
         a.SelectMany((x, i) => (x == 10) ? b.Select(y => Tuple.Create(y, i)) : c.Select(y => Tuple.Create(y, i)), (x, i1, y, i2) => Tuple.Create(x, i1, y.Item1, y.Item2, i2))
             .Materialize().Select(x => x.ToString()).Subscribe(x => list.Add(x));
         a.OnNext(10);
         a.OnNext(100);
         // do
         b.OnNext(200);
         c.OnNext(300);
         a.OnCompleted();
         b.OnError(new Exception());
         c.OnNext(400);
         c.OnCompleted();
         // check
         list.IsCollection("OnNext((10, 0, 200, 0, 0))", "OnNext((100, 1, 300, 1, 0))", "OnError(System.Exception)");
     }
     UniRx.Scheduler.SetDefaultForUnity();
 }
开发者ID:neuecc,项目名称:UniRx,代码行数:65,代码来源:TestImporter.cs

示例11: ResultSelectorEnumerableWithIndex

 public void ResultSelectorEnumerableWithIndex()
 {
     SetScehdulerForImport();
     {
         // OnCompleted Case
         var a = new Subject<int>();
         var list = new List<string>();
         a.SelectMany((x, i) => (x == 10) ? Enumerable.Range(i, 3) : Enumerable.Repeat(i, 3), (x, i1, y, i2) => Tuple.Create(x, i1, y, i2))
          .Materialize().Select(x => x.ToString()).Subscribe(x => list.Add(x));
         a.OnNext(10);
         a.OnNext(100);
         // do
         a.OnCompleted();
         // check
         list.IsCollection("OnNext((10, 0, 0, 0))", "OnNext((10, 0, 1, 1))", "OnNext((10, 0, 2, 2))", "OnNext((100, 1, 1, 0))", "OnNext((100, 1, 1, 1))", "OnNext((100, 1, 1, 2))", "OnCompleted()");
     }
     {
         // OnError Case
         var a = new Subject<int>();
         var list = new List<string>();
         a.SelectMany((x, i) => (x == 10) ? Enumerable.Range(i, 3) : Enumerable.Repeat(i, 3), (x, i1, y, i2) => Tuple.Create(x, i1, y, i2))
             .Materialize().Select(x => x.ToString()).Subscribe(x => list.Add(x));
         a.OnNext(10);
         a.OnNext(100);
         // do
         a.OnError(new Exception());
         // check
         list.IsCollection("OnNext((10, 0, 0, 0))", "OnNext((10, 0, 1, 1))", "OnNext((10, 0, 2, 2))", "OnNext((100, 1, 1, 0))", "OnNext((100, 1, 1, 1))", "OnNext((100, 1, 1, 2))", "OnError(System.Exception)");
     }
     UniRx.Scheduler.SetDefaultForUnity();
 }
开发者ID:neuecc,项目名称:UniRx,代码行数:31,代码来源:TestImporter.cs

示例12: SelectMany

 public void SelectMany()
 {
     SetScehdulerForImport();
     var a = new Subject<int>();
     var b = new Subject<int>();
     var list = new List<int>();
     a.SelectMany(_ => b).Subscribe(x => list.Add(x));
     a.OnNext(10);
     a.OnCompleted();
     b.OnNext(100);
     list.Count.Is(1);
     list[0].Is(100);
     UniRx.Scheduler.SetDefaultForUnity();
 }
开发者ID:neuecc,项目名称:UniRx,代码行数:14,代码来源:TestImporter.cs

示例13: ObserveNoteTagged

        public static IObservable<string> ObserveNoteTagged(this ObservableCollection<Note> notes)
        {
            var newNotes = new Subject<Note>();
            var newTags = new Subject<string>();
            newNotes
                .SelectMany(x => x.Tags.ObserveCollectionChangedArgs())
                .SelectMany(x => x.NewItems.Cast<string>())
                .Subscribe(newTags);
            notes.ObserveCollectionChangedArgs()
                .SelectMany(x => x.NewItems.Cast<Note>())
                .Subscribe(newNotes);

            return newTags;
        }
开发者ID:shishkin,项目名称:Stimpack,代码行数:14,代码来源:ViewModels.cs

示例14: GroupJoinBugRepro

        public void GroupJoinBugRepro()
        {
            Subject<int> left = new Subject<int>();
            Subject<int> right = new Subject<int>();

            Subject<Tuple<int,IObservable<int>>> groups =
                new Subject<Tuple<int,IObservable<int>>>();

            var groupJoinSubscription = left.GroupJoin(right,
                l => Observable.Never<Unit>().Finally(() => Debug.WriteLine("Left window subscription terminated")),
                r => Observable.Never<Unit>().Finally(() => Debug.WriteLine("Right window subscription terminated")),
                (l, rs) => new Tuple<int, IObservable<int>>(l, rs)
                )
                .Subscribe(groups);

            var groupsSubscription = groups
                .SelectMany(g => g.Item2.Select(r => new Tuple<int, int>(g.Item1, r)))
                .Select(t => String.Format("{0},{1}", t.Item1, t.Item2))
                .Subscribe(x => Debug.WriteLine(x));

            left.OnNext(0);
            left.OnNext(1);

            right.OnNext(2);

            Debug.WriteLine("Cancelling GroupJoin");
            groupJoinSubscription.Dispose();

            Debug.WriteLine("Cancelling Groups");
            groupsSubscription.Dispose();
        }
开发者ID:richardszalay,项目名称:raix,代码行数:31,代码来源:GroupJoinFixture.cs

示例15: computeBallPossession


//.........这里部分代码省略.........
                            }
                            //empty state
                            else
                            {
                                return new EventInfo
                                {
                                    state = "empty",
                                    player_id = MetaData.SENSOR_MAP[min_dist_sensor_id],
                                    ts = min_dist_Player.ts,
                                    ball_sensor_id=b.ballData.sensor_id,
                                    ballData=b.ballData
                                };

                            }
                        }
                        //game state is invalid either due to current ball is not in field or ts of
                        //ball and/or player sensors are out of bounds
                        else
                            return new EventInfo
                            {
                                state = "outOfFieldOrEnded",
                                player_id = MetaData.SENSOR_MAP[min_dist_sensor_id],
                                ts = min_dist_Player.ts,
                                ball_sensor_id=b.ballData.sensor_id,
                                ballData=b.ballData
                            };

                    }).Where(data =>
                    {
                        //possession state changes only occur on a hit or if game ends/ball out of field
                        return !(data.state.Equals("empty") || data.state.Equals("invalid"));
                    }).Subscribe(eventInfoStream);

            return eventInfoStream.SelectMany(data =>
                  {

                      if (data.state.Equals("outOfFieldOrEnded"))
                      {
                          //the player who possesses the ball hits it out of the field and
                          //the outOfFieldOrEnded state is for the active ball.
                          if (data.player_id.Equals(playerWithBallPossession)
                              && data.ball_sensor_id == ballSensorId)
                          {
                              //increment this players hit count
                              playerHitsMap[data.player_id] += 1;
                              //increment this player's possession time.
                              playerPossessionTimeMap[data.player_id] = data.ts - playerTsMap[data.player_id];
                              //No player is currently in possession of the ball
                              playerWithBallPossession = "";
                              //the ball is no longer active in field
                              ballSensorId = -1;

                              //publish state change
                              return new List<Update>
                                {
                                    new Update{
                                    toPublish = true,
                                    possessionData = new PlayerBallPossession
                                        {
                                            player_id = data.player_id,
                                            time = playerPossessionTimeMap[data.player_id],
                                            hits = playerHitsMap[data.player_id],
                                            ts = data.ts
                                        }
                                    }
                                };
开发者ID:mindis,项目名称:rticonnextdds-reactive,代码行数:67,代码来源:BallPossessionQuery.cs


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