title: RXJS Stop propagation of Observable chain if certain condition is met
body: <h3>Introduction</h3>
  
  <p>I'm trying to create a route guard in <code>Angular2+</code> using Observable from the shared service which holds the string value of current user role.<br>
  The problem is obviously in shifting my mind from Promises to Observables. </p>
  
  <blockquote>
    <p>What I made so far is based on heuristics and try &amp; error approach but
    I hit the wall by killing the browser <strong>Solved thanks to danday74</strong></p>
  </blockquote>
  
  <p>.</p>
  
  <h3>Attempt (improved thanks to @danday74)</h3>
  
  <p>With the help of <a href="https://stackoverflow.com/questions/34523338/rxjs-sequence-equvalent-to-promise-then" title="here">RxJS sequence equvalent to promise.then()?</a> i've translated what i want to do into this chain:</p>
  
  <pre><code>canActivate(route: ActivatedRouteSnapshot): Observable&lt;boolean&gt; | boolean {
          return this.auth.isRoleAuthenticated(route.data.roles)
              .mergeMap((isRoleAuthenticated: boolean) =&gt; {
                  return isRoleAuthenticated ? Observable.of(true) : this.auth.isRole(Roles.DEFAULT_USER);
              })
              .do((isDefaultUser: boolean) =&gt; {
                  const redirectUrl: string = isDefaultUser ? 'SOMEWHERE' : 'SOMEWHERE_ELSE';
                  this.router.navigate([redirectUrl]);
              })
              .map((isDefaultUser: boolean) =&gt; {
                  return false;
              });
      }
  </code></pre>
  
  <h3>Question</h3>
  
  <p>How to stop further propagation of observable chain if <code>isRoleAuthenticated = true</code>? I need to return that boolean value if such condition is met and make sure <code>.do</code> operator block is not called after.<br>
  Limitation is that boolean value must be returned from <code>canActivate</code> guard.</p>