-
Notifications
You must be signed in to change notification settings - Fork 5
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 set.Find method #18
Conversation
Thank you for this contribution! I have a few suggestions. First, the names: Second, you might consider a slightly different API. It's useful to know whether "any" or "all" members pass a given test, but it's more useful to know which one caused the test to pass or fail. Here's an API that can do that: // First traverses s in an indeterminate order and returns the first element that makes the given function true.
// The boolean result is true if such an element is found, false otherwise.
func (s Of[T]) First(f func(T) bool) (T, bool) Now Third suggestion: don't put this in The fourth suggestion is to wait a few more weeks for Go 1.23 to arrive. As you may know, it will include a major new feature, "range over function," that will make this module's |
Oh, I just remembered: please see also #2 (comment) |
Thanks Bob. The However, I don't think the conversion of |
I revised the PR. It implements |
Pull Request Test Coverage Report for Build 10237222541Details
💛 - Coveralls |
You have a point. Sorry to be unclear with my fourth suggestion, which I intended to pre-empt the third suggestion: put However, since that will require a new major version of this module, I have no objection to adding your change to the current version. Kindly merge the latest |
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, thank you!
Ah, the auth token used by CI doesn't have the permission it needs to add a comment to this PR (apparently because the change comes from a fork of this repo). I'll merge this change anyway and fix that later. Thank you again. |
These two methods are frequently present in other collection APIs (Scala and Kotlin for example).
The existing
Has
method is in one sense a special case, where the predicate function is an equality test.Exists
andForall
allow any comparator function, not just a simple equality test.Although
Exists
andForall
are logically similar, both are needed for completeness because they are not direct inverses of each other.If you like this PR, I can do a similar one for
slices
.