<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.microsoft.co.il/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Bnaya Eshet : aggregate</title><link>http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/aggregate/default.aspx</link><description>Tags: aggregate</description><dc:language>en</dc:language><generator>CommunityServer 2007.1 (Build: 20917.1142)</generator><item><title>Rx TOC</title><link>http://blogs.microsoft.co.il/blogs/bnaya/archive/2012/04/04/rx-toc.aspx</link><pubDate>Thu, 05 Apr 2012 00:09:09 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:1054323</guid><dc:creator>bnaya</dc:creator><slash:comments>0</slash:comments><description>&lt;h2&gt;Rx TOC&lt;/h2&gt;  &lt;p&gt;this is a TOC (table of content) which summaries my previous post about Rx.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/bnaya/IMG_1113_2865_4B2E8647.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="Rx, Reactive Extension, IObservable, IObserver, Window, Buffer, Scan, Sample, Aggregate, LINQ, Distinct, Exception, Handling, TOC" border="0" alt="Rx, Reactive Extension, IObservable, IObserver, Window, Buffer, Scan, Sample, Aggregate, LINQ, Distinct, Exception, Handling, TOC" src="http://blogs.microsoft.co.il/blogs/bnaya/IMG_1113_2865_thumb_0B047E9B.png" width="485" height="327" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/bnaya/archive/2010/02/25/rx-for-beginners-toc.aspx"&gt;Rx - for beginners TOC&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/bnaya/archive/2010/02/23/rx-code-cartoon.aspx"&gt;Rx – Code cartoon&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/bnaya/archive/2011/12/22/rx-buffer.aspx"&gt;Rx - Buffer&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/bnaya/archive/2011/12/31/rx-window.aspx"&gt;Rx - Window&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/bnaya/archive/2012/01/05/rx-sample.aspx"&gt;Rx - Sample&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/bnaya/archive/2012/01/22/rx-exception-handling.aspx"&gt;Rx - Exception Handling&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/bnaya/archive/2012/01/24/rx-aggregate-vs-scan.aspx"&gt;Rx - Aggregate vs. Scan&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/bnaya/archive/2012/02/02/rx-distinctuntilchanged.aspx"&gt;Rx - DistinctUntilChanged&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/bnaya/archive/2012/02/14/rx-and-time-related-operators.aspx"&gt;Rx and Time related operators&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=1054323" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/Rx/default.aspx">Rx</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/IObserver/default.aspx">IObserver</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/IObservable/default.aspx">IObservable</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/IQbservable/default.aspx">IQbservable</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/Reactive/default.aspx">Reactive</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/IScheduler/default.aspx">IScheduler</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/Reactive+Extension/default.aspx">Reactive Extension</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/Buffer/default.aspx">Buffer</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/Window/default.aspx">Window</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/Sample/default.aspx">Sample</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/exception/default.aspx">exception</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/linq/default.aspx">linq</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/scan/default.aspx">scan</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/aggregate/default.aspx">aggregate</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/TOC/default.aspx">TOC</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/Distinct/default.aspx">Distinct</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/Handling/default.aspx">Handling</category></item><item><title>Rx - Aggregate vs. Scan</title><link>http://blogs.microsoft.co.il/blogs/bnaya/archive/2012/01/24/rx-aggregate-vs-scan.aspx</link><pubDate>Tue, 24 Jan 2012 18:25:52 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:996264</guid><dc:creator>bnaya</dc:creator><slash:comments>0</slash:comments><description>&lt;h2&gt;Rx - Aggregate vs. Scan&lt;/h2&gt;  &lt;p&gt;this post will focus on 2 &lt;strong&gt;Rx&lt;/strong&gt; operators &lt;strong&gt;Aggregate&lt;/strong&gt; and &lt;strong&gt;Scan&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/bnaya/IMG_6783_7D4B337A.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="Rx, Reactive extension, aggregate, scan, Iobservable, IObserver" border="0" alt="Rx, Reactive extension, aggregate, scan, Iobservable, IObserver" src="http://blogs.microsoft.co.il/blogs/bnaya/IMG_6783_thumb_7E6F80BF.png" width="408" height="267" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;both &lt;strong&gt;Aggregate&lt;/strong&gt; and &lt;strong&gt;Scan&lt;/strong&gt; are dealing with &lt;strong&gt;event stream&lt;/strong&gt; &lt;strong&gt;accumulation&lt;/strong&gt;, the only difference is that &lt;strong&gt;Aggregate&lt;/strong&gt; produce &lt;strong&gt;single result&lt;/strong&gt; (upon the stream completion)     &lt;br /&gt;and &lt;strong&gt;Scan&lt;/strong&gt; present an ongoing runtime accumulation which &lt;strong&gt;react for each&lt;/strong&gt; &lt;strong&gt;OnNext&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;both operators has 2 overloads with the same signature:&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d07dc14d-8452-41ff-9e19-a46a2e27a954" class="wlWriterEditableSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;"&gt;Code Snippet&lt;/div&gt; &lt;div style="background:#ddd;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#2b91af;"&gt;IObservable&lt;/span&gt;&amp;lt;TSource&amp;gt; Aggregate&amp;lt;TSource&amp;gt;(&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;IObservable&lt;/span&gt;&amp;lt;TSource&amp;gt; source, &lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af;"&gt;Func&lt;/span&gt;&amp;lt;TSource, TSource, TSource&amp;gt; accumulator);&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#2b91af;"&gt;IObservable&lt;/span&gt;&amp;lt;TSource&amp;gt; Scan&amp;lt;TSource&amp;gt;(&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;IObservable&lt;/span&gt;&amp;lt;TSource&amp;gt; source, &lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af;"&gt;Func&lt;/span&gt;&amp;lt;TSource, TSource, TSource&amp;gt; accumulator);&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#2b91af;"&gt;IObservable&lt;/span&gt;&amp;lt;TAccumulate&amp;gt; Aggregate&amp;lt;TSource, TAccumulate&amp;gt;(&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;IObservable&lt;/span&gt;&amp;lt;TSource&amp;gt; source,&lt;/li&gt; &lt;li&gt;    TAccumulate seed, &lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="color:#2b91af;"&gt;Func&lt;/span&gt;&amp;lt;TAccumulate, TSource, TAccumulate&amp;gt; accumulator);&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="color:#2b91af;"&gt;IObservable&lt;/span&gt;&amp;lt;TAccumulate&amp;gt; Scan&amp;lt;TSource, TAccumulate&amp;gt;(&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff;"&gt;this&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;IObservable&lt;/span&gt;&amp;lt;TSource&amp;gt; source, &lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    TAccumulate seed,&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#2b91af;"&gt;Func&lt;/span&gt;&amp;lt;TAccumulate, TSource, TAccumulate&amp;gt; accumulator);&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;the first overload (line 1,5) gets a simple accumulation Func&amp;lt;T,T,T&amp;gt; which get the previous accumulated value and the current value as parameters and should return new accumulated value (on &lt;font color="#666666"&gt;the first accumulation the previous accumulated value will be default(T)&lt;/font&gt;).&lt;/p&gt;  &lt;p&gt;the second overload define a seed value for the first accumulation and a Func&amp;lt;TAccumulate, TSource, TAccumulate&amp;gt; which get the previous accumulated value and the current value as parameters and should return new accumulated value.    &lt;br /&gt;notice that the accumulated value type can be different from the current value.&lt;/p&gt;  &lt;p&gt;for example the following stream:&lt;/p&gt;    &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:06d0c54b-1524-4522-bebb-4ccb780ebae9" class="wlWriterEditableSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;"&gt;Code Snippet&lt;/div&gt; &lt;div style="background:#fff;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; xs = &lt;span style="color:#2b91af;"&gt;Observable&lt;/span&gt;.Range(1, 10);&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; result = xs.Aggregate((acc, i) =&amp;gt; acc + i);&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;result.ForEach(item =&amp;gt; &lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.WriteLine(item));&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;    &lt;p&gt;will project a single result (55).&lt;/p&gt;  &lt;p&gt;while the Scan version:&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:114575c2-364d-44d6-82a5-df5bb97d5b23" class="wlWriterEditableSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;"&gt;Code Snippet&lt;/div&gt; &lt;div style="background:#fff;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; xs = &lt;span style="color:#2b91af;"&gt;Observable&lt;/span&gt;.Range(1, 10);&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; result = xs.Scan((acc, i) =&amp;gt; acc + i);&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;result.ForEach(item =&amp;gt; &lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.WriteLine(item));&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;will project each accumulation interval:&lt;/p&gt;  &lt;p&gt;1    &lt;br /&gt;3     &lt;br /&gt;6     &lt;br /&gt;10     &lt;br /&gt;15     &lt;br /&gt;21     &lt;br /&gt;28     &lt;br /&gt;36     &lt;br /&gt;45     &lt;br /&gt;55&lt;/p&gt;  &lt;p&gt;both operator can become very handy within a Window operator.&lt;/p&gt;  &lt;p&gt;for more information about the Window operator see this &lt;a href="http://blogs.microsoft.co.il/blogs/bnaya/archive/2011/12/31/rx-window.aspx" target="_blank"&gt;post&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;for example, you may want to accumulate stream of customers which enter a store on per hour base.&lt;/p&gt;  &lt;p&gt;you can use the Window operator combine with the Aggregate operator to get per hour report    &lt;br /&gt;or using the Window combine with the Scan operation to get continues report per hour (&lt;font color="#666666"&gt;it will let you to react immediately for a live data, for example you can react when more then 100 customer were enter the store within un hour or less&lt;/font&gt;).&lt;/p&gt;  &lt;p&gt;the following code will demonstrate the aggregate scenario, but I should warn you, you are now stepping into some dark art code (which is the result of some concurrency behavior which I personally hope that the Rx team will address in the future in more intuitive way).&lt;/p&gt;  &lt;p&gt;&lt;font color="#666666"&gt;I consider to to add a few operator in future version of &lt;a href="http://rxcontrib.codeplex.com/" target="_blank"&gt;Rx Contrib&lt;/a&gt; which will handle this task more intuitively.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font color="#666666"&gt;and I will also post a work-through series of how to use the &lt;a href="http://rxcontrib.codeplex.com/" target="_blank"&gt;Rx Contrib&lt;/a&gt; libraries.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;what you will see is not the most intuitive code snippet but it is what you need in order to get the job done.&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:ba15472d-1005-4b60-bfb8-3798071f4258" class="wlWriterEditableSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;"&gt;Code Snippet&lt;/div&gt; &lt;div style="background:#ddd;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; storeStreamMock = &lt;span style="color:#2b91af;"&gt;Observable&lt;/span&gt;.Generate&amp;lt;&lt;span style="color:#2b91af;"&gt;Random&lt;/span&gt;, &lt;span style="color:#2b91af;"&gt;Unit&lt;/span&gt;&amp;gt;(&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;Random&lt;/span&gt;(),   &lt;span style="color:#008000;"&gt;// random object&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    rnd =&amp;gt; &lt;span style="color:#0000ff;"&gt;true&lt;/span&gt;,    &lt;span style="color:#008000;"&gt;// continue forever (exit term)&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    rnd =&amp;gt; rnd,     &lt;span style="color:#008000;"&gt;// next iteration value (ignored)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    rnd =&amp;gt; &lt;span style="color:#2b91af;"&gt;Unit&lt;/span&gt;.Default, &lt;span style="color:#008000;"&gt;// projection (allways project Unit.Default)&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    rnd =&amp;gt; &lt;span style="color:#2b91af;"&gt;TimeSpan&lt;/span&gt;.FromMilliseconds(rnd.Next(10, 100))); &lt;span style="color:#008000;"&gt;// deley between iterations&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="color:#2b91af;"&gt;IObservable&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;Task&lt;/span&gt;&amp;lt;&lt;span style="color:#0000ff;"&gt;int&lt;/span&gt;&amp;gt;&amp;gt; accStream =&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; win &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; storeStreamMock.Window(&lt;span style="color:#2b91af;"&gt;TimeSpan&lt;/span&gt;.FromSeconds(1))&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="color:#0000ff;"&gt;select&lt;/span&gt; win.Aggregate(0, (acc, cur) =&amp;gt; acc + 1).ToTask();&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;accStream&lt;/li&gt; &lt;li&gt;    .ObserveOn(&lt;span style="color:#2b91af;"&gt;Scheduler&lt;/span&gt;.TaskPool)&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    .ForEach(item =&amp;gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.WriteLine(item.Result));&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;line 1-6 are generating a mock of store observable by using the Generate factory, you can completely ignore this part.&lt;/p&gt;  &lt;p&gt;at line 9 we define a window of 5 second.&lt;/p&gt;  &lt;p&gt;line 10 define the aggregation and export the aggregated value into a Task (TPL).&lt;/p&gt;  &lt;p&gt;it is part of the dark art, otherwise we will end up with blocking and contentions.&lt;/p&gt;  &lt;p&gt;the last part of the dark art is that you should process the result within the subscribe in parallel (line 13).&lt;/p&gt;  &lt;p&gt;you can find different suggestion of how to complete such task in &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/rx/thread/635834a4-87fe-455e-8733-3d2129899d58?prof=required" target="_blank"&gt;this&lt;/a&gt; thread. &lt;/p&gt;  &lt;h5&gt;Summary&lt;/h5&gt;  &lt;p&gt;both Scan and Aggregate are a very useful operators,&lt;/p&gt;  &lt;p&gt;but you should be careful while using it within a Window.&amp;#160; &lt;/p&gt;  &lt;br /&gt;&lt;a href="http://dotnetshoutout.com/Rx-Aggregate-vs-Scan-Bnaya-Eshet"&gt;&lt;img style="border-right-width:0px;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fblogs.microsoft.co.il%2Fblogs%2Fbnaya%2Farchive%2F2012%2F01%2F24%2Frx-aggregate-vs-scan.aspx" /&gt;&lt;/a&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=996264" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/SELA/default.aspx">SELA</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/Rx/default.aspx">Rx</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/IObserver/default.aspx">IObserver</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/Parallel/default.aspx">Parallel</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/IObservable/default.aspx">IObservable</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/Task/default.aspx">Task</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/Thread/default.aspx">Thread</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/TPL/default.aspx">TPL</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/Reactive+Extension/default.aspx">Reactive Extension</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/scan/default.aspx">scan</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/aggregate/default.aspx">aggregate</category></item></channel></rss>