Is there a way to map associative arrays
bearophile via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Aug 1 16:22:05 PDT 2014
Freddy:
> uint[uint] test;
>
> void main(){
> test=[0:2 ,1:3 ,2:4];
> writeln(test.map!(a=>a-2));
> }
If you need keys or values you have .keys .values, .byKey,
.byValue (the first two are eager). If you need both you are out
of luck, and if you want to write safe code it's better to use a
foreach loop. If you want to live dangerously you can use a
test.byKey.zip(test.byValue).
Take a look in Rosettacode, there are examples for all of them.
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list