Logo

Programming-Idioms

History of Idiom 112 > diff from v4 to v5

Edit summary for version 5 by :
New D implementation by user [piou]

Version 4

2016-01-05, 09:50:26

Version 5

2016-01-09, 17:59:37

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.

Imports
import std.algorithm;
import std.array;
Code
auto mySortedMap = mymap.byKeyValue
                        .array
                        .sort!((a, b) => a.key < b.key);

foreach (p ; mySortedMap) {
    doStuff(p.key, p.value);
}