RX Observable.TakeWhile checks condition BEFORE each element but I need to perform the check after

前端 未结 6 2152
谎友^
谎友^ 2020-12-30 11:50

Observable.TakeWhile allows you to run a sequence as long as a condition is true (using a delegate so we can perform computations on the actual sequence objects), but it\'s

6条回答
  •  滥情空心
    2020-12-30 11:58

    Perhaps the following way will be useful to someone. You must use the "Do" method and the empty "Subscribe" method.

        listOfCommands.ToObservable()
        .Do(x =>
        {
            Debug.WriteLine("{0} of {1}", x.CurrentIndex, x.TotalCount);
        })
        .TakeWhile(c => c.CurrentIndex != c.TotalCount)
        .Subscribe();
    

    This way you get the result without writing your own extensions.

提交回复
热议问题