【发布时间】:2011-02-16 11:52:42
【问题描述】:
The question but in C#. 那么Java有C#的命令吗?我需要它来处理 Matches-SearchTerm-Files-relationship。
foreach(var i in BunchOfItems.SelectMany(k => k.Items)) {}
[为什么不用 for 循环?] 我已经在嵌套的 for 循环中完成了这样的结构,但它们很快就会变得臃肿。所以我更喜欢上面这样更简洁的东西。
public static Stack<Integer[]> getPrintPoss(String s,File f,Integer maxViewPerF)
{
Stack<File> possPrint = new Stack<File>();
Integer[] poss = new Integer[4]();
int u,size;
for(File f:files)
{
size = f2S(f).length();
u = Math.min(maxViewsPerF,size);
for(int i=0; i<u;i++)
{
// Do something --- bloated, and soon out of control
// wants more succintly
}
}
return possPrint;
}
【问题讨论】:
-
这个库有一个 selectMany() 实现,它看起来像你的要求:for(val i : BunchOfItems.selectMany(bunchItemSelector()) { }。见github.com/nicholas22/jpropel-light