is std.algorithm.joiner lazy?
Puming via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Apr 7 00:07:40 PDT 2016
Hi:
when I use map with joiner, I found that function in map are
called. In the document it says joiner is lazy, so why is the
function called?
say:
int[] mkarray(int a) {
writeln("mkarray called!");
return [a * 2]; // just for test
}
void main() {
auto xs = [1, 2];
auto r = xs.map!(x=>mkarray(x)).joiner;
}
running this will get the output:
mkarray called!
mkarray called!
I suppose joiner does not consume?
when I actually consume the result by writlen, I get more output:
mkarray called!
mkarray called!
[2mkarray called!
mkarray called!
, 4]
I don't understand
More information about the Digitalmars-d-learn
mailing list