Skip to content

Commit 9e5834d

Browse files
fix: align find-first and subtype stream guidance
1 parent 8d89c71 commit 9e5834d

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

evals-reference/04-primary-address-review/criteria.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"context": "Reference review coverage for findAny/findFirst and collect-then-first cleanup.",
2+
"context": "Reference review coverage for findFirst behavior preservation and collect-then-first cleanup.",
33
"type": "weighted_checklist",
44
"checklist": [
55
{
@@ -15,16 +15,16 @@
1515
"description": "Says collecting all primary addresses just to inspect emptiness/read the first result is unnecessary."
1616
},
1717
{
18-
"name": "Chooses findAny when matches are equivalent",
18+
"name": "Chooses findFirst to preserve first-match behavior",
1919
"category": "stream_quality",
2020
"max_score": 20,
21-
"description": "Recommends filter(Address::primary).findAny().orElse(null) if any primary address is acceptable."
21+
"description": "Recommends filter(Address::primary).findFirst().orElse(null) to preserve the current get(0) encounter-order behavior."
2222
},
2323
{
24-
"name": "Names the findFirst exception",
24+
"name": "Names the findAny exception",
2525
"category": "stream_quality",
2626
"max_score": 20,
27-
"description": "Says findFirst is appropriate only if encounter order defines which primary address should win."
27+
"description": "Says findAny is appropriate only if the domain explicitly says all matching primary addresses are equivalent and encounter order does not define which one should win."
2828
}
2929
],
3030
"metadata": {

skills/java-streams/SKILL.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ Keep these rules in view:
5555
`mapMulti` only when it makes a small zero-or-one/one-to-few transformation clearer or avoids
5656
many tiny stream allocations.
5757
4. Use primitive streams for primitive aggregation. Keep `reduce(identity, op)` for immutable
58-
non-primitive accumulation such as `BigDecimal`.
58+
non-primitive accumulation such as `BigDecimal`. For subtype-specific numeric totals, filter and
59+
cast to the subtype before `mapToInt`/`mapToLong`/`mapToDouble`; do not map unrelated elements to
60+
zero as a sentinel.
5961
5. Choose collectors by result semantics, and state duplicate-key/null contracts explicitly. When a
6062
later step needs an expensive check result, carry `element + result` with a baseline-compatible
6163
holder; use `Map.entry` only on Java 9+ when both values are non-null.

0 commit comments

Comments
 (0)