2011-02-07 62 views
1

我通過可觀察到的,我看要符合特定的條件,例如,監視股票報價流 -我怎麼能從IObservable獲取歷史記錄?

Observable 
.Empty<Quote> 
.Where(q => q.Price > watchPrice) 
.Subscribe(q => { // do stuff }); 

現在,在「做的東西」的地步,是我最想要的是以獲得where子句中出現的最後3個「q」,比如BufferWithCount(),但Subscribe()中的每個條目都包含最後3個條目。這樣我就可以保存導致條件評估的報價更改的快照。

僞大理石圖 -

in - a  b  c  d  e  f 
out - a  ba cba dcb edc fde 

任何想法表示讚賞

回答

5

喜歡這個?

static void Main() 
    { 
     new[] {"a", "b", "c", "d", "e", "f"} 
      .ToObservable() 
      .Scan(Enumerable.Empty<string>(), (x, y) => x.StartWith(y).Take(3)) 
      .Subscribe(x => 
          { 
           x.Run(Console.Write); 
           Console.WriteLine(); 
          }); 
     Console.ReadLine(); 
    } 
+0

傳說中。發揮魅力!謝謝 – 2011-02-08 02:27:13