title: How to filter a list using an async predicate
body: <p>Suppose you have a list of strings (or of any other type, just using string as an example), e.g.</p>
  
  <pre><code>IEnumerable&lt;string&gt; fullList = ...;
  </code></pre>
  
  <p>and an async predicate, e.g.</p>
  
  <pre><code>static Task&lt;bool&gt; IncludeString(string s) { ... }
  </code></pre>
  
  <p>What is the simplest way of filtering the list by that predicate, with the following constraints:</p>
  
  <ol>
  <li>Predicates should not be run sequentially (assume the list is long and the async predicate is slow)</li>
  <li>Resulting filtered list should preserve ordering</li>
  </ol>
  
  <p>I did find a solution, but it involves creating a temporary list that has the result of the predicate for each entry, and then using that to do the filtering. It just doesn't feel elegant enough. Here it is:</p>
  
  <pre><code>var includedIndices = await Task.WhenAll(fullList.Select(IncludeString));
  var filteredList = fullList.Where((_, i) =&gt; includedIndices[i]);
  </code></pre>
  
  <p>It feels like something that should be possible with a simple framework call, but I wasn't able to find one.</p>