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

iterutil: More ergonomic interface #83737

Merged
merged 1 commit into from
Jul 5, 2022

Conversation

andrewbaptist
Copy link
Collaborator

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

@andrewbaptist andrewbaptist requested a review from a team July 2, 2022 01:29
@andrewbaptist andrewbaptist requested review from a team as code owners July 2, 2022 01:29
@andrewbaptist andrewbaptist requested review from a team and gh-casper and removed request for a team July 2, 2022 01:29
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Contributor

@postamar postamar left a 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 {
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

Copy link
Contributor

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
@andrewbaptist
Copy link
Collaborator Author

bors r=postamar

@craig
Copy link
Contributor

craig bot commented Jul 5, 2022

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Jul 5, 2022

Build succeeded:

@craig craig bot merged commit cff9d8b into cockroachdb:master Jul 5, 2022
@andrewbaptist andrewbaptist deleted the ergonomic_iterutil branch December 15, 2023 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants