My exact scenario is inserting data to database in batches, so I want to accumulate DOM objects then every 1000, flush them.
I implemented it by putting code in the accumulator to detect fullness then flush, but that seems wrong - the flush control should come from the caller.
I could convert the stream to a List then use subList in an iterative fashion, but that too seems clunky.
It there a neat way to take action every n elements then continue with the stream while only processing the stream once?