1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-24 07:49:41 +02:00

fix(code): remove code that is no longer necessary EE-6078 (#10256)

This commit is contained in:
andres-portainer 2023-09-05 22:35:16 -03:00 committed by GitHub
parent c748385879
commit 4a39122415
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 33 additions and 224 deletions

View file

@ -1,69 +1,5 @@
package slices
// Contains is a generic function that returns true if the element is contained within the slice
func Contains[T comparable](elems []T, v T) bool {
return ContainsFunc(elems, func(s T) bool {
return s == v
})
}
// Contains is a generic function that returns true if the element is contained within the slice
func ContainsFunc[T any](elems []T, f func(T) bool) bool {
for _, s := range elems {
if f(s) {
return true
}
}
return false
}
func Find[T any](elems []T, f func(T) bool) (T, bool) {
for _, s := range elems {
if f(s) {
return s, true
}
}
// return default value
var result T
return result, false
}
// IndexFunc returns the first index i satisfying f(s[i]),
// or -1 if none do.
func IndexFunc[E any](s []E, f func(E) bool) int {
for i, v := range s {
if f(v) {
return i
}
}
return -1
}
// RemoveItem removes the first element from the slice that satisfies the given predicate
func RemoveItem[E comparable](s []E, predicate func(E) bool) []E {
index := IndexFunc(s, predicate)
if index == -1 {
return s
}
return RemoveIndex(s, index)
}
// RemoveIndex removes the element at the given index from the slice
func RemoveIndex[T any](s []T, index int) []T {
if len(s) == 0 {
return s
}
if index < 0 || index >= len(s) {
return s
}
s[index] = s[len(s)-1]
return s[:len(s)-1]
}
// Map applies the given function to each element of the slice and returns a new slice with the results
func Map[T, U any](s []T, f func(T) U) []U {
result := make([]U, len(s))