-
Notifications
You must be signed in to change notification settings - Fork 226
allow iterating over a fieldpath's ShapeRefs #250
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
Conversation
a-hilaly
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jaypipes!
|
/test s3-controller-test |
vijtrip2
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
pkg/fieldpath/path.go
Outdated
| // At returns the part of the Path at the supplied index, or empty string if | ||
| // index exceeds boundary. | ||
| func (p *Path) At(index int) string { | ||
| if index < 0 || len(p.parts) < 0 || index > len(p.parts)-1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
| if index < 0 || len(p.parts) < 0 || index > len(p.parts)-1 { | |
| if index < 0 || len(p.parts) == 0 || index > len(p.parts)-1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doh. copy/pasta mistake on my part. nice catch! fixed.
pkg/fieldpath/path.go
Outdated
| // e.g. given Path $A containing "X.Y", $A.CopyAt(0) would return a new Path | ||
| // containing just "X". $A.CopyAt(1) would return a new Path containing "X.Y". | ||
| func (p *Path) CopyAt(index int) *Path { | ||
| if index < 0 || len(p.parts) < 0 || index > len(p.parts)-1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think length function will never return less than 0. You can just check for empty i.e." == 0"
| if index < 0 || len(p.parts) < 0 || index > len(p.parts)-1 { | |
| if index < 0 || len(p.parts) == 0 || index > len(p.parts)-1 { |
Adds a few utility methods to `pkg/fieldpath.Path` to make it easier to inspect associated ShapeRefs at different parts of the path: * `Path.At(int)` returns the path part at the supplied index. * `Path.CopyAt(int)` returns a new Path up to the supplied index. * `Path.ShapeRefAt(*shapeRef, int)` returns a ShapeRef corresponding to the path part at the supplied index. * `Path.IterShapeRefs(*shapeRef)` returns a slice of *ShapeRef that can be used to iterate over the ShapeRefs associated with each of the Path's parts. Signed-off-by: Jay Pipes <jaypipes@gmail.com>
90f8a04 to
928bd84
Compare
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: A-Hilaly, jaypipes, vijtrip2 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Adds a few utility methods to
pkg/fieldpath.Pathto make it easier toinspect associated ShapeRefs at different parts of the path:
Path.At(int)returns the path part at the supplied index.Path.CopyAt(int)returns a new Path up to the supplied index.Path.ShapeRefAt(*shapeRef, int)returns a ShapeRef corresponding tothe path part at the supplied index.
Path.IterShapeRefs(*shapeRef)returns a slice of *ShapeRef that canbe used to iterate over the ShapeRefs associated with each of the
Path's parts.
Signed-off-by: Jay Pipes jaypipes@gmail.com
By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license.