title: Catch Complete Within RxJS Pipe
body: <p>I have an observable which just complete in case if the process is canceled.</p>
  <p>I'm trying to use that observable in another observable pipe with a switchMap() in a recursive way.</p>
  <p>I would like to &quot;catch&quot; the complete within the pipe.</p>
  <p>Here is an example:</p>
  <pre><code>function removeComponent(path: string): Observable&lt;any&gt; {
      ...
      // This method returns an observable with some result if the component is removed.
      // But, just complete in some cases.
  }
  
  function removeMultipleComponent(paths: string[]): Observable&lt;string&gt; {
      if (paths.length &gt; 1) {
          return removeComponent(path[0]).pipe(
  
  
              // I would like to catch the complete here.
  
  
              switchMapTo(
                  of(paths[0]),
                  removeMultipleComponent(paths.slice(1))
              )
          );
      }
      return removeComponent(path[0]);
  }
  </code></pre>
  <p>Is there any way to catch an observable complete within the pipe()?</p>
  <p><strong>Update: Solution based on Hodossy Szabolcs comment</strong></p>
  <pre><code>function removeMultipleComponent(paths: string[]): Observable&lt;string&gt; {
      if (paths.length &gt; 1) {
          return removeComponent(path[0]).pipe(
              defaultIfEmpty('random text'),
              switchMap((value) =&gt; {
                  if (value === 'random text') {
                      return removeMultipleComponent(paths.slice(1));
                  } else {
                      return merge(
                          of(paths[0]),
                          removeMultipleComponent(paths.slice(1))
                      );
                  }
              })
          );
      }
      return removeComponent(path[0]);
  }
  </code></pre>