diff --git a/src/R3/Operators/IgnoreElements.cs b/src/R3/Operators/IgnoreElements.cs index cf8ef116..9155d42a 100644 --- a/src/R3/Operators/IgnoreElements.cs +++ b/src/R3/Operators/IgnoreElements.cs @@ -4,21 +4,27 @@ public static partial class ObservableExtensions { public static Observable IgnoreElements(this Observable source) { - return new IgnoreElements(source); + return new IgnoreElements(source, null); + } + + public static Observable IgnoreElements(this Observable source, Action doOnNext) + { + return new IgnoreElements(source, doOnNext); } } -internal sealed class IgnoreElements(Observable source) : Observable +internal sealed class IgnoreElements(Observable source, Action? doOnNext) : Observable { protected override IDisposable SubscribeCore(Observer observer) { - return source.Subscribe(new _IgnoreElements(observer)); + return source.Subscribe(new _IgnoreElements(observer, doOnNext)); } - sealed class _IgnoreElements(Observer observer) : Observer + sealed class _IgnoreElements(Observer observer, Action? doOnNext) : Observer { protected override void OnNextCore(T value) { + doOnNext?.Invoke(value); } protected override void OnErrorResumeCore(Exception error) diff --git a/src/R3/Operators/IgnoreOnErrorResume.cs b/src/R3/Operators/IgnoreOnErrorResume.cs new file mode 100644 index 00000000..33d82b4f --- /dev/null +++ b/src/R3/Operators/IgnoreOnErrorResume.cs @@ -0,0 +1,40 @@ +namespace R3; + +public static partial class ObservableExtensions +{ + public static Observable IgnoreOnErrorResume(this Observable source) + { + return new IgnoreOnErrorResume(source, null); + } + + public static Observable IgnoreOnErrorResume(this Observable source, Action? doOnErrorResume) + { + return new IgnoreOnErrorResume(source, doOnErrorResume); + } +} + +internal sealed class IgnoreOnErrorResume(Observable source, Action? doOnErrorResume) : Observable +{ + protected override IDisposable SubscribeCore(Observer observer) + { + return source.Subscribe(new _IgnoreOnErrorResume(observer, doOnErrorResume)); + } + + sealed class _IgnoreOnErrorResume(Observer observer, Action? doOnErrorResume) : Observer + { + protected override void OnNextCore(T value) + { + observer.OnNext(value); + } + + protected override void OnErrorResumeCore(Exception error) + { + doOnErrorResume?.Invoke(error); + } + + protected override void OnCompletedCore(Result result) + { + observer.OnCompleted(result); + } + } +} diff --git a/src/R3/Operators/_Operators.cs b/src/R3/Operators/_Operators.cs index 5f5882d2..487c7db4 100644 --- a/src/R3/Operators/_Operators.cs +++ b/src/R3/Operators/_Operators.cs @@ -12,6 +12,8 @@ public static partial class ObservableExtensions // TODO:not-tested:CombineLatest, Zip, ZipLatest, WithLatestFrom // Switch, Pairwise +// IgnoreElements + // Standard Query: // Distinct, DistinctBy, DistinctUntilChanged, Scan, DefaultIfEmpty