On Thu, 20 Jan 2011 02:40:29 +0100, bearophile <bearophileh...@lycos.com> wrote:

Simen kjaeraas:

Why use map()? The correct solution for this looks like so:


import std.range;

void main( ) {
     auto aa = [1:"a", 2:"b", 3:"c"];
     auto result = zip( aa.keys, aa.values );
}

That result is not the requested one:
[(10,"aa"), (30,"bb"), (50,"cc")]
And that result is not generated by lazily as the task asks (keys and values return true arrays).

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.


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 ) );
}

--
Simen

Reply via email to