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

2.x: Add Maybe.flatMapSingle #4614

Merged
merged 3 commits into from Sep 27, 2016
Merged

2.x: Add Maybe.flatMapSingle #4614

merged 3 commits into from Sep 27, 2016

Conversation

vanniktech
Copy link
Collaborator

Gave that implementation a try. Feedback is welcome I think there are improvements that can be done.


final Function<? super T, ? extends SingleSource<T>> mapper;

final SingleObserver<T> singleObserver = new SingleObserver<T>() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure whether this is the right approach

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid anonymous inner classes such as this.

SingleSource<T> ss;

try {
ss = ObjectHelper.requireNonNull(mapper.apply(null), "The mapper returned a null SingleSource");
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the question whether the mapper should be used or not. I thought it might make sense that Maybe.empty() should also go through flatMapSingle

final SingleObserver<T> singleObserver = new SingleObserver<T>() {
@Override
public void onSubscribe(final Disposable d) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't compose the disposable from the Single.


final Function<? super T, ? extends SingleSource<T>> mapper;

final SingleObserver<T> singleObserver = new SingleObserver<T>() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please avoid anonymous inner classes such as this.

SingleSource<T> ss;

try {
ss = ObjectHelper.requireNonNull(mapper.apply(null), "The mapper returned a null SingleSource");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't map onComplete and mapper shouldn't anticipate null from the library anyaway.

@codecov-io
Copy link

codecov-io commented Sep 27, 2016

Current coverage is 78.14% (diff: 85.00%)

Merging #4614 into 2.x will increase coverage by <.01%

@@                2.x      #4614   diff @@
==========================================
  Files           553        555     +2   
  Lines         36128      36202    +74   
  Methods           0          0          
  Messages          0          0          
  Branches       5559       5561     +2   
==========================================
+ Hits          28231      28289    +58   
- Misses         5891       5905    +14   
- Partials       2006       2008     +2   

Powered by Codecov. Last update d85d40e...78c90c7

@akarnokd akarnokd added this to the 2.0 RC4 milestone Sep 27, 2016
@vanniktech
Copy link
Collaborator Author

@akarnokd could you check again? I think I've figured it out now how this should all work


@Override
public void onComplete() {
// Ignored.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will hang the output Single. You should signal a NoSuchElementException instead.

@Override
protected void subscribeActual(SingleObserver<? super T> s) {
FlatMapMaybeObserver<T> parent = new FlatMapMaybeObserver<T>(s, mapper);
s.onSubscribe(parent);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to pull this out.


@Override
public void onSubscribe(Disposable d) {
DisposableHelper.replace(this, d);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setOnce() + actual.onSubscribe(this)

* @see <a href="http://reactivex.io/documentation/operators/flatmap.html">ReactiveX operators documentation: FlatMap</a>
*/
@SchedulerSupport(SchedulerSupport.NONE)
public final Single<T> flatMapSingle(final Function<? super T, ? extends SingleSource<T>> mapper) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function<? super T, ? extends SingleSource<? extends R>>

@vanniktech
Copy link
Collaborator Author

Thanks for bearing with me on this one ... :D

@akarnokd akarnokd merged commit d3a5776 into ReactiveX:2.x Sep 27, 2016
@vanniktech vanniktech deleted the 2.x_maybe_flatmapSingle branch September 27, 2016 13:42
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

3 participants