gremlin> g.V().hasLabel("Category").
......1> inE("belongsTo").as('a').outV().
......2> path().
......3> from('a').
......4> by(coalesce(values('lockedPosition'),constant(0))).
......5> by('name').
......6> fold().
......7> index().
......8> unfold().
......9> order().
.....10> by(choose(limit(local,1).limit(local,1).is(neq(0)),limit(local,1).limit(local,1),tail(local))).
.....11> by(limit(local,1),desc).
.....12> fold().
.....13> union(range(local,1,-1).unfold(),limit(local,1)).fold().unfold()
==>[[0,Product6],1]
==>[[0,Product1],2]
==>[[3,Product10],9]
==>[[0,Product7],3]
==>[[0,Product2],4]
==>[[0,Product8],5]
==>[[0,Product3],6]
==>[[7,Product9],7]
==>[[0,Product4],8]
==>[[0,Product5],0]
gremlin> g.V().hasLabel("Category").
......1> inE("belongsTo").as('a').outV().
......2> path().
......3> from('a').
......4> by(coalesce(values('lockedPosition'),constant(0))).
......5> by('name').
......6> fold().
......7> index().
......8> unfold().
......9> order().
.....10> by(choose(limit(local,1).limit(local,1).is(neq(0)),limit(local,1).limit(local,1),tail(local))).
.....11> by(limit(local,1),desc).
.....12> fold().
.....13> union(range(local,1,-1).unfold(),limit(local,1)).fold().unfold()
==>[[0,Product6],1]
==>[[0,Product1],2]
==>[[3,Product10],9]
==>[[0,Product7],3]
==>[[0,Product2],4]
==>[[0,Product8],5]
==>[[0,Product3],6]
==>[[7,Product9],7]
==>[[0,Product4],8]
==>[[0,Product5],0]