Skip to content

Correct fold() reference example for list vs map seed with addAll - #3554

Merged
spmallette merged 1 commit into
apache:masterfrom
spmallette:docs-fold-step-callout7
Jul 23, 2026
Merged

Correct fold() reference example for list vs map seed with addAll#3554
spmallette merged 1 commit into
apache:masterfrom
spmallette:docs-fold-step-callout7

Conversation

@spmallette

Copy link
Copy Markdown
Contributor

The Fold Step section of the reference documentation annotated the example g.inject(["a":1],["b":2]).fold([], addAll) as "a mechanism for merging Map instances" where a later key occurrence replaces an earlier one. That description does not match what the line does. With a list seed ([]), addAll collects the incoming maps into a list, producing [[a:1],[b:2]] with no merging and no key replacement. The described last-writer-wins merge only happens with a map seed.

This change:

  • Keeps the existing list-seed example, which is correct and useful.
  • Rewrites its callout to describe the actual list-seed behavior (collect the maps into a list, [[a:1],[b:2]], no merge).
  • Adds a companion map-seed example, g.inject(["a":1],["b":2]).fold([:], addAll), with a callout describing the real putAll merge ([a:1,b:2], last occurrence wins).
  • Makes the seed-type dependence of addAll explicit: a list seed collects elements into a list, while a map seed merges the maps.

Both examples are executed at doc-build time. The rendered outputs confirm the documented results: the list seed yields [[a:1],[b:2]] and the map seed yields [a:1,b:2]. Callouts 1-6 and unrelated content are unchanged.

The Fold Step reference example annotated g.inject(["a":1],["b":2]).fold([], addAll)
as merging Map instances with last-writer-wins key replacement. With a list seed,
addAll actually collects the incoming maps into a list ([[a:1],[b:2]]) with no
merging. Rewrite that callout to describe the list-seed behavior accurately and add
a companion map-seed example, g.inject(["a":1],["b":2]).fold([:], addAll), whose
callout describes the real putAll merge ([a:1,b:2], last occurrence wins). Make the
seed-type dependence of addAll explicit.

Assisted-by: Kiro:claude-opus-4.8
@spmallette
spmallette merged commit 80c0635 into apache:master Jul 23, 2026
28 checks passed
@spmallette
spmallette deleted the docs-fold-step-callout7 branch July 23, 2026 18:13
@codecov-commenter

codecov-commenter commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.41%. Comparing base (a28cd1f) to head (9c200eb).
⚠️ Report is 347 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3554      +/-   ##
============================================
+ Coverage     76.35%   76.41%   +0.05%     
- Complexity    13424    14280     +856     
============================================
  Files          1012     1036      +24     
  Lines         60341    64561    +4220     
  Branches       7075     7656     +581     
============================================
+ Hits          46076    49336    +3260     
- Misses        11548    12132     +584     
- Partials       2717     3093     +376     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants