RxJava 2.x Single is not extending Publisher

Created on 31 Oct 2016  路  2Comments  路  Source: ReactiveX/RxJava

Hi, I think Single should implement also org.reactivestreams.Publisher like Flowable.
Right now in io.reactivex.rxjava2 2.0.0 Single doesn't implement Publisher and this leads to being unable to do the following:

Flowable<String> colors = Flowable.fromArray("red", "green", "blue",
                "red", "yellow", "green", "green");

        Flowable<GroupedFlowable<String, String>> groupedColorsStream = colors
                                                                           .groupBy(val -> val);

        Flowable<Pair<String, Long>>
                countedColors = groupedColorsStream
                                        .flatMap(groupedFlow -> groupedFlow
                                                                    .count()
                                                                    .map(countVal -> new Pair<>(groupedFlow.getKey(), countVal))
                                        );
        countedColors.subscribe(System.out::println);

since count() returns Single, and flatMap has the signature:

    public final <R> Flowable<R> flatMap(Function<? super T, ? extends Publisher<? extends R>> mapper) {
        return this.flatMap(mapper, false, bufferSize(), bufferSize());
    }
Question

Most helpful comment

It's not possible because of the receiver types are incompatible. Use toFlowable or flatMapSingle instead.

All 2 comments

It's not possible because of the receiver types are incompatible. Use toFlowable or flatMapSingle instead.

Thanks for answering

Was this page helpful?
0 / 5 - 0 ratings

Related issues

midnight-wonderer picture midnight-wonderer  路  3Comments

archenroot picture archenroot  路  3Comments

theblang picture theblang  路  3Comments

ZakTaccardi picture ZakTaccardi  路  3Comments

dsvoronin picture dsvoronin  路  4Comments