title: Is there an elegant way to process a stream in chunks?
body: <p>My exact scenario is inserting data to database in batches, so I want to accumulate DOM objects then every 1000, flush them.</p>
  
  <p>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.</p>
  
  <p>I could convert the stream to a List then use subList in an iterative fashion, but that too seems clunky.</p>
  
  <p>It there a neat way to take action every n elements then continue with the stream while only processing the stream once?</p>