Rx 中是否有一些扩展方法来执行以下场景?
我有一个值来开始抽水(绿色圆圈)和其他值来停止抽水(芦苇圈),蓝色圆圈应该是预期值,我不希望这个命令被取消和重新创建(即“TakeUntil”和“SkipUntil”将不起作用)。
使用 LINQ 的实现将是这样的:
public static IEnumerable<T> TakeBetween<T>(this IEnumerable<T> source, Func<T, bool> entry, Func<T, bool> exit)
{
bool yield = false;
foreach (var item in source)
{
if (!yield)
{
if (!entry(item))
continue;
yield = true;
continue;
}
if (exit(item))
{
yield = false;
continue;
}
yield return item;
}
}
怎么会有同样的逻辑IObservable<T>
呢?