Correct fold() reference example for list vs map seed with addAll - #3554
Merged
Conversation
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
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Fold Step section of the reference documentation annotated the example
g.inject(["a":1],["b":2]).fold([], addAll)as "a mechanism for mergingMapinstances" where a later key occurrence replaces an earlier one. That description does not match what the line does. With a list seed ([]),addAllcollects 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:
[[a:1],[b:2]], no merge).g.inject(["a":1],["b":2]).fold([:], addAll), with a callout describing the realputAllmerge ([a:1,b:2], last occurrence wins).addAllexplicit: 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.