On Tuesday, 27 August 2019 at 16:25:00 UTC, Samir wrote:
On Sunday, 25 August 2019 at 17:01:23 UTC, a11e99z wrote:
auto foo = ["VXE":8, "BZP":5, "JLC":2];

On Sunday, 25 August 2019 at 19:03:10 UTC, JN wrote:
I think normal lambdas are better than these string ones:

foo.byPair.array.sort!((a, b) => a[0] < b[0]).map!(a => a[1]).writeln;

On Sunday, 25 August 2019 at 21:13:05 UTC, Paul Backus wrote:
You can also use names instead of numeric indices:

foo.byPair.array.sort!((a, b) => a.key < b.key).map!(a => a.value);

a11e99z, JN, Paul: Thank you all for your replies and help. As I've mentioned on the list before, I really struggle to understand how some of the std.algorithm functions such as `map` work when combined with things like `array`, `sort` and especially `zip` but really appreciate the support I find here on the forum.


It isn't really hard:
.array() turns the range into an array, so that sort() can work.
sort() takes "callback" function to test the elements while sorting and determine the proper position in the array. map() select the property from each element, putting that requested property into an array.

Reply via email to