I understand where you are coming from. For Iterator we cover that in the documentation:
Provide the standard Groovy size() method for Iterator. The iterator will become exhausted of elements after determining the size value. It would just be that a Stream *may* become exhausted after calling size(). The documentation already says "terminal operator" but we could elaborate on that aspect. Cheers, Paul. On Thu, Jun 5, 2025 at 12:10 PM Christopher Smith <chrylis+gro...@gmail.com> wrote: > > My only hesitation is that "count" seems like an imperative to me, and it's > not obvious that "size" will both evaluate and exhaust (if possible) a > stream. Streams aren't quite like other aggregate objects. > > > On Wed, Jun 4, 2025, 18:12 Paul King <pa...@asert.com.au> wrote: >> >> In StreamGroovyMethods, I created a size() method for Stream that is >> an alias for count(): >> >> https://github.com/apache/groovy/pull/2247 >> >> (Suggested on Slack by Vampire aka Björn Kautler) >> >> Let me know if you have any feedback. One of the pain points Groovy >> proposes to offer is always having a size() method on an aggregate >> thing and relieving the developer from having to know whether that >> thing offers size(), length, length(), count() and other options. So, >> I am +1 on adding this in Groovy 5. It appears to me to be like a >> missing feature we didn't spot for earlier Groovy versions, so I am >> thinking we should backport to GROOVY_4_0_X. Thoughts? >> >> Cheers, >> Paul.