Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an example that shows how to use constants with paths #251

Open
krlawrence opened this issue Dec 21, 2022 · 0 comments
Open

Add an example that shows how to use constants with paths #251

krlawrence opened this issue Dec 21, 2022 · 0 comments

Comments

@krlawrence
Copy link
Owner

In the book, many examples feature the sack step to produce a total distance. In some cases, if all you want is the total, the path step is enough. A by modulator can be used to inject a constant value of zero for path elements that do not have a 'dist' property.

gremlin> g.V(44).repeat(outE().inV().simplePath()).times(2).path().by('code').by('dist').limit(3)
==>[SAF,549,DFW,1197,YYZ]
==>[SAF,549,DFW,1751,YVR]
==>[SAF,549,DFW,4736,LHR]

gremlin> g.V(44).repeat(outE().inV().simplePath()).times(2).path().by(constant(0)).by('dist').limit(3)
==>[0,549,0,1197,0]
==>[0,549,0,1751,0]
==>[0,549,0,4736,0]

gremlin> g.V(44).repeat(outE().inV().simplePath()).times(2).path().by(constant(0)).by('dist').limit(3).sum(lo
cal)
==>1746
==>2300
==>5285      
@krlawrence krlawrence self-assigned this Dec 21, 2022
@krlawrence krlawrence added this to New issues in Planning via automation Dec 21, 2022
@krlawrence krlawrence moved this from New issues to Medium Priority in Planning Dec 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Planning
  
Medium Priority
Development

No branches or pull requests

1 participant