Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.2.2
    • Fix Version/s: 3.3.0, 3.2.4
    • Component/s: process
    • Labels:
      None

      Description

      choose() supports choose(predicateTraversal,trueTraversal,falseTraversal).

      I have lots of code that does this:

      choose(blah(), bloop(), identity())
      

      That is, if the predicate traversal doesn't hold, I simply want the incoming traverser to be emitted – identity(). This is sort of like optional(), but the predicate is something different from the branch. It would be nice to be able to simply say:

      choose(blah(),bloop())
      

      ...where its understood that a "false" means identity().

        Issue Links

          Activity

          Hide
          githubbot ASF GitHub Bot added a comment -

          GitHub user okram opened a pull request:

          https://github.com/apache/tinkerpop/pull/472

          TINKERPOP-1508: Add choose(predicate,trueTraversal)

          https://issues.apache.org/jira/browse/TINKERPOP-1508

          Added `GraphTraversal.choose(predicate,traversal)` and `GraphTraversal.choose(traversal,traversal)`. These are implemented as `choose(traversal,identity())`. Up to this point, `choose()` has been if/then/else-semantics and now with addition, we have if/then-semantics.

          VOTE +1

          You can merge this pull request into a Git repository by running:

          $ git pull https://github.com/apache/tinkerpop TINKERPOP-1508

          Alternatively you can review and apply these changes as the patch at:

          https://github.com/apache/tinkerpop/pull/472.patch

          To close this pull request, make a commit to your master/trunk branch
          with (at least) the following in the commit message:

          This closes #472


          commit 659865bdb1a5e2db9e01847eb641101cab3d090a
          Author: Marko A. Rodriguez <okrammarko@gmail.com>
          Date: 2016-10-31T19:23:42Z

          added choose(predicate,traversal) which is a map to choose(predicate,traversal,identity()) and gives us if/then-semantics instead of always requiring if/then/else-semantics.


          Show
          githubbot ASF GitHub Bot added a comment - GitHub user okram opened a pull request: https://github.com/apache/tinkerpop/pull/472 TINKERPOP-1508 : Add choose(predicate,trueTraversal) https://issues.apache.org/jira/browse/TINKERPOP-1508 Added `GraphTraversal.choose(predicate,traversal)` and `GraphTraversal.choose(traversal,traversal)`. These are implemented as `choose(traversal,identity())`. Up to this point, `choose()` has been if/then/else-semantics and now with addition, we have if/then-semantics. VOTE +1 You can merge this pull request into a Git repository by running: $ git pull https://github.com/apache/tinkerpop TINKERPOP-1508 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/tinkerpop/pull/472.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #472 commit 659865bdb1a5e2db9e01847eb641101cab3d090a Author: Marko A. Rodriguez <okrammarko@gmail.com> Date: 2016-10-31T19:23:42Z added choose(predicate,traversal) which is a map to choose(predicate,traversal,identity()) and gives us if/then-semantics instead of always requiring if/then/else-semantics.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user dkuppitz commented on a diff in the pull request:

          https://github.com/apache/tinkerpop/pull/472#discussion_r85858468

          — Diff: gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/ChooseStepTest.java —
          @@ -38,7 +42,10 @@
          return Arrays.asList(
          __.choose(values("name")).option("marko", out()).option(none, in()),
          __.choose(values("name")).option("marko", in()).option(none, out()),

          • __.choose(values("name")).option("josh", out()).option(none, in())
            + __.choose(values("name")).option("josh", out()).option(none, in()),
            + __.choose(out("knows").is(P.gt(0)), out("knows"), out("knows")),
            + __.choose(out("knows").is(P.gt(0)), out("knows"), out("created")),
            + __.choose(out("knows").is(P.gt(0)), out("knows"))
              • End diff –

          It's pretty irrelevant for these tests, but `out("knows").is(gt(0))` makes no sense at all. Was it meant to be `out("knows").count().is(gt(0))`?

          Show
          githubbot ASF GitHub Bot added a comment - Github user dkuppitz commented on a diff in the pull request: https://github.com/apache/tinkerpop/pull/472#discussion_r85858468 — Diff: gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/ChooseStepTest.java — @@ -38,7 +42,10 @@ return Arrays.asList( __.choose(values("name")).option("marko", out()).option(none, in()), __.choose(values("name")).option("marko", in()).option(none, out()), __.choose(values("name")).option("josh", out()).option(none, in()) + __.choose(values("name")).option("josh", out()).option(none, in()), + __.choose(out("knows").is(P.gt(0)), out("knows"), out("knows")), + __.choose(out("knows").is(P.gt(0)), out("knows"), out("created")), + __.choose(out("knows").is(P.gt(0)), out("knows")) End diff – It's pretty irrelevant for these tests, but `out("knows").is(gt(0))` makes no sense at all. Was it meant to be `out("knows").count().is(gt(0))`?
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user okram commented on a diff in the pull request:

          https://github.com/apache/tinkerpop/pull/472#discussion_r85862272

          — Diff: gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/ChooseStepTest.java —
          @@ -38,7 +42,10 @@
          return Arrays.asList(
          __.choose(values("name")).option("marko", out()).option(none, in()),
          __.choose(values("name")).option("marko", in()).option(none, out()),

          • __.choose(values("name")).option("josh", out()).option(none, in())
            + __.choose(values("name")).option("josh", out()).option(none, in()),
            + __.choose(out("knows").is(P.gt(0)), out("knows"), out("knows")),
            + __.choose(out("knows").is(P.gt(0)), out("knows"), out("created")),
            + __.choose(out("knows").is(P.gt(0)), out("knows"))
              • End diff –

          Yea, I meant `count()`. I can add it before merge.

          Show
          githubbot ASF GitHub Bot added a comment - Github user okram commented on a diff in the pull request: https://github.com/apache/tinkerpop/pull/472#discussion_r85862272 — Diff: gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/ChooseStepTest.java — @@ -38,7 +42,10 @@ return Arrays.asList( __.choose(values("name")).option("marko", out()).option(none, in()), __.choose(values("name")).option("marko", in()).option(none, out()), __.choose(values("name")).option("josh", out()).option(none, in()) + __.choose(values("name")).option("josh", out()).option(none, in()), + __.choose(out("knows").is(P.gt(0)), out("knows"), out("knows")), + __.choose(out("knows").is(P.gt(0)), out("knows"), out("created")), + __.choose(out("knows").is(P.gt(0)), out("knows")) End diff – Yea, I meant `count()`. I can add it before merge.
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user dkuppitz commented on the issue:

          https://github.com/apache/tinkerpop/pull/472

          VOTE: +1

          Show
          githubbot ASF GitHub Bot added a comment - Github user dkuppitz commented on the issue: https://github.com/apache/tinkerpop/pull/472 VOTE: +1
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user PommeVerte commented on the issue:

          https://github.com/apache/tinkerpop/pull/472

          VOTE +1

          Show
          githubbot ASF GitHub Bot added a comment - Github user PommeVerte commented on the issue: https://github.com/apache/tinkerpop/pull/472 VOTE +1
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user asfgit closed the pull request at:

          https://github.com/apache/tinkerpop/pull/472

          Show
          githubbot ASF GitHub Bot added a comment - Github user asfgit closed the pull request at: https://github.com/apache/tinkerpop/pull/472

            People

            • Assignee:
              okram Marko A. Rodriguez
              Reporter:
              okram Marko A. Rodriguez
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development