rust-itertools / itertools

Extra iterator adaptors, iterator methods, free functions, and macros.
https://docs.rs/itertools/
Apache License 2.0
2.72k stars 309 forks source link

feat: add combinations_up_to #687

Closed maratik123 closed 1 year ago

maratik123 commented 1 year ago

Add combinations_up_to to iterator functions

Philippe-Cholet commented 1 year ago

I think the name combinations_up_to is nice. What's weird for me is that it starts with "k" items then decrease instead of starting with 0 items then increase, that would feel more natural, something like: vec![], vec![1], vec![2], vec![3], vec![4], vec![1, 2], vec![1, 3], ... which is not even the reverse order of the current behavior. Then maybe we could impl DoubleEndedIterator for it (to be able to call .rev() on it).

EDIT: Currently I think it's something like (0..=k).rev().flat_map(|i| iter.clone().combinations(i)). Is that needed?

maratik123 commented 1 year ago

EDIT: Currently I think it's something like (0..=k).rev().flat_map(|i| iter.clone().combinations(i)). Is that needed?

Yes, agree with you. Seems that this PR is not needed. Closing it now.