title: Create stream lazily
body: <p>How can a stream be created lazily? During migration of collection based code I have run into this pattern multiple times:</p>
  
  <pre><code>Collection collection = veryExpensiveCollectionCreation();
  return Stream.concat(firstStream, collection.stream());
  </code></pre>
  
  <p>The resulting concatenated stream is typically processed lazily, as we know. Therefore the expensive collection is not needed at all, if the stream processing stops in the first part of the concatenated stream.</p>
  
  <p>So for performance reasons I would like to defer the creation of the entire collection until the concatenated stream actually tries to iterate the elements of the second part of the concatenation.</p>
  
  <p>Pseudo code would look like</p>
  
  <pre><code>return Stream.concat(firstStream, new LazyStreamProvider() {
      Stream&lt;Something&gt; createStream() {
           return veryExpensiveCollectionCreation().stream();
      }
  );
  </code></pre>
  
  <p>Edit: I'm aware refactoring the collection creation to streams would be best, to make all of the API stream aware. However, this is part of another component with a non modifiable API in this case.</p>