-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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: switchMapSingle and switchMapCompletable #4853
Comments
You mean 1.x? I have no plans for that and I don't want to keep 1.x alive for too long. I'd like to stop enhancing 1.x in 6 months and enter it into a bugfix-only mode. Otherwise 3rd party libraries may delay their upgrade way longer. |
He wants |
@vanniktech exactly |
Ah right. No plans for extending any other xMap operator |
But then And then there's also
|
If it is not on the roadmap because you don't want to add any more xMap operators, then I understand. But if it is due to lack of the time, would you consider accepting contributions on the topic? |
Sure, but these operators are not easy. |
Yes, I know, those are one of the hardest. Cheers! |
Any progress on this? |
I'm happy to have a look at this one if @tomaszpolanski doesn't have time at the moment. |
@davidmoten It would be great! My available time now is pretty limited. |
So the list of new operators is quite big. Currently:
I imagine we can add support for all of these operators straight away using composition and write dedicated operators later one by one. An example would be public final <R> Observable<R> switchMapSingle(
final Function<? super T, ? extends SingleSource<? extends R>> mapper) {
Function<? super T, Observable<R>> mapper2 = t ->
{
SingleSource<? extends R> source = mapper.apply(t);
Single<? extends R> single;
if (source instanceof Single) {
single = (Single<? extends R>) source;
} else {
single = Single.unsafeCreate(source);
}
return (Observable<R>) single.toObservable();
};
return switchMap(mapper2, bufferSize());
} This is just to demo the idea, I wouldn't use an anonymous class and lambdas are just used for readability. @akarnokd any interest in this? |
Indeed.
If you do this, there is an unwritten guideline that the main base types should have no (anonymous) inner classes. It helped me a lot before not having to deal with Flowable$1$2 and similar entries. The go-to place for these are in
I'm more interested in the direct implementations but at least the overall usefullness of the API extension could be vetted. |
Yep no problems. I've appreciated consistent naming of non-anon classes inside operators for debugging purposes and code searches too.
Sure. I'll proceed with PRs with unit tests for the new operators and I'm happy to have a stab at dedicated operators after that. |
What is expected behaviour for |
In the mean time, would it be correct to assume that an acceptable workaround for this is as follows?: .toObservable()
|
@feresr |
@marcinsus I don't fully understand your question. Use |
The problem he talks about is that switchMapCompletable does not exist. switchMapSingle returns an Observable of the Single type. So technically switchMapCompletable should return Void. (Which it can't, because that has no instance.) So he asks if the signature should rather expose some |
An |
You are right as But now I find it weird that |
A stream of 5 elements flatMap'd to a stream of a single element still results in a stream of 5 elements. |
I'm working on implementing I'm wondering if the library should also have implementations of |
|
Ahh yes that makes sense. So is there any reason to implement |
Actually, |
Ok I'll keep at it then |
Did anything ever come of this? |
So there are plans to implement the other operators, but not in any particular timeframe? |
The listed operators can simply expressed with the existing default operators and |
Hey,
the addition of
flatMapSingle
/flatMapCompletable
made the usage ofSingle
andCompletable
way nicer in RxJava 2.Do you consider adding
switchMapSingle
/switchMapCompletable
to RxJava 2 as well?Cheers
The text was updated successfully, but these errors were encountered: