Suppose I have an object containing a collection, each item from the specified collection contains a collection, and each collection contains a collection.
And I want to iterate over the deepest objects and apply the same code to it.
The imperative is trivial, but is there a way lambda is all this?
Here's what the code looks like today:
My object o;
SecretType computedThingy = 78;
for (FirstLevelOfCollection coll : o.getList()) {
for (SecondLevelOfCollection colColl : coll.getSet()) {
for (MyCoolTinyObjects mcto : colColl.getFoo()) {
mcto.setSecretValue(computedThingy);
}
}
}
I see how to make lambda from the deepest loop:
colColl.getFoo().stream().forEach(x -> x.setSecretValue(computedThingy)
But can I do more?
tisek source
share