-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
I'm not a bit fan of yaml, but in the case of the patterns, it's IMO preferable, since multi-line code snippets are easier to read and write. I know you are known to dislike and bash yaml, and in general I agree, but in this case ...
E.g. here's part of the the collectors-teeing pattern in yaml:
oldApproach: Two Passes
modernApproach: teeing()
oldCode: |
long count = items.stream().count();
double sum = items.stream()
.mapToDouble(Item::price)
.sum();
var result = new Stats(count, sum);
modernCode: |
var result = items.stream().collect(
Collectors.teeing(
Collectors.counting(),
Collectors.summingDouble(Item::price),
Stats::new
)
);
summary: Compute two aggregations in a single stream pass.
explanation: Collectors.teeing() sends each element to two downstream collectors and merges the results. This avoids streaming the data twice or using a mutable accumulator.
whyModernWins:
- icon: ⚡
title: Single pass
desc: Process the stream once instead of twice.
- icon: 🧩
title: Composable
desc: Combine any two collectors with a merger function.
I will create a PR for this.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels