internal/sliceutil: add Deref utility

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-11-06 11:33:08 +01:00
parent 6881ae72c7
commit ff019cd853

View File

@@ -1,5 +1,18 @@
package sliceutil
func Deref[T any](slice []*T) []T {
if slice == nil {
return nil
}
out := make([]T, 0, len(slice))
for _, p := range slice {
if p != nil {
out = append(out, *p)
}
}
return out
}
func Dedup[T comparable](slice []T) []T {
keys := make(map[T]struct{})
out := make([]T, 0, len(slice))