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) bool

Parameters & Attributes

NameTypeDescription
sSInput slice; may share its backing array.
ffunc(E) boolPredicate 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 }))}
Go Reference