Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.x: Merge as() into to() #6514

Merged
merged 2 commits into from
Jun 19, 2019
Merged

3.x: Merge as() into to() #6514

merged 2 commits into from
Jun 19, 2019

Conversation

akarnokd
Copy link
Member

@akarnokd akarnokd commented Jun 19, 2019

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 now Flowable.to(FlowableConverter<T, R>)
  • Observable.to(Function<Observable<T>, R>) is now Observable.to(ObservableConverter<T, R>)
  • Maybe.to(Function<Flowable<T>, R>) is now Maybe.to(MaybeConverter<T, R>)
  • Single.to(Function<Flowable<T>, R>) is now Maybe.to(SingleConverter<T, R>)
  • Completable.to(Function<Completable, R>) is now Completable.to(CompletableConverter<R>)
  • ParallelFlowable.to(Function<ParallelFlowable<T>, R) is now ParallelFlowable.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>, Integer>() {
    @Override
    public Integer apply(Flowable<Integer> t) throws Exception {
        return t.blockingFirst();
    }
});

// after
source.to(new FlowableConverter<Integer, Integer>() {
    @Override
    public Integer apply(Flowable<Integer> t) {
        return t.blockingFirst();
    }
});

Resolves: #5654

@codecov
Copy link

codecov bot commented Jun 19, 2019

Codecov Report

❗ No coverage uploaded for pull request base (3.x@cb03724). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff           @@
##             3.x    #6514   +/-   ##
======================================
  Coverage       ?   98.14%           
  Complexity     ?     6288           
======================================
  Files          ?      675           
  Lines          ?    45146           
  Branches       ?     6246           
======================================
  Hits           ?    44307           
  Misses         ?      293           
  Partials       ?      546
Impacted Files Coverage Δ Complexity Δ
src/main/java/io/reactivex/Flowable.java 100% <100%> (ø) 566 <1> (?)
src/main/java/io/reactivex/Completable.java 100% <100%> (ø) 119 <1> (?)
...n/java/io/reactivex/parallel/ParallelFlowable.java 100% <100%> (ø) 49 <1> (?)
src/main/java/io/reactivex/Maybe.java 100% <100%> (ø) 172 <1> (?)
src/main/java/io/reactivex/Observable.java 100% <100%> (ø) 541 <1> (?)
src/main/java/io/reactivex/Single.java 100% <100%> (ø) 148 <1> (?)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cb03724...319a231. Read the comment docs.

@akarnokd akarnokd merged commit a672013 into ReactiveX:3.x Jun 19, 2019
@akarnokd akarnokd deleted the ConverterTo3x branch June 19, 2019 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant