import "github.com/greenbone/opensight-golang-libraries/pkg/slices"
- func Contains[T comparable](elements []T, value T) bool
- func ContainsLambda[T any](elements []T, filterFunction func(element T) bool) bool
func Contains
func Contains[T comparable](elements []T, value T) bool
Contains is a generic function that checks if a given value exists in a slice of comparable elements. It takes in a slice of elements and a value, and returns true if the value is found in the slice, false otherwise.
Example
names := []string{"Alice", "Bob", "Charlie"}
fmt.Println(Contains(names, "Bob")) // Output: true
func ContainsLambda
func ContainsLambda[T any](elements []T, filterFunction func(element T) bool) bool
ContainsLambda checks if an element in the given slice satisfies the provided filter function. It returns true if at least one element satisfies the filter function, otherwise it returns false.
Example
numbers := []int{1, 2, 3, 4, 5}
isEven := func(n int) bool { return n%2 == 0 }
fmt.Println(ContainsLambda(numbers, isEven)) // Output: true
Generated by gomarkdoc
Copyright (C) 2022-2023 [Greenbone AG][Greenbone AG]
Licensed under the GNU General Public License v3.0 or later.