RxJava zip with empty list of observables

Based on post type i need to push item to observable list. So in case when if closure is not used (for example post.type != SomeType) my observable list is empty.

So due to that im receiving NoSuchElementException all the time from Single.zip

Here is my sample code

val observableList = mutableListOf<Single<Response>>()

if (post.type == SomeType) {
      observableList.add(addNewObservable()) <-- adding API call to the lsit
}

return Single.zip(observableList) { arg -> arg } <-- Throws error NoSuchElementException

I figured that i can use for post type != SomeType :

observableList.add(Single.just(Response(""))

And this will work fine.

So is there a better solution for it? How can i avoid that error?

Answer:1

I am planning to architect a centralized logging system for one of our project which has multiple components written in Java , Python & Scala. I want to collect logs from different components ( ...

I am getting array bound error but to my mind, array starts from 0, so what is wrong with this code? public class Quadratic { public static void main(String[] args) { double b = Double....

I am using REST Assured, but when I try to send the request I am getting the below error:- javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed:...

I am writing a software test automation tool and I have a Journal Record Proc in a DLL. Now when the Proc gets called by Windows I want to call a method in a Java class from it. Is this possible ?