title: Java how to build a stream on top of an existing interface
body: <p>I have an existing interface that allows me to access a theoretically infinite collection as follows: </p>
  
  <pre><code>List&lt;Element&gt; retrieve(int start, int end);
  
  //example
  retrieve(5, 10); // retrieves the elements 5 through 10.
  </code></pre>
  
  <p>Now I would like to build a Java stream on top of this existing interface so that I can stream as many elements as I need without requesting a large list at once.</p>
  
  <p>How would I go about doing this? </p>
  
  <p>I looked at examples of Java streams and all I can find are examples of how to create stream from collections that are completely in memory. I currently load in 30 elements at a time and do the necessary processing but it would be cleaner if I could abstract that logic away and just return a stream instead.</p>