Comment #0 by lt.infiltrator — 2014-03-18T18:19:12Z
http://dpaste.dzfl.pl/f2d178081ee8
-----------------------------------------------------------
import std.algorithm : map, reduce;
class A {
long fun() {
return 1 + sub.map!(s => s.fun()).reduce!((a, b) => a + b)(0L);
}
A[] sub;
}
void main() { }
----------------------------------------------------------
Fails to compile:
/d414/f619.d(5): Error: template std.algorithm.reduce cannot deduce function from argument types !((a, b) => a + b)(MapResult!(__lambda1, A[]), long), candidates are: /opt/compilers/dmd2/include/std/algorithm.d(701): std.algorithm.reduce(fun...) if (fun.length >= 1)
Comment #1 by bearophile_hugs — 2014-03-18T18:35:14Z
I think this is an invalid issue. reduce currently takes as first argument the seed and as second the range. This is the correct code:
return 1 + reduce!((a, b) => a + b)(0L, sub.map!(s => s.fun));
There are plans in fixing reduce.
Also voting your own entry, and doing it twice, is not so good :-)
Comment #2 by lt.infiltrator — 2014-03-18T18:40:50Z
Of course. I keep forgetting about that with reduce.
As for the voting, I use it to keep track of issues (I don't see a bookmark or similar option), and I just spread my votes out evenly.
Comment #3 by bearophile_hugs — 2014-03-18T19:50:39Z
(In reply to comment #2)
> Of course. I keep forgetting about that with reduce.
>
> As for the voting, I use it to keep track of issues (I don't see a bookmark or
> similar option), and I just spread my votes out evenly.
You can perform an advanced search, to find your own issues.