title: How to fetch the data from a collection of optionals?
body: <p>I have a method returning a collection of products:</p>
  
  <pre><code>Collection&lt;Product&gt; getProducts() { ... }  
  </code></pre>
  
  <p>Each product may have a guarantee. But it is not required.</p>
  
  <pre><code>interface Product {
      Optional&lt;Guarantee&gt; getGuarantee();
  }
  </code></pre>
  
  <p>Now I need to go through all the products and check if the quarantees have expired. The non-expired ones should be collected into a list.</p>
  
  <p>This is what I do:</p>
  
  <pre><code>List&lt;Optional&lt;Guarantee&gt;&gt; optionalGar = getProducts().stream()
        .map(f -&gt; f.getGuarantee()).collect(Collectors.toList());
  
  List&lt;Guarantee&gt; gar = optionalGar.stream()    
        .map(op -&gt; op.orElse(null))             
        .filter(Objects::nonNull)
        .filter(g -&gt; !g.hasExpired())
        .collect(Collectors.toList());
  </code></pre>
  
  <p>Is there any way to avoid using <code>.orElse(null)</code>? </p>
  
  <p>(Replacing it by <code>op.get()</code> would cause an exception in case the optional is empty)  </p>
  
  <p><em>P.S: I'm free to chose between Java 8 and Java 9 so both solutions (not sure if the'll be different) are welcome</em></p>