I'm trying to create a single Observable which OnNext stream comes from one observable and which OnError stream comes from another observable.
The reason why I'm doing this is because I'm trying to wrap a class that is outside of my control and uses events to communicate its state. It has two events, one that indicates its done (bool) and one that indicates that an Exception occurs.
IObservable<Exception> error = Observable.FromEventPattern<ExceptionRoutedEventArgs>(foo, "Failed")
.Select(x => x.EventArgs.ErrorException);
IObservable<bool> opened = Observable.FromEventPattern<RoutedEventArgs>(foo, "Opened")
.Select(x => ((Bar)x.Sender).IsOpen);
Now I cannot use the standard Observable.Merge
since both observable have a different generic parameter. But In pseudo code I would like to accomplish this:
Observable.Merge(opened, error, (op, err) =>
{
if(op) { return op;}
if(err != null){return Observable.Throw(err);}
}
Now there are a lot of reasons why the code above doesn't remotely resemble anything that can exist but I hope the intent is clear.
I think a way to make this work is to use a Subject<> but I've heard that those should be avoid that since it introduces state in a functional concept. And I have the idea that combining two observables into one observables OnNext and OnError stream seems like it should exist :)