public static IModelObservable <T> Take <T>(this IModelObservable <T> source, int number) { return(Create <T>( o => { int count = 0; IDisposable disposable = null; disposable = source.Observe( i => { count++; if (count <= number) { o.OnNext(i); } else { disposable.Dispose(); } }, o.OnCompleted ); return disposable; } )); }
public static IModelObservable <TSubModel> Select <TModel, TSubModel>(this IModelObservable <TModel> source, Func <TModel, TSubModel> selector) { return(Create <TSubModel>( o => { var disposable = source.Observe( i => { o.OnNext(selector(i)); }, o.OnCompleted ); return disposable; } )); }
public static IModelObservable <T> Where <T>(this IModelObservable <T> source, Func <T, bool> predicate) { return(Create <T>( o => { var disposable = source.Observe( i => { if (predicate(i)) { o.OnNext(i); } }, o.OnCompleted ); return disposable; } )); }