Note that although this optimization is not performed today in the reference implementation, for an operation such as IntStream.rangeClosed(from, to).summaryStatistics() , it is not necessary to actually IntStream.rangeClosed(from, to).summaryStatistics() over all the values.
It can simply return new IntSummaryStatistics((long)to-from+1, from, to, ((long)from+to)*((long)to-from+1)/2) .
As already mentioned, this optimization does not occur today, but it is an example that sometimes there are ways to calculate such statistics without having to repeat each value, so it was a significant limitation that the only way to populate xxxSummaryStatistics was to acceptโ separate values โโ(and combine , but for this an existing instance of statistics is required, which must be filled in somehow).
source share