> What exactly does iterate() do?

A Gremlin expression yields a Pipeline and
        Pipeline<S,E> implements Iterator<S,E>

Thus, a Gremlin expression doesn't return the results of a traversal, only a 
lazy iterator for .next()'ing results. For people doing a traversal to yield a 
sideEffect (e.g. aggregate, groupCount, etc.), iterate() is there to 
"while(hasNext()) { next() }" for you to "fill up" your side effect data 
structure.

Finally, the Gremlin REPL automagically iterates and System.out.printlns() any 
objects in an Iterator it gets so thats why the behavior in the Gremlin REPL 
looks like a Gremlin expression returns results.

Hope that is clear,
Marko.

http://markorodriguez.com

> A
> 
> On Thu, Nov 17, 2011 at 4:07 PM, Marko Rodriguez <okramma...@gmail.com> wrote:
>> Hey Alfredas,
>> 
>> Be sure to iterate your pipeline....
>> 
>>        x = []; g.v(1).out("from").out("to").aggregate(x).loop(3){it.loops < 
>> 4}.iterate(); x
>> 
>> * NOTE: You can also do:
>>        g.v(1).out("from").out("to").aggregate(x).loop(3){it.loops < 4} >>-1
>>   but the >> convention is no longer with us in Gremlin 1.4-SNAPSHOT.
>> 
>> HTH,
>> Marko.
>> 
>> http://markorodriguez.com
>> 
>> On Nov 17, 2011, at 7:21 AM, Alfredas Chmieliauskas wrote:
>> 
>>> Dear all,
>>> This concerns gremlin plugin and the script engine.
>>> Maybe there's an explanation for this behavior:
>>> 1) gremlin> x = [];
>>> g.v(1).out("from").out("to").aggregate(x).loop(3){it.loops < 4};
>>>     gremlin> x;
>>> 
>>> ==> v[7]
>>> ==> v[3]
>>> ==> v[5]
>>> 
>>> 2) gremlin> x = [];
>>> g.v(1).out("from").out("to").aggregate(x).loop(3){it.loops < 4}; x;
>>> returns nothing...
>>> 
>>> Thanks,
>>> 
>>> Alfredas
>>> _______________________________________________
>>> Neo4j mailing list
>>> User@lists.neo4j.org
>>> https://lists.neo4j.org/mailman/listinfo/user
>> 
>> _______________________________________________
>> Neo4j mailing list
>> User@lists.neo4j.org
>> https://lists.neo4j.org/mailman/listinfo/user
>> 
> _______________________________________________
> Neo4j mailing list
> User@lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user

_______________________________________________
Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to