Another task

bearophile bearophileHUGS at lycos.com
Wed Jan 19 17:58:46 PST 2011


Simen kjaeraas:

> Soz, I read a bit too fast. It /is/ lazy, though perhaps not the way
> you meant. This returns the right thing, but does not *read* lazily
>  from the AA, a task I am unsure how, if at all possible, one should
> perform.

In the task was written:
> If possible read things lazily from the associative array.

D AAs have byKey and byValue that return a lazy iterator. So if we add a "byItem" or "byPair" or "byKeyValue" you are able to read pairs lazily :-)


> import std.algorithm;
> import std.range;
> 
> void main( ) {
>      auto aa = [1:"a", 2:"b", 3:"c"];
>      auto result = map!"tuple(a[0]*10,a[1]~a[1])"( zip( aa.keys, aa.values  
> ) );
> }

This is a nice solution I didn't think about, thank you :-) It doesn't read data lazily from the AA as requested, but it's not bad looking.

Bye and thank you,
bearophile


More information about the Digitalmars-d mailing list