aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlan Donovan <adonovan@google.com>2026-03-11 15:22:55 -0400
committerAlan Donovan <adonovan@google.com>2026-03-12 10:56:55 -0700
commit0dc89195f9aece70476320be3fc9d6d657904056 (patch)
treed72a1c41306f80bc40b44d5474160bf4c92d4e5b /src
parent9e2189ef8e04d2745d18ac870ae54dcdcbc008db (diff)
downloadgo-0dc89195f9aece70476320be3fc9d6d657904056.tar.xz
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>
Diffstat (limited to 'src')
-rw-r--r--src/bytes/bytes.go1
-rw-r--r--src/slices/slices.go1
-rw-r--r--src/strings/strings.go1
3 files changed, 3 insertions, 0 deletions
diff --git a/src/bytes/bytes.go b/src/bytes/bytes.go
index 787ea86f00..98f78f10c3 100644
--- a/src/bytes/bytes.go
+++ b/src/bytes/bytes.go
@@ -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
}
diff --git a/src/slices/slices.go b/src/slices/slices.go
index c68962a9f6..138b21fc0d 100644
--- a/src/slices/slices.go
+++ b/src/slices/slices.go
@@ -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
}
diff --git a/src/strings/strings.go b/src/strings/strings.go
index 28289a35bf..367e0a8e24 100644
--- a/src/strings/strings.go
+++ b/src/strings/strings.go
@@ -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
}