Skip to content

v3: The marble diagram for cast is incredibly misleading. #7605

@derektom14

Description

@derektom14

Here's the current marble diagram for Observable.cast/Flowable.cast:

http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Observable.html#cast-java.lang.Class-

We see that the input is a series of shapes of different colors (red square, yellow circle, green diamond, green circle, red star), and it is cast to pentagon, so the result is a series of shapes of the input colors, but all pentagons. This would imply that the cast function somehow emits a transformation of the input object, but that isn't the case at all. It makes no transformations.

A more fitting diagram example would have an input of (red square, yellow square, green circle, blue square), effectively an Observable<Shape>, with a cast to square, for Observable<Square>. The resulting output would be a red square, then a yellow square, then an error, because a green circle is not a square. The documentation should also clearly state that a ClassCastException occurs on an incorrect cast. The ofType diagram is far more accurate.

The Single.cast and Maybe.cast diagrams are also flawed:

http://reactivex.io/RxJava/3.x/javadoc/io/reactivex/rxjava3/core/Single.html#cast-java.lang.Class-

When the input is a diamond, and the cast is to a circle, the output apparently completes with no elements, mirroring ofType(Circle.class) rather than cast(Circle.class). It should emit an exception instead.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions