title: RxJava/Kotlin Observable method call chain - how to terminate?
body: <p>I want to implement method to edit a note, save it to local database (cache) and then send it to the server as a POST request. I am learning RxJava and I wanted to create <code>Observable</code> from the note and then apply transformations on it, like to map it to an Entity model and saving. The issue that my method returns Completable and this chain returns <code>Observable&lt;Completable&gt;</code>. How to unwrap the <code>Completable</code> from this <code>Observable</code> which I used only to start RxJava stuff. Each <code>editNote()</code> methods returns a <code>Completable</code>.</p>
  
  <pre><code> override fun editNote(note: Note): Completable {
      return Observable.just(note)
          .map { mapper.mapToEntity(it) }
          .map { noteEntity -&gt;
              factory.getCacheDataStore().editNote(noteEntity)
                  .andThen { factory.getRemoteDataStore().editNote(noteEntity) }
          }
  }
  </code></pre>
  
  <p>=======================================================</p>
  
  <h1>UPDATE</h1>
  
  <p>Finally, I managed to find "a solution" but I am not sure it is correct :-)</p>
  
  <pre><code>override fun editNote(note: Note): Completable {
      return Observable.just(note)
          .map { mapper.mapToEntity(it) }
          .flatMapCompletable { noteEntity -&gt;
              factory.getCacheDataStore().editNote(noteEntity)
                  .andThen { factory.getRemoteDataStore().editNote(noteEntity) }
          }
  }
  </code></pre>