You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems to me, that the only difference is that std does not return the value of the functor, But I'm not sure, and don't want to introduce a subtle error by switching over if i don't need the key.
Could we include a small comment in the documentation to help users choose between itertools' and std's implementation?
The text was updated successfully, but these errors were encountered:
I think your intuition that they yield the same chunks is correct.
slice::chunk_by works on slices and when you iterate over it, you'll get slices. Its predicate has the form FnMut(&T, &T)->bool, i.e. you tell it if two consecutive elements belong to the same chunk.
Itertools::chunk_by works on iterators. This is a bit more general, but needs more work compared to the pure slice version. iirc, it's a bit more cumbersome to use, too. Its functor has the form FnMut(Item)->K and it requires K: PartialEq, so that this functor extracts a "key" from the item, and uses K's equality to determine if they belong to the same chunk.
I think we should adopt what std does on slices here: In particular, our closure should be a predicate (seems strictly more general that what we currently have) and the documentation should be in line with std's. @jswrenn Thoughts?
Yes, bool seems to me, more intuitive and perhaps more useful too.
I'm happy to close this issue since you've covered my concern, but I'll leave it open for someone else to close, since an interesting question has been posed.
I think we should adopt what std does on slices here: In particular, our closure should be a predicate (seems strictly more general that what we currently have) and the documentation should be in line with std's. @jswrenn Thoughts?
Hello!
std has chunk_by and so does itertools
It seems to me, that the only difference is that std does not return the value of the functor, But I'm not sure, and don't want to introduce a subtle error by switching over if i don't need the
key
.Could we include a small comment in the documentation to help users choose between itertools' and std's implementation?
The text was updated successfully, but these errors were encountered: