I assume that "B" is an indexed property called "myId":
g.V().has('myId','B').
union(__(),
repeat(out()).emit()).
drop()
The use of union()
does two things as in this case it has two arguments. The first is the __()
. This is just an identity function. It includes the "B" vertex in the result of dropped vertices. In other words, the union()
receives the "B" vertex as it's input, and we do nothing with it except include it in the results of the union()
. The second argument to the union
takes the "B" vertex and traverses out recursively to find all the child vertices. The use of emit()
here is important because it tells the repeat to return all the child vertices it finds along the way (and not just the leaves of the tree).
In the comments it was mentioned that __()
is not supported by Microsoft's version of Gremlin in their .NET client. Hopefully they are working on that. I guess you can work around that with this bit of ugliness (or something similar i suppose):
g.V().has('myId','B').
union(fold().unfold(),
repeat(out()).emit()).
drop()
Another approach might be to use store()
:
g.V().has('myId','B').
store('d').
repeat(out().store('d')).
cap('d').
unfold().
drop()
The store
approach isn't as nice as the previous approach because it has to build a List
in memory that you extract from the "d" side-effect with cap()
and then unfold that list back to the iterator to be dropped.