mirror of
https://github.com/golang/go.git
synced 2026-04-02 01:10:27 +09:00
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:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user