Where is Observable.Iterate() in Rx 1.0.10621.0/1.1.10621.0
I'm finding a few examples online of Reactive Extensions that require the use of Observable.Iterate(), but the package from NuGet, Rx version 1.0.10621.0 does not seem to include it. Unless I'm doing it all wrong?
I assume that it was renamed, but I can't f开发者_如何学编程ind any posts regarding that. Anyone know?
From Rx Forum:
Wes Dyer:
What about Observable.Iterate?
Use the Observable.Create that takes a Func, Task> which works exactly the same as Iterate except that it uses async await to drive it.
An extension method Iterate could look like this:
public static IObservable<T> Iterate<T, TIter>([NotNull] this IObservable<TIter> source, [NotNull] T iterationStart, [NotNull] Func<TIter, T, T> iterator)
{
return Observable.Create<T>(observer =>
{
T previousElement = iterationStart;
return source.Subscribe(
value =>
{
T currentElement = iterator(value, previousElement);
observer.OnNext(currentElement);
previousElement = currentElement;
},
observer.OnError,
observer.OnCompleted
);
}).StartWith(iterationStart);
}
精彩评论