title: RxJS - Map over last element of a stream
body: <p>I have a stream that will either complete or throw an exception (ie. not an infinite stream). </p>
  
  <p>It emits 2 values (say A and B) before it finishes. Is it possible to map the last value emitted to something else?</p>
  
  <pre><code>stream$
      .debounceTime(100)
      .mergeMap(element =&gt;
        api(stream$, ...) // This emits A B
          .last()
          .map(lastElement =&gt; f(lastElement.result)) // produces C based on B
  </code></pre>
  
  <p>Now I have a stream containing just <code>C</code>, is it possible to keep <code>A</code> (so that the <code>$stream</code> emits <code>A C</code>) without resorting to have local variables to store the intermediate stream?</p>