Trying to build a graphtraversal dynamically, but i've a question on how to initialize the traversal with a dummy step. I'm using inject() as the dummy step, does anyone know if this will cause any harm or suggest a better step to be used as a dummy.
pseudocode: fn setVertexProperties(properties): final GraphTraversal<vertex, vertex> gt = __.inject(); foreach((k,v)-> gt.property(k,v)); end fn
thanks
If you are building up a traversal dynamically in code then using inject
is fine.
In more concrete terms something like this is commonly done:
t = g.inject(0)
t.addV('A')
t.addV('B')
t.iterate()
An inject
step yields a DefaultGraphTraversal
to which other steps can be added.
If you know your traversal will be doing a lot of, let's say, addV
steps, then another way to go is to just do one addV
to create the traversal object. As in:
t = g.addV('A')
t.addV('B')
t.addV('C')
t.iterate()