title: RxJava Single to Completable to Single - how to pass the result of the first Single to the second Single
body: <p>In the following method, how do I pass the result of the first Single to the second Single?</p>
  
  <p>As it's written now, when it returns, <code>somethingId</code> is empty. If I change the value in the returned <code>Single.just(somethingId)</code> to something other than the empty string it will return that value.</p>
  
  <p>What's interesting is that if I breakpoint into the method it stops on line 7 before it goes to line 5 and 6.</p>
  
  <p>The documentation for the <code>andThen</code> on line 7 says:</p>
  
  <blockquote>
    <p>Returns a Single which will subscribe to this Completable and once that is completed then
         will subscribe to the {@code next} SingleSource.</p>
  </blockquote>
  
  <p>Why does it seem to be executing in that order and/or is there a better way to do this?</p>
  
  <pre><code>1 override fun downloadSomething(): Single&lt;String&gt; {
  2    var somethingId = ""
  3    return remoteDataSource.downloadSomething() // this is a Single
  4        .flatMapCompletable { something -&gt;
  5            somethingId = something.id
  6            saveSomething(something) // this is a Completable
  7        }.andThen(Single.just(somethingId))
  8 }
  </code></pre>
  
  <p>The only thing I can think to do at this point is return a Single for the <code>saveSomething()</code> method on line 6 (which works). However I'm then changing the signature of that method just so I can use it in this particular method which doesn't feel right. Surely there's a way to get this to work without doing that? </p>