Como iterar listas aninhadas com fluxos lambda?
Estou tentando refatorar o seguinte código para expressões lambda com `stream, especialmente os loops foreach aninhados:
public static Result match (Response rsp) {
Exception lastex = null;
for (FirstNode firstNode : rsp.getFirstNodes()) {
for (SndNode sndNode : firstNode.getSndNodes()) {
try {
if (sndNode.isValid())
return parse(sndNode); //return the first match, retry if fails with ParseException
} catch (ParseException e) {
lastex = e;
}
}
}
//throw the exception if all elements failed
if (lastex != null) {
throw lastex;
}
return null;
}
Estou começando com:
rsp.getFirstNodes().forEach().?? // how to iterate the nested 2ndNodes?