Search code examples
gremlintinkerpopamazon-neptune

Is the none() step supported in Gremlin?


I'm building a system for composable traversals in my app and have a case where the none() step would be helpful. I need to explicitly return no traversal. It does not seem to be implemented in Gremlin javascript.

"errorType": "TypeError", "errorMessage": "o.none is not a function"

Is there a reason this has been omitted? Should it not be used? I'm working around it by using hasId("x") which should never exist and thus return no traversal, but it's a hack.

      g.V().choose(
        hasCommentingUnlocked({
          traversal: hasAccessToPrivateUserData({
            traversal: __,
            isAdmin,
            userId,
            grantedTraversal: __.identity(),
            declinedTraversal: __.hasId("x"), // __.none() would be helpful here
          }),
          P,
        }),
        __.constant(true),
        __.constant(false)
      )

Solution

  • none() should probably be implemented for consistency in gremlin-javascript, but it really is more of an internal step to be used as a marker for iterate() which filters all results. When the server sees none() it knows that iterate() is called. That said, the adage I've learned from years of open source software development is "if you build it, people will use it" so none() has come to find some use cases.

    Of course, it's hard to say if your use case is one that needs none() given your example. I tend to find the use case for none() fairly narrow so it wouldn't surprise me at all to find another way to write your traversal to avoid using it in the first place.