Programming-Idioms

History of Idiom 163 > diff from v6 to v7

Edit summary for version 7 :
New Rust implementation by user [GobbleCock]

Version 6

Version 7

Idiom #163 Print list elements by group of 2

Print all the list elements, two by two, assuming list length is even.

Idiom #163 Print list elements by group of 2

Print all the list elements, two by two, assuming list length is even.

Code
for pair in list.chunks(2) {
    println!("({}, {})", pair[0], pair[1]);
}
Doc URL
https://doc.rust-lang.org/nightly/std/primitive.slice.html#method.chunks
Demo URL
https://play.rust-lang.org/?gist=6da21f02bad77882524e04ce175d8d9d&version=stable&mode=debug