title: How to make a future that gets completed when any of the given CompletableFutures is completed with a result that matches a certain predicate?
body: <p>I have a list of <code>CompletableFuture&lt;MyService&gt;</code>:</p>
  
  <pre><code>List&lt;CompletableFuture&lt;MyService&gt;&gt;
  </code></pre>
  
  <p>where <code>MyService</code> is immutable like the following:</p>
  
  <pre><code>public class MyService {
      public boolean isAvailable() {
           return true; // or false
      }
  }
  </code></pre>
  
  <p>I now want a future that is completed when one of the futures:</p>
  
  <ul>
  <li>is completed; <strong>and</strong></li>
  <li>for the <code>MyService</code> instance as provided by that future: <code>MyService.isAvailable()</code> returns <code>true</code></li>
  </ul>
  
  <p>When proceeding, I need to have the <code>MyService</code> instance that is available. In other words, I want a <code>CompletableFuture&lt;MyService&gt;</code> which completes when the two conditions are met.</p>
  
  <p>How can I do this? I know I can use <code>CompletableFuture.anyOf(...)</code> to proceeed when one of the futures completes, but I am unsure how to integrate the second requirement: <code>MyService.isAvailable()</code> must be true.</p>