How to get Sum of “last” items of N hot Observable instances?

后端 未结 2 445
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-11 04:56

EDIT: On 09/15/2013 - I am describing my scenario further broken into steps to help everybody understand my situation better. Added the source for whole application for down

2条回答
  •  误落风尘
    2020-12-11 05:37

    Lots of questions! Maybe time to brush up on your Rx skillz? Pretty much all of your recent questions are covered in my web site IntroToRx.com. Having a deep understanding of Rx, will allow you to answer these fairly simple questions much more quickly than asking on a forum. You should be able to read the book in less than 3 days.

    Anyway....

    1 Do you want a running sum or just a single sum at the end?

    2 Then, do you want a sum for all values for all streams, or the sums of each stream?

    To get a single sum value for a sequence you use the .Sum() operator. http://introtorx.com/Content/v1.0.10621.0/07_Aggregation.html#MaxAndMin

    To get a running total, use the Scan operator. http://introtorx.com/Content/v1.0.10621.0/07_Aggregation.html#Scan

    So the answer is probably something like this (untested):

    sources.Select(source=>source.Scan(0m, (acc, value)=>acc+=value)).Merge();
    

提交回复
热议问题