Skip to content

IntroToRx Documentation Partitioning.Buffer Code May Be Wrong #2336

Description

@reillybainet

(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<IList<IAisMessageType1to3>> shipStatusChanges =
    perShipObservables.SelectMany(shipMessages => shipMessages
        .OfType<IAisMessageType1to3>()
        .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<IList<IAisMessageType1to3>> shipStatusChanges =
    perShipObservables.SelectMany(shipMessages => shipMessages
        .OfType<IAisMessageType1to3>()
        .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}" +

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions