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 chunk_while iterator #436

Closed

Conversation

pwoolcoc
Copy link

This is an iterator that is a mix of std::slice::chunks and fold.
Instead of chunking the source up into predictable lengths though, it
allows the user to inspect each element of the source, along with a
state, and decide when the chunk is big enough.

@pwoolcoc
Copy link
Author

Sorry if I should have taken this to the stdlib first, but given

if your feature involves heap allocation, such as storing elements in a Vec, then it can't be accepted into libcore, and you should propose it for itertools directly instead.

I figured I would just bring it here, since it uses a Vec internally

@pwoolcoc
Copy link
Author

two things I'm unhappy with:

  1. type Item = Vec<T>. I wish that could be type Item = &'a [T], but then I run into the problem of tying 'a to self in fn next(&mut self, ...). If anyone has a way I can do this, I'm all ears.
  2. B: Clone. I'm not sure if there's a way to do this or not, but every time it starts accumulating a new chunk, it needs to reset the state. Again, if there's a better way, I'd love to hear about it

@phimuemue
Copy link
Member

Hi there!

Regarding type Item=Vec<T>: Do you think we could we make this a "lazy" chunking operation? (iirc such as GroupBy.)

This is an iterator that is a mix of `std::slice::chunks` and `fold`.
Instead of chunking the source up into predictable lengths though, it
allows the user to inspect each element of the source, along with a
state, and decide when the chunk is big enough.
@pwoolcoc pwoolcoc force-pushed the add-chunk-while-iterator branch from a6fc4e3 to 7c75b7f Compare April 15, 2020 20:29
@pwoolcoc
Copy link
Author

@phimuemue thanks, I'm looking into that right now and I'll update here when I can

@Philippe-Cholet
Copy link
Member

@pwoolcoc Hi, do you want to update your work on chunk_while here?

@Philippe-Cholet
Copy link
Member

I would prompty reopen if needed.

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

Successfully merging this pull request may close these issues.

3 participants