Logo

Programming-Idioms

History of Idiom 112 > diff from v16 to v17

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

Version 16

2017-10-28, 10:33:16

Version 17

2018-06-12, 19:01:23

Idiom #112 Iterate over map entries, ordered by keys

Print each key k with its value x from an associative array mymap, in ascending order of k.

Idiom #112 Iterate over map entries, ordered by keys

Print each key k with its value x from an associative array mymap, in ascending order of k.

Extra Keywords
traverse traversal
Extra Keywords
traverse traversal
Code
for (k, x) in mymap {
    println!("({}, {})", k, x);
}
Comments bubble
This assumes mymap is a BTreeMap as it is sorted by the keys.
Doc URL
https://doc.rust-lang.org/stable/std/collections/struct.BTreeMap.html#method.iter