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 the @discardableResult attribute to OrderedSet.insert(_:at:) #21

Merged
merged 3 commits into from
Apr 14, 2021

Conversation

kielgillard
Copy link
Contributor

@kielgillard kielgillard commented Apr 13, 2021

Fixes #19.

It does not seem appropriate to write a test for this change. However, I am open to other points of view and will gladly own further work.

Checklist

  • I've read the Contribution Guidelines
  • My contributions are licensed under the Swift license.
  • I've followed the coding style of the rest of the project.
  • I've added tests covering all new code paths my change adds to the project (if appropriate).
  • I've added benchmarks covering new functionality (if appropriate).
  • I've verified that my change does not break any existing tests or introduce unexplained benchmark regressions.
  • I've updated the documentation if necessary.

Copy link
Member

@lorentey lorentey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, thank you!

It would be useful to check if there any other APIs in the package that are currently missing this attribute -- if we missed one, we may have missed others.

@lorentey
Copy link
Member

@swift-ci test

@kielgillard
Copy link
Contributor Author

I did wonder if the following functions should have this attribute, too:
updateOrAppend(_ item: Element) -> Element?
updateOrInsert(_ item: Element, at index: Index) -> (originalMember: Element?, index: Index)

@lorentey
Copy link
Member

@kielgillard I think so, if only by analogue to SetAlgebra's update(with:) requirement. Can you add those to this PR? 😊

(I wonder how often these would be used without looking at the return value, but there is nothing wrong with discarding it, either -- and I don't think we want to force people to do the _ = foo.updateOrAppend(...) dance to achieve that.)

@kielgillard
Copy link
Contributor Author

@swift-ci test

@kielgillard
Copy link
Contributor Author

@lorentey done.

My intuition is people will probably be using these "update or" APIs specifically for the return value but, like you said, there's no need for the API to be a jerk about it in case you don't want it!

@lorentey
Copy link
Member

Looks good, thanks! 👍

@swift-ci test

@lorentey lorentey merged commit 0096c5b into apple:main Apr 14, 2021
@lorentey lorentey added this to the 0.0.3 milestone May 28, 2021
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.

OrderedSet.insert should be @discardableResult
2 participants