itertools
itertools copied to clipboard
Add chunks_exact method
Would like to request an _exact version of the chunks method akin to how slices work. I believe this would be useful functionality.
+1 to that!
Like array_chunks? Or something else?
I'm unsure how best to represent the tail for this. Slices have it easy, since https://doc.rust-lang.org/nightly/std/primitive.slice.html#method.as_chunks can just split it up-front into the chunks part and the less-than-the-chunk-size tail (https://github.com/rust-lang/rust/issues/76354).
@mzr @JosephKyser Would it be fine for your uses if this only worked on ExactSizeIterators? The simplest version of this would be something like
if self.len() < N { None }
else { Some(array::from_fn(|_| self.inner.next().unwrap())) }
but if it needs to build up state as it go and return that for the tail later it gets much messier.