Search code examples
gremlindatastax-enterprise-graph

Create a empty array inside a Gremlin traversal?


This sounds silly but is there a way to create a empty array inside a Gremlin traversal?

For the query below:

g.V().has('person','name', 'marko').project('a', 'b').by().by()

I want to project b as an empty array. I have tried:

g.V().has('person','name', 'marko').project('a', 'b').by().by(constant("").fold())

But constant("").fold() is not actually empty constant("").fold().count() returns 1. This applies to constant(null).fold() as well.


Solution

  • An empty array/collection would actually be a fold() of nothing. You'll get nothing if you filter everything, hence:

    g.V().has('person','name','marko').
      project('a', 'b').
        by().
        by(__.not(identity()).fold())