Standard library / slices
slices.ContainsFunc()
Reports whether any element satisfies the predicate. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func ContainsFunc[S ~[]E, E any](s S, f func(E) bool) boolParameters & Attributes
| Name | Type | Description |
|---|---|---|
| s | S | Input slice; may share its backing array. |
| f | func(E) bool | Predicate callback, true for a matching element. |
Return Value
bool
Reports whether any element satisfies the predicate.
Working Example
Example Snippetgo
package main
import ( "fmt" "slices")
func main() { fmt.Println(slices.ContainsFunc([]int{2, 4, 7}, func(v int) bool { return v%2 != 0 }))}