title: How to filter out observable values based on observable property of each value
body: <p>Suppose I have an Observable of items</p>
  
  <pre><code>let items$ = Observable&lt;Item[]&gt;
  </code></pre>
  
  <p>and each Item has a property <code>isSelected$</code>, which itself is an Observable:</p>
  
  <pre><code>private isSelected$: Observable&lt;boolean&gt;
  </code></pre>
  
  <p>What would be the best way to receive a list of all items that are currently selected? My solution doesn't look quite right:</p>
  
  <pre><code>items$.pipe(
      switchMap(items =&gt;
          combineLatest(items.map(item =&gt;
                  item.isSelected$.pipe(
                      map(isSelected =&gt; ({item: item, isSelected: isSelected})))),
              map(items =&gt; items.filter(item =&gt; item.isSelected).map(item =&gt; item.item))
          )))
  </code></pre>
  
  <p>It works and I have used it before, but it's such a complicated construct for something I have to do quite often. There must be a better way.</p>
  
  <p><strong>Note:</strong> The subscriber needs a list of all the selected items, not a stream of individual items.</p>
  
  <p><strong>Example:</strong>
  <code>items$</code> would emit the following list:</p>
  
  <pre><code>[{id: 1, isSelected$: of(true)}, 
      {id: 2, isSelected$: of(false)}, 
      {id:3, isSelected$: of(true)}]
  </code></pre>
  
  <p>And as a result in our subscribe, we would like to get the list:</p>
  
  <pre><code>[{id: 1}, {id: 3}]
  </code></pre>