title: Android RxJava: Chaining two requests and doing some logic inbetween
body: <p>Hi i am trying to create a chain of network requests using flatmap but dont quite understand the process on how to do this.</p>
  
  <p>The goal is to do this:</p>
  
  <p>do networkRequest 1
  once i get a result from networkRequestOne, do some bit of logic on that result and then execute the next networkRequestTwo and the call onSuccess with teh returned response value from networkRequestTwo.</p>
  
  <p>current code:</p>
  
  <pre><code>delegator.requestOne(requestData)
                  .flatMap ({  response -&gt;
                      if(response.isSuccessful){
                          cookieStorage.saveSessionCookies(response.header(cookieStorage.COOKIE_HEADER_NAME)!!)
                      }
                      return delegator.requestTwo
  
                  })
                  .observeOn(AndroidSchedulers.mainThread())
                  .subscribeOn(Schedulers.io())
                  .subscribe(object : SingleObserver&lt;ResponseTwo&gt;() {
                      @Override
                      fun onSubscribe(Disposable d) {
                      }
  
                      @Override
                      fun onSuccess(responseTwo :ResponseTwo) {
                          callback.onSuccess(responseTwo)
                      }
  
                      @Override
                      public void onError(Throwable e) {
  
                      }
                  });
  </code></pre>
  
  <p>both delegator.requestOne and delegator.requestTwo both hooked up to a retrofit call that returns  a Single observable</p>