-
Notifications
You must be signed in to change notification settings - Fork 755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do operator can perform unexpected type conversion on observable sequence #2147
Comments
I think if we were to do this it would probably look more like this public static IObservable<TSource> Do<TSource, TObserver>(
this IObservable<TSource> source,
IObserver<TObserver> observer)
where TSource : class, TObserver
{
return source.Do<TSource>(observer);
} This also points to a simple change to your example that would mean you wouldn't have run into the problem: var rx = Observable.Return("hello");
IObserver<object> subject = new Subject<object>();
rx = rx.Do<string>(subject); This would also work: var rx = Observable.Return("hello");
IObserver<string> subject = new Subject<object>();
rx = rx.Do(subject); So I think this all shows that the following two statements are true:
Because of 2, this proposal doesn't look to me like it would enable anyone to do anything they can't already do today. So this would boil down to a question of ease of use: does this make Rx an easier library to use? Clearly it makes it easier to use However, I'd ask you to consider this: I've come round to the position that using So I'm not sure that adding features to make So my current position is that an addition such as this would be sending out completely the wrong message: it would be an implicit encouragement to use an Rx feature ( I would not remove The strongest argument in favour that I can see here is that if this overload of The biggest downside is that we have a long-term goal of discouraging the use of So, now that I've explained my reasons for reluctance, does that change your view at all? Or do you still believe we should add this despite my misgivings? |
@idg10 this line blew me away It makes of course complete sense, somehow contravariance always gets me! I agree with your reasoning, and to be honest I was also worried how someone else somewhere might be bitten by a change like this, so I am happy to close this issue, especially now we have a really simple and documented workaround.
I did get curious about your stance on the use of I've found the latter to be incredibly powerful for composition, as they allow enabling / disabling logging, monitoring and other side-effects in a chain without having to rewrite any code. I am with you that I very rarely use |
Bug report
6.0.1
Tested in both .NET Framework and .NET 8.0
The result of the
Do
operator should not change the type of the resulting observable sequence, i.e. it should behave as a pure side-effect, such that adding or removingDo
should have no effect on the type of the sequence.Specifically in this case,
Do
should returnIObservable<string>
.The output of
Do
is of typeIObservable<object>
.Proposed signature overload
The following is provided merely as an example of a function overload which can be used to workaround the current problem, and to inspire potential future revisions of the current implementation:
The text was updated successfully, but these errors were encountered: