Files
DankMaterialShell/core/internal/utils/slices.go
T
bbedward 396d490979 feat(screenshot+colorpicker): support 10-bit colors via
wp_color_manager_v1

Also fix a bunch of unrelated go vet issues
2026-08-19 14:34:56 -04:00

49 lines
925 B
Go

package utils
import "slices"
func Filter[T any](items []T, predicate func(T) bool) []T {
var result []T
for _, item := range items {
if predicate(item) {
result = append(result, item)
}
}
return result
}
func Find[T any](items []T, predicate func(T) bool) (T, bool) {
for _, item := range items {
if predicate(item) {
return item, true
}
}
var zero T
return zero, false
}
func Map[T, U any](items []T, transform func(T) U) []U {
result := make([]U, len(items))
for i, item := range items {
result[i] = transform(item)
}
return result
}
func Contains[T comparable](items []T, target T) bool {
return slices.Contains(items, target)
}
func Any[T any](items []T, predicate func(T) bool) bool {
return slices.ContainsFunc(items, predicate)
}
func All[T any](items []T, predicate func(T) bool) bool {
for _, item := range items {
if !predicate(item) {
return false
}
}
return true
}