Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Done
-
None
-
None
Description
With GremlinSugar, we can provide metaClass overrides.
http://www.tinkerpop.com/docs/3.0.0.M1/#_sugar_plugin
mbroecheler was interested in making things more concise in Gremlin-Groovy. Here is what is possible:
g.V.match('a', a.out('knows').b b.out('created').c).select(['a','c']){it.name}
The above assumes that the variables a,b,c are NOT defined in the scope of the console. When the groovysh_engine throws the "Property does not exist", intercept and generate a "g.of().as('a')". This may be a little too much to ask, so we could also do:
g.V.match('a', _a.out('knows')._b _b.out('created')._c).select(['a','c']){it.name}
The problem here is that Java8 no longer allows _ to start a method or variable name. With Groovy3 going full Java8, this may go away. We can then do this:
g.V.match('a', as('a').out('knows').as('b') as('b').out('created').as('c')).select(['a','c']){it.name}
This is extremely simple to implement and is efficient as as() will be a metaClass.as =
{closure}that will simply generate g.of().as('a').