Problem
The Streams skill already recommends Collectors.joining, but the capture workflow missed a custom conditional delimiter reduction. This is a detection and equivalence gap: a broad reduce("", ...) rewrite is unsafe when an empty mapped value can collide with the accumulator's empty-string sentinel.
Area
Evals or scoring
Describe the solution you want
Add a reference eval for recognizing a hand-written first-element delimiter accumulator and replacing it with Collectors.joining(delimiter) only after proving that the reducer has no additional semantics.
Code before the prompt was executed
return arguments.stream()
.map(Quoter::quote)
.reduce("", (left, right) -> {
if (left.isEmpty()) {
return right;
}
return left + " " + right;
});
Assume the domain quoter always returns a non-null, non-empty string, including for an empty raw argument.
Prompt that caused the implementation
The original prompt required a complete Java-source API-reuse audit:
- Audit every tracked Java source for worthwhile replacements with the Java standard library or a directly declared dependency.
- Implement only changes that clearly reduce code, complexity, duplication, or maintenance risk.
- Preserve observable behavior, ordering, failure semantics, null handling, concurrency, security, and relevant performance characteristics.
- Add focused regression tests for each affected boundary.
This prompt should have triggered the Streams skill and capture workflow for a custom string reduction.
Later prompt that exposed the issue
A maintainer later asked whether the Streams capture issue had been created and requested a durable capture fix.
Prompt-produced code before maintainer correction
return arguments.stream()
.map(Quoter::quote)
.collect(Collectors.joining(" "));
The implementation is preferred for the proven domain, but the reusable detection lesson was not captured.
Why the prompt-produced code is weak
The code is not weak; the missing capture is. Existing guidance finds String.join after materialization but does not teach agents to inspect custom delimiter reductions. The safety proof matters because Stream.of("", "x") produces "x" with the old sentinel reducer and " x" with joining(" ").
Behavior-equivalence analysis
For the proven quoter, both forms return "" for no elements, the only mapped value for one element, and ordered space-delimited mapped values for many elements. The mapped values are non-null and non-empty, so the sentinel cannot collide with data. The eval must include empty source, one item, many items, an empty mapped-value counterexample, and null behavior.
Maintainer-preferred code
return arguments.stream()
.map(Quoter::quote)
.collect(Collectors.joining(" "));
Why the replacement is better
The collector directly names delimiter joining and removes branching plus repeated string concatenation from the reducer.
Desired eval behavior
- Reward detecting conditional first-element delimiter reducers.
- Reward
Collectors.joining only after proving mapped values cannot collide with the empty sentinel and have compatible null behavior.
- Reward preserving encounter order and empty-source behavior.
- Reward retaining a custom reducer when it performs quoting, filtering, normalization, or other domain work.
Anti-patterns the eval should reject
- Rewriting every
.reduce("", ...) mechanically.
- Claiming equivalence without the empty-mapped-value counterexample.
- Moving domain quoting or filtering into an opaque accumulator.
- Ignoring null behavior.
Suggested eval name
conditional-delimiter-reduce-to-joining
Examples
The before/after pipeline above is the minimal case. A scan marker for .reduce("", may be useful, but every hit must remain review-only.
Alternatives considered
Existing joining guidance is insufficient because it states the destination API without testing recognition of this source shape or its sentinel collision. No open issue covers delimiter reductions.
Current workaround
Search custom string reductions manually and prove the accumulator identity cannot also be a valid mapped value.
Additional context
No user-facing contract change is intended. Begin with a classified reference eval before broadening runtime rules.
AI Assistance
AI prompts / session logs (optional)
Prepared with Codex assistance from a maintainer review of a behavior-preserving Java API-reuse audit.
Problem
The Streams skill already recommends
Collectors.joining, but the capture workflow missed a custom conditional delimiter reduction. This is a detection and equivalence gap: a broadreduce("", ...)rewrite is unsafe when an empty mapped value can collide with the accumulator's empty-string sentinel.Area
Evals or scoring
Describe the solution you want
Add a reference eval for recognizing a hand-written first-element delimiter accumulator and replacing it with
Collectors.joining(delimiter)only after proving that the reducer has no additional semantics.Code before the prompt was executed
Assume the domain quoter always returns a non-null, non-empty string, including for an empty raw argument.
Prompt that caused the implementation
The original prompt required a complete Java-source API-reuse audit:
This prompt should have triggered the Streams skill and capture workflow for a custom string reduction.
Later prompt that exposed the issue
A maintainer later asked whether the Streams capture issue had been created and requested a durable capture fix.
Prompt-produced code before maintainer correction
The implementation is preferred for the proven domain, but the reusable detection lesson was not captured.
Why the prompt-produced code is weak
The code is not weak; the missing capture is. Existing guidance finds
String.joinafter materialization but does not teach agents to inspect custom delimiter reductions. The safety proof matters becauseStream.of("", "x")produces"x"with the old sentinel reducer and" x"withjoining(" ").Behavior-equivalence analysis
For the proven quoter, both forms return
""for no elements, the only mapped value for one element, and ordered space-delimited mapped values for many elements. The mapped values are non-null and non-empty, so the sentinel cannot collide with data. The eval must include empty source, one item, many items, an empty mapped-value counterexample, and null behavior.Maintainer-preferred code
Why the replacement is better
The collector directly names delimiter joining and removes branching plus repeated string concatenation from the reducer.
Desired eval behavior
Collectors.joiningonly after proving mapped values cannot collide with the empty sentinel and have compatible null behavior.Anti-patterns the eval should reject
.reduce("", ...)mechanically.Suggested eval name
conditional-delimiter-reduce-to-joiningExamples
The before/after pipeline above is the minimal case. A scan marker for
.reduce("",may be useful, but every hit must remain review-only.Alternatives considered
Existing joining guidance is insufficient because it states the destination API without testing recognition of this source shape or its sentinel collision. No open issue covers delimiter reductions.
Current workaround
Search custom string reductions manually and prove the accumulator identity cannot also be a valid mapped value.
Additional context
No user-facing contract change is intended. Begin with a classified reference eval before broadening runtime rules.
AI Assistance
AI prompts / session logs (optional)
Prepared with Codex assistance from a maintainer review of a behavior-preserving Java API-reuse audit.