mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
internal/sliceutil: add Deref utility
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user