0
我有下面的代碼片段(在Mark Isaacson's talk at DConf 2015看到)元組(__ lambda3)映射功能(S)不能返回void:
import std.stdio, std.range, std.algorithm;
void main(string[] args)
{
bool[string] seen;
bool keepLine(S)(S line){
if(line in seen){
return false;
}
seen[line.idup] = true;
return true;
}
stdin
.byLine
.filter!(a => keepLine(a))
.map!(a => a.writeln)
.walk;
}
爲什麼會變成這樣給我下面的錯誤:
/usr/include/dmd/phobos/std/algorithm/iteration.d(476): Error: static assert "Mapping function(s) must not return void: tuple(__lambda3)"
main.d(17): instantiated from here: map!(FilterResult!(__lambda2, ByLine!(char, char)))
Failed: ["dmd", "-v", "-o-", "main.d", "-I."]
?
非常感謝!這正是我需要的。 – Patryk