title: Using Java 8 Stream Reduce to return List after performing operation on each element using previous elements values
body: <p>I'm new to Streams and Reduce so I'm trying it out and have hit a problem:</p>
  
  <p>I have a list of counters which have a start counter and end counter. The startcounter of an item is always the endcounter of the previous. I have a list of these counters <code>listItems</code> which I want to loop through efficiently, filter out inactive records and then reduce the list into a new List where all the StartCounters are set. I have the following code:</p>
  
  <pre><code>List&lt;CounterChain&gt; active = listItems.stream()
                  .filter(e -&gt; e.getCounterStatus() == CounterStatus.ACTIVE)
                  .reduce(new ArrayList&lt;CounterChain&gt;(), (a,b) -&gt; { b.setStartCounter(a.getEndCounter()); return b; });
  </code></pre>
  
  <p>But it doesn't really work and I'm kind of stuck, can anyone give me a few suggestions to help me get this working? Or is there an equally efficient better way to do this? Thanks!</p>