multizip
Zip 3, 4, 5 or more Rust iterators
Description
With Rust's stdlib you can only zip 2 iterators at a time:
let a: = vec!;
let b: = vec!;
let c: = vec!;
let d: = vec!;
let abc = a.iter.zip.zip
.map| aa+bb+cc);
// (( , ), )
// ^~~~~~~~~~^~~~~~^ awkward!
let abcd = a.iter.zip.zip.zip
.map, &dd)| aa+bb+cc+dd);
// ((( , ), ), )
// ^~~~~~~~~~~^~~~~~^~~~~~^ ughhh!
With multizip
, you get a flattened version of zip
:
let abc = zip3
.map )
// ( , , )
// ^~~~~~~~~~~~~~^ oooh!
let abcd = zip4
.map
// ( , , , )
// ^~~~~~~~~~~~~~~~~~~^ sweet!
How to use
TODO: upload to crates.io and update here with Cargo instructions.
FAQ
How much variables can I zip together?
Rust supports up to 12 variables in a single tuple, so the following are
implemented: zip2()
, zip3()
, zip4()
..., zip12()
.
If you need more than 12, something is probably wrong with your design. Consider something more appropriate than tuples.
What is the advantage of multizip::zip2()
over std::iter::zip()
?
The only advantage is the symmetry of arguments, e.g. zip2(a.iter(), b.iter())
over a.iter().zip(b.iter())
.
Author
Marc Dupont -- mdup.fr