-
Notifications
You must be signed in to change notification settings - Fork 111
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 component/foreach helpers #81
Conversation
This adds a `Component` helper type and a `ForEach` helper method. The first attempt used an interface but interfaces imply allocation. We really can't afford to allocate here.
Opinionated: Paths should start with /, dammit!
Note: this changes the behavior of paths. Rational:
|
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.
LGTM, useful abstraction.
return []Protocol{c.protocol} | ||
} | ||
|
||
func (c *Component) Decapsulate(o Multiaddr) Multiaddr { |
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.
I guess Decapsulate
doesn't make much sense in the context of a single component, so it becomes equivalent to a Filter operation, i.e. returns itself if there's a match?
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.
Basically. Personally, given the new SplitFunc
, I'm not sure how useful decapsulate is in general.
component.go
Outdated
// ForEach walks over the multiaddr, component by component. | ||
// | ||
// This function iterates over components *by value* to avoid allocating. | ||
func ForEach(m Multiaddr, cb func(c Component) bool) { |
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.
Would it make sense to add a Filter
function that returns the components for a given protocol?
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.
Not sure about filter but I'm adding SplitFirst
, SplitLast
, SplitFunc
, etc. functions.
This adds a
Component
helper type and aForEach
helper method.The first attempt used an interface but interfaces imply allocation. We really
can't afford to allocate here.