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

Combination on zero-sized array #361

Closed
leeopop opened this issue Jul 31, 2019 · 1 comment · Fixed by #383
Closed

Combination on zero-sized array #361

leeopop opened this issue Jul 31, 2019 · 1 comment · Fixed by #383

Comments

@leeopop
Copy link

leeopop commented Jul 31, 2019

Combination(0) seems to return an empty array.
However, the result differs when the original list is empty or not.

I think it would be better to produce [] instead of None.

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=dad32c5aeae27dcd9b14ce8475b5fa79

use itertools::*; // 0.8.0
fn main() {
    let a: Vec<usize> = vec![1usize];
    let b: Vec<usize> = vec![];
    println!("{:?}", a.iter().combinations(0).next()); // Some([])
    println!("{:?}", b.iter().combinations(0).next()); // None
}

https://www.wolframalpha.com/input/?i=0+choose+0
https://www.wolframalpha.com/input/?i=1+choose+0

@leeopop
Copy link
Author

leeopop commented Jul 31, 2019

#174 solves (n, 0), but it seems not to work for (0,0)

andersk added a commit to andersk/itertools-rs that referenced this issue Nov 12, 2019
Fixes rust-itertools#361 while also simplifying the code.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
andersk added a commit to andersk/itertools-rs that referenced this issue Nov 12, 2019
Fixes rust-itertools#361 while also simplifying the code.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
bors bot added a commit that referenced this issue Jan 14, 2020
383: Fix combinations(0) and combinations_with_replacement(0). r=jswrenn a=andersk

The empty combination is always a valid combination of length 0.

Fixes #361 while also simplifying the code.

Co-authored-by: Anders Kaseorg <andersk@mit.edu>
@bors bors bot closed this as completed in 13aa10e Jan 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant