krlawrence / graph

Practical Gremlin - An Apache TinkerPop Tutorial
Apache License 2.0
830 stars 251 forks source link

Add an example that shows how to select all but the last item in a collection/stream #216

Open krlawrence opened 3 years ago

krlawrence commented 3 years ago

There is no list separator type syntax in Gremlin. This is one way to achieve the [0:-2] type pattern.

gremlin> g.V(1,2,3,4).fold().sideEffect(tail(local).store('t')).unfold().where(neq('t')).by().by(unfold())
==>v[1]
==>v[2]
==>v[3]  

Also add an example that shows how to pick the penultimate value is a stream such as

gremlin> g.V(1,2,3,4).tail(2).limit(1)
==>v[3]