-
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
RxJava2 Observable.zip
taking Iterable
and a zipper
is broken
#4524
Comments
Totally possible. Can you post a small unit test that fails? |
@Test
public void zipIterableOfObservables() {
List<Observable<Integer>> observables =
new ArrayList<Observable<Integer>>();
observables.add(Observable.just(1, 2, 3));
observables.add(Observable.just(1, 2, 3));
Observable.zip(observables, new Function<Integer[], Integer>() {
@Override
public Integer apply(Integer[] o) throws Exception {
int sum = 0;
for (int i : o) {
sum += i;
}
return sum;
}
}).test().assertResult(2, 4, 6);
} Please note that if we use lambda as a zipper, it eventually generates what the above test has. |
FYI, the following works and it's what is generated with the 1.x signature: @Test
public void zipIterableOfObservables() {
List<Observable<Integer>> observables =
new ArrayList<Observable<Integer>>();
observables.add(Observable.just(1, 2, 3));
observables.add(Observable.just(1, 2, 3));
Observable.zip(observables, new Function<Object[], Object>() {
@Override
public Object apply(Object[] o) throws Exception {
int sum = 0;
for (Object i : o) {
sum += (Integer) i;
}
return sum;
}
}).test().assertResult(2, 4, 6);
} |
Thanks. The underlying problem is that we can't do Currently I can't write a PR. @vanniktech could you change all |
Sure 👍 |
Closing via #4525. |
BTW, why use array instead of |
Using array has reduced allocation cost and less indirection. |
I've Singles of different types to run with Single.zip, and I'm getting ClassCastException as SingleZipIterable. Is it wrong zipping Singles of different type together? |
You have to be careful which index you cast back to what type. |
My Single.zip returns io.reactivex.internal.operators.single.SingleZipIterable but I'm expecting a Single, any Advice? |
Please provide a standalone unit test that demonstrates your problem. |
http://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Observable.html#zip-java.lang.Iterable-io.reactivex.functions.Function-
The
zipper
signature isFunction<? super T[]>, ? extends R> zipper
, where use ofT[]
breaks it. Just invoke it with nonObject
T, and aClassCastException
is thrown.I checked with
Single
andFlowable
, they have different signatures for the comparablezip
operators. They useObject[]
whereT[]
is used forObservable
, which are also consistent with the 1.x zip operator.I think this is just a bug in the signature.
The text was updated successfully, but these errors were encountered: