Asssociative Array by Key-Value-Pair

"Nordlöw" via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Dec 15 14:58:41 PST 2014


On Monday, 15 December 2014 at 14:41:43 UTC, bearophile wrote:
> Nordlöw:
>
>> Is there a combined property of AAs that combine keys and 
>> values typically
>>
>> .pairs()
>>
>> or
>>
>> .byPairs()
>>
>> I need to sort the elements of an AA by value and then 
>> retrieved corresponding keys in the order sorted.
>
> You can add an eager pairs() function to Phobos that returns an 
> array of tuples.
>
> byPairs can't be done in object.d for the dependency from 
> tuples that aren't yet (and perhaps never) built-in in D, and 
> it can't be done in Phobos because it needs access to 
> unspecified runtime functions.
>
> Bye,
> bearophile

Ok. Thanks.

Is

Tuple!(Key,Value)[] pairs(Key,Value)(Value[Key] aa);

a suitable contender for now?

I especially wonder about the mutability of parameter aa.

BTW: Why doesn't aa.byKey.map work?


More information about the Digitalmars-d-learn mailing list