Skip to content

comparing two boolean values and the unary 'not' #217

@Pippin555

Description

@Pippin555

This is not an issue, but a request for a smarter solution,

I would like to compare two boolean values with an 'is' operator. But that operator is not available for groovysh_evaluate.

    t = (g.V()
         .limit(1)
         .sack(assign)
         .by(constant(true))
         .sack(is)
         .by(constant(false))
         .sack()
         )

When I try to negate a boolean value, there is no operator for that either.

          .sack(assign)
           .by(constant(true))
           .sack(not)
          .sack()

In the end I wrote a solution with a .choose, comparing with constant(true), see below.

Another solution is to convert boolean to int 0 and 1 and then use .math('x - y'), when that gives 0, the booleans are the same.

I can't believe that there is no shorter way to achieve this.

This determines the exclusive-or for the values in as('x') and as('y'):

        .choose(
                or_(
                    and_(
                        select('x').is(true),
                        select('y').is(true)),
                    and_(
                        select('x').is(false),
                        select('y').is(false))),
                constant(false),
                constant(true))

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions