5 ms·
A matter of personal taste, but I greatly prefer the lambda style (though I wish the example had the .stream() on the following line). I have been coding Java
by ap22213 11y ago
A matter of personal taste, but I greatly prefer the lambda style (though I wish the example had the .stream() on the following line).
I have been coding Java (and C-style) languages for a really long time. And, I still have some cognitive delay when traversing multiple indented scopes. Not a long delay, but long enough to be slightly annoying.
With the lambda style, I can quickly glance down the text column to see what's going on. Stream -> Map -> Filter -> Collect.
After using lambdas enough, one starts to subconsciously cull the stream() and collect() calls. So, when I look at it, I really see Map -> Filter.
But what really, really annoys me is that exception handling can't be applied to the whole stream processing statement. This leads to code that looks like:
collection
.stream()
.map(o -> {
try {
return o.oToC();
} catch(Exception e) {
// handle
}
return new C();
})
.reduce((c1, c2) -> {
try {
return c1.combine(c2);
} catch(Exception e) {
// handle
}
return c1;
});
For that, I have had to write a bunch of helper functions that wrap and throw the exceptions.