Logo

Programming-Idioms

History of Idiom 113 > diff from v8 to v9

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

Version 8

2016-01-08, 10:00:37

Version 9

2016-01-09, 17:25:32

Idiom #113 Iterate over map entries, ordered by values

Print each key k with its value x from an associative array mymap, in ascending order of x.
Note that multiple entries may exist for the same value x.

Idiom #113 Iterate over map entries, ordered by values

Print each key k with its value x from an associative array mymap, in ascending order of x.
Note that multiple entries may exist for the same value x.

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

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