dotnet / dotnet/reactive

Do operator can perform unexpected type conversion on observable sequence

Open
#2,147 2 comments 0 reactions 0 assignees View on GitHub
[area] Rx
Dominant language
C#
Stars
7.2k
Forks
798
PR merge metrics
No merged PRs in 30d

Description

#### Bug report

> Which library version?

6.0.1

> What are the platform(s), environment(s) and related component version(s)?

Tested in both .NET Framework and .NET 8.0

> What is the use case or problem?

```c#
var rx = Observable.Return("hello");
IObserver subject = new Subject();

rx = rx.Do(subject);
```

> What is the expected outcome?

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 removing `Do` should have no effect on the type of the sequence.

Specifically in this case, `Do` should return `IObservable`.

> What is the actual outcome?

The output of `Do` is of type `IObservable`.

#### 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:

```c#
static IObservable Do(this IObservable source, IObserver subject)
where TSource : class, TObserver
{
return source.Do(subject.OnNext, subject.OnError, subject.OnCompleted);
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.