Iterate/sort associative array by value?

Seb seb at wilzba.ch
Sun Apr 7 20:02:15 UTC 2019


On Sunday, 7 April 2019 at 18:22:00 UTC, Robert M. Münch wrote:
> On 2019-04-07 17:16:12 +0000, Seb said:
>
>> Then you can do:
>> 
>> ---
>> ["a": 1].byPair.array.sort!((a, b) => a.value < 
>> a.value).release.each!writeln;
>> ---
>> 
>> You'll have a sorted array with key and value props.
>
> This seems to be really tricky:
>
> int[uint] myArray;
>
> foreach(key, value; myArray.byPair.array.sort!((a, b) => 
> a.value < a.value)){...}
>
> Error: no property sort for type Tuple!(uint, "key", int, 
> "value")[]

You forgot to import std.algorithm.
In doubt, use std.experimental.all or with 2.086 it will just be 
`import STD;`


More information about the Digitalmars-d-learn mailing list