Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add chunks_exact method #664

Open
JosephKyser opened this issue Dec 10, 2022 · 3 comments
Open

Add chunks_exact method #664

JosephKyser opened this issue Dec 10, 2022 · 3 comments

Comments

@JosephKyser
Copy link

Would like to request an _exact version of the chunks method akin to how slices work. I believe this would be useful functionality.

@mzr
Copy link

mzr commented Feb 29, 2024

+1 to that!

@jswrenn
Copy link
Member

jswrenn commented Feb 29, 2024

Like array_chunks? Or something else?

@scottmcm
Copy link
Contributor

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 (rust-lang/rust#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants