Sequential edge creation between streamed vertices
I would like to create an edge between vertices as they are streamed in sequence from a traversal. I want to connect each vertex to the next one in the stream, like a linear chain of vertices with a
next
next
edge.
For example, given this
g.V().hasLabel("person").values("name")
g.V().hasLabel("person").values("name")
produces:
==> josh==> peter==> marko==> vadas
==> josh==> peter==> marko==> vadas
I'd like to achieve something like
josh -next-> peter -next-> marko -next-> vadas
josh -next-> peter -next-> marko -next-> vadas
My current approach is to create a "sliding window" of vertex pairs:
This works, but I’m not sure if this is the idiomatic way to do this. I think modeling data where vertices are explicitly ordered through an edge connection is not uncommon, right?
Solution
i think that's about as good as most approaches. we're missing a step that coudl simplify this code though. i've long wanted a
partition()
partition()
step so that you could change all that code to just: