title: How do I sum the values in a Reactor Flux stream?
body: <p>Suppose I have a repository with a <code>findAll()</code> method that returns an <code>Iterable</code> of <code>State</code>, where <code>State</code> is a class representing a US state that has two fields (with getter/setters): <code>name</code>, and <code>population</code>.  </p>
  
  <p>I want to get the sum of the population fields for all <code>State</code>s in my Flux. 
   I create a Flux from an Iterable, as follows:</p>
  
  <pre><code>Flux f = Flux.fromIterable(stateRepo.findAll());
  </code></pre>
  
  <p>I've got my Flux, but I don't know of a good way to sum up its values. 
   I've tried something like</p>
  
  <pre><code>int total = 0;
  f.map(s -&gt; s.getPopulation()).subscribe(p -&gt; total += v);
  return total;
  </code></pre>
  
  <p>However, the compiler says that total "should be final or effectively final".  Adding <code>final</code> obviously won't work, because I'm trying to add to it.</p>
  
  <p>How do I go about summing (or any other aggregate function) on a Flux?</p>