fold initial value derived from the graph

34 views
Skip to first unread message

Bailey Glen

unread,
Oct 13, 2017, 12:56:54 PM10/13/17
to Gremlin-users
How do you provide an initial value to fold that is derived from the traversal. For instance
g.V().values('pval').flatmap(
  _as('cur_val')
  .union(flatMap( <generate some value>
  )).fold(select('cur_val'), sum))



Daniel Kuppitz

unread,
Oct 13, 2017, 3:36:28 PM10/13/17
to gremli...@googlegroups.com
Why not simplify your query and just use sum()? E.g. instead of

g.V(1).as("a").out("knows").values("age").fold(select("a").by("age"), sum)

...you could do:

gremlin> g.V(1).as("a").union(identity(), out("knows")).values("age").sum()
==>88

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-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/9baee25d-f29c-4c51-9aea-7ac69c585a98%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bailey Glen

unread,
Nov 6, 2017, 11:26:27 AM11/6/17
to Gremlin-users
I used sum as a simplified example, I'm actually attempting to apply a lambda function to perform some calculations.
Is it possible to have the initial fold value derived from the graph?


On Friday, October 13, 2017 at 3:36:28 PM UTC-4, Daniel Kuppitz wrote:
Why not simplify your query and just use sum()? E.g. instead of

g.V(1).as("a").out("knows").values("age").fold(select("a").by("age"), sum)

...you could do:

gremlin> g.V(1).as("a").union(identity(), out("knows")).values("age").sum()
==>88

Cheers,
Daniel

On Fri, Oct 13, 2017 at 9:56 AM, Bailey Glen <baile...@gmail.com> wrote:
How do you provide an initial value to fold that is derived from the traversal. For instance
g.V().values('pval').flatmap(
  _as('cur_val')
  .union(flatMap( <generate some value>
  )).fold(select('cur_val'), sum))



--
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.

Daniel Kuppitz

unread,
Nov 6, 2017, 2:10:54 PM11/6/17
to gremli...@googlegroups.com
Is it possible to have the initial fold value derived from the graph?

No, fold() can only have a constant / static initial value, but you can always use a map() lambda step and do whatever you want with all the information available on the current traverser.

Cheers,
Daniel


To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/5ecc7fa5-ccc3-464e-a17c-efa94095d61e%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages