Created
January 17, 2018 17:55
-
-
Save GeorgeTsiokos/85eafc6ac095422c4f98e9f8ca76e8ee to your computer and use it in GitHub Desktop.
Rx IgnoreElements and change sequence type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public static class ObservableExtensions | |
{ | |
public static IObservable<TResponse> IgnoreElements<TSource, TResponse>(this IObservable<TSource> sequence) => new IgnoreElementsObservable<TSource, TResponse>(sequence); | |
sealed class IgnoreElementsObservable<TSource, TResult> : IObservable<TResult> | |
{ | |
readonly IObservable<TSource> _sequence; | |
public IgnoreElementsObservable(IObservable<TSource> sequence) => _sequence = sequence; | |
public IDisposable Subscribe(IObserver<TResult> observer) => _sequence.Subscribe(new IgnoreElmentsObserver<TSource, TResult>(observer)); | |
} | |
sealed class IgnoreElmentsObserver<TSource, TResult> : IObserver<TSource> | |
{ | |
readonly IObserver<TResult> _observer; | |
public IgnoreElmentsObserver(IObserver<TResult> observer) => _observer = observer; | |
public void OnCompleted() => _observer.OnCompleted(); | |
public void OnNext(TSource value) | |
{ | |
// ignore | |
} | |
public void OnError(Exception error) => _observer.OnError(error); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment