joiner and map, strange behavior
Stephan Schiffels
stephan_schiffels at mac.com
Tue Mar 12 10:21:14 PDT 2013
Hi,
I am struggling with understanding this behavior. In the code
below, the function "getVec" is called 8 times, but it should be
called only 4 times (once for each call inside of map).
Any explanations?
Stephan
import std.stdio;
import std.algorithm;
import std.array;
int[] getVec(size_t i) {
writeln("getVec is called");
auto vals = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]
];
return vals[i];
}
void main() {
auto result = [0, 1, 2, 3].map!(getVec).joiner.array;
writeln(result);
}
More information about the Digitalmars-d-learn
mailing list