Logo

Programming-Idioms

History of Idiom 113 > diff from v12 to v13

Edit summary for version 13 by :
[D]

Version 12

2016-01-09, 18:01:55

Version 13

2016-01-09, 18:04:14

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