bytes,slices,strings: ContainsFunc: document short-circuit semantics

I assume this was the intent but was not documented as an oversight.

Change-Id: I2d62b8b28ed7bca0d935788a39579b13d6503624
Reviewed-on: https://go-review.googlesource.com/c/go/+/754242
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Austin Clements <austin@google.com>
This commit is contained in:
Alan Donovan
2026-03-11 15:22:55 -04:00
parent 9e2189ef8e
commit 0dc89195f9
3 changed files with 3 additions and 0 deletions

View File

@@ -89,6 +89,7 @@ func ContainsRune(b []byte, r rune) bool {
}
// ContainsFunc reports whether any of the UTF-8-encoded code points r within b satisfy f(r).
// It stops as soon as a call to f returns true.
func ContainsFunc(b []byte, f func(rune) bool) bool {
return IndexFunc(b, f) >= 0
}

View File

@@ -120,6 +120,7 @@ func Contains[S ~[]E, E comparable](s S, v E) bool {
// ContainsFunc reports whether at least one
// element e of s satisfies f(e).
// It stops as soon as a call to f returns true.
func ContainsFunc[S ~[]E, E any](s S, f func(E) bool) bool {
return IndexFunc(s, f) >= 0
}

View File

@@ -74,6 +74,7 @@ func ContainsRune(s string, r rune) bool {
}
// ContainsFunc reports whether any Unicode code points r within s satisfy f(r).
// It stops as soon as a call to f returns true.
func ContainsFunc(s string, f func(rune) bool) bool {
return IndexFunc(s, f) >= 0
}