我需要知道4个可观察流中的最新值何时与谓词匹配。
对于只有两个流,我可以将CombineLatest与Where结合使用。
如何使用n> 2流实现此目的。
感谢。
编辑:回答我想要实现的目标
void Main()
{
var s1 = Observable.Interval(TimeSpan.FromMilliseconds(50));
var s2 = Observable.Interval(TimeSpan.FromMilliseconds(60));
var s3 = Observable.Interval(TimeSpan.FromMilliseconds(70));
var s4 = Observable.Interval(TimeSpan.FromMilliseconds(80));
Observable.CombineLatest(s1, s2, s3, s4)
.Where(xs => xs.All(x => x > 10 && x < 20))
.Subscribe(x =>
{
x.Dump();
});
}
答案 0 :(得分:3)
我认为您仍然可以使用CombineLatest,或者我可能错过了您的要求。
[TestMethod]
public void GreaterThan2StreamsCombineLatest()
{
//Arrange
var s1 = Observable.Return(1).Concat(Observable.Return(10));
var s2 = Observable.Return(2);
var s3 = Observable.Return(3);
var expected = "They're all greater than 1";
var result = string.Empty;
//Act
Observable.CombineLatest(s1, s2, s3)
.Where(xs => xs.All(x => x > 1))
.Subscribe(x =>
{
x.ToList().ForEach(Console.WriteLine);
result = "They're all greater than 1";
});
//Assert
Assert.AreEqual(expected, result);
}