2.x: add Observable.switchMapSingle and switchMapSingleDelayError#5161
2.x: add Observable.switchMapSingle and switchMapSingleDelayError#5161akarnokd merged 1 commit intoReactiveX:2.xfrom
Conversation
akarnokd
left a comment
There was a problem hiding this comment.
Looks good but some changes are required.
| } else { | ||
| single = Single.unsafeCreate(source); | ||
| } | ||
| return (Observable<R>) single.toObservable(); |
There was a problem hiding this comment.
You could just use:
return RxJavaPlugins.onAssembly(new SingleToObservable(mapper.apply(t)));| * @since 2.0.8 | ||
| */ | ||
| @Experimental | ||
| @CheckReturnValue |
| * @since 2.0.8 | ||
| */ | ||
| @Experimental | ||
| @CheckReturnValue |
|
|
||
| private static <T, R> Function<T, Observable<R>> convertSingleMapperToObservableMapper( | ||
| final Function<? super T, ? extends SingleSource<? extends R>> mapper) { | ||
| return new Function<T, Observable<R>>() { |
There was a problem hiding this comment.
ObjectHelper.requireNonNull(mapper, "mapper is null");
There was a problem hiding this comment.
Please avoid anonymous inner classes.
f2e0b0e to
b733386
Compare
|
updated with suggested changes |
|
unrelated ci failure |
Tracking via #5154. Could be due to low timeout settings and Travis overload. Just rerun the build next time; I did it just now. |
| @Test | ||
| public void switchMapSingleFunctionDoesntReturnSingle() { | ||
| Observable.just(0) | ||
| .switchMapSingle(new Function<Object, SingleSource<Integer>>() { |
There was a problem hiding this comment.
I remember that with flatMapSingle there was in the initial draft a few errors that errors weren't propagated correctly. Should not those cases also be tested that in the future once the operators receive custom implementations everything still works correctly?
There was a problem hiding this comment.
I don't think so. At the moment those cases have full coverage. If we make custom implementations then a whole suite of tests need to be added just get coverage back up again and it will be an obvious timesaver to duplicate the tests you refer to.
|
|
||
| @Override | ||
| public Observable<R> apply(T t) throws Exception { | ||
| return RxJavaPlugins.onAssembly(new SingleToObservable<R>(mapper.apply(t))); |
There was a problem hiding this comment.
check that mapper.apply(t) does not return null?
There was a problem hiding this comment.
Indeed, this should do it:
return RxJavaPlugins.onAssembly(new SingleToObservable<R>(
ObjectHelper.requireNonNull(mapper.apply(t), "The mapper returned a null value")));
Codecov Report
@@ Coverage Diff @@
## 2.x #5161 +/- ##
============================================
+ Coverage 95.86% 95.88% +0.02%
- Complexity 5648 5652 +4
============================================
Files 621 621
Lines 39962 39972 +10
Branches 5610 5610
============================================
+ Hits 38309 38329 +20
+ Misses 665 657 -8
+ Partials 988 986 -2
Continue to review full report at Codecov.
|
b733386 to
315fb80
Compare
|
updated with null check on mapper call and added unit tests for null mapper and null mapper call result. Not proposing to duplicate all tests. @akarnokd what would you like? |
|
Don't duplicate tests. When the specialized implementation happens, that will ask for proper coverage by itself. |
This is a new operator discussed in #4853. The issue refers to a goodly number of new operators which I'll do bit by bit as my time allows and to ensure review is not too daunting.