Github user newkek commented on a diff in the pull request: https://github.com/apache/tinkerpop/pull/921#discussion_r213361478 --- Diff: docs/src/recipes/cycle-detection.asciidoc --- @@ -48,6 +48,31 @@ the length of the cycle is known to be three and there is no need to exceed that cycle. It returned three, because there was one for each vertex that started the cycle (i.e. one for `A`, one for `B` and one for `C`). This next line introduce deduplication to only return unique cycles. +Note that these traversals won't detect self-loops (vertices directly connected to themselves). +To do so, you would need to `.emit()` a Traverser before the repeat()-loop. + +[gremlin-groovy] +---- +g.addV().property(id,'a').as('a'). + addV().property(id,'b').as('b'). + addV().property(id,'c').as('c'). + addV().property(id,'d').as('d'). + addE('knows').from('a').to('b'). + addE('knows').from('b').to('c'). + addE('knows').from('c').to('a'). + addE('knows').from('a').to('d'). + addE('knows').from('c').to('d'). + addE('self').from('a').to('a').iterate() +g.V().as('a'). + emit(). + repeat(outE().inV().simplePath()). + times(2). + outE().inV().where(eq('a')). + path(). + by(id). + by(label) +---- + --- End diff -- Hm the issue with the Traversal below is that it improves things further by formatting results more and doing unidirectional traversing on an unrestricted path length. Since the examples get more complicated as you progress through the document, if I put this self loop traversal under the more complicated one it feels like going backwards. Additionally the traversal below refers to the modern graph, whereas the first one and this self-loop one are similar, wdyt?
---