Skip to content

Latest commit

 

History

History
61 lines (38 loc) · 1.81 KB

File metadata and controls

61 lines (38 loc) · 1.81 KB

Greenbone Logo

slices

import "github.com/greenbone/opensight-golang-libraries/pkg/slices"

Index

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[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

License

Copyright (C) 2022-2023 [Greenbone AG][Greenbone AG]

Licensed under the GNU General Public License v3.0 or later.