Uploaded image for project: 'TinkerPop'
  1. TinkerPop
  2. TINKERPOP-1849

Provide a way to fold() with an index

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.3.0
    • 3.4.0
    • process
    • None

    Description

      In Groovy you can call withIndex() to generate output like this:

      gremlin> g.V().fold().next().withIndex()
      ==>[v[1],0]
      ==>[v[2],1]
      ==>[v[3],2]
      ==>[v[4],3]
      ==>[v[5],4]
      ==>[v[6],5]
      

      We can currently simulate this with Gremlin via:

      gremlin> g.V().project("a","b").by().by(select("x").count(local)).store("x").map(union(select('a'), select('b')).fold()).fold().next()
      ==>[v[1],0]
      ==>[v[2],1]
      ==>[v[3],2]
      ==>[v[4],3]
      ==>[v[5],4]
      ==>[v[6],5]
      

      but it's not easy to follow, efficient, or potentially foolproof. Perhaps we can add an option to fold() that would take an enum of "fold operators".

      Attachments

        Issue Links

          Activity

            People

              dkuppitz Daniel Kuppitz
              spmallette Stephen Mallette
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: