-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
iterutil: More ergonomic interface #83737
Conversation
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. Much nicer! Thanks for this.
// Done tells if the error is ErrStopIteration, i.e., should the iteration stop. | ||
func Done(err error) bool { return errors.Is(err, errStopIteration) } | ||
// Map the nil if it is StopIteration, or keep the error otherwise | ||
func Map(err error) error { |
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.
If we want iterutil to be more monadic shouldn't this be a Filter
instead of a Map
?
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 spent a little time thinking about how to do this, and couldn't come up with a great solution. If anything the original Done
was much closer to Filter
. The problem with it in this case, is trying to both exit a loop early as well as return either success or fail.
Let me know if you think I should look at a different alternative or just merge this one in.
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.
Your change is a strict improvement over what there was so I feel very good about it 👍
Replace the Done call in iterutil with Map. This removes a lot of duplicate code and simplifies the way it is used. There are no functional changes as a result of this. Release note: None
e3c3c87
to
075da4b
Compare
bors r=postamar |
Build failed (retrying...): |
Build succeeded: |
Replace the Done call in iterutil with Map. This removes a lot of
duplicate code and simplifies the way it is used. There are no
functional changes as a result of this.
Release note: None