2.x: Add Maybe.flatMapSingle#4614
2.x: Add Maybe.flatMapSingle#4614akarnokd merged 3 commits intoReactiveX:2.xfrom vanniktech:2.x_maybe_flatmapSingle
Conversation
|
|
||
| final Function<? super T, ? extends SingleSource<T>> mapper; | ||
|
|
||
| final SingleObserver<T> singleObserver = new SingleObserver<T>() { |
There was a problem hiding this comment.
Not sure whether this is the right approach
There was a problem hiding this comment.
Please avoid anonymous inner classes such as this.
| SingleSource<T> ss; | ||
|
|
||
| try { | ||
| ss = ObjectHelper.requireNonNull(mapper.apply(null), "The mapper returned a null SingleSource"); |
There was a problem hiding this comment.
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) { | ||
|
|
There was a problem hiding this comment.
This doesn't compose the disposable from the Single.
|
|
||
| final Function<? super T, ? extends SingleSource<T>> mapper; | ||
|
|
||
| final SingleObserver<T> singleObserver = new SingleObserver<T>() { |
There was a problem hiding this comment.
Please avoid anonymous inner classes such as this.
| SingleSource<T> ss; | ||
|
|
||
| try { | ||
| ss = ObjectHelper.requireNonNull(mapper.apply(null), "The mapper returned a null SingleSource"); |
There was a problem hiding this comment.
We don't map onComplete and mapper shouldn't anticipate null from the library anyaway.
Current coverage is 78.14% (diff: 85.00%)@@ 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
|
|
@akarnokd could you check again? I think I've figured it out now how this should all work |
|
|
||
| @Override | ||
| public void onComplete() { | ||
| // Ignored. |
There was a problem hiding this comment.
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); |
|
|
||
| @Override | ||
| public void onSubscribe(Disposable d) { | ||
| DisposableHelper.replace(this, d); |
There was a problem hiding this comment.
setOnce() + actual.onSubscribe(this)
| * @return the Single returned from {@code mapper} when applied to the item emitted by the source Maybe | ||
| * @see <a href="http://reactivex.io/documentation/operators/flatmap.html">ReactiveX operators documentation: FlatMap</a> | ||
| */ | ||
| @SchedulerSupport(SchedulerSupport.NONE) |
There was a problem hiding this comment.
Function<? super T, ? extends SingleSource<? extends R>>
|
Thanks for bearing with me on this one ... :D |
Gave that implementation a try. Feedback is welcome I think there are improvements that can be done.