Wie iteriere ich verschachtelte Listen mit Lambda-Streams?
Ich versuche, den folgenden Code mit `stream in Lambda-Ausdrücke umzuwandeln, insbesondere in die verschachtelten foreach-Schleifen:
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;
}
Ich fange an mit:
rsp.getFirstNodes().forEach().?? // how to iterate the nested 2ndNodes?