title: Rxjava zip operator filter second Observable by checking data with first Observable android
body: <p>I am using <code>.zip</code> operator to combine 2 <code>API calls</code> </p>
  
  <p><strong>What I want</strong></p>
  
  <p>I wanted to get filtered values from <code>2nd Observable</code> based on some <code>ids</code> from <code>1st Observable</code></p>
  
  <p><strong>Eg</strong></p>
  
  <p><code>1st Observable</code> returns data like (sample data)</p>
  
  <pre><code>"categories": [
  {
              "category": "1",
              "category_name": "Wedding Venues",
              "category_photo_url": "http://www.marriager.com/uploads/album/0463373001465466151-0463467001465466151.jpeg",
              "category_type_id": "1",
  </code></pre>
  
  <p><code>2nd Observable</code> returns data like :</p>
  
  <pre><code>"data": [
          {
              "cat_id": "1",
              "category_name": "Wedding Venues",
              "status": "1",
              "order_id": "1",
              "category_type_id": "1"
          },
  </code></pre>
  
  <p>I wanted to filter my 2nd Observable data to only return values that matches  <strong>category_type_id</strong> from 1st Observable</p>
  
  <p><strong>My Code</strong></p>
  
  <pre><code>Observable obsService = retrofitService.loadService(getSharedPref().getVendorId());
  Observable obsCategory = retrofitService.loadCategory();
  
  Observable&lt;ServiceAndCategory&gt; obsCombined = Observable.zip(obsService.observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()), obsCategory.observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()), new Func2&lt;ServiceModel, CategoryModel, ServiceAndCategory&gt;() {
              @Override
              public ServiceAndCategory call(ServiceModel serviceModel, CategoryModel categoryModel) {
                  return new ServiceAndCategory(serviceModel, categoryModel);
              }
          });
          obsCombined.observeOn(AndroidSchedulers.mainThread())
                  .subscribeOn(Schedulers.io());
  
          obsCombined.subscribe(new Subscriber&lt;ServiceAndCategory&gt;() {
              @Override
              public void onCompleted() {
  
  
              }
  
              @Override
              public void onError(Throwable e) {
                  if (e instanceof UnknownHostException || e instanceof ConnectException) {
                      mPresenter.onNetworkError();
                  } else if (e instanceof SocketTimeoutException) {
                      mPresenter.onTimeOutError();
                  } else {
                      mPresenter.onServerError();
                  }
              }
  
              @Override
              public void onNext(ServiceAndCategory model) {
  
                  mPresenter.onSuccess(model);
              }
          });
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>basically I want to apppy the following logic</p>
  
  <pre><code>this.categoryList = combinedModel.categoryModel.getData();
          serviceList = combinedModel.serviceModel.getData().getCategories();
  
          for (int i = 0; i &lt; serviceList.size(); i++) {
  
              for (int j = 0; j &lt; categoryList.size(); j++) {
  
                  if (!serviceList.get(i).getCategoryTypeId().equals(categoryList.get(j).getCategoryTypeId())) {
  
                      categoryList.remove(j);
  
                  }
  
              }
  
          }
  </code></pre>