Skip to content

Step Closures

okram edited this page Feb 20, 2013 · 4 revisions

Many Gremlin steps take a user-defined function (or functions). These steps have the form:

step{ // some function }

A Gremlin closure/function can take either one or two arguments. If passed one argument, then the argument references the current object passing through the step. For instance:

gremlin> g.v(1).out.transform{}

The variable it is a shorthand for naming the argument as follows:

gremlin> g.v(1).out.transform{v ->} 

If two arguments are passed to the closure, then the second argument represents the variable map of the Gremlin pipeline. When a step is named using as, then the last object that has passed through that named step can be accessed in the step closure. For instance:

gremlin> g.v(1)'x').out.transform{v,m -> + ' ' +}        
==>josh ripple
==>josh lop

The variable m has a get(String name) method which allows getting the value last seen at the particular named step.

Something went wrong with that request. Please try again.