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

}

Reply via email to