d求值两次map
void main()
{
import std.algorithm, std.stdio;
[1,2,3,4,5].
map!((x){
writeln("mapping ", x);
return x;
}).
filter!(x=>x>2).
front.
writeln();
}
map
每次调用front
时调用lambda
.如果想要缓存
版本,请使用cache
:
void main()
{
import std.algorithm, std.stdio;
[1,2,3,4,5].
map!((x){
writeln("mapping ", x);
return x;
}).
cache. //加上.
filter!(x=>x>2).
front.
writeln();
}