code: @NotNull
      public OptionalDouble average() {
          long count = 0;
          double sum = 0d;
          while (iterator.hasNext()) {
              sum += iterator.nextDouble();
              count++;
          }
          if (count == 0) return OptionalDouble.empty();
          return OptionalDouble.of(sum / (double) count);
      }
docs: Returns the average of elements in this stream.
  
  <p>This is a terminal operation.
  
  @return the average of elements in this stream