title: Conditionally apply pipe operators
body: <p>I need a <code>timeout</code> operator to throw an error when parameter <code>isTimeoutNeeded</code> is True, so that I could handle the case if the subscribed observable do not emit any value after X seconds.</p>
  
  <pre><code>if (isTimeoutNeeded) {
      this.service.getData()
        .pipe(
            timeout(10000),
            ...
        )
        .subscribe((...) =&gt; ...);
  } else {
      this.service.getData()
      .pipe( 
         ... 
      )    
      .subscribe((...) =&gt; ...);
  }
  </code></pre>
  
  <p>Is it possible to write this in a rxjs way by conditionally adding <code>timeout</code> operator when needed? </p>
  
  <p>I have tried using <code>iif</code> and <code>switchMap</code> but it did not work.</p>
  
  <pre><code> this.service.getData()
      .pipe(
         mergeMap((response) =&gt;
            iif(() =&gt; !isTimeoutNeeded,
            of(response),
            of(response).pipe(timeout(10000)) // did not apply timeout if isTimeoutNeeded = True
         )
      )
      .subscribe((...) =&gt; ...);
  </code></pre>
  
  <p><code>switchMap</code></p>
  
  <pre><code> this.service.getData()
      .pipe(
             switchMap((response) =&gt; {
                  if (!isTimeoutNeeded) {
                      return of(response);
                  }
                  return of(response).timeout(10000); // did not apply timeout if isTimeoutNeeded = True
              })
              .....
         )
      )
      .subscribe((...) =&gt; ...);
  </code></pre>