The beauty of Rx is that you can create your own operators based on other operators. This is due to the functional side of Rx.
You can create a new statement that encapsulates all common behavior and accepts small differences in the quality of the parameters:
Use it like this:
this.WhenAnyValue(x => x.Listras) .ThrottledSelect(millis, im => GetArray.FromChannels(im, 0, 1)) .ToProperty(this, x => x.Grayscale, out _grayscale); this.WhenAnyValue(x => x.Grayscale) .ThrottledSelect(millis, ar => Gaussian.GaussianConvolution(ar, 1.5)) .ToProperty(this, x => x.BlurMenor, out _blurMenor); this.WhenAnyValue(x => x.BlurMenor) .ThrottledSelect(millis, ar => { ConversorImagem.Converter(ar, out BitmapSource im); return im; }) .ToProperty(this, x => x.ImagemBlurMenor, out _imagemBlurMenor); this.WhenAnyValue(x => x.BlurMenor) .ThrottledSelect(millis, ar => Gaussian.VerticalGaussianConvolution(ar, 5)) .ToProperty(this, x => x.BlurMaior, out _blurMaior); this.WhenAnyValue(x => x.BlurMaior) .ThrottledSelect(millis, ar => { ConversorImagem.Converter(ar, out BitmapSource im); return im; }) .ToProperty(this, x => x.ImagemBlurMaior, out _imagemBlurMaior); this.WhenAnyValue(x => x.BlurMenor, x => x.BlurMaior)
If you feel a little less adventurous, you can, of course, use it as a regular method, which is perceived as observable:
public IObservable<T> ThrottledSelect<TIn, TOut>(IObservable<TIn> source, int milliseconds, Func<TIn, TOut> selector) => source .Where(item => item != null) .Throttle(TimeSpan.FromMilliseconds(milliseconds)) .ObserveOn(TaskPoolScheduler.Default) .Select(selector) .ObserveOn(RxApp.MainThreadScheduler)
And use it as follows:
ThrottledSelect(this.WhenAnyValue(x => x.Diferença), millis, ar => { ConversorImagem.Converter(ar, out BitmapSource im); return im; }) .ToProperty(this, x => x.ImagemDiferença, out _imagemDiferença);