getClass和getTitle都返回string
类型
显然正在返回另一个数组,但我不确定这些类型是否被正确推断,是这种情况吗?
这怎么是D中的错误? 之前我曾尝试过writeln(Array int),但不知怎的,它还没有使用map!字符串
writeln(listChildren().map!(x=>getClass(x)));
[x" 46 6F 72 65 67 72 6F 75 6E 64 53 74 61 67 69 6E 67 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF" c,x" 46 6F 72 65 67 72 6F 75 6E 64 53 74 61 67 69 6E 67 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF" c,x" 74 6F 6F 6C 74 69 70 73 5F 63 6C 61 73 73 33 32 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF" c,...]
writeln(listChildren().map!(x=>getTitle(x)));
[" \ 0"," \ 0"," \ 0"," \ 0"," \ 0& #34;," \ 0"," \ 0"," \ 0"," \ 0"," \ 0& #34;," \ 0"," \ 0"," \ 0"," \ 0"," \ 0& #34;," geany.exe \ 0"," \ 0"," \ 0",x" 4D 65 64 69 64 6F 72 20 64 65 20 6C 61 20 62 61 74 65 72 ED 61 00" c," \ 0","网络弹出\ 0"," \ 0", " \ 0"," geany.exe \ 0"," geany.exe \ 0"," geany.exe \ 0",& #34; geany.exe \ 0"," geany.exe \ 0"," geany.exe \ 0",...]
注意:当我使用
时listChildren().map!getClass.each!writeln;
我得到了预期的结果,但我需要使用上一个表单来组成新值
答案 0 :(得分:0)
检查以下代码:
auto s = [1, 2, 3].map!(a => a.to!string);
pragma(msg, typeof(s));
您可以看到map
的返回类型为MapResult
,可用于迭代。
map
是一个惰性函数,仅在请求时计算值,因此您需要使用结果的所有元素来获得所需的内容。
在.array()
之后添加.map
以便使用所有元素并将结果转换为数组,然后writeln
它们,您将获得整数数组的相同输出。
writeln(listChildren().map!(x => getClass(x)).array());