3.x: Merge as() into to() by akarnokd · Pull Request #6514 · ReactiveX/RxJava (original) (raw)
In 2.x, the to()
operator used the generic Function
to allow assembly-time conversion of flows into arbitrary types. The drawback of this approach was that each base reactive type had the same Function
interface in their method signature, thus it was impossible to implement multiple converters for different reactive types within the same class. To work around this issue, the as
operator and XConverter
interfaces have been introduced in 2.x, which interfaces are distinct and can be implemented on the same class. Changing the signature of to
in 2.x was not possible due to the pledged binary compatibility of the library.
From 3.x, the as()
methods have been removed and the to()
methods now each work with their respective XConverer
interfaces:
Flowable.to(Function<Flowable<T>, R>)
is nowFlowable.to(FlowableConverter<T, R>)
Observable.to(Function<Observable<T>, R>)
is nowObservable.to(ObservableConverter<T, R>)
Maybe.to(Function<Flowable<T>, R>)
is nowMaybe.to(MaybeConverter<T, R>)
Single.to(Function<Flowable<T>, R>)
is nowMaybe.to(SingleConverter<T, R>)
Completable.to(Function<Completable, R>)
is nowCompletable.to(CompletableConverter<R>)
ParallelFlowable.to(Function<ParallelFlowable<T>, R)
is nowParallelFlowable.to(ParallelFlowableConverter<T, R>)
If one was using these methods with a lambda expression, only a recompilation is needed:
// before source.to(flowable -> flowable.blockingFirst());
// after source.to(flowable -> flowable.blockingFirst());
If one was implementing a Function interface (typically anonymously), the interface type, type arguments and the throws
clause have to be adjusted
// before source.to(new Function<Flowable, Integer>() { @Override public Integer apply(Flowable t) throws Exception { return t.blockingFirst(); } });
// after source.to(new FlowableConverter<Integer, Integer>() { @Override public Integer apply(Flowable t) { return t.blockingFirst(); } });
Resolves: #5654