-
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
FuncN generic varargs parameter #1277
Comments
I missed this issue being opened ... do you want to pick this up again? |
Sure, though I'm off for holidays for a couple of weeks now, so I'm a little of the radar.. I believe these Object[] arrays was where I stumbled |
Considering how badly this will break any code using Java doesn't really have a good way of handling this type of scenario, and Here is a workaround (using int[]): List<Observable<Integer>> iterable = Arrays.asList(Observable.from(1), Observable.from(2), Observable.from(3));
Observable<int[]> observable = Observable.zip(iterable, ns -> Arrays.stream(ns).mapToInt(n -> (Integer) n).toArray());
observable.forEach(i -> System.out.println("Int[]: " + Arrays.toString(i))); Retaining the arity and types: Observable.zip(Observable.from(1), Observable.from(2), Observable.from(3), (a, b, c) -> Arrays.asList(a, b, c)); |
I came across this same issue, but with Currently I'm using the following overload of
The definition of
Firstly, the type information gets lost. A user would presume Additionally, I personally find the use of varargs a bit confusing. I passed in a It might be a good idea to introduce the following function definition for V2:
That way a list is passed into |
This is how we solved the problem in Kotlin: fun <T, R> List<Observable<T>>.combineLatest(combineFunction: (List<T>) -> R): Observable<R> =
Observable.combineLatest(
this,
{ xs: Array<out Any> ->
combineFunction(xs.toList() as List<T>)
}
) |
I agree, this should be revised for v2.
That's not how |
The signature looks like: public static <T, R> Observable<R> combineLatest(ObservableConsumable<? extends T>[] sources, Function<? super Object[], ? extends R> combiner) So, If that's the case, I've made a commit for this change for |
It was a long time ago, but I think we had some type inference problems due to the contravariant input to the function. The question is that how many extra unchecked warnings pop up due to the change. |
Yes, I do get one unchecked cast now. I suppressed it using: bobvanderlinden@477696b It's due to the Queue being of type Object. 2 different types of objects are being polled and offered to the queue each time ( The same unchecked warning occurs here: https://github.com/bobvanderlinden/RxJava/blob/477696bc5364cddbef317106f77039657e3facf7/src/main/java/io/reactivex/internal/operators/observable/ObservableCombineLatest.java#L221. There it's being suppressed as well. The problem is with the queue containing two types of objects. Using 2 queues might be a solution for the type-checking problem, or a pair of objects in the queue, but I guess the current method is used for performance reasons? |
If these are limited to the operators themselves, then there is no problem with the extra
Yes.
Sure. I've merged a PR targeting |
Thanks for the feedback. PR #4211 submitted. |
Flowable doesn't seem to have a similar feature, right? |
@micHar This is an old issue; could you be more specific about what you think is missing?
|
I'm confused. Looked into the pull request which seems to be merged and can find e.g. this:
But in 2.1.8 there's only
So this has been deleted and is impossible to implement, right? |
As mentioned [1] [2] it would be nice for
Observable.zip(iterable, funcn)
to handle iterables of the same type, without having to go about casting the object to an integer for making something like this to workMaking
FuncN<R>
intoFuncN<T, R>
kind of snowballed on me as I reached theOperatorZip$Zip
which seems to be needing theObject
type.The text was updated successfully, but these errors were encountered: