dotnet / dotnet/reactive

IntroToRx Documentation Partitioning.Buffer Code May Be Wrong

Open Beginner friendly
#2,336 0 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

(I *really* appreciate all of your work on this. I'd do a "PR" but I don't use git and don't really feel comfortable trying to do a PR here as my first one ever.)

#### Bug / Documentation Typo

Intro To Rx documentation 3rd edition Updated for Rx.NET v6.1

08_Partitioning.md

In the buffering example, the code is

```
IObservable> shipStatusChanges =
perShipObservables.SelectMany(shipMessages => shipMessages
.OfType()
.DistinctUntilChanged(m => m.NavigationStatus)
.Buffer(2, 1));

IDisposable sub = shipStatusChanges.Subscribe(m => Console.WriteLine(
$"Ship {((IAisMessage)m[0]).Mmsi} changed status from" +
$" {m[1].NavigationStatus} to {m[1].NavigationStatus}" +
$" at {DateTimeOffset.UtcNow}"));
```

I think it should be

```
IObservable> shipStatusChanges =
perShipObservables.SelectMany(shipMessages => shipMessages
.OfType()
.DistinctUntilChanged(m => m.NavigationStatus)
.Buffer(2, 1));

IDisposable sub = shipStatusChanges.Subscribe(m => Console.WriteLine(
$"Ship {((IAisMessage)m[0]).Mmsi} changed status from" +
$" {m[0].NavigationStatus} to {m[1].NavigationStatus}" +
$" at {DateTimeOffset.UtcNow}"));
```

That is, the line

```
$" {m[1].NavigationStatus} to {m[1].NavigationStatus}" +
```

should have the first array subscript changed from 1 to 0. As I understand it, the Buffer will pair consecutive samples so m[0] should be the old state and m[1] should be the new state so it should be

```
$" {m[0].NavigationStatus} to {m[1].NavigationStatus}" +
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Open 08_Partitioning.md and locate the buffering example in the Intro To Rx documentation. Verify that the message describes a transition from m[0] to m[1], then correct the duplicated array subscript; the example should show the previous and new navigation statuses in that order.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.