title: How to average BigDecimals using Streams?
body: <p>I'm wanting to take the following method:</p>
  
  <pre><code>public BigDecimal mean(List&lt;BigDecimal&gt; bigDecimals, RoundingMode roundingMode) {
      BigDecimal sum = BigDecimal.ZERO;
      int count=0;
      for(BigDecimal bigDecimal : bigDecimals) {
          if(null != bigDecimal) {
              sum = sum.add(bigDecimal);
              count++;
          }
      }
      return sum.divide(new BigDecimal(count), roundingMode);
  }
  </code></pre>
  
  <p>and update it using the Streams api.  Here's what I've got thus far:</p>
  
  <pre><code>public BigDecimal average(List&lt;BigDecimal&gt; bigDecimals, RoundingMode roundingMode) {
      BigDecimal sum = bigDecimals.stream()
          .map(Objects::requireNonNull)
          .reduce(BigDecimal.ZERO, BigDecimal::add);
      long count = bigDecimals.stream().filter(Objects::nonNull).count();
      return sum.divide(new BigDecimal(count), roundingMode);
  }
  </code></pre>
  
  <p>Is there a way to do this without streaming twice (the second time to get the count)?</p>