-
Notifications
You must be signed in to change notification settings - Fork 17.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
bytes, strings: add ContainsFunc #54386
Comments
Cf #53983 |
This was waiting on slices.ContainsFunc. Now that we've accepted that proposal, it seems fine to also have bytes.ContainsFunc and strings.ContainsFunc. |
Based on the discussion above, this proposal seems like a likely accept. |
No change in consensus, so accepted. 🎉 |
Change https://go.dev/cl/460216 mentions this issue: |
I propose to add
ContainsFunc
to packagestrings
andbytes
.The
{bytes,strings}.ContainsFunc
functions replace codes which only check whether the string contains a Unicode code point satisfying the condition or not using{bytes,strings}.IndexFunc
.In the Go repository, there are 6 codes (out of 9 using
$PKG.IndexFunc(...)
) to be replaced by the proposedContainsFunc
functions.In the Kubernetes repository, I find 2 codes (out of 3 using
$PKG.IndexFunc(...)
).Using
ContainsFunc
in these if statements will definitely improve the code readability. Also, I believe API symmetry reduces the frustration of coding (I cannot explain why there areContains
,ContainsAny
,ContainsRune
but notContainsFunc
to Go newbies). Currently, we need to translate what we actually want to check into comparison of returned index against numbers (which may lead to pointless discussion of which is better>= 0
or!= -1
).The text was updated successfully, but these errors were encountered: