Another task
spir
denis.spir at gmail.com
Thu Jan 20 06:30:26 PST 2011
On 01/20/2011 11:12 AM, bearophile wrote:
> And I suggest to add a third associative array member function that
returns a range of key,value tuples, as in Python3. This allows to solve
the task like this:
> auto r = map!q{ tuple(a[0]*10, a[1]~a[1]) }(aa.byPair());
Yes, this is the only nice looking, high-level, and D-style solution.
While I by far prefer avoiding stringcode:
auto r = map!((p) (tuple(p[0]*10, p[1]~p[1])) (aa.byPair());
where p means pair; should be correct, should'nt it?
I think for a newcomer the most difficult part is related to tuples:
* find them (in std.typecons!!!)
* catch after much time, pains, research, they should not even try to
construct a tuple using Tuple!, but using the convenience tuple() func
instead.
And also that map expects a range, which an AA is not according to my
trials (code rejected at link time until I used byKey). Or am I wrong?
PS: sh*t, I cannot have this work, what's wrong?
auto pairs = map!
((int i) {return tuple(10*i, aa[i]~aa[i]);})
(aa.byKey());
Denis
_________________
vita es estrany
spir.wikidot.com
More information about the Digitalmars-d
mailing list