title: Get one object from observable array
body: <p>How do you write a function that takes an <code>Observable&lt;T[]&gt;</code> and returns <code>Observable&lt;T&gt;</code>?</p>
  
  <p>For example, I have two methods:</p>
  
  <pre><code>getTransactions(): Observable&lt;Transaction[]&gt;{
          ...
      }
  getTransaction(id: number): Observable&lt;Transaction&gt;{
      return this.getTransactions().pipe(find(txn =&gt; txn.id === id));
  }
  </code></pre>
  
  <p>I get the error that type 'Observable' is not assignable to type 'Observable'. Type 'Transaction[] is not assignable to type 'Transaction'. Property 'id' is missing in type 'Transaction[]'.</p>
  
  <p>As I understand, the observable pipe functions (map, single, find, max, etc.) pertain to a stream of data (i.e., while the observable is emitting multiple items over time) and are not useful when the observable emits a single item (which happens to be an array) at once.</p>
  
  <p>What is the proper way to write the <code>getTransaction(id)</code> function? I tried:</p>
  
  <pre><code>let transactions : Transaction[] = [];
  this.getTransactions().subscribe(txns =&gt; transactions=txns);
  return of(transactions.find(txn =&gt; txn.id === id));
  </code></pre>
  
  <p>But this causes an error saying 'transaction' is undefined. I'm very new to Angular etc. so any instruction is helpful. Thank you!</p>
  
  <p><a href="https://stackblitz.com/edit/angular-stackblitz-demo-nt6q23" rel="noreferrer" title="Stackblitz">Stackblitz</a></p>
  
  <p>I'm using:<br>
  Angular CLI: 6.0.3<br>
  Angular: 6.0.1<br>
  rxjs: 6.1.0</p>