This is an automated email from the ASF dual-hosted git repository.

spmallette pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git


The following commit(s) were added to refs/heads/master by this push:
     new 80c06354ae Correct fold() callout for list vs map seed with addAll
80c06354ae is described below

commit 80c06354aeb79c183d20da22f4eff0ff4e81fe48
Author: Stephen Mallette <[email protected]>
AuthorDate: Thu Jul 23 17:59:21 2026 +0000

    Correct fold() callout for list vs map seed with addAll
    
    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
---
 docs/src/reference/the-traversal.asciidoc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/docs/src/reference/the-traversal.asciidoc 
b/docs/src/reference/the-traversal.asciidoc
index 94606c60f7..36e66f67ca 100644
--- a/docs/src/reference/the-traversal.asciidoc
+++ b/docs/src/reference/the-traversal.asciidoc
@@ -2181,6 +2181,7 @@ g.V().values('age').fold(0) {a,b -> a + b} <4>
 g.V().values('age').fold(0, sum) <5>
 g.V().values('age').sum() <6>
 g.inject(["a":1],["b":2]).fold([], addAll) <7>
+g.inject(["a":1],["b":2]).fold([:], addAll) <8>
 ----
 
 <1> A parameterless `fold()` will aggregate all the objects into a list and 
then emit the list.
@@ -2189,7 +2190,8 @@ g.inject(["a":1],["b":2]).fold([], addAll) <7>
 <4> What is the total age of the people in the graph?
 <5> The same as before, but using a built-in bi-function.
 <6> The same as before, but using the <<sum-step,`sum()`-step>>.
-<7> A mechanism for merging `Map` instances. If a key occurs in more than a 
single `Map`, the later occurrence will replace the earlier.
+<7> With a list seed (`[]`), `addAll` collects the incoming `Map` traversers 
into a list, yielding `[[a:1],[b:2]]`. The two maps are gathered as separate 
elements, so they are not merged and no key replacement occurs.
+<8> With a map seed (`[:]`), `addAll` instead merges the incoming maps into a 
single `Map` (via `putAll`), yielding `[a:1,b:2]`. If a key occurs in more than 
a single `Map`, the later occurrence replaces the earlier. The behavior of 
`addAll` therefore depends on the seed type: a list seed collects the elements 
into a list, while a map seed merges the maps.
 
 *Additional References*
 

Reply via email to