title: Returning error early from a function that returns an observable
body: <p>I have a function and a validation helper function that reads in a tsv file as a string. I'm trying to practice my reactive programming by even doing synchronous tasks using rxjs. I know this might not be the perfect use case for it, but I know it should be possible.</p>
  
  <p>Here's it in pseudocode in it's simplest form:</p>
  
  <pre class="lang-js prettyprint-override"><code>public readTsv(tsv: string): Observable&lt;TsvAsObject&gt; {
    if (!tsv || tsv.length &lt; 1) {
      return Observable.throw('null or empty tsv file passed');
    }
    // check tsv headers
    this.validHeadersObs(tsv.split('\n')[0]) // pass the first line of the tsv string
      .filter(valid =&gt; valid === false)
      .subscribe(() =&gt; {
        return Observable.throw('invalid tsv headers')
      });
  
    // omitted logic that processes the tsv and then returns it as an observable
  
    return Observable.of(tsvAsObject);
  }
  </code></pre>
  
  <p>I've tested my validHeaders() function and I know that it works. It returns a stream of booleans checking each column header. As soon as a pair of headers doesn't match, it will return an Observable.of(false):</p>
  
  <pre class="lang-js prettyprint-override"><code>private validHeadersObs(headerLine: string): Observable&lt;boolean&gt; {
    const headers$ = Observable.from(headerLine.split('\t'));
    const validHeaders = ['columnName1', 'columnName2', 'columnName3'];
  
    return headers$
      .mergeMap((value, index) =&gt; Observable.of(value === validHeaders[index]));
  }
  </code></pre>
  
  <p>The problem is that readTsv() does not return <code>Observable.throw('invalid tsv headers')</code> because I'm not sure how to return early from the function from within a subscribe. Is there a way to "double return" from inside an arrow function?</p>