ifThenElse and return values

23 views
Skip to first unread message

Mike Oxford

unread,
Feb 23, 2015, 6:40:59 PM2/23/15
to gremli...@googlegroups.com
If the pipe finds something, return it.  Otherwise create it.

v1 = g.V.has('p1','abc').has('p2','xyz').ifThenElse{ _().hasNext() } {42} {<removed>}
==>42

Working as expected.

v1 = g.V.has('p1','abc').has('p2','xyz').ifThenElse{ _().hasNext() } {_()} {<removed>}
==>Script72@7cae269e

Not working as expected.

v1 = g.V.has('p1','abc').has('p2','xyz').ifThenElse{ _().hasNext() } {_().next()} {<removed>}
==>Script74@59640688

Not working as expected.


I cannot use .cap ("java.lang.ClassCastException: com.tinkerpop.pipes.branch.IfThenElsePipe cannot be cast to com.tinkerpop.pipes.sideeffect.SideEffectPipe") 
I tried wrapping the whole thing in a closure but that just gave "No such property: cap for class: Script79"

Why does the first one return the value but subsequent ones return what looks to be a reference to the closure itself?  Shouldn't it run the closure and return the result?

How do you get return values out of an ifThenElse pipe?

Thanks!



Daniel Kuppitz

unread,
Feb 24, 2015, 9:01:37 AM2/24/15
to gremli...@googlegroups.com
Hi Mike,

ifThenElse uses lambdas, hence you shouldn't use the identity pipe. Instead the true and false branches should start with it.

However, it.hasNext() is pointless, as it's always true; otherwise the ifThenElse step wouldn't be evaluated.

Cheers,
Daniel


--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/e4e14e81-7952-4b20-9665-9fe1e0c2b256%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages