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
Multiunzip supports only up to 12 iterators #696
Comments
Hi there, wow, 37, that's quite a bit. As far as I know, itertools could theoretically support it (iirc, we generate the Can you - at least as a first step - fork itertools yourself and copy-paste the macro call for 37 elements? Or can you work around it? If there's enough demand or compile times do not skyrocket, we could think about offering the Alternatively: Should/could we offer a simple macro that allows users to implement As a sidenote: If we touch this, we could possibly simplify the macro a little bit. |
Definitely not a big issue that needs to be solved. I ended up doing something like this: let my_vec = (
my_iter.map(|val| val.0).collect_vec(),
my_iter.map(|val| val.1).collect_vec(),
// etc
); Another alternative with less iterations could probably be let mut my_vec: (Vec<String>, Vec<String>) = (vec![], vec![]); // etc
for val in my_iter {
my_vec.0.push(val.0);
my_vec.1.push(val.1);
} Anyways, just wanted to made you aware of my use case. Feel free to close this issue if needed. |
I think that sticking with 12-tuples for consistency with Maybe it could be implemented for arrays, though? Getting |
Hey, I also triggered this limitation, and also agree that consistency with
One possible way out is providing a derive-macro to be implemented on a user's structure. #[derive(Debug, Multiunzip)]
pub struct Person {
age: u32,
name: String,
}
fn main() {
let persons = vec![
Person {
age: 20,
name: "Alice".to_string(),
},
Person {
age: 25,
name: "Bob".to_string(),
},
];
let persons_unzipped = PersonUnzipped::multiunzip(persons.into_iter());
assert_eq!(persons_unzipped.age, vec![20, 25]);
assert_eq!(persons_unzipped.name, vec!["Alice".to_string(), "Bob".to_string()]);
}
// Proc-Generated
#[derive(Default)]
pub struct PersonUnzipped {
age: Vec<u32>,
name: Vec<String>,
}
// Proc-Generated
impl PersonUnzipped {
// The same implementation as multiunzip
pub fn multiunzip<IT: Iterator<Item = Person>>(it: IT) -> Self {
let mut res = PersonUnzipped::default();
let PersonUnzipped {
age,
name,
} = &mut res;
it.fold((), |(), v| {
age.extend(std::iter::once(v.age));
name.extend(std::iter::once(v.name));
});
res
}
} I understand that it is unlikely to ever make it in itertools as-is because it is absolutely not the itertools philosophy. That being said, hopefully the above will help people who are blocked by this issue :) |
I was trying to multiunzip an iterator of tuples of 37 elements, and I was getting this error:
Turns out, it is because multiunzip only supports up to 12 iterators.
Two questions:
The text was updated successfully, but these errors were encountered: