itertools
itertools copied to clipboard
Add `chunk_while` iterator
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.
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<T>, 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
two things I'm unhappy with:
type Item = Vec<T>. I wish that could betype Item = &'a [T], but then I run into the problem of tying'ato self infn next(&mut self, ...). If anyone has a way I can do this, I'm all ears.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
Hi there!
Regarding type Item=Vec<T>: Do you think we could we make this a "lazy" chunking operation? (iirc such as GroupBy.)
@phimuemue thanks, I'm looking into that right now and I'll update here when I can
@pwoolcoc Hi, do you want to update your work on chunk_while here?
I would prompty reopen if needed.