Logo

Programming-Idioms

History of Idiom 113 > diff from v10 to v11

Edit summary for version 11 by :
[D]

Version 10

2016-01-09, 17:59:41

Version 11

2016-01-09, 18:01:31

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;
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);
}
Code
auto mySortedMap = mymap.byKeyValue
                        .array
                        .sort!((a, b) => a.value < b.value)
			.each!(p => writeln(p.key," ",p.value));