title: Consuming Rest Service the functional way
body: <p>So I was curious as to how would the following code be rewritten more effiently with the java8 streams API. </p>
  
  <pre><code>public static List&lt;FlightInfo&gt; getResults(String origin,List&lt;String&gt; destinations)  {
  
      final String uri = "https://api.searchflight.com/;
      List&lt;FlightInfo&gt; results = new LinkedList&lt;FlightInfo&gt;();
  
      for(String destination:destinations) {
  
  
              RestTemplate restTemplate = new RestTemplate();
  
              String params = getParams(origin,destination);
              FlightInfo result = restTemplate.postForObject(uri+params,FlightInfo.class);
  
              results.add(result);
      }
  
      return results;
  
  }
  </code></pre>
  
  <p>After this method is done doing what its is doing and I receive the list of FLightInfo objects, I am converting it into a stream and will be doing various transformations on it (group by, etc). Now it is pretty apparant that this is a long running operation. Furthermore it actually combines multiple rest calls to the web service, so I already have most of the data obtained by the time I make the last call, but I would not  start processing it before the whole method returns. </p>
  
  <p>Is there a way to do all that a bit more reactively? Could I return a stream immediatelly and have the operations on that stream process data as it comes down the pipe or this is a bit too much to ask? How would that be done in Java 8. That </p>