tinkerpop/gremlin-python: next() vs iterate()
Asked Answered
A

1

5

What is the difference between next() and iterate() when working with gremlin? Why does next() return the added vertex when calling g.addV(), but iterate() does not? When should I use next() and when should I use iterate()?

Austinaustina answered 25/11, 2019 at 1:39 Comment(0)
L
12

The answer is already in your question. You'll use .next(), when you need the result (and you are expecting exactly one result), and you'll use .iterate(), when you don't need the result (typically mutation queries, that add/change properties, edges and/or vertices).

Lehman answered 25/11, 2019 at 1:59 Comment(1)
It is also worth noting that if you expect more than one result, .toList() will return a list of all the results.Rochkind

© 2022 - 2024 — McMap. All rights reserved.