Say for example I have an enumerable
dim e = Enumerable.Range(0, 1024)
I\'d like to be able to do
dim o = e.ToObservable(Timesp
I have also looked for the solution and after reading the intro to rx made my self one:
There is an Observable.Generate()
overload which I have used to make my own ToObservable()
extension method, taking TimeSpan
as period:
public static class MyEx {
public static IObservable ToObservable(this IEnumerable enumerable, TimeSpan period)
{
return Observable.Generate(
enumerable.GetEnumerator(),
x => x.MoveNext(),
x => x,
x => x.Current,
x => period);
}
public static IObservable ToObservable(this IEnumerable enumerable, Func getPeriod)
{
return Observable.Generate(
enumerable.GetEnumerator(),
x => x.MoveNext(),
x => x,
x => x.Current,
x => getPeriod(x.Current));
}
}
Already tested in LINQPad. Only concerning about what happens with the enumerator instance after the resulting observable is e.g. disposed. Any corrections appreciated.