union() as a Start Step
g.union(branches...) starts a traversal without V(). It differs from Apache TinkerPop 3.8.2
in two details.
The seed is null
- TinkerPop: the start union has no incoming traverser of its own.
- Graphersal: a root traversal whose first step is
union()gets exactly one seed traverser holdingnull; child traversals are never seeded. A branch such as__.identity()therefore yields thatnull:g.union(__.identity())returns onenull.
A branch that opens with inject() is its own start
- Graphersal: such a branch runs over an empty source instead of the seed.
- Why: otherwise
g.union(__.inject(1), __.inject(2))would echo the seed and returnnull, 1, null, 2instead of1, 2. In the middle of a traversalinject()still emits the incoming traverser as well.
g.union(__.inject(1), __.inject(2)).toList() // 1, 2
g.union(__.identity()).toList() // null
g.union(__.V("1"), __.V("4")).values("name").toList()
Nested V()/E() in a branch start from the incoming traverser and extend its path.