mirror of
https://github.com/moby/moby.git
synced 2026-07-12 10:35:14 +00:00
commit a0807e7cfe configured golangci-lint
to use go1.23 semantics, which alowed linters like `copyloopvar` to lint
using thee correct semantics.
go1.22 now creates a copy of variables when assigned in a loop; make sure we
don't have files that may downgrade semantics to go1.21 in case that also means
disabling that feature; https://go.dev/ref/spec#Go_1.22
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
35 lines
729 B
Go
35 lines
729 B
Go
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
|
|
//go:build go1.22
|
|
|
|
package sliceutil
|
|
|
|
func Dedup[T comparable](slice []T) []T {
|
|
keys := make(map[T]struct{})
|
|
out := make([]T, 0, len(slice))
|
|
for _, s := range slice {
|
|
if _, ok := keys[s]; !ok {
|
|
out = append(out, s)
|
|
keys[s] = struct{}{}
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
func Map[S ~[]In, In, Out any](s S, fn func(In) Out) []Out {
|
|
res := make([]Out, len(s))
|
|
for i, v := range s {
|
|
res[i] = fn(v)
|
|
}
|
|
return res
|
|
}
|
|
|
|
func Mapper[In, Out any](fn func(In) Out) func([]In) []Out {
|
|
return func(s []In) []Out {
|
|
res := make([]Out, len(s))
|
|
for i, v := range s {
|
|
res[i] = fn(v)
|
|
}
|
|
return res
|
|
}
|
|
}
|