2011-02-07 65 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