Making associatvie array from array of pairs

Dfr deflexor at yandex.ru
Wed Dec 25 06:41:31 PST 2013


On Tuesday, 24 December 2013 at 14:39:16 UTC, Timon Gehr wrote:
> On 12/24/2013 12:36 PM, Dfr wrote:
>> Let's say i have array of kind:
>>
>> auto a = [["1","0000FF"], ["2", "00FF00"], ...];
>>
>> Is there simple way to turn it into associative array of kind:
>>
>> string[string] b = ["1": "0000FF", "2": "00FF00", ...];
>>
>>
>
> void main(){
>     import std.array, std.algorithm, std.typecons;
>     auto a = [["1","0000FF"], ["2", "00FF00"], /+...+/];
>     auto aa = a.map!(x=>tuple(x[0],x[1])).assocArray;
>
>     import std.stdio;
>     writeln(aa);
> }

This example looks cleanest, but not compile with error:

Error: no property 'assocArray' for type 'MapResult!(__lambda9, 
immutable(char[][])[])'


More information about the Digitalmars-d-learn mailing list